changeset 1152:acf14d68b7c8

mailimport: if template is given in subject, use first we find there (can be at beginning or end), src cosmetics
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 10 Aug 2006 09:45:52 +0200
parents 056cd240cff9
children ad1080735ef8 820518f0118e
files MoinMoin/mail/mailimport.py
diffstat 1 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/mail/mailimport.py	Wed Aug 09 23:08:22 2006 +0200
+++ b/MoinMoin/mail/mailimport.py	Thu Aug 10 09:45:52 2006 +0200
@@ -20,7 +20,7 @@
 # python, at least up to 2.4, ships a broken parser for headers
 from MoinMoin.support.HeaderFixed import decode_header
 
-input = sys.stdin
+infile = sys.stdin
 
 debug = False
 
@@ -114,9 +114,13 @@
             pagename_tpl = msg[addr][0]
 
     if not pagename_tpl:
-        m = re_subject.match(msg['subject'])
+        subj = msg['subject'].strip()
+        m = re_subject.search(subj)
         if m:
             pagename_tpl = m.group(1)
+            # remove the pagename template from the subject:
+            subj = re_subject.sub('', subj, 1).strip()
+        msg['subject'] = subj
     else:
         # special fix for outlook users :-)
         if pagename_tpl[-1] == pagename_tpl[0] == "'":
@@ -151,11 +155,11 @@
         to the wiki. """
     return import_mail_from_message(request, email.message_from_string(string))
 
-def import_mail_from_file(request, input):
-    """ Reads an RFC 822 compliant message from the file `input` and imports it to
+def import_mail_from_file(request, infile):
+    """ Reads an RFC 822 compliant message from the file `infile` and imports it to
         the wiki. """
 
-    return import_mail_from_message(request, email.message_from_file(input))
+    return import_mail_from_message(request, email.message_from_file(infile))
 
 def import_mail_from_message(request, message):
     """ Reads a message generated by the email package and imports it
@@ -238,14 +242,14 @@
         table_header = (u"\n\n## mail_overview (don't delete this line)\n" +
                         u"|| '''[[GetText(From)]] ''' || '''[[GetText(To)]] ''' || '''[[GetText(Subject)]] ''' || '''[[GetText(Date)]] ''' || '''[[GetText(Link)]] ''' || '''[[GetText(Attachments)]] ''' ||\n"
                        )
+        from_col = msg['from_addr'][0] or msg['from_addr'][1]
+        to_col = msg['to_addr'][0] or msg['to_addr'][1]
+        subj_col = msg['subject']
+        date_col = msg['date']
+        page_col = pagename
+        attach_col = " ".join(attachment_links)
         new_line = u'|| %s || %s || %s || [[DateTime(%s)]] || ["%s"] || %s ||' % (
-            msg['from_addr'][0] or msg['from_addr'][1],
-            msg['to_addr'][0] or msg['to_addr'][1],
-            msg['subject'],
-            msg['date'],
-            pagename,
-            " ".join(attachment_links),
-            )
+                    from_col, to_col, subj_col, date_col, page_col, attach_col)
         if found_table is not None:
             content = "\n".join(old_content[:table_ends] + [new_line] + old_content[table_ends:])
         else:
@@ -263,7 +267,7 @@
     request = RequestCLI(url=url)
 
     try:
-        import_mail_from_file(request, input)
+        import_mail_from_file(request, infile)
     except ProcessingError, e:
         print >>sys.stderr, "An error occured while processing the message:", e.args