1.1 --- a/imiptools/handlers/person.py Thu Dec 18 19:21:28 2014 +0100
1.2 +++ b/imiptools/handlers/person.py Thu Dec 18 22:18:53 2014 +0100
1.3 @@ -15,6 +15,9 @@
1.4 url_base = MANAGER_URL or "http://%s/" % gethostname()
1.5 return "%s/%s" % (url_base.rstrip("/"), MANAGER_PATH.lstrip("/"))
1.6
1.7 +def get_object_url(uid):
1.8 + return "%s/%s" % (get_manager_url().rstrip("/"), uid)
1.9 +
1.10 class PersonHandler(Handler):
1.11
1.12 "Handling mechanisms specific to people."
1.13 @@ -99,13 +102,18 @@
1.14 for recipient in self.recipients:
1.15 self.store.set_freebusy_for_other(get_uri(recipient), freebusy, sender)
1.16
1.17 - def reply(self):
1.18 + def wrap(self, method, text, from_organiser=True, link=True):
1.19
1.20 "Wrap any valid message and pass it on to the recipient."
1.21
1.22 - attendee = get_address(self.get_value("ATTENDEE"))
1.23 - if attendee:
1.24 - return "REPLY", MIMEText("A reply has been received from %s." % attendee)
1.25 + texts = []
1.26 + texts.append(text)
1.27 + if link:
1.28 + texts.append("If your mail program cannot handle this "
1.29 + "message, you may view the details here:\n\n%s" %
1.30 + get_object_url(self.uid))
1.31 +
1.32 + return method, MIMEText("\n".join(texts))
1.33
1.34 class Event(PersonHandler):
1.35
1.36 @@ -145,26 +153,24 @@
1.37
1.38 def publish(self):
1.39
1.40 - # NOTE: Register details of any relevant event.
1.41 + "Register details of any relevant event."
1.42
1.43 - # The message is now wrapped and passed on to the recipient.
1.44 -
1.45 - return "PUBLISH", MIMEText("Details of an event have been received.")
1.46 + self._record_and_deliver("VEVENT", from_organiser=True, queue=False)
1.47 + return self.wrap("PUBLISH", "Details of an event have been received.", from_organiser=True, link=True)
1.48
1.49 def refresh(self):
1.50
1.51 - # NOTE: Update details of any active event.
1.52 + "Update details of any active event."
1.53
1.54 - # The message is now wrapped and passed on to the recipient.
1.55 -
1.56 - return "REFRESH", MIMEText("An event update has been received.")
1.57 + self._record_and_deliver("VEVENT", from_organiser=True, queue=False)
1.58 + return self.wrap("REFRESH", "An event update has been received.", from_organiser=True, link=True)
1.59
1.60 def reply(self):
1.61
1.62 "Record replies and notify the recipient."
1.63
1.64 self._record_and_deliver("VEVENT", from_organiser=False, queue=False)
1.65 - return PersonHandler.reply(self)
1.66 + return self.wrap("REPLY", "A reply has been received.", from_organiser=False, link=True)
1.67
1.68 def request(self):
1.69
1.70 @@ -174,8 +180,7 @@
1.71
1.72 # The message is now wrapped and passed on to the recipient.
1.73
1.74 - url = "%s/%s" % (get_manager_url().rstrip("/"), self.uid)
1.75 - return "REQUEST", MIMEText("A request has been queued and can be viewed here: %s" % url)
1.76 + return "REQUEST", MIMEText("A request has been queued and can be viewed here: %s" % get_object_url(self.uid))
1.77
1.78 class Freebusy(PersonHandler, CommonFreebusy):
1.79
1.80 @@ -185,18 +190,19 @@
1.81
1.82 "Register free/busy information."
1.83
1.84 - self._record_freebusy(from_organiser=True)
1.85 + # NOTE: This could be configured to not produce a message.
1.86
1.87 - # The message is now wrapped and passed on to the recipient.
1.88 -
1.89 - return "PUBLISH", MIMEText("Details of a contact's availability have been received.")
1.90 + self._record_freebusy(from_organiser=True)
1.91 + return self.wrap("PUBLISH", "A free/busy update has been received.", from_organiser=True, link=False)
1.92
1.93 def reply(self):
1.94
1.95 "Record replies and notify the recipient."
1.96
1.97 + # NOTE: This could be configured to not produce a message.
1.98 +
1.99 self._record_freebusy(from_organiser=False)
1.100 - return PersonHandler.reply(self)
1.101 + return self.wrap("REPLY", "A reply has been received.", from_organiser=False, link=False)
1.102
1.103 def request(self):
1.104
1.105 @@ -235,7 +241,8 @@
1.106
1.107 # The message is now wrapped and passed on to the recipient.
1.108
1.109 - return "PUBLISH", MIMEText("Details of a journal entry have been received.")
1.110 + self._record_and_deliver("VJOURNAL", from_organiser=True, queue=False)
1.111 + return self.wrap("PUBLISH", "Details of a journal entry have been received.", from_organiser=True, link=False)
1.112
1.113 class Todo(PersonHandler):
1.114
1.115 @@ -275,26 +282,24 @@
1.116
1.117 def publish(self):
1.118
1.119 - # NOTE: Register details of any relevant item.
1.120 + "Register details of any relevant item."
1.121
1.122 - # The message is now wrapped and passed on to the recipient.
1.123 -
1.124 - return "PUBLISH", MIMEText("Details of an item have been received.")
1.125 + self._record_and_deliver("VTODO", from_organiser=True, queue=False)
1.126 + return self.wrap("PUBLISH", "Details of an item have been received.", from_organiser=True, link=True)
1.127
1.128 def refresh(self):
1.129
1.130 - # NOTE: Update details of any active item.
1.131 + "Update details of any active item."
1.132
1.133 - # The message is now wrapped and passed on to the recipient.
1.134 -
1.135 - return "REFRESH", MIMEText("An item update has been received.")
1.136 + self._record_and_deliver("VTODO", from_organiser=True, queue=False)
1.137 + return self.wrap("REFRESH", "An item update has been received.", from_organiser=True, link=True)
1.138
1.139 def reply(self):
1.140
1.141 "Record replies and notify the recipient."
1.142
1.143 self._record_and_deliver("VTODO", from_organiser=False, queue=False)
1.144 - return PersonHandler.reply(self)
1.145 + return self.wrap("REPLY", "A reply has been received.", from_organiser=False, link=True)
1.146
1.147 def request(self):
1.148