From da49ac5b1e1e11878c3fdf9c58c1d24a0354f158 Mon Sep 17 00:00:00 2001 From: ashiire <31418397+ashiire@users.noreply.github.com> Date: Wed, 11 Jan 2023 12:20:51 +0100 Subject: [PATCH 1/3] improve named part/attachment detection will now detect filenames for parts if the part specifies Content-Disposition without a filename parameter and Content-Type with a name parameter --- mshow.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mshow.c b/mshow.c index 1cd2cbc..b4463e9 100644 --- a/mshow.c +++ b/mshow.c @@ -158,11 +158,11 @@ mime_filename(struct message *msg) static char buf[512]; char *v; char *filename = 0; - - if ((v = blaze822_hdr(msg, "content-disposition"))) { - if (blaze822_mime2231_parameter(v, "filename", - buf, sizeof buf, "UTF-8")) - filename = buf; + + if ((v = blaze822_hdr(msg, "content-disposition")) && + blaze822_mime2231_parameter(v, "filename", + buf, sizeof buf, "UTF-8")) { + filename = buf; } else if ((v = blaze822_hdr(msg, "content-type"))) { if (blaze822_mime2231_parameter(v, "name", buf, sizeof buf, "UTF-8")) From 52dbd42252147a1b2c9d6e58d04be2ea0c6aea1a Mon Sep 17 00:00:00 2001 From: ashiire <31418397+ashiire@users.noreply.github.com> Date: Wed, 11 Jan 2023 12:20:51 +0100 Subject: [PATCH 2/3] improve named part/attachment detection will now detect filenames for parts if the part specifies Content-Disposition without a filename parameter and Content-Type with a name parameter --- mshow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mshow.c b/mshow.c index b4463e9..d0871f2 100644 --- a/mshow.c +++ b/mshow.c @@ -158,7 +158,7 @@ mime_filename(struct message *msg) static char buf[512]; char *v; char *filename = 0; - + if ((v = blaze822_hdr(msg, "content-disposition")) && blaze822_mime2231_parameter(v, "filename", buf, sizeof buf, "UTF-8")) { From ef0406d94baab08d3b6e737790aeff504de58e69 Mon Sep 17 00:00:00 2001 From: nay Date: Wed, 16 Aug 2023 16:50:05 +0200 Subject: [PATCH 3/3] t/1702-mshow-attachments.t: add tests for named part/attachment detection --- t/1702-mshow-attachments.t | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 t/1702-mshow-attachments.t diff --git a/t/1702-mshow-attachments.t b/t/1702-mshow-attachments.t new file mode 100755 index 0000000..73f2517 --- /dev/null +++ b/t/1702-mshow-attachments.t @@ -0,0 +1,53 @@ +#!/bin/sh -e +cd ${0%/*} +. ./lib.sh +plan 2 + +# Different naming scenarios for named parts +cat <tmp +Content-Type: multipart/mixed; boundary=----_NextPart_000_00DE_01D6A2E8.A7446C80 + +------_NextPart_000_00DE_01D6A2E8.A7446C80 + +no header, part is not attachment +------_NextPart_000_00DE_01D6A2E8.A7446C80 +Content-Type: text/plain; charset=UTF-8 + +CT w/o name, part is not attachment +------_NextPart_000_00DE_01D6A2E8.A7446C80 +Content-Type: text/plain; charset=UTF-8; name="ctn.txt" + +CT with name, part is attachment +------_NextPart_000_00DE_01D6A2E8.A7446C80 +Content-Disposition: attachment + +CD w/o filename, part is not attachment +------_NextPart_000_00DE_01D6A2E8.A7446C80 +Content-Type: text/plain; charset=UTF-8 +Content-Disposition: attachment + +CD w/o filename, CT w/o name, part is not attachment +------_NextPart_000_00DE_01D6A2E8.A7446C80 +Content-Type: text/plain; charset=UTF-8; name="cd_ctn.txt" +Content-Disposition: attachment + +CD w/o filename, CT with name, part is attachment +------_NextPart_000_00DE_01D6A2E8.A7446C80 +Content-Disposition: attachment; filename="cdf.txt" + +CD with filename, part is attachment +------_NextPart_000_00DE_01D6A2E8.A7446C80 +Content-Type: text/plain; charset=UTF-8; name="cdf_ct.txt" +Content-Disposition: attachment + +CD with filename, CT w/o name, part is attachment +------_NextPart_000_00DE_01D6A2E8.A7446C80 +Content-Type: text/plain; charset=UTF-8; name="cdf_ctn.txt" +Content-Disposition: attachment; filename="cdf_ctn.txt" + +CD with filename, CT with name, part is attachment +------_NextPart_000_00DE_01D6A2E8.A7446C80-- +EOF + +check 'mail has 10 parts' 'mshow -t ./tmp | wc -l | grep 11' +check 'mail has 5 named parts/attachments' 'mshow -t ./tmp | grep .*name=\".*\" | wc -l | grep 5'