1.1 --- a/imip_agent.py Mon Sep 22 18:28:56 2014 +0200
1.2 +++ b/imip_agent.py Mon Sep 22 22:07:27 2014 +0200
1.3 @@ -46,15 +46,16 @@
1.4
1.5 # Processing of incoming messages.
1.6
1.7 -def process(f, args):
1.8 +def process(f, original_recipients, recipients):
1.9
1.10 - "Process content from the stream 'f' accompanied by the given 'args'."
1.11 -
1.12 - recipient = args[0]
1.13 + """
1.14 + Process content from the stream 'f' accompanied by the given
1.15 + 'original_recipients' and 'recipients'.
1.16 + """
1.17
1.18 msg = message_from_file(f)
1.19 print >>open("/tmp/imip.txt", "a"), "----"
1.20 - print >>open("/tmp/imip.txt", "a"), args
1.21 + print >>open("/tmp/imip.txt", "a"), original_recipients, recipients
1.22 print >>open("/tmp/imip.txt", "a"), "----"
1.23 print >>open("/tmp/imip.txt", "a"), msg.as_string()
1.24 print >>open("/tmp/imip.txt", "a")
1.25 @@ -65,7 +66,7 @@
1.26 if part.get_content_type() in itip_content_types and \
1.27 part.get_param("method"):
1.28
1.29 - handle_itip_part(part, recipient)
1.30 + handle_itip_part(part, original_recipients)
1.31
1.32 def get_itip_elements(elements):
1.33 d = {}
1.34 @@ -98,7 +99,7 @@
1.35 else:
1.36 return None
1.37
1.38 -def handle_itip_part(part, recipient):
1.39 +def handle_itip_part(part, recipients):
1.40 method = part.get_param("method")
1.41
1.42 # Decode the data and parse it.
1.43 @@ -126,7 +127,7 @@
1.44
1.45 # Dispatch to a handler and obtain any response.
1.46
1.47 - handler = cls(details)
1.48 + handler = cls(details, recipients)
1.49 part = methods[method](handler)()
1.50
1.51 if part:
1.52 @@ -136,8 +137,16 @@
1.53
1.54 "General handler support."
1.55
1.56 - def __init__(self, details):
1.57 + def __init__(self, details, recipients):
1.58 +
1.59 + """
1.60 + Initialise the handler with the 'details' of a calendar object and the
1.61 + 'recipients' of the object.
1.62 + """
1.63 +
1.64 self.details = details
1.65 + self.recipients = set(recipients)
1.66 +
1.67 self.uid = get_value(details, "UID")
1.68 self.sequence = get_value(details, "SEQUENCE")
1.69 self.store = imip_store.FileStore()
1.70 @@ -148,6 +157,9 @@
1.71 def get_value(self, name, single=True):
1.72 return get_value(self.details, name, single)
1.73
1.74 + def filter_by_recipients(self, attr_values):
1.75 + return [a for attr, value in attendees if value in self.recipients]
1.76 +
1.77 class Event(Handler):
1.78
1.79 "An event handler."
1.80 @@ -202,6 +214,10 @@
1.81 attendees = self.get_attr_value("ATTENDEE", False)
1.82 organiser = self.get_attr_value("ORGANIZER")
1.83
1.84 + # Only provide details for recipients who are also attendees.
1.85 +
1.86 + attendees = self.filter_by_recipients(attendees)
1.87 +
1.88 if not attendees and not organiser:
1.89 return
1.90
1.91 @@ -306,6 +322,26 @@
1.92 }
1.93
1.94 if __name__ == "__main__":
1.95 - process(sys.stdin, sys.argv[1:])
1.96 + try:
1.97 + # Obtain the different kinds of recipients.
1.98 +
1.99 + original_recipients = []
1.100 + recipients = []
1.101 +
1.102 + l = []
1.103 +
1.104 + for arg in sys.argv[1:]:
1.105 + if arg == "-o":
1.106 + l = original_recipients
1.107 + elif arg == "-r":
1.108 + l = recipients
1.109 + else:
1.110 + l.append(arg)
1.111 +
1.112 + process(sys.stdin, original_recipients, recipients)
1.113 + except:
1.114 + sys.exit(EX_SOFTWARE)
1.115 + else:
1.116 + sys.exit(0)
1.117
1.118 # vim: tabstop=4 expandtab shiftwidth=4