From 1ee2451e8ed9878b58b90ba088b52030c5ce85c7 Mon Sep 17 00:00:00 2001 From: Jani Nikula <jani.nikula@intel.com> Date: Thu, 17 Jan 2019 11:39:07 +0200 Subject: [PATCH] dim: fix message_print_body() for complex multipart messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 v2: only print text/plain (Daniel) Fixes: f9bd24c201de ("dim: Add extract-tags command") Fixes: e98467377af5 ("dim: Dumbest base64 parser ever for apply-pull") Cc: Ville Syrjala <ville.syrjala@linux.intel.com> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Jani Nikula <jani.nikula@intel.com> --- dim | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/dim b/dim index b8a9689..18a0f36 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_type() == 'text/plain': + print(part.get_payload(decode=True)) print_msg(open('$1', 'r')) EOF -- GitLab