[CalendarServer-changes] [3280] CalendarServer/branches/users/sagen/localization-3218/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Thu Oct 30 12:16:16 PDT 2008
Revision: 3280
http://trac.macosforge.org/projects/calendarserver/changeset/3280
Author: sagen at apple.com
Date: 2008-10-30 12:16:16 -0700 (Thu, 30 Oct 2008)
Log Message:
-----------
HTML templates for invites are read from files (directory specified in config.py). If file doesn't exist, a simple built-in template will be used. If HTML template doesn't reference the calendar icon, the icon image is not attached to the email.
Modified Paths:
--------------
CalendarServer/branches/users/sagen/localization-3218/twistedcaldav/config.py
CalendarServer/branches/users/sagen/localization-3218/twistedcaldav/mail.py
Modified: CalendarServer/branches/users/sagen/localization-3218/twistedcaldav/config.py
===================================================================
--- CalendarServer/branches/users/sagen/localization-3218/twistedcaldav/config.py 2008-10-30 19:06:29 UTC (rev 3279)
+++ CalendarServer/branches/users/sagen/localization-3218/twistedcaldav/config.py 2008-10-30 19:16:16 UTC (rev 3280)
@@ -228,7 +228,8 @@
"Password" : "", # For account receving mail
},
"AddressPatterns" : [], # Reg-ex patterns to match iMIP-able calendar user addresses
- "MailIconsDirectory": "/usr/share/caldavd/images", # Directory containing date-specific icons for email invitations
+ "MailTemplatesDirectory": "/usr/share/caldavd/templates", # Directory containing HTML templates for email invitations (invite.html, cancel.html)
+ "MailIconsDirectory": "/usr/share/caldavd/images", # Directory containing date-specific icons for email invitations (cal-icon-mm-dd.tiff)
},
},
Modified: CalendarServer/branches/users/sagen/localization-3218/twistedcaldav/mail.py
===================================================================
--- CalendarServer/branches/users/sagen/localization-3218/twistedcaldav/mail.py 2008-10-30 19:06:29 UTC (rev 3279)
+++ CalendarServer/branches/users/sagen/localization-3218/twistedcaldav/mail.py 2008-10-30 19:16:16 UTC (rev 3280)
@@ -484,7 +484,7 @@
calendar = ical.Component.fromString(request.content.read())
headers = request.getAllHeaders()
self.mailer.outbound(headers['originator'], headers['recipient'],
- calendar, language='fr')
+ calendar, language='en')
# TODO: what to return?
return """
@@ -752,12 +752,11 @@
msg["Message-ID"] = msgId
cancelled = (calendar.propertyValue("METHOD") == "CANCEL")
- msg["Subject"] = (
- _("Event cancelled") if cancelled else
- _("Event invitation: %(summary)s") % {
- 'summary' : details['summary']
- }
- )
+ formatString = (_("Event cancelled: %(summary)s") if cancelled else
+ _("Event invitation: %(summary)s"))
+ details['subject'] = msg['Subject'] = formatString % {
+ 'summary' : details['summary']
+ }
msgAlt = MIMEMultipart("alternative")
msg.attach(msgAlt)
@@ -788,9 +787,17 @@
"%s <%s>" % (orgCN, orgEmail))
# plain text version
- plainTemplate = u"""%(inviteLabel)s: %(summary)s
+ if cancelled:
+ plainTemplate = u"""%(subject)s
%(orgLabel)s: %(plainOrganizer)s
+%(dateLabel)s: %(dateInfo)s %(recurrenceInfo)s
+%(timeLabel)s: %(timeInfo)s %(durationInfo)s
+"""
+ else:
+ plainTemplate = u"""%(subject)s
+
+%(orgLabel)s: %(plainOrganizer)s
%(locLabel)s: %(location)s
%(dateLabel)s: %(dateInfo)s %(recurrenceInfo)s
%(timeLabel)s: %(timeInfo)s %(durationInfo)s
@@ -798,12 +805,7 @@
%(attLabel)s: %(plainAttendees)s
"""
- # TODO: work on cancellations
- if cancelled:
- plainText = _("Event cancelled")
- else:
- # print plainTemplate, details
- plainText = plainTemplate % details
+ plainText = plainTemplate % details
msgPlain = MIMEText(plainText.encode("UTF-8"), "plain", "UTF-8")
msgAlt.attach(msgPlain)
@@ -831,10 +833,34 @@
details['iconName'] = iconName
- htmlTemplate = u"""<html>
+ templateDir = config.Scheduling["iMIP"]["MailTemplatesDirectory"].rstrip("/")
+ templateName = "cancel.html" if cancelled else "invite.html"
+ templatePath = os.path.join(templateDir, templateName)
+
+ if not os.path.exists(templatePath):
+ # Fall back to built-in simple templates:
+ if cancelled:
+
+ htmlTemplate = u"""<html>
<body><div>
- <img src="cid:%(iconName)s"/>
+ <h1>%(subject)s</h1>
+ <p>
+ <h3>%(orgLabel)s:</h3> %(htmlOrganizer)s
+ </p>
+ <p>
+ <h3>%(dateLabel)s:</h3> %(dateInfo)s %(recurrenceInfo)s
+ </p>
+ <p>
+ <h3>%(timeLabel)s:</h3> %(timeInfo)s %(durationInfo)s
+ </p>
+
+ """
+
+ else:
+
+ htmlTemplate = u"""<html>
+ <body><div>
<p>%(inviteLabel)s</p>
<h1>%(summary)s</h1>
@@ -858,26 +884,30 @@
</p>
"""
- if cancelled:
- htmlText = _("Event cancelled")
- else:
- htmlText = htmlTemplate % details
+ else: # HTML template file exists
+ with open(templatePath) as templateFile:
+ htmlTemplate = templateFile.read()
+
+ htmlText = htmlTemplate % details
+
self.log_info(htmlText)
msgHtml = MIMEText(htmlText.encode("UTF-8"), "html", "UTF-8")
msgHtmlRelated.attach(msgHtml)
# an image for html version
- iconFile = open(iconPath)
- msgIcon = MIMEImage(iconFile.read(),
- _subtype='tiff;x-apple-mail-type=stationery;name="%s"' %
- (iconName,))
- iconFile.close()
- msgIcon.add_header("Content-ID", "<%s>" % (iconName,))
- msgIcon.add_header("Content-Disposition", "inline;filename=%s" %
- (iconName,))
- msgHtmlRelated.attach(msgIcon)
+ if os.path.exists(iconPath) and htmlTemplate.find("cid:%(iconName)s") != -1:
+ with open(iconPath) as iconFile:
+ msgIcon = MIMEImage(iconFile.read(),
+ _subtype='tiff;x-apple-mail-type=stationery;name="%s"' %
+ (iconName,))
+
+ msgIcon.add_header("Content-ID", "<%s>" % (iconName,))
+ msgIcon.add_header("Content-Disposition", "inline;filename=%s" %
+ (iconName,))
+ msgHtmlRelated.attach(msgIcon)
+
# the icalendar attachment
self.log_debug("Mail gateway sending calendar body: %s" % (str(calendar)))
msgIcal = MIMEText(str(calendar), "calendar", "UTF-8")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20081030/ab419bd4/attachment-0001.html>
More information about the calendarserver-changes
mailing list