changeset 700:45cf56e067c5

Added support for looking in cc and bcc.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Tue, 16 May 2006 17:46:42 +0200
parents ea6dab2f43f7
children 276079601342
files MoinMoin/mailimport.py MoinMoin/multiconfig.py
diffstat 2 files changed, 18 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/mailimport.py	Tue May 16 17:16:44 2006 +0200
+++ b/MoinMoin/mailimport.py	Tue May 16 17:46:42 2006 +0200
@@ -64,6 +64,9 @@
    
     to_addr = parseaddr(decode_2044(message['To']))
     from_addr = parseaddr(decode_2044(message['From']))
+    cc_addr = parseaddr(decode_2044(message['Cc']))
+    bcc_addr = parseaddr(decode_2044(message['Bcc']))
+    
     subject = decode_2044(message['Subject'])
     date = time.strftime("%Y-%m-%d %H:%M", time.gmtime(mktime_tz(parsedate_tz(message['Date']))))
     
@@ -94,20 +97,25 @@
             elif ct == 'text/html':
                 html_data.append(payload.decode(cs))
             elif not part.is_multipart():
-                log("Unknown mail part", repr((part.get_charsets(), part.get_content_charset(), part.get_content_type(), part.is_multipart(), )))
+                log("Unknown mail part " + repr((part.get_charsets(), part.get_content_charset(), part.get_content_type(), part.is_multipart(), )))
 
     return {'text': u"".join(text_data), 'html': u"".join(html_data),
-            'attachments': attachments, 'to_addr': to_addr, 'from_addr': from_addr,
+            'attachments': attachments,
+            'to_addr': to_addr, 'from_addr': from_addr, 'cc_addr': cc_addr, 'bcc_addr': bcc_addr,
             'subject': subject, 'date': date}
 
-def get_pagename_content(msg, email_subpage_template):
+def get_pagename_content(msg, email_subpage_template, wiki_address):
     """ Generates pagename and content according to the specification
         that can be found on MoinMoin:FeatureRequests/WikiEMoinMoin\mailintegration """
 
     generate_summary = False
     choose_html = True
     
-    pagename_tpl = msg['to_addr'][0]
+    pagename_tpl = ""
+    for addr in ('to_addr', 'cc_addr', 'bcc_addr'):
+        if msg[addr][1].strip().lower() == wiki_address:
+            pagename_tpl = msg[addr][0]
+
     if not pagename_tpl:
         m = re_subject.match(msg['subject'])
         if m:
@@ -148,13 +156,14 @@
 
     request = RequestCLI(url=url)
     email_subpage_template = request.cfg.email_subpage_template
+    wiki_address = request.cfg.email_wiki_address or request.cfg.mail_from
 
     request.user = user.get_by_email_address(request, msg['from_addr'][1])
     
     if not request.user:
         raise ProcessingError("No suitable user found for mail address %r" % (msg['from_addr'][1], ))
 
-    d = get_pagename_content(msg, email_subpage_template)
+    d = get_pagename_content(msg, email_subpage_template, wiki_address)
     pagename = d['pagename']
     generate_summary = d['generate_summary']
 
@@ -219,10 +228,11 @@
                 table_ends = lineno + 1
         
         table_header = (u"\n\n## mail_overview (don't delete this line)\n" +
-                        u"|| '''[[GetText(From)]] ''' || '''[[GetText(Subject)]] ''' || '''[[GetText(Date)]] ''' || '''[[GetText(Link)]] ''' || '''[[GetText(Attachments)]] ''' ||\n"
+                        u"|| '''[[GetText(From)]] ''' || '''[[GetText(To)]] ''' || '''[[GetText(Subject)]] ''' || '''[[GetText(Date)]] ''' || '''[[GetText(Link)]] ''' || '''[[GetText(Attachments)]] ''' ||\n"
                        )
-        new_line = u'|| %s || %s || %s || ["%s"] || %s ||' % (
+        new_line = u'|| %s || %s || %s || %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,
--- a/MoinMoin/multiconfig.py	Tue May 16 17:16:44 2006 +0200
+++ b/MoinMoin/multiconfig.py	Tue May 16 17:46:42 2006 +0200
@@ -240,6 +240,7 @@
     edit_locking = 'warn 10' # None, 'warn <timeout mins>', 'lock <timeout mins>'
     edit_rows = 20
     email_subpage_template = u"$from-$date-$subj" # used for mail import
+    email_wiki_address = None # the e-mail address for e-mails that should go into the wiki
                 
     hacks = {} # { 'feature1': value1, ... }
                # Configuration for features still in development.