1.1 --- a/imiptools/content.py Wed Jan 28 00:32:44 2015 +0100
1.2 +++ b/imiptools/content.py Wed Jan 28 01:04:24 2015 +0100
1.3 @@ -22,9 +22,11 @@
1.4
1.5 from datetime import datetime, timedelta
1.6 from email.mime.text import MIMEText
1.7 +from imiptools.config import MANAGER_PATH, MANAGER_URL
1.8 from imiptools.dates import *
1.9 from imiptools.period import have_conflict, insert_period, remove_period
1.10 from pytz import timezone
1.11 +from socket import gethostname
1.12 from vCalendar import parse, ParseError, to_dict
1.13 from vRecurrence import get_parameters, get_rule
1.14 import email.utils
1.15 @@ -277,14 +279,14 @@
1.16 # Dispatch to a handler and obtain any response.
1.17
1.18 handler = cls(details, senders, recipient, messenger)
1.19 - result = methods[method](handler)()
1.20 + results = methods[method](handler)()
1.21
1.22 # Aggregate responses for a single message.
1.23
1.24 - if result:
1.25 - response_method, part = result
1.26 - outgoing = method != response_method
1.27 - all_results.append((outgoing, part))
1.28 + if results:
1.29 + for result in results:
1.30 + outgoing, part = result
1.31 + all_results.append((outgoing, part))
1.32
1.33 return all_results
1.34
1.35 @@ -336,6 +338,15 @@
1.36 finally:
1.37 out.close()
1.38
1.39 +# References to the Web interface.
1.40 +
1.41 +def get_manager_url():
1.42 + url_base = MANAGER_URL or "http://%s/" % gethostname()
1.43 + return "%s/%s" % (url_base.rstrip("/"), MANAGER_PATH.lstrip("/"))
1.44 +
1.45 +def get_object_url(uid):
1.46 + return "%s/%s" % (get_manager_url().rstrip("/"), uid)
1.47 +
1.48 class Handler:
1.49
1.50 "General handler support."
1.51 @@ -363,6 +374,19 @@
1.52 except OSError:
1.53 self.publisher = None
1.54
1.55 + def wrap(self, text, link=True):
1.56 +
1.57 + "Wrap any valid message for passing to the recipient."
1.58 +
1.59 + texts = []
1.60 + texts.append(text)
1.61 + if link:
1.62 + texts.append("If your mail program cannot handle this "
1.63 + "message, you may view the details here:\n\n%s" %
1.64 + get_object_url(self.uid))
1.65 +
1.66 + return [(False, MIMEText("\n".join(texts)))]
1.67 +
1.68 # Access to calendar structures and other data.
1.69
1.70 def get_items(self, name, all=True):