1.1 --- a/imiptools/__init__.py Tue Jan 27 01:29:36 2015 +0100
1.2 +++ b/imiptools/__init__.py Tue Jan 27 18:48:58 2015 +0100
1.3 @@ -66,6 +66,19 @@
1.4
1.5 # Handle messages with iTIP parts.
1.6
1.7 + for recipient in original_recipients:
1.8 + self.process_for_recipient(msg, recipient, senders, outgoing_only)
1.9 +
1.10 + def process_for_recipient(self, msg, recipient, senders, outgoing_only):
1.11 +
1.12 + """
1.13 + Process the given 'msg' for a single 'recipient', having the given
1.14 + 'senders', and with the given 'outgoing_only' status.
1.15 +
1.16 + Processing individually means that contributions to resulting messages
1.17 + may be constructed according to individual preferences.
1.18 + """
1.19 +
1.20 all_responses = []
1.21 handled = False
1.22
1.23 @@ -73,7 +86,7 @@
1.24 if part.get_content_type() in itip_content_types and \
1.25 part.get_param("method"):
1.26
1.27 - all_responses += handle_itip_part(part, senders, original_recipients, self.handlers, self.messenger)
1.28 + all_responses += handle_itip_part(part, senders, recipient, self.handlers, self.messenger)
1.29 handled = True
1.30
1.31 # When processing outgoing messages, no replies or deliveries are
1.32 @@ -112,30 +125,29 @@
1.33
1.34 # Determine whether to wrap, accompany or replace the message.
1.35
1.36 - for recipient in original_recipients:
1.37 - preferences = Preferences(get_uri(recipient))
1.38 + preferences = Preferences(get_uri(recipient))
1.39
1.40 - incoming = preferences.get("incoming")
1.41 + incoming = preferences.get("incoming")
1.42
1.43 - if incoming == "message-only":
1.44 - messages = [msg]
1.45 - else:
1.46 - summary = self.messenger.make_summary_message(msg, forwarded_parts)
1.47 - if incoming == "summary-then-message":
1.48 - messages = [summary, msg]
1.49 - elif incoming == "message-then-summary":
1.50 - messages = [msg, summary]
1.51 - elif incoming == "summary-only":
1.52 - messages = [summary]
1.53 - else: # incoming == "summary-wraps-message":
1.54 - messages = [self.messenger.wrap_message(msg, forwarded_parts)]
1.55 + if incoming == "message-only":
1.56 + messages = [msg]
1.57 + else:
1.58 + summary = self.messenger.make_summary_message(msg, forwarded_parts)
1.59 + if incoming == "summary-then-message":
1.60 + messages = [summary, msg]
1.61 + elif incoming == "message-then-summary":
1.62 + messages = [msg, summary]
1.63 + elif incoming == "summary-only":
1.64 + messages = [summary]
1.65 + else: # incoming == "summary-wraps-message":
1.66 + messages = [self.messenger.wrap_message(msg, forwarded_parts)]
1.67
1.68 - for message in messages:
1.69 - if "-d" in sys.argv:
1.70 - print >>sys.stderr, "Forwarded parts..."
1.71 - print message
1.72 - elif self.lmtp_socket:
1.73 - self.messenger.sendmail(recipient, message.as_string(), lmtp_socket=self.lmtp_socket)
1.74 + for message in messages:
1.75 + if "-d" in sys.argv:
1.76 + print >>sys.stderr, "Forwarded parts..."
1.77 + print message
1.78 + elif self.lmtp_socket:
1.79 + self.messenger.sendmail(recipient, message.as_string(), lmtp_socket=self.lmtp_socket)
1.80
1.81 # Unhandled messages are delivered as they are.
1.82
1.83 @@ -144,7 +156,7 @@
1.84 print >>sys.stderr, "Unhandled parts..."
1.85 print msg
1.86 elif self.lmtp_socket:
1.87 - self.messenger.sendmail(original_recipients, msg.as_string(), lmtp_socket=self.lmtp_socket)
1.88 + self.messenger.sendmail(recipient, msg.as_string(), lmtp_socket=self.lmtp_socket)
1.89
1.90 def process_args(self, args, stream):
1.91
2.1 --- a/imiptools/content.py Tue Jan 27 01:29:36 2015 +0100
2.2 +++ b/imiptools/content.py Tue Jan 27 18:48:58 2015 +0100
2.3 @@ -241,11 +241,11 @@
2.4
2.5 # Handler mechanism objects.
2.6
2.7 -def handle_itip_part(part, senders, recipients, handlers, messenger):
2.8 +def handle_itip_part(part, senders, recipient, handlers, messenger):
2.9
2.10 """
2.11 Handle the given iTIP 'part' from the given 'senders' for the given
2.12 - 'recipients' using the given 'handlers' and information provided by the
2.13 + 'recipient' using the given 'handlers' and information provided by the
2.14 given 'messenger'. Return a list of responses, each response being a tuple
2.15 of the form (is-outgoing, message-part).
2.16 """
2.17 @@ -276,7 +276,7 @@
2.18
2.19 # Dispatch to a handler and obtain any response.
2.20
2.21 - handler = cls(details, senders, recipients, messenger)
2.22 + handler = cls(details, senders, recipient, messenger)
2.23 result = methods[method](handler)()
2.24
2.25 # Aggregate responses for a single message.
2.26 @@ -340,16 +340,16 @@
2.27
2.28 "General handler support."
2.29
2.30 - def __init__(self, details, senders=None, recipients=None, messenger=None):
2.31 + def __init__(self, details, senders=None, recipient=None, messenger=None):
2.32
2.33 """
2.34 Initialise the handler with the 'details' of a calendar object and the
2.35 - 'senders' and 'recipients' of the object (if specifically indicated).
2.36 + 'senders' and 'recipient' of the object (if specifically indicated).
2.37 """
2.38
2.39 self.details = details
2.40 self.senders = senders and set(map(get_address, senders))
2.41 - self.recipients = recipients and set(map(get_address, recipients))
2.42 + self.recipient = recipient and get_address(recipient)
2.43 self.messenger = messenger
2.44
2.45 self.uid = get_value(details, "UID")
2.46 @@ -424,24 +424,24 @@
2.47 else:
2.48 return mapping
2.49
2.50 - def filter_by_recipients(self, mapping):
2.51 + def filter_by_recipient(self, mapping):
2.52
2.53 """
2.54 Return a list of items from 'mapping' filtered using recipient
2.55 information.
2.56 """
2.57
2.58 - if self.recipients:
2.59 - addresses = map(get_address, mapping)
2.60 - return map(get_uri, self.recipients.intersection(addresses))
2.61 + if self.recipient:
2.62 + addresses = set(map(get_address, mapping))
2.63 + return map(get_uri, addresses.intersection([self.recipient]))
2.64 else:
2.65 return mapping
2.66
2.67 def require_organiser_and_attendees(self, from_organiser=True):
2.68
2.69 """
2.70 - Return the organiser and attendees for the current object, filtered by
2.71 - the recipients of interest. Return None if no identities are eligible.
2.72 + Return the organiser and attendees for the current object, filtered for
2.73 + the recipient of interest. Return None if no identities are eligible.
2.74
2.75 Organiser and attendee identities are provided as lower case values.
2.76 """
2.77 @@ -451,7 +451,7 @@
2.78
2.79 # Only provide details for attendees who sent/receive the message.
2.80
2.81 - attendee_filter_fn = from_organiser and self.filter_by_recipients or self.filter_by_senders
2.82 + attendee_filter_fn = from_organiser and self.filter_by_recipient or self.filter_by_senders
2.83
2.84 attendees = {}
2.85 for attendee in attendee_filter_fn(attendee_map):
2.86 @@ -462,7 +462,7 @@
2.87
2.88 # Only provide details for an organiser who sent/receives the message.
2.89
2.90 - organiser_filter_fn = from_organiser and self.filter_by_senders or self.filter_by_recipients
2.91 + organiser_filter_fn = from_organiser and self.filter_by_senders or self.filter_by_recipient
2.92
2.93 if not organiser_filter_fn(dict([organiser_item])):
2.94 return None
3.1 --- a/imiptools/handlers/person.py Tue Jan 27 01:29:36 2015 +0100
3.2 +++ b/imiptools/handlers/person.py Tue Jan 27 18:48:58 2015 +0100
3.3 @@ -23,6 +23,7 @@
3.4 from imiptools.config import MANAGER_PATH, MANAGER_URL
3.5 from imiptools.content import Handler, get_address, get_uri, to_part, uri_dict, uri_items
3.6 from imiptools.handlers.common import CommonFreebusy
3.7 +from imiptools.profile import Preferences
3.8 from socket import gethostname
3.9 from vCalendar import to_node
3.10
3.11 @@ -131,8 +132,7 @@
3.12 pass
3.13
3.14 for sender, sender_attr in uri_items(self.get_items(from_organiser and "ORGANIZER" or "ATTENDEE")):
3.15 - for recipient in self.recipients:
3.16 - self.store.set_freebusy_for_other(get_uri(recipient), freebusy, sender)
3.17 + self.store.set_freebusy_for_other(get_uri(self.recipient), freebusy, sender)
3.18
3.19 def wrap(self, method, text, from_organiser=True, link=True):
3.20