X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=mimedecode.py;h=d239a1fe2234e332cb78b7d96387c687c98c6e70;hb=f0f753ad009f6bd7089e0d6d3fce3ffd111734f5;hp=0714c874863da054c9f9b01f9b0a0e4d7958d551;hpb=fc09d21b965308d826973fd6e897bdc66a406830;p=mimedecode.git diff --git a/mimedecode.py b/mimedecode.py index 0714c87..d239a1f 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -364,9 +364,9 @@ def decode_part(msg): for content_type in masks: if content_type in g.save_headers_mask: _save_message(msg, outstring, save_headers=True, save_body=False) - elif content_type in g.save_body_mask: + if content_type in g.save_body_mask: _save_message(msg, outstring, save_headers=False, save_body=True) - elif content_type in g.save_message_mask: + if content_type in g.save_message_mask: _save_message(msg, outstring, save_headers=True, save_body=True) for content_type in masks: @@ -377,6 +377,26 @@ def decode_multipart(msg): "Decode multipart" decode_headers(msg) + boundary = msg.get_boundary() + + masks = [] + ctype = msg.get_content_type() + if ctype: + masks.append(ctype) + mtype = ctype.split('/')[0] + masks.append(mtype + '/*') + masks.append('*/*') + + for content_type in masks: + if content_type in g.ignore_mask: + output_headers(msg) + output("%sMessage body of type %s skipped.%s" % (os.linesep, ctype, os.linesep)) + if boundary: + output("%s--%s--%s" % (os.linesep, boundary, os.linesep)) + return + elif content_type in g.error_mask: + raise ValueError, "content type %s prohibited" % ctype + output_headers(msg) if msg.preamble: # Preserve the first part, it is probably not a RFC822-message @@ -385,8 +405,6 @@ def decode_multipart(msg): output(os.linesep) first_subpart = True - boundary = msg.get_boundary() - for subpart in msg.get_payload(): if boundary: if first_subpart: