[CalendarServer-changes] [7881] CalendarServer/branches/users/glyph/imip-and-admin-html/ twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu Aug 11 21:36:35 PDT 2011


Revision: 7881
          http://trac.macosforge.org/projects/calendarserver/changeset/7881
Author:   glyph at apple.com
Date:     2011-08-11 21:36:35 -0700 (Thu, 11 Aug 2011)
Log Message:
-----------
pull out rendering to a different function

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/mail.py
    CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/test/test_mail.py

Modified: CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/mail.py
===================================================================
--- CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/mail.py	2011-08-12 04:36:23 UTC (rev 7880)
+++ CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/mail.py	2011-08-12 04:36:35 UTC (rev 7881)
@@ -1261,29 +1261,13 @@
 
             details['iconName'] = iconName = "calicon.png"
 
-            templateDir = config.Scheduling.iMIP.MailTemplatesDirectory.rstrip("/")
-            templateName = "cancel.html" if canceled else "invite.html"
-            templatePath = os.path.join(templateDir, templateName)
+            addIcon, htmlText = self.renderHTML(details, canceled)
 
-            if not os.path.exists(templatePath):
-                # Fall back to built-in simple templates:
-                if canceled:
-                    htmlTemplate = htmlCancelTemplate
-                else:
-                    htmlTemplate = htmlInviteTemplate
-            else: # HTML template file exists
-
-                with open(templatePath) as templateFile:
-                    htmlTemplate = templateFile.read()
-
-            htmlText = htmlTemplate % details
-
         msgHtml = MIMEText(htmlText.encode("UTF-8"), "html", "UTF-8")
         msgHtmlRelated.attach(msgHtml)
 
         # an image for html version
-        if (iconPath != None and os.path.exists(iconPath) and
-            htmlTemplate.find("cid:%(iconName)s") != -1):
+        if addIcon and iconPath != None and os.path.exists(iconPath):
 
             with open(iconPath) as iconFile:
                 msgIcon = MIMEImage(iconFile.read(),
@@ -1308,6 +1292,38 @@
         return msgId, msg.as_string()
 
 
+    def renderHTML(self, details, canceled):
+        """
+        Render HTML message part based on invitation details and a flag
+        indicating whether the message is a cancellation.
+
+        @return: a 2-tuple of (should add icon (C{bool}), html text (C{str})).
+            The first element indicates whether the MIME generator needs to add
+            a L{cid:} icon image part to satisfy the HTML links.
+        """
+
+        templateDir = config.Scheduling.iMIP.MailTemplatesDirectory.rstrip("/")
+        templateName = "cancel.html" if canceled else "invite.html"
+        templatePath = os.path.join(templateDir, templateName)
+
+        if not os.path.exists(templatePath):
+            # Fall back to built-in simple templates:
+            if canceled:
+                htmlTemplate = htmlCancelTemplate
+            else:
+                htmlTemplate = htmlInviteTemplate
+        else: # HTML template file exists
+
+            with open(templatePath) as templateFile:
+                htmlTemplate = templateFile.read()
+        htmlText = htmlTemplate % details
+
+        # If the template refers to an icon in a cid: link, it needs to be added
+        # in the MIME.
+        addIcon = (htmlTemplate.find("cid:%(iconName)s") != -1)
+        return (addIcon, htmlText)
+
+
     def getEventDetails(self, calendar, language='en'):
 
         # Get the most appropriate component

Modified: CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/test/test_mail.py
===================================================================
--- CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/test/test_mail.py	2011-08-12 04:36:23 UTC (rev 7880)
+++ CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/test/test_mail.py	2011-08-12 04:36:35 UTC (rev 7881)
@@ -536,6 +536,7 @@
         self.assertIn(expectedHTML, htmlPart)
 
 
+
 def partByType(message, contentType):
     """
     Retrieve a MIME part from an L{email.message.Message} based on a content
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110811/a72d7c88/attachment.html>


More information about the calendarserver-changes mailing list