1.1 --- a/imip_manager.py Tue Oct 28 00:09:46 2014 +0100
1.2 +++ b/imip_manager.py Tue Oct 28 16:55:26 2014 +0100
1.3 @@ -4,11 +4,11 @@
1.4
1.5 sys.path.append("/var/lib/imip-agent")
1.6
1.7 -from imiptools import Messenger
1.8 from imiptools.content import Handler, \
1.9 format_datetime, get_address, get_datetime, \
1.10 get_item, get_uri, get_utc_datetime, get_values, \
1.11 parse_object, to_part, to_timezone
1.12 +from imiptools.mail import Messenger
1.13 from imiptools.period import have_conflict
1.14 from vCalendar import to_node
1.15 import markup
2.1 --- a/imiptools/__init__.py Tue Oct 28 00:09:46 2014 +0100
2.2 +++ b/imiptools/__init__.py Tue Oct 28 16:55:26 2014 +0100
2.3 @@ -1,21 +1,10 @@
2.4 #!/usr/bin/env python
2.5
2.6 from email import message_from_file
2.7 -from email.mime.message import MIMEMessage
2.8 -from email.mime.multipart import MIMEMultipart
2.9 -from email.mime.text import MIMEText
2.10 -from smtplib import LMTP, SMTP
2.11 from imiptools.content import handle_itip_part
2.12 +from imiptools.mail import Messenger
2.13 import sys
2.14
2.15 -MESSAGE_SENDER = "resources+agent@example.com"
2.16 -
2.17 -MESSAGE_SUBJECT = "Calendar system message"
2.18 -
2.19 -MESSAGE_TEXT = """\
2.20 -This is a response to a calendar message sent by your calendar program.
2.21 -"""
2.22 -
2.23 # Postfix exit codes.
2.24
2.25 EX_TEMPFAIL = 75
2.26 @@ -35,61 +24,6 @@
2.27 l += [s.strip() for s in v.split(",")]
2.28 return l
2.29
2.30 -class Messenger:
2.31 -
2.32 - "Sending of outgoing messages."
2.33 -
2.34 - def __init__(self, sender=None, subject=None, body_text=None):
2.35 - self.sender = sender or MESSAGE_SENDER
2.36 - self.subject = subject or MESSAGE_SUBJECT
2.37 - self.body_text = body_text or MESSAGE_TEXT
2.38 -
2.39 - def sendmail(self, recipients, data, lmtp_socket=None):
2.40 -
2.41 - """
2.42 - Send a mail to the given 'recipients' consisting of the given 'data',
2.43 - delivering to a local mail system using LMTP if 'lmtp_socket' is
2.44 - provided.
2.45 - """
2.46 -
2.47 - if lmtp_socket:
2.48 - smtp = LMTP(lmtp_socket)
2.49 - else:
2.50 - smtp = SMTP("localhost")
2.51 -
2.52 - smtp.sendmail(self.sender, recipients, data)
2.53 - smtp.quit()
2.54 -
2.55 - def make_message(self, parts, recipients):
2.56 -
2.57 - "Make a message from the given 'parts' for the given 'recipients'."
2.58 -
2.59 - message = MIMEMultipart("mixed", _subparts=parts)
2.60 - message.preamble = self.body_text
2.61 - payload = message.get_payload()
2.62 - payload.insert(0, MIMEText(self.body_text))
2.63 -
2.64 - message["From"] = self.sender
2.65 - for recipient in recipients:
2.66 - message["To"] = recipient
2.67 - message["Subject"] = self.subject
2.68 -
2.69 - return message
2.70 -
2.71 - def wrap_message(self, msg, parts):
2.72 -
2.73 - "Wrap 'msg' and provide the given 'parts' as the primary content."
2.74 -
2.75 - message = MIMEMultipart("mixed", _subparts=parts)
2.76 - message.preamble = self.body_text
2.77 - message.get_payload().append(MIMEMessage(msg))
2.78 -
2.79 - message["From"] = msg["From"]
2.80 - message["To"] = msg["To"]
2.81 - message["Subject"] = msg["Subject"]
2.82 -
2.83 - return message
2.84 -
2.85 class Processor:
2.86
2.87 "The processing framework."
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/imiptools/mail.py Tue Oct 28 16:55:26 2014 +0100
3.3 @@ -0,0 +1,71 @@
3.4 +#!/usr/bin/env python
3.5 +
3.6 +from email.mime.message import MIMEMessage
3.7 +from email.mime.multipart import MIMEMultipart
3.8 +from email.mime.text import MIMEText
3.9 +from smtplib import LMTP, SMTP
3.10 +
3.11 +MESSAGE_SENDER = "resources+agent@example.com"
3.12 +
3.13 +MESSAGE_SUBJECT = "Calendar system message"
3.14 +
3.15 +MESSAGE_TEXT = """\
3.16 +This is a response to a calendar message sent by your calendar program.
3.17 +"""
3.18 +
3.19 +class Messenger:
3.20 +
3.21 + "Sending of outgoing messages."
3.22 +
3.23 + def __init__(self, sender=None, subject=None, body_text=None):
3.24 + self.sender = sender or MESSAGE_SENDER
3.25 + self.subject = subject or MESSAGE_SUBJECT
3.26 + self.body_text = body_text or MESSAGE_TEXT
3.27 +
3.28 + def sendmail(self, recipients, data, lmtp_socket=None):
3.29 +
3.30 + """
3.31 + Send a mail to the given 'recipients' consisting of the given 'data',
3.32 + delivering to a local mail system using LMTP if 'lmtp_socket' is
3.33 + provided.
3.34 + """
3.35 +
3.36 + if lmtp_socket:
3.37 + smtp = LMTP(lmtp_socket)
3.38 + else:
3.39 + smtp = SMTP("localhost")
3.40 +
3.41 + smtp.sendmail(self.sender, recipients, data)
3.42 + smtp.quit()
3.43 +
3.44 + def make_message(self, parts, recipients):
3.45 +
3.46 + "Make a message from the given 'parts' for the given 'recipients'."
3.47 +
3.48 + message = MIMEMultipart("mixed", _subparts=parts)
3.49 + message.preamble = self.body_text
3.50 + payload = message.get_payload()
3.51 + payload.insert(0, MIMEText(self.body_text))
3.52 +
3.53 + message["From"] = self.sender
3.54 + for recipient in recipients:
3.55 + message["To"] = recipient
3.56 + message["Subject"] = self.subject
3.57 +
3.58 + return message
3.59 +
3.60 + def wrap_message(self, msg, parts):
3.61 +
3.62 + "Wrap 'msg' and provide the given 'parts' as the primary content."
3.63 +
3.64 + message = MIMEMultipart("mixed", _subparts=parts)
3.65 + message.preamble = self.body_text
3.66 + message.get_payload().append(MIMEMessage(msg))
3.67 +
3.68 + message["From"] = msg["From"]
3.69 + message["To"] = msg["To"]
3.70 + message["Subject"] = msg["Subject"]
3.71 +
3.72 + return message
3.73 +
3.74 +# vim: tabstop=4 expandtab shiftwidth=4