1.1 --- a/imiptools/__init__.py Mon Feb 02 00:12:53 2015 +0100
1.2 +++ b/imiptools/__init__.py Mon Feb 02 00:15:36 2015 +0100
1.3 @@ -21,9 +21,11 @@
1.4
1.5 from email import message_from_file
1.6 from imiptools.content import handle_itip_part
1.7 -from imiptools.data import get_addresses, get_uri
1.8 +from imiptools.data import get_addresses, get_uri, make_freebusy, to_part
1.9 +from imiptools.dates import get_timestamp
1.10 from imiptools.mail import Messenger
1.11 from imiptools.profile import Preferences
1.12 +import imip_store
1.13 import sys
1.14
1.15 # Postfix exit codes.
1.16 @@ -114,7 +116,16 @@
1.17 # Reply using any outgoing parts in a new message.
1.18
1.19 if outgoing_parts:
1.20 +
1.21 + # Obtain free/busy details, if configured to do so.
1.22 +
1.23 + fb = self.get_freebusy_for_recipient(recipient)
1.24 +
1.25 for outgoing_recipient, parts in outgoing_parts.items():
1.26 +
1.27 + # Bundle free/busy messages, if configured to do so.
1.28 +
1.29 + if fb: parts.append(fb)
1.30 message = self.messenger.make_outgoing_message(parts, [outgoing_recipient])
1.31
1.32 if "-d" in sys.argv:
1.33 @@ -163,6 +174,27 @@
1.34 elif self.lmtp_socket:
1.35 self.messenger.sendmail(recipient, msg.as_string(), lmtp_socket=self.lmtp_socket)
1.36
1.37 + def get_freebusy_for_recipient(self, recipient):
1.38 +
1.39 + """
1.40 + Return a list of responses containing free/busy information for the
1.41 + given 'recipient'.
1.42 + """
1.43 +
1.44 + organiser = get_uri(recipient)
1.45 + preferences = Preferences(organiser)
1.46 +
1.47 + if preferences.get("freebusy_sharing") == "share" and \
1.48 + preferences.get("freebusy_bundling") == "always":
1.49 +
1.50 + # Invent a unique identifier.
1.51 +
1.52 + utcnow = get_timestamp()
1.53 + uid = "imip-agent-%s-%s" % (utcnow, recipient)
1.54 +
1.55 + freebusy = imip_store.FileStore().get_freebusy(organiser)
1.56 + return to_part("PUBLISH", [make_freebusy(freebusy, uid, organiser)])
1.57 +
1.58 def process_args(self, args, stream):
1.59
1.60 """