1.1 --- a/imip_agent.py Wed Sep 24 16:05:03 2014 +0200
1.2 +++ b/imip_agent.py Wed Sep 24 16:35:16 2014 +0200
1.3 @@ -17,7 +17,7 @@
1.4 except ImportError:
1.5 from StringIO import StringIO
1.6
1.7 -OWNER = "resource+manager@example.com"
1.8 +MESSAGE_SENDER = "resources+agent@example.com"
1.9
1.10 MESSAGE_SUBJECT = "Calendar system message"
1.11
1.12 @@ -172,11 +172,12 @@
1.13
1.14 # Processing of incoming messages.
1.15
1.16 -def process(f, original_recipients, recipients):
1.17 +def process(f, original_recipients, recipients, this_sender):
1.18
1.19 """
1.20 Process content from the stream 'f' accompanied by the given
1.21 - 'original_recipients' and 'recipients'.
1.22 + 'original_recipients' and 'recipients', together with details of
1.23 + 'this_sender' (the sender address on messages sent by this service).
1.24 """
1.25
1.26 msg = message_from_file(f)
1.27 @@ -200,7 +201,7 @@
1.28 message = MIMEMultipart("alternative", _subparts=all_parts)
1.29 message.preamble = MESSAGE_TEXT
1.30
1.31 - message["From"] = OWNER
1.32 + message["From"] = this_sender
1.33 for sender in senders:
1.34 message["To"] = sender
1.35 message["Subject"] = MESSAGE_SUBJECT
1.36 @@ -208,7 +209,7 @@
1.37 if "-d" in sys.argv:
1.38 print message
1.39 else:
1.40 - sendmail(OWNER, senders, message.as_string())
1.41 + sendmail(this_sender, senders, message.as_string())
1.42
1.43 def to_part(method, calendar):
1.44
1.45 @@ -607,24 +608,38 @@
1.46
1.47 def main():
1.48
1.49 - # Obtain the different kinds of recipients.
1.50 + "Interpret program arguments and process input."
1.51 +
1.52 + # Obtain the different kinds of recipients plus sender address.
1.53
1.54 original_recipients = []
1.55 recipients = []
1.56 + senders = []
1.57
1.58 l = []
1.59
1.60 for arg in sys.argv[1:]:
1.61 +
1.62 + # Switch to collecting recipients.
1.63 +
1.64 if arg == "-o":
1.65 l = original_recipients
1.66 elif arg == "-r":
1.67 l = recipients
1.68 +
1.69 + # Switch to collecting senders.
1.70 +
1.71 + elif arg == "-s":
1.72 + l = senders
1.73 +
1.74 + # Ignore debugging options.
1.75 +
1.76 elif arg == "-d":
1.77 pass
1.78 else:
1.79 l.append(arg)
1.80
1.81 - process(sys.stdin, original_recipients, recipients)
1.82 + process(sys.stdin, original_recipients, recipients, senders and senders[0] or MESSAGE_SENDER)
1.83
1.84 if __name__ == "__main__":
1.85 if "-d" in sys.argv[1:]: