imip-agent

Changeset

832:e2877c3d0b58
2015-10-14 Paul Boddie raw files shortlog changelog graph Define outgoing users using a combination of sender address and object details. Removed the organiser and attendee check for outgoing handling of ADD messages, adding a new object check.
imiptools/__init__.py (file) imiptools/handlers/person_outgoing.py (file)
     1.1 --- a/imiptools/__init__.py	Tue Oct 13 23:33:25 2015 +0200
     1.2 +++ b/imiptools/__init__.py	Wed Oct 14 00:46:48 2015 +0200
     1.3 @@ -93,10 +93,15 @@
     1.4                           ).process(msg, senders)
     1.5  
     1.6          # However, outgoing messages do not usually presume anything about the
     1.7 -        # eventual recipients and focus on the sender instead.
     1.8 +        # eventual recipients and focus on the sender instead. If possible, the
     1.9 +        # sender is identified, but since this may be the calendar system (and
    1.10 +        # the actual sender is defined in the object), and since the recipient
    1.11 +        # may be in a Bcc header that is not available here, it may be left as
    1.12 +        # None and deduced from the object content later. 
    1.13  
    1.14          else:
    1.15 -            Recipient(None, messenger, store, publisher, preferences_dir, self.handlers, self.outgoing_only, self.debug
    1.16 +            senders = [sender for sender in get_addresses(get_all_values(msg, "From") or []) if sender != config.MESSAGE_SENDER]
    1.17 +            Recipient(senders and senders[0] or None, messenger, store, publisher, preferences_dir, self.handlers, self.outgoing_only, self.debug
    1.18                       ).process(msg, senders)
    1.19  
    1.20      def process_args(self, args, stream):
     2.1 --- a/imiptools/handlers/person_outgoing.py	Tue Oct 13 23:33:25 2015 +0200
     2.2 +++ b/imiptools/handlers/person_outgoing.py	Wed Oct 14 00:46:48 2015 +0200
     2.3 @@ -21,7 +21,8 @@
     2.4  """
     2.5  
     2.6  from imiptools.client import Client
     2.7 -from imiptools.data import get_uri, uri_dict, uri_values
     2.8 +from imiptools.config import MESSAGE_SENDER
     2.9 +from imiptools.data import get_uri, uri_dict, uri_items, uri_values
    2.10  from imiptools.handlers import Handler
    2.11  from imiptools.handlers.common import CommonEvent
    2.12  
    2.13 @@ -38,9 +39,21 @@
    2.14          in this way.
    2.15          """
    2.16  
    2.17 -        if self.obj:
    2.18 +        if self.obj and not self.user:
    2.19              from_organiser = method in self.organiser_methods
    2.20 -            self.user = get_uri(self.obj.get_value(from_organiser and "ORGANIZER" or "ATTENDEE"))
    2.21 +            if from_organiser:
    2.22 +                self.user = get_uri(self.obj.get_value("ORGANIZER"))
    2.23 +
    2.24 +            # Since there may be many attendees in an attendee-provided outgoing
    2.25 +            # message, because counter-proposals can have more than one
    2.26 +            # attendee, the attendee originating from the calendar system is
    2.27 +            # chosen.
    2.28 +
    2.29 +            else:
    2.30 +                calendar_uri = get_uri(MESSAGE_SENDER)
    2.31 +                for attendee, attendee_attr in uri_items(self.obj.get_items("ATTENDEE")):
    2.32 +                    if attendee_attr.get("SENT-BY") == calendar_uri:
    2.33 +                        self.user = get_uri(attendee)
    2.34  
    2.35      def _add(self):
    2.36  
    2.37 @@ -49,14 +62,11 @@
    2.38          if not Client.is_participating(self):
    2.39              return False
    2.40  
    2.41 -        # Obtain valid organiser and attendee details.
    2.42 +        # Check for event using UID.
    2.43  
    2.44 -        oa = self.require_organiser_and_attendees()
    2.45 -        if not oa:
    2.46 +        if not self.have_new_object():
    2.47              return False
    2.48  
    2.49 -        (organiser, organiser_attr), attendees = oa
    2.50 -
    2.51          # Ignore unknown objects.
    2.52  
    2.53          if not self.get_stored_object_version():