# HG changeset patch # User Paul Boddie # Date 1422832536 -3600 # Node ID 841c99fe689bb847f9846d5fec4f072872c18303 # Parent a24c32fa9ae1c6a3d66096a3e28074d78e5b0af2 Introduced simplistic free/busy bundling at the top level of processing. This is not particularly usable because free/busy objects will be published regardless of whether any other parts are already providing free/busy replies. However, the approach at least avoids the potential generation of duplicate parts for individual recipients. diff -r a24c32fa9ae1 -r 841c99fe689b imiptools/__init__.py --- a/imiptools/__init__.py Mon Feb 02 00:12:53 2015 +0100 +++ b/imiptools/__init__.py Mon Feb 02 00:15:36 2015 +0100 @@ -21,9 +21,11 @@ from email import message_from_file from imiptools.content import handle_itip_part -from imiptools.data import get_addresses, get_uri +from imiptools.data import get_addresses, get_uri, make_freebusy, to_part +from imiptools.dates import get_timestamp from imiptools.mail import Messenger from imiptools.profile import Preferences +import imip_store import sys # Postfix exit codes. @@ -114,7 +116,16 @@ # Reply using any outgoing parts in a new message. if outgoing_parts: + + # Obtain free/busy details, if configured to do so. + + fb = self.get_freebusy_for_recipient(recipient) + for outgoing_recipient, parts in outgoing_parts.items(): + + # Bundle free/busy messages, if configured to do so. + + if fb: parts.append(fb) message = self.messenger.make_outgoing_message(parts, [outgoing_recipient]) if "-d" in sys.argv: @@ -163,6 +174,27 @@ elif self.lmtp_socket: self.messenger.sendmail(recipient, msg.as_string(), lmtp_socket=self.lmtp_socket) + def get_freebusy_for_recipient(self, recipient): + + """ + Return a list of responses containing free/busy information for the + given 'recipient'. + """ + + organiser = get_uri(recipient) + preferences = Preferences(organiser) + + if preferences.get("freebusy_sharing") == "share" and \ + preferences.get("freebusy_bundling") == "always": + + # Invent a unique identifier. + + utcnow = get_timestamp() + uid = "imip-agent-%s-%s" % (utcnow, recipient) + + freebusy = imip_store.FileStore().get_freebusy(organiser) + return to_part("PUBLISH", [make_freebusy(freebusy, uid, organiser)]) + def process_args(self, args, stream): """