[Zope3-checkins] CVS: Products3/z3checkins - message.py:1.39

Gintautas Miliauskas gintas at pov.lt
Thu Apr 29 09:40:25 EDT 2004


Update of /cvs-repository/Products3/z3checkins
In directory cvs.zope.org:/tmp/cvs-serv20415

Modified Files:
	message.py 
Log Message:
Converted z3checkins to use 'email' instead of 'rfc822' (which is obsolete).

I18n issues are still not dealt with, but 'email' provides functionality to
deal with them so this shouldn't be too hard to fix.


=== Products3/z3checkins/message.py 1.38 => 1.39 ===
--- Products3/z3checkins/message.py:1.38	Thu Apr 29 08:35:07 2004
+++ Products3/z3checkins/message.py	Thu Apr 29 09:39:54 2004
@@ -8,7 +8,8 @@
 """
 
 import re
-import rfc822
+import email
+import email.Utils
 import mailbox
 import time
 from StringIO import StringIO
@@ -175,34 +176,30 @@
 
         if not hasattr(input, 'readline'):
             full_text = str(input)
-            input = StringIO(full_text)
         elif hasattr(input, 'seek') and hasattr(input, 'tell'):
             old_pos = input.tell()
             full_text = input.read()
             input.seek(old_pos)
         else:
             full_text = input.read()
-            input = StringIO(full_text)
 
-        m = rfc822.Message(input)
-        subject = m.getheader('Subject') or ''
-        subject = subject.replace('\n', '')
-        message_id = m.getheader('Message-Id')
+        m = email.message_from_string(full_text)
+        subject = m.get('Subject', '').replace('\n', '')
+        message_id = m.get('Message-Id', None)
         if message_id is None:
             raise FormatError("Message does not have a message id")
         if message_id[0] == "<" and message_id[-1] == ">":
-            message_id = message_id[1:-1]
-        author = m.getheader('From')
-        author_name, author_email = m.getaddr('From')
-
-        date = m.getheader('Date')
+            message_id = message_id[1:-1] # strip angle brackets
+        author = m.get('From', '')
+        author_name, author_email = email.Utils.parseaddr(author)
+        date = m.get('Date', '')
 
         # Fix incorrect timezones (+XX:XX instead of RFC-822 mandated +XXXX)
         if date[-3] == ':':
             date = date[:-3] + date[-2:]
 
         (year, month, day, hours, minutes, seconds,
-         weekday, yearday, dst, tzoffset) = rfc822.parsedate_tz(date)
+         weekday, yearday, dst, tzoffset) = email.Utils.parsedate_tz(date)
 
         # XXX a workaround to deal with messages that don't specify a timezone
         if tzoffset is None:
@@ -211,7 +208,7 @@
         date = datetime(year, month, day, hours, minutes, seconds,
                         tzinfo=FixedTimezone(tzoffset / 60))
 
-        checkin_info = self.tryToParseCheckinMessage(subject, m, input)
+        checkin_info = self.tryToParseCheckinMessage(subject, m)
         if checkin_info is not None:
             directory, log_message, branch = checkin_info
             return CheckinMessage(message_id=message_id,
@@ -226,11 +223,11 @@
                        author_email=author_email, subject=subject,
                        date=date, full_text=full_text)
 
-    def tryToParseCheckinMessage(self, subject, msg, input):
+    def tryToParseCheckinMessage(self, subject, msg):
         """Detect and parse CVS/Subversion checkin messages.
 
         Returns a tuple (directory, log_message, branch) for checkin
-        messages, and None if message is not a checkin message.
+        messages, and None if the message is not a checkin message.
         """
 
         if subject.startswith("Re:"):
@@ -250,8 +247,7 @@
         else:
             return None
 
-        msg.rewindbody()
-        body_lines = input.readlines()
+        body_lines = msg.get_payload().splitlines()
         try:
             log_message, branch = self.extract_log(body_lines)
         except FormatError:
@@ -271,7 +267,7 @@
                     or line.startswith("Removed:")
                     or line.startswith("Deleted:")
                     or line.startswith("Property changes on:")
-                    or line == "Status:\n"
+                    or line == "Status:"
                     ):
                     break
                 else:
@@ -284,7 +280,7 @@
                     branch = line[len('      Tag: '):].strip()
         if not in_log_msg:
             raise FormatError("Could not find log message")
-        return "".join(log_message).strip(), branch
+        return "\n".join(log_message).strip(), branch
 
 
 class MessageContainerAdapter:




More information about the Zope3-Checkins mailing list