changeset 1238:820518f0118e

merge with main
author Franz Pletz <fpletz AT franz-pletz DOT org>
date Thu, 10 Aug 2006 13:28:52 +0200
parents 0a947454dec7 (current diff) acf14d68b7c8 (diff)
children 20f59999e79c
files
diffstat 2 files changed, 25 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/mail/mailimport.py	Thu Aug 10 01:47:41 2006 +0200
+++ b/MoinMoin/mail/mailimport.py	Thu Aug 10 13:28: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
@@ -206,8 +210,7 @@
                 break
 
     # build an attachment link table for the page with the e-mail
-    escape_link = lambda x: x.replace(" ", "%20")
-    attachment_links = [""] + [u"[attachment:%s attachment:%s]" % tuple([escape_link(u"%s/%s" % (pagename, x))] * 2) for x in attachments]
+    attachment_links = [""] + [u'''[attachment:"%s/%s" %s]''' % (pagename, att, att) for att in attachments]
 
     # assemble old page content and new mail body together
     old_content = Page(request, pagename).get_raw_body()
@@ -239,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:
@@ -264,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
 
--- a/MoinMoin/request/__init__.py	Thu Aug 10 01:47:41 2006 +0200
+++ b/MoinMoin/request/__init__.py	Thu Aug 10 13:28:52 2006 +0200
@@ -9,6 +9,12 @@
 
 import os, re, time, sys, cgi, StringIO
 import copy
+
+try:
+    set
+except:
+    from sets import Set as set
+
 from MoinMoin import config, wikiutil, user, caching, error
 from MoinMoin.util import IsWin9x
 
@@ -66,7 +72,7 @@
         elif state is None:
             result = "- (%s)" % state
         else:
-            print "Got state %r" % state
+            #print "Got state %r" % state
             result = "%.3fs (still running)" % (time.time() - self.timings[timer])
         return result