1.1 --- a/imiptools/__init__.py Tue Oct 28 00:09:46 2014 +0100
1.2 +++ b/imiptools/__init__.py Tue Oct 28 16:55:26 2014 +0100
1.3 @@ -1,21 +1,10 @@
1.4 #!/usr/bin/env python
1.5
1.6 from email import message_from_file
1.7 -from email.mime.message import MIMEMessage
1.8 -from email.mime.multipart import MIMEMultipart
1.9 -from email.mime.text import MIMEText
1.10 -from smtplib import LMTP, SMTP
1.11 from imiptools.content import handle_itip_part
1.12 +from imiptools.mail import Messenger
1.13 import sys
1.14
1.15 -MESSAGE_SENDER = "resources+agent@example.com"
1.16 -
1.17 -MESSAGE_SUBJECT = "Calendar system message"
1.18 -
1.19 -MESSAGE_TEXT = """\
1.20 -This is a response to a calendar message sent by your calendar program.
1.21 -"""
1.22 -
1.23 # Postfix exit codes.
1.24
1.25 EX_TEMPFAIL = 75
1.26 @@ -35,61 +24,6 @@
1.27 l += [s.strip() for s in v.split(",")]
1.28 return l
1.29
1.30 -class Messenger:
1.31 -
1.32 - "Sending of outgoing messages."
1.33 -
1.34 - def __init__(self, sender=None, subject=None, body_text=None):
1.35 - self.sender = sender or MESSAGE_SENDER
1.36 - self.subject = subject or MESSAGE_SUBJECT
1.37 - self.body_text = body_text or MESSAGE_TEXT
1.38 -
1.39 - def sendmail(self, recipients, data, lmtp_socket=None):
1.40 -
1.41 - """
1.42 - Send a mail to the given 'recipients' consisting of the given 'data',
1.43 - delivering to a local mail system using LMTP if 'lmtp_socket' is
1.44 - provided.
1.45 - """
1.46 -
1.47 - if lmtp_socket:
1.48 - smtp = LMTP(lmtp_socket)
1.49 - else:
1.50 - smtp = SMTP("localhost")
1.51 -
1.52 - smtp.sendmail(self.sender, recipients, data)
1.53 - smtp.quit()
1.54 -
1.55 - def make_message(self, parts, recipients):
1.56 -
1.57 - "Make a message from the given 'parts' for the given 'recipients'."
1.58 -
1.59 - message = MIMEMultipart("mixed", _subparts=parts)
1.60 - message.preamble = self.body_text
1.61 - payload = message.get_payload()
1.62 - payload.insert(0, MIMEText(self.body_text))
1.63 -
1.64 - message["From"] = self.sender
1.65 - for recipient in recipients:
1.66 - message["To"] = recipient
1.67 - message["Subject"] = self.subject
1.68 -
1.69 - return message
1.70 -
1.71 - def wrap_message(self, msg, parts):
1.72 -
1.73 - "Wrap 'msg' and provide the given 'parts' as the primary content."
1.74 -
1.75 - message = MIMEMultipart("mixed", _subparts=parts)
1.76 - message.preamble = self.body_text
1.77 - message.get_payload().append(MIMEMessage(msg))
1.78 -
1.79 - message["From"] = msg["From"]
1.80 - message["To"] = msg["To"]
1.81 - message["Subject"] = msg["Subject"]
1.82 -
1.83 - return message
1.84 -
1.85 class Processor:
1.86
1.87 "The processing framework."