imip-agent

Change of imiptools/content.py

89:ba35611d36e2
imiptools/content.py
     1.1 --- a/imiptools/content.py	Tue Oct 28 22:59:00 2014 +0100
     1.2 +++ b/imiptools/content.py	Tue Oct 28 23:01:26 2014 +0100
     1.3 @@ -223,12 +223,13 @@
     1.4  
     1.5  # Handler mechanism objects.
     1.6  
     1.7 -def handle_itip_part(part, recipients, handlers):
     1.8 +def handle_itip_part(part, senders, recipients, handlers, messenger):
     1.9  
    1.10      """
    1.11 -    Handle the given iTIP 'part' for the given 'recipients' using the given
    1.12 -    'handlers'. Return a list of responses, each response being a tuple of the
    1.13 -    form (is-outgoing, message-part).
    1.14 +    Handle the given iTIP 'part' from the given 'senders' for the given
    1.15 +    'recipients' using the given 'handlers' and information provided by the
    1.16 +    given 'messenger'. Return a list of responses, each response being a tuple
    1.17 +    of the form (is-outgoing, message-part).
    1.18      """
    1.19  
    1.20      method = part.get_param("method")
    1.21 @@ -257,10 +258,10 @@
    1.22  
    1.23                  # Dispatch to a handler and obtain any response.
    1.24  
    1.25 -                handler = cls(details, recipients)
    1.26 +                handler = cls(details, senders, recipients, messenger)
    1.27                  result = methods[method](handler)()
    1.28  
    1.29 -                # Concatenate responses for a single calendar object.
    1.30 +                # Aggregate responses for a single message.
    1.31  
    1.32                  if result:
    1.33                      response_method, part = result
    1.34 @@ -318,15 +319,17 @@
    1.35  
    1.36      "General handler support."
    1.37  
    1.38 -    def __init__(self, details, recipients=None):
    1.39 +    def __init__(self, details, senders=None, recipients=None, messenger=None):
    1.40  
    1.41          """
    1.42          Initialise the handler with the 'details' of a calendar object and the
    1.43 -        'recipients' of the object (if specifically indicated).
    1.44 +        'senders' and 'recipients' of the object (if specifically indicated).
    1.45          """
    1.46  
    1.47          self.details = details
    1.48 +        self.senders = senders and set(senders)
    1.49          self.recipients = recipients and set(recipients)
    1.50 +        self.messenger = messenger
    1.51  
    1.52          self.uid = get_value(details, "UID")
    1.53          self.sequence = get_value(details, "SEQUENCE")
    1.54 @@ -368,9 +371,19 @@
    1.55      def can_schedule(self, freebusy, periods):
    1.56          return can_schedule(freebusy, periods, self.uid)
    1.57  
    1.58 +    def filter_by_senders(self, values):
    1.59 +        addresses = map(get_address, values)
    1.60 +        if self.senders:
    1.61 +            return self.senders.intersection(addresses)
    1.62 +        else:
    1.63 +            return addresses
    1.64 +
    1.65      def filter_by_recipients(self, values):
    1.66          addresses = map(get_address, values)
    1.67 -        return self.recipients and self.recipients.intersection(addresses) or addresses
    1.68 +        if self.recipients:
    1.69 +            return self.recipients.intersection(addresses)
    1.70 +        else:
    1.71 +            return addresses
    1.72  
    1.73      def require_organiser_and_attendees(self):
    1.74  
    1.75 @@ -388,7 +401,15 @@
    1.76          for attendee in map(get_uri, self.filter_by_recipients(attendee_map)):
    1.77              attendees[attendee] = attendee_map[attendee]
    1.78  
    1.79 -        if not attendees and not organiser:
    1.80 +        if not attendees or not organiser:
    1.81 +            return None
    1.82 +
    1.83 +        # Reject organisers that do not match any senders.
    1.84 +
    1.85 +        organiser_value, organiser_attr = self.get_item("ORGANIZER")
    1.86 +        sent_by = organiser_attr.get("SENT-BY")
    1.87 +
    1.88 +        if not self.filter_by_senders([organiser_value] + (sent_by and [sent_by] or [])):
    1.89              return None
    1.90  
    1.91          return organiser, attendees