1.1 --- a/README.txt Thu Aug 20 23:52:18 2015 +0200
1.2 +++ b/README.txt Fri Aug 21 14:47:53 2015 +0200
1.3 @@ -129,7 +129,10 @@
1.4
1.5 In this simpler environment, recipient details must be manually edited in the
1.6 virtual alias map files, but this permits a very transparent way of
1.7 -administering the system.
1.8 +administering the system. To add support for delivery to local mailboxes, the
1.9 +following alternative to virtual_alias_maps is provided as an example:
1.10 +
1.11 + virtual_alias_maps_local Defines recipients and local users
1.12
1.13 Naturally, the above recipient identification configuration examples can be
1.14 disregarded in favour of other ways of defining mail recipients, subject to
2.1 --- a/conf/postfix/master.cf.items Thu Aug 20 23:52:18 2015 +0200
2.2 +++ b/conf/postfix/master.cf.items Fri Aug 21 14:47:53 2015 +0200
2.3 @@ -1,6 +1,7 @@
2.4 imip_resources unix - n n - - pipe
2.5 flags=FR user=imip-agent:lmtp argv=/var/lib/imip-agent/imip_resource.py
2.6 -o ${original_recipient}
2.7 +# Replace "-l $lmtp_socket" with "-L" for local SMTP delivery.
2.8 imip_people unix - n n - - pipe
2.9 flags=FR user=imip-agent:lmtp argv=/var/lib/imip-agent/imip_person.py
2.10 -o ${original_recipient} -l $lmtp_socket
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/conf/postfix/simple/virtual_alias_maps_local Fri Aug 21 14:47:53 2015 +0200
3.3 @@ -0,0 +1,7 @@
3.4 +paul.boddie@example.com people+paul.boddie@example.com
3.5 +vincent.vole@example.com people+vincent.vole@example.com
3.6 +resource-car-porsche911@example.com resources+resource-car-porsche911@example.com
3.7 +resource-room-confroom@example.com resources+resource-room-confroom@example.com
3.8 +resource-room-sauna@example.com resources+resource-room-sauna@example.com
3.9 +local+paul.boddie@example.com paulb
3.10 +local+vincent.vole@example.com vole
4.1 --- a/imiptools/__init__.py Thu Aug 20 23:52:18 2015 +0200
4.2 +++ b/imiptools/__init__.py Fri Aug 21 14:47:53 2015 +0200
4.3 @@ -111,6 +111,7 @@
4.4 store_dir = []
4.5 publishing_dir = []
4.6 preferences_dir = []
4.7 + local_smtp = False
4.8 outgoing_only = False
4.9
4.10 l = []
4.11 @@ -124,7 +125,7 @@
4.12
4.13 # Switch to collecting recipients.
4.14
4.15 - if arg == "-o":
4.16 + elif arg == "-o":
4.17 l = original_recipients
4.18
4.19 # Switch to collecting senders.
4.20 @@ -137,6 +138,11 @@
4.21 elif arg == "-l":
4.22 l = lmtp
4.23
4.24 + # Detect sending to local users via SMTP.
4.25 +
4.26 + elif arg == "-L":
4.27 + local_smtp = True
4.28 +
4.29 # Switch to getting the store directory.
4.30
4.31 elif arg == "-S":
4.32 @@ -159,7 +165,7 @@
4.33 else:
4.34 l.append(arg)
4.35
4.36 - self.messenger = Messenger(lmtp_socket=lmtp and lmtp[0] or None, sender=senders and senders[0] or None)
4.37 + self.messenger = Messenger(lmtp_socket=lmtp and lmtp[0] or None, local_smtp=local_smtp, sender=senders and senders[0] or None)
4.38 self.store_dir = store_dir and store_dir[0] or None
4.39 self.publishing_dir = publishing_dir and publishing_dir[0] or None
4.40 self.preferences_dir = preferences_dir and preferences_dir[0] or None
4.41 @@ -317,7 +323,7 @@
4.42 print >>sys.stderr, "Forwarded parts..."
4.43 print message
4.44 elif self.messenger.local_delivery():
4.45 - self.messenger.sendmail(get_address(self.user), message.as_string())
4.46 + self.messenger.sendmail([get_address(self.user)], message.as_string())
4.47
4.48 # Unhandled messages are delivered as they are.
4.49
4.50 @@ -326,7 +332,7 @@
4.51 print >>sys.stderr, "Unhandled parts..."
4.52 print msg
4.53 elif self.messenger.local_delivery():
4.54 - self.messenger.sendmail(get_address(self.user), msg.as_string())
4.55 + self.messenger.sendmail([get_address(self.user)], msg.as_string())
4.56
4.57 def can_provide_freebusy(self, handlers):
4.58
5.1 --- a/imiptools/mail.py Thu Aug 20 23:52:18 2015 +0200
5.2 +++ b/imiptools/mail.py Fri Aug 21 14:47:53 2015 +0200
5.3 @@ -40,13 +40,15 @@
5.4
5.5 "Sending of outgoing messages."
5.6
5.7 - def __init__(self, lmtp_socket=None, sender=None, subject=None, body_text=None, preamble_text=None):
5.8 + def __init__(self, lmtp_socket=None, local_smtp=False, sender=None, subject=None, body_text=None, preamble_text=None):
5.9
5.10 """
5.11 - Deliver to a local mail system using LMTP if 'lmtp_socket' is provided.
5.12 + Deliver to a local mail system using LMTP if 'lmtp_socket' is provided
5.13 + or if 'local_smtp' is given as a true value.
5.14 """
5.15
5.16 self.lmtp_socket = lmtp_socket
5.17 + self.local_smtp = local_smtp
5.18 self.sender = sender or MESSAGE_SENDER
5.19 self.subject = subject or MESSAGE_SUBJECT
5.20 self.body_text = body_text or MESSAGE_TEXT
5.21 @@ -56,9 +58,9 @@
5.22
5.23 "Return whether local delivery is performed using this messenger."
5.24
5.25 - return self.lmtp_socket is not None
5.26 + return self.lmtp_socket is not None or self.local_smtp
5.27
5.28 - def sendmail(self, recipients, data, sender=None, outgoing_bcc=None, lmtp_socket=None):
5.29 + def sendmail(self, recipients, data, sender=None, outgoing_bcc=None):
5.30
5.31 """
5.32 Send a mail to the given 'recipients' consisting of the given 'data',
5.33 @@ -77,10 +79,27 @@
5.34
5.35 if outgoing_bcc:
5.36 recipients = list(recipients) + ["%s+%s" % (OUTGOING_PREFIX, outgoing_bcc)]
5.37 + elif self.local_smtp:
5.38 + recipients = [self.make_local(recipient) for recipient in recipients]
5.39
5.40 smtp.sendmail(sender or self.sender, recipients, data)
5.41 smtp.quit()
5.42
5.43 + def make_local(self, recipient):
5.44 +
5.45 + """
5.46 + Make the 'recipient' an address for local delivery. For this to function
5.47 + correctly, a virtual alias or equivalent must be defined for addresses
5.48 + of the following form:
5.49 +
5.50 + local+NAME@DOMAIN
5.51 +
5.52 + Such aliases should direct delivery to the local recipient.
5.53 + """
5.54 +
5.55 + parts = recipient.split("+", 1)
5.56 + return "%s+%s" % ("local", parts[-1])
5.57 +
5.58 def make_outgoing_message(self, parts, recipients, sender=None, outgoing_bcc=None):
5.59
5.60 """