Browse Source

Do proper email encoding.

tags/0.6.0
ShyPike 15 years ago
parent
commit
67342869ce
  1. 3
      language/email-fr-fr.tmpl
  2. 29
      sabnzbd/emailer.py
  3. 6
      sabnzbd/interface.py

3
language/email-fr-fr.tmpl

@ -1,3 +1,4 @@
#encoding UTF-8
##
## Template Email pour SABnzbd
## Ceci est un template Cheetah
@ -9,7 +10,7 @@
to: $to
from: $from
date: $date
subject: SABnzbd <!--#if $status then "Succès" else "Echec" #--> du téléchargement $name
subject: SABnzbd <!--#if $status#-->Succès<!--#else#-->Echec<!--#end if#--> du téléchargement $name
X-priority: 5
X-MS-priority: 5
## Le contenu du message, la ligne vide est obligatoire !

29
sabnzbd/emailer.py

@ -98,11 +98,9 @@ def send(message):
logging.error(Ta('error-mailAuth'))
return failure
message = _prepare_message(message)
try:
if isinstance(message, unicode):
message = message.encode('utf8')
for recipient in cfg.email_to():
mailconn.sendmail(cfg.EMAIL_FROM.get(), recipient, message)
mailconn.sendmail(cfg.email_from(), cfg.email_to(), message)
except:
logging.error(Ta('error-mailSend'))
return failure
@ -222,3 +220,26 @@ def _decode_file(path):
fp.close()
return source.decode(encoding)
################################################################################
from email.message import Message
RE_HEADER = re.compile(r'^([^:]+):(.*)')
def _prepare_message(txt):
""" Do the proper message encodings
"""
msg = Message()
msg.set_charset('UTF-8')
payload = []
body = False
for line in txt.encode('utf-8').split('\n'):
if not line:
body = True
if body:
payload.append(line)
else:
m = RE_HEADER.search(line)
if m:
msg.add_header(m.group(1).strip(), m.group(2).strip())
msg.set_payload('\n'.join(payload), 'UTF-8')
return msg.as_string()

6
sabnzbd/interface.py

@ -2558,9 +2558,9 @@ class ConnectionInfo:
pack['download'] = ['action 1', 'action 2']
pack['unpack'] = ['action 1', 'action 2']
self.__lastmail= emailer.endjob('Test Job', 123, 'unknown', True,
os.path.normpath(os.path.join(cfg.complete_dir.get_path(), '/unknown/Test Job')),
str(123*MEBI), pack, 'my_script', 'Line 1\nLine 2\nLine 3\n', 0)
self.__lastmail= emailer.endjob('T\xe9st Job', 123, 'unknown', True,
os.path.normpath(os.path.join(cfg.complete_dir.get_path(), '/unknown/T\xe9st Job')),
str(123*MEBI), pack, 'my_script', 'Line 1\nLine 2\nLin\xe9 3\n', 0)
raise dcRaiser(self.__root, kwargs)
@cherrypy.expose

Loading…
Cancel
Save