summaryrefslogtreecommitdiff
path: root/loader/lib/parser.py
diff options
context:
space:
mode:
authorMagnus Hagander2013-01-09 17:06:57 +0000
committerMagnus Hagander2013-01-09 17:06:57 +0000
commit6bbfafc102007fe7f7be6de35a6ef55d16cf6640 (patch)
tree4da47657f303c581e6dd3bcb87833ab2f8d1ccf4 /loader/lib/parser.py
parentb0f89ab23c87945965cf2406b8f7b998c9be2534 (diff)
Turn any non-first text/plain parts into attachments
Instead of ignoring them because they're text/plain, only ignore the first one and specifically the one matching our footers. This should deal with the case when there is a textfile attached that has no name.
Diffstat (limited to 'loader/lib/parser.py')
-rw-r--r--loader/lib/parser.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/loader/lib/parser.py b/loader/lib/parser.py
index 033cb1e..5ecc396 100644
--- a/loader/lib/parser.py
+++ b/loader/lib/parser.py
@@ -234,6 +234,7 @@ class ArchivesParser(object):
return None
def get_attachments(self):
+ self.attachments_found_first_plaintext = False
self.recursive_get_attachments(self.msg)
def _clean_filename_encoding(self, filename):
@@ -275,6 +276,7 @@ class ArchivesParser(object):
elif container.get_content_type() == 'multipart/alternative':
# Alternative is not an attachment (we decide)
# It's typilcally plantext + html
+ self.attachments_found_first_plaintext = True
return
elif container.is_multipart():
# Other kinds of multipart, such as multipart/signed...
@@ -301,6 +303,22 @@ class ArchivesParser(object):
if container.has_key('Content-Disposition') and container['Content-Disposition'].startswith('attachment'):
self.attachments.append((self._extract_filename(container), container.get_content_type(), container.get_payload(decode=True)))
return
+ # If we have already found one text/plain part, make all
+ # further text/plain parts attachments
+ if self.attachments_found_first_plaintext:
+ # However, this will also *always* catch the MIME part added
+ # by majordomo with the footer. So if that one is present,
+ # we need to explicitly exclude it again.
+ b = container.get_payload(decode=True)
+ if not self._re_footer.match(b):
+ # We know there is no name for this one
+ self.attachments.append((None, container.get_content_type(), b))
+ return
+
+ # Ok, so this was a plaintext that we ignored. Set the flag
+ # that we have now ignored one, so we'll make the next one
+ # an attachment.
+ self.attachments_found_first_plaintext = True
# No name, and text/plain, so ignore it
re_msgid = re.compile('^\s*<(.*)>\s*')