changeset 718:7df204e270ff

Mail import - Added support for 8 bit mails, renamed config fields from email_ to mail_import_, added support for DateTime macro, fixed table recognition.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Tue, 23 May 2006 20:38:51 +0200
parents ab91620af608
children da5e56d3f5ca
files MoinMoin/mailimport.py MoinMoin/multiconfig.py MoinMoin/script/xmlrpc/mailimport.py MoinMoin/xmlrpc/ProcessMail.py
diffstat 4 files changed, 17 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/mailimport.py	Tue May 23 20:35:25 2006 +0200
+++ b/MoinMoin/mailimport.py	Tue May 23 20:38:51 2006 +0200
@@ -65,7 +65,7 @@
     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']))))
+    date = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(mktime_tz(parsedate_tz(message['Date']))))
     
     log("Processing mail:\n To: %r\n From: %r\n Subject: %r" % (to_addr, from_addr, subject))
     
@@ -162,8 +162,8 @@
         to the wiki. """
     msg = process_message(message)
 
-    email_subpage_template = request.cfg.email_subpage_template
-    wiki_address = request.cfg.email_wiki_address or request.cfg.mail_from
+    email_subpage_template = request.cfg.mail_import_subpage_template
+    wiki_address = request.cfg.mail_import_wiki_address or request.cfg.mail_from
 
     request.user = user.get_by_email_address(request, msg['from_addr'][1])
     
@@ -174,7 +174,7 @@
     pagename = d['pagename']
     generate_summary = d['generate_summary']
 
-    comment = u"Imported mail from '%s' re '%s'" % (msg['from_addr'][0], msg['subject'])
+    comment = u"Mail: '%s'" % (msg['subject'], )
     
     page = PageEditor(request, pagename, do_editor_backup=0)
     
@@ -239,7 +239,7 @@
         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"
                        )
-        new_line = u'|| %s || %s || %s || %s || ["%s"] || %s ||' % (
+        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'],
@@ -247,7 +247,7 @@
             pagename,
             " ".join(attachment_links),
             )
-        if found_table:
+        if found_table is not None:
             content = "\n".join(old_content[:table_ends] + [new_line] + old_content[table_ends:])
         else:
             content = "\n".join(old_content) + table_header + new_line
--- a/MoinMoin/multiconfig.py	Tue May 23 20:35:25 2006 +0200
+++ b/MoinMoin/multiconfig.py	Tue May 23 20:38:51 2006 +0200
@@ -239,9 +239,6 @@
     }
     edit_locking = 'warn 10' # None, 'warn <timeout mins>', 'lock <timeout mins>'
     edit_rows = 20
-    email_subpage_template = u"$from-$date-$subject" # used for mail import
-    email_wiki_address = None # the e-mail address for e-mails that should go into the wiki
-    email_secret = ""
                 
     hacks = {} # { 'feature1': value1, ... }
                # Configuration for features still in development.
@@ -270,7 +267,11 @@
     mail_login = None # or "user pwd" if you need to use SMTP AUTH
     mail_sendmail = None # "/usr/sbin/sendmail -t -i" to not use SMTP, but sendmail
     mail_smarthost = None
-    mail_from = None # u'Jrgen Wiki <noreply@jhwiki.org>'
+    mail_from = None # u'Juergen Wiki <noreply@jhwiki.org>'
+
+    mail_import_subpage_template = u"$from-$date-$subject" # used for mail import
+    mail_import_wiki_address = None # the e-mail address for e-mails that should go into the wiki
+    mail_import_secret = ""
     
     navi_bar = [u'RecentChanges', u'FindPage', u'HelpContents', ]
     nonexist_qm = 0
--- a/MoinMoin/script/xmlrpc/mailimport.py	Tue May 23 20:35:25 2006 +0200
+++ b/MoinMoin/script/xmlrpc/mailimport.py	Tue May 23 20:38:51 2006 +0200
@@ -32,7 +32,7 @@
         
         s = xmlrpclib.ServerProxy(url)
 
-        result = s.ProcessMail(secret, input.read())
+        result = s.ProcessMail(secret, xmlrpclib.Binary(input.read()))
         
         if result != "OK":
             print >>sys.stderr, result
--- a/MoinMoin/xmlrpc/ProcessMail.py	Tue May 23 20:35:25 2006 +0200
+++ b/MoinMoin/xmlrpc/ProcessMail.py	Tue May 23 20:38:51 2006 +0200
@@ -11,10 +11,12 @@
 def execute(xmlrpcobj, secret, mail):
     request = xmlrpcobj.request
     secret = xmlrpcobj._instr(secret)
-    # hmm, repeated re-encoding looks suboptimal in terms of speed
-    mail = xmlrpcobj._instr(mail).encode("utf-8") 
+    mail = str(mail)
     
-    if request.cfg.email_secret != secret:
+    if not request.cfg.mail_import_secret:
+        return u"No password set"
+    
+    if request.cfg.mail_import_secret != secret:
         return u"Invalid password"
     
     try: