changeset 5132:df8f5b4546ca

mailimport: fix endless looping while trying to import a forwarded mail This is just a fix to solve the endless looping / crash. It needs further improvement, currently the From/To/... header data of the forwarded mail is not processed at all and thus not visible later in the wiki. The body of it is visible, though, but just appears appended to the main mail body.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 06 Sep 2009 22:35:50 +0200
parents 4c08211daaaa
children a362cdd8c418
files MoinMoin/mail/mailimport.py
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/mail/mailimport.py	Sun Sep 06 19:36:44 2009 +0200
+++ b/MoinMoin/mail/mailimport.py	Sun Sep 06 22:35:50 2009 +0200
@@ -232,7 +232,8 @@
 
     for att in msg['attachments']:
         i = 0
-        while 1:
+        while i < 1000: # do not create a gazillion attachments if something
+                        # strange happens, give up after 1000.
             if i == 0:
                 fname = att.filename
             else:
@@ -244,13 +245,16 @@
                 else:
                     fname = att.filename + new_suffix
             try:
-                # get the fname again, it might have changed
-                fname, fsize = add_attachment(request, pagename, fname, att.data)
-                attachments.append(fname)
+                # att.data can be None for forwarded message content - we can
+                # just ignore it, the forwarded message's text will be present
+                # nevertheless
+                if att.data is not None:
+                    # get the fname again, it might have changed
+                    fname, fsize = add_attachment(request, pagename, fname, att.data)
+                    attachments.append(fname)
+                break
             except AttachmentAlreadyExists:
                 i += 1
-            else:
-                break
 
     # build an attachment link table for the page with the e-mail
     attachment_links = [""] + [u'''[[attachment:%s|%s]]''' % ("%s/%s" % (pagename, att), att) for att in attachments]