1.1 --- a/imiptools/mail.py Wed Nov 04 23:35:16 2015 +0100
1.2 +++ b/imiptools/mail.py Thu Nov 05 00:58:02 2015 +0100
1.3 @@ -25,22 +25,22 @@
1.4 from email.mime.text import MIMEText
1.5 from smtplib import LMTP, SMTP
1.6
1.7 -MESSAGE_SUBJECT = "Calendar system message"
1.8 +# Fake gettext function for strings to be translated later.
1.9 +
1.10 +_ = lambda s: s
1.11
1.12 -MESSAGE_TEXT = """\
1.13 -This is a message from the calendar system.
1.14 -"""
1.15 +MESSAGE_SUBJECT = _("Calendar system message")
1.16
1.17 -PREAMBLE_TEXT = """\
1.18 +PREAMBLE_TEXT = _("""\
1.19 This message contains several different parts, one of which will contain
1.20 calendar information that will only be understood by a suitable program.
1.21 -"""
1.22 +""")
1.23
1.24 class Messenger:
1.25
1.26 "Sending of outgoing messages."
1.27
1.28 - def __init__(self, lmtp_socket=None, local_smtp=False, sender=None, subject=None, body_text=None, preamble_text=None):
1.29 + def __init__(self, lmtp_socket=None, local_smtp=False, sender=None, subject=None, preamble_text=None):
1.30
1.31 """
1.32 Deliver to a local mail system using LMTP if 'lmtp_socket' is provided
1.33 @@ -50,9 +50,13 @@
1.34 self.lmtp_socket = lmtp_socket
1.35 self.local_smtp = local_smtp
1.36 self.sender = sender or MESSAGE_SENDER
1.37 - self.subject = subject or MESSAGE_SUBJECT
1.38 - self.body_text = body_text or MESSAGE_TEXT
1.39 - self.preamble_text = preamble_text or PREAMBLE_TEXT
1.40 + self.subject = subject
1.41 + self.preamble_text = preamble_text
1.42 +
1.43 + # The translation method is set by the client once locale information is
1.44 + # known.
1.45 +
1.46 + self.gettext = None
1.47
1.48 def local_delivery(self):
1.49
1.50 @@ -115,7 +119,8 @@
1.51 message["To"] = recipient
1.52 if outgoing_bcc:
1.53 message["Bcc"] = "%s+%s" % (OUTGOING_PREFIX, outgoing_bcc)
1.54 - message["Subject"] = self.subject
1.55 + message["Subject"] = self.subject or \
1.56 + self.gettext and self.gettext(MESSAGE_SUBJECT) or MESSAGE_SUBJECT
1.57
1.58 return message
1.59
1.60 @@ -153,7 +158,8 @@
1.61 "Return a container for the given 'parts'."
1.62
1.63 message = MIMEMultipart("mixed", _subparts=parts)
1.64 - message.preamble = self.preamble_text
1.65 + message.preamble = self.preamble_text or \
1.66 + self.gettext and self.gettext(PREAMBLE_TEXT) or PREAMBLE_TEXT
1.67 return message
1.68
1.69 def _copy_headers(self, message, msg):