[CalendarServer-changes] [7889] CalendarServer/branches/users/glyph/imip-and-admin-html/ twistedcaldav/mail.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Aug 11 21:38:05 PDT 2011


Revision: 7889
          http://trac.macosforge.org/projects/calendarserver/changeset/7889
Author:   glyph at apple.com
Date:     2011-08-11 21:38:05 -0700 (Thu, 11 Aug 2011)
Log Message:
-----------
move plain text message part rendering out to a function too

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/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:37:54 UTC (rev 7888)
+++ CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/mail.py	2011-08-12 04:38:05 UTC (rev 7889)
@@ -189,8 +189,14 @@
             inviteLabel = inviteLabel,
         )
 
-    return subjectFormatString, labels
+        # The translations we get back from gettext are utf-8 encoded
+        # strings, so convert to unicode
+        for key in labels.keys():
+            if isinstance(labels[key], str):
+                labels[key] = labels[key].decode("utf-8")
 
+    return subjectFormatString.decode("utf-8"), labels
+
 #
 # Mail gateway service config
 #
@@ -1252,7 +1258,7 @@
         # The translations we get back from gettext are utf-8 encoded strings,
         # so convert to unicode.
 
-        details['subject'] = msg['Subject'] = subjectFormat.decode('utf-8') % {
+        details['subject'] = msg['Subject'] = subjectFormat % {
             'summary' : details['summary']
         }
 
@@ -1265,33 +1271,8 @@
             msgAlt = MIMEMultipart("alternative")
             msg.attach(msgAlt)
 
-            plainAttendeeList = []
-            for cn, mailto in attendees:
-                if cn:
-                    plainAttendeeList.append(cn if not mailto else
-                        "%s <%s>" % (cn, mailto))
-                elif mailto:
-                    plainAttendeeList.append("<%s>" % (mailto,))
-
-            details['plainAttendees'] = ", ".join(plainAttendeeList)
-
-            details['plainOrganizer'] = (orgCN if not orgEmail else
-                "%s <%s>" % (orgCN, orgEmail))
-
-            # The translations we get back from gettext are utf-8 encoded
-            # strings, so convert to unicode
-            for key in details.keys():
-                if isinstance(details[key], str):
-                    details[key] = details[key].decode("utf-8")
-
-            # plain text version
-            if canceled:
-                plainTemplate = plainCancelTemplate
-            else:
-                plainTemplate = plainInviteTemplate
-
-            plainText = plainTemplate % details
-
+            plainText = self.renderPlainText(details, (orgCN, orgEmail),
+                                             attendees, canceled)
             msgPlain = MIMEText(plainText.encode("UTF-8"), "plain", "UTF-8")
             msgAlt.attach(msgPlain)
 
@@ -1333,6 +1314,33 @@
         return msgId, msg.as_string()
 
 
+    def renderPlainText(self, details, (orgCN, orgEmail), attendees, canceled):
+        """
+        Render text/plain message part based on invitation details and a flag
+        indicating whether the message is a cancellation.
+        """
+        plainAttendeeList = []
+        for cn, mailto in attendees:
+            if cn:
+                plainAttendeeList.append(cn if not mailto else
+                    "%s <%s>" % (cn, mailto))
+            elif mailto:
+                plainAttendeeList.append("<%s>" % (mailto,))
+
+        details['plainAttendees'] = ", ".join(plainAttendeeList)
+
+        details['plainOrganizer'] = (orgCN if not orgEmail else
+            "%s <%s>" % (orgCN, orgEmail))
+
+        # plain text version
+        if canceled:
+            plainTemplate = plainCancelTemplate
+        else:
+            plainTemplate = plainInviteTemplate
+
+        return plainTemplate % details
+
+
     def renderHTML(self, details, organizer, attendees, canceled):
         """
         Render HTML message part based on invitation details and a flag
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110811/9d748e27/attachment-0001.html>


More information about the calendarserver-changes mailing list