Commit e98467377af5 ("dim: Dumbest base64 parser ever for apply-pull")
broke dim apply-pull for complex multipart messages, such as [1] with
mime structure:

└┬╴multipart/mixed 11398 bytes
 ├┬╴multipart/signed inline 2051 bytes
 │├─╴text/plain inline 1470 bytes
 │└─╴application/pgp-signature [signature.asc] 195 bytes
 └─╴text/plain inline 219 bytes

The problem lies in the original message_print_body() which would not
recurse beyond the first multipart nesting level. Use the message walk()
function to also find the text/plain part within the multipart/signed
part.

[1] http://mid.mail-archive.com/20190117074604.GI18272@zhen-hp.sh.intel.com

Fixes: f9bd24c201de ("dim: Add extract-tags command")
Fixes: e98467377af5 ("dim: Dumbest base64 parser ever for apply-pull")
Cc: Ville Syrjala <ville.syrj...@linux.intel.com>
Cc: Daniel Vetter <daniel.vet...@ffwll.ch>
Signed-off-by: Jani Nikula <jani.nik...@intel.com>
---
 dim | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/dim b/dim
index b8a9689027b6..68285e3239d5 100755
--- a/dim
+++ b/dim
@@ -432,18 +432,11 @@ message_print_body ()
        python2 <<EOF
 import email
 
-def print_part(part):
-    mtype = part.get_content_maintype()
-    if mtype == 'text':
-        print(part.get_payload(decode=True))
-
 def print_msg(file):
     msg = email.message_from_file(file)
-    if msg.is_multipart():
-        for part in msg.get_payload():
-            print_part(part)
-    else:
-        print_part(msg)
+    for part in msg.walk():
+        if part.get_content_maintype() == 'text':
+            print(part.get_payload(decode=True))
 
 print_msg(open('$1', 'r'))
 EOF
-- 
2.20.1

_______________________________________________
dim-tools mailing list
dim-tools@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dim-tools

Reply via email to