1.1 --- a/imiptools/handlers/person.py Wed Jan 28 00:32:44 2015 +0100
1.2 +++ b/imiptools/handlers/person.py Wed Jan 28 01:04:24 2015 +0100
1.3 @@ -19,21 +19,11 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 -from email.mime.text import MIMEText
1.8 -from imiptools.config import MANAGER_PATH, MANAGER_URL
1.9 from imiptools.content import Handler, get_address, get_uri, to_part, uri_dict, uri_items
1.10 from imiptools.handlers.common import CommonFreebusy
1.11 from imiptools.profile import Preferences
1.12 -from socket import gethostname
1.13 from vCalendar import to_node
1.14
1.15 -def get_manager_url():
1.16 - url_base = MANAGER_URL or "http://%s/" % gethostname()
1.17 - return "%s/%s" % (url_base.rstrip("/"), MANAGER_PATH.lstrip("/"))
1.18 -
1.19 -def get_object_url(uid):
1.20 - return "%s/%s" % (get_manager_url().rstrip("/"), uid)
1.21 -
1.22 class PersonHandler(Handler):
1.23
1.24 "Handling mechanisms specific to people."
1.25 @@ -134,19 +124,6 @@
1.26 for sender, sender_attr in uri_items(self.get_items(from_organiser and "ORGANIZER" or "ATTENDEE")):
1.27 self.store.set_freebusy_for_other(get_uri(self.recipient), freebusy, sender)
1.28
1.29 - def wrap(self, method, text, from_organiser=True, link=True):
1.30 -
1.31 - "Wrap any valid message and pass it on to the recipient."
1.32 -
1.33 - texts = []
1.34 - texts.append(text)
1.35 - if link:
1.36 - texts.append("If your mail program cannot handle this "
1.37 - "message, you may view the details here:\n\n%s" %
1.38 - get_object_url(self.uid))
1.39 -
1.40 - return method, MIMEText("\n".join(texts))
1.41 -
1.42 class Event(PersonHandler):
1.43
1.44 "An event handler."
1.45 @@ -155,63 +132,54 @@
1.46
1.47 # NOTE: Queue a suggested modification to any active event.
1.48
1.49 - # The message is now wrapped and passed on to the recipient.
1.50 -
1.51 - return "ADD", MIMEText("An addition to an event has been received.")
1.52 + return self.wrap("An addition to an event has been received.", link=False)
1.53
1.54 def cancel(self):
1.55
1.56 "Queue a cancellation of any active event."
1.57
1.58 self._record_and_deliver("VEVENT", from_organiser=True, queue=False, cancel=True)
1.59 - return self.wrap("CANCEL", "A cancellation has been received.", from_organiser=True, link=True)
1.60 + return self.wrap("A cancellation has been received.", link=False)
1.61
1.62 def counter(self):
1.63
1.64 # NOTE: Queue a suggested modification to any active event.
1.65
1.66 - # The message is now wrapped and passed on to the recipient.
1.67 -
1.68 - return "COUNTER", MIMEText("A counter proposal has been received.")
1.69 + return self.wrap("A counter proposal has been received.", link=False)
1.70
1.71 def declinecounter(self):
1.72
1.73 # NOTE: Queue a suggested modification to any active event.
1.74
1.75 - # The message is now wrapped and passed on to the recipient.
1.76 -
1.77 - return "DECLINECOUNTER", MIMEText("A declining counter proposal has been received.")
1.78 + return self.wrap("A declining counter proposal has been received.", link=False)
1.79
1.80 def publish(self):
1.81
1.82 "Register details of any relevant event."
1.83
1.84 self._record_and_deliver("VEVENT", from_organiser=True, queue=False)
1.85 - return self.wrap("PUBLISH", "Details of an event have been received.", from_organiser=True, link=True)
1.86 + return self.wrap("Details of an event have been received.")
1.87
1.88 def refresh(self):
1.89
1.90 "Update details of any active event."
1.91
1.92 self._record_and_deliver("VEVENT", from_organiser=True, queue=False)
1.93 - return self.wrap("REFRESH", "An event update has been received.", from_organiser=True, link=True)
1.94 + return self.wrap("An event update has been received.")
1.95
1.96 def reply(self):
1.97
1.98 "Record replies and notify the recipient."
1.99
1.100 self._record_and_deliver("VEVENT", from_organiser=False, queue=False)
1.101 - return self.wrap("REPLY", "A reply has been received.", from_organiser=False, link=True)
1.102 + return self.wrap("A reply has been received.")
1.103
1.104 def request(self):
1.105
1.106 "Hold requests and notify the recipient."
1.107
1.108 self._record_and_deliver("VEVENT", from_organiser=True, queue=True)
1.109 -
1.110 - # The message is now wrapped and passed on to the recipient.
1.111 -
1.112 - return "REQUEST", MIMEText("A request has been queued and can be viewed here: %s" % get_object_url(self.uid))
1.113 + return self.wrap("A request has been received.")
1.114
1.115 class Freebusy(PersonHandler, CommonFreebusy):
1.116
1.117 @@ -227,7 +195,7 @@
1.118
1.119 preferences = Preferences(get_uri(self.recipient))
1.120 if preferences.get("freebusy_messages") == "notify":
1.121 - return self.wrap("PUBLISH", "A free/busy update has been received.", from_organiser=True, link=False)
1.122 + return self.wrap("A free/busy update has been received.", link=False)
1.123
1.124 def reply(self):
1.125
1.126 @@ -239,7 +207,7 @@
1.127
1.128 preferences = Preferences(get_uri(self.recipient))
1.129 if preferences.get("freebusy_messages") == "notify":
1.130 - return self.wrap("REPLY", "A reply to a free/busy request has been received.", from_organiser=False, link=False)
1.131 + return self.wrap("A reply to a free/busy request has been received.", link=False)
1.132
1.133 def request(self):
1.134
1.135 @@ -262,26 +230,20 @@
1.136
1.137 # NOTE: Queue a suggested modification to any active entry.
1.138
1.139 - # The message is now wrapped and passed on to the recipient.
1.140 -
1.141 - return "ADD", MIMEText("An addition to a journal entry has been received.")
1.142 + return self.wrap("An addition to a journal entry has been received.", link=False)
1.143
1.144 def cancel(self):
1.145
1.146 # NOTE: Queue a suggested modification to any active entry.
1.147
1.148 - # The message is now wrapped and passed on to the recipient.
1.149 -
1.150 - return "CANCEL", MIMEText("A cancellation has been received.")
1.151 + return self.wrap("A cancellation has been received.", link=False)
1.152
1.153 def publish(self):
1.154
1.155 # NOTE: Register details of any relevant entry.
1.156
1.157 - # The message is now wrapped and passed on to the recipient.
1.158 -
1.159 self._record_and_deliver("VJOURNAL", from_organiser=True, queue=False)
1.160 - return self.wrap("PUBLISH", "Details of a journal entry have been received.", from_organiser=True, link=False)
1.161 + return self.wrap("Details of a journal entry have been received.")
1.162
1.163 class Todo(PersonHandler):
1.164
1.165 @@ -291,64 +253,53 @@
1.166
1.167 # NOTE: Queue a suggested modification to any active item.
1.168
1.169 - # The message is now wrapped and passed on to the recipient.
1.170 -
1.171 - return "ADD", MIMEText("An addition to an item has been received.")
1.172 + return self.wrap("An addition to an item has been received.", link=False)
1.173
1.174 def cancel(self):
1.175
1.176 # NOTE: Queue a suggested modification to any active item.
1.177
1.178 - # The message is now wrapped and passed on to the recipient.
1.179 -
1.180 - return "CANCEL", MIMEText("A cancellation has been received.")
1.181 + return self.wrap("A cancellation has been received.", link=False)
1.182
1.183 def counter(self):
1.184
1.185 # NOTE: Queue a suggested modification to any active item.
1.186
1.187 - # The message is now wrapped and passed on to the recipient.
1.188 -
1.189 - return "COUNTER", MIMEText("A counter proposal has been received.")
1.190 + return self.wrap("A counter proposal has been received.", link=False)
1.191
1.192 def declinecounter(self):
1.193
1.194 # NOTE: Queue a suggested modification to any active item.
1.195
1.196 - # The message is now wrapped and passed on to the recipient.
1.197 -
1.198 - return "DECLINECOUNTER", MIMEText("A declining counter proposal has been received.")
1.199 + return self.wrap("A declining counter proposal has been received.", link=False)
1.200
1.201 def publish(self):
1.202
1.203 "Register details of any relevant item."
1.204
1.205 self._record_and_deliver("VTODO", from_organiser=True, queue=False)
1.206 - return self.wrap("PUBLISH", "Details of an item have been received.", from_organiser=True, link=True)
1.207 + return self.wrap("Details of an item have been received.")
1.208
1.209 def refresh(self):
1.210
1.211 "Update details of any active item."
1.212
1.213 self._record_and_deliver("VTODO", from_organiser=True, queue=False)
1.214 - return self.wrap("REFRESH", "An item update has been received.", from_organiser=True, link=True)
1.215 + return self.wrap("An item update has been received.")
1.216
1.217 def reply(self):
1.218
1.219 "Record replies and notify the recipient."
1.220
1.221 self._record_and_deliver("VTODO", from_organiser=False, queue=False)
1.222 - return self.wrap("REPLY", "A reply has been received.", from_organiser=False, link=True)
1.223 + return self.wrap("A reply has been received.")
1.224
1.225 def request(self):
1.226
1.227 "Hold requests and notify the recipient."
1.228
1.229 self._record_and_deliver("VTODO", from_organiser=True, queue=True)
1.230 -
1.231 - # The message is now wrapped and passed on to the recipient.
1.232 -
1.233 - return "REQUEST", MIMEText("A request has been queued.")
1.234 + return self.wrap("A request has been received.")
1.235
1.236 # Handler registry.
1.237