From f84b5c5f091e050234e6e55545b22555db659f20 Mon Sep 17 00:00:00 2001 From: kidhab <32387157+kidhab@users.noreply.github.com> Date: Mon, 11 Apr 2022 20:19:59 +0200 Subject: [PATCH] Add check for MIME encoded messages As far as I understand MIME-encoded message can be broken down into parts based upon its contents. While most mail programs add the plain text part as the first part this is not true for all programs. In fact mail2deck couldn't import the body when processing certain plain text mails with attachments - because the plain text part wasn't at position 1.1. With this fix imap_fetchbody requests sub-part 1 of part 1 and, if it is empty/ non-existent, it requests part 1. --- index.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index f73f5e6..bfde88d 100644 --- a/index.php +++ b/index.php @@ -73,11 +73,15 @@ if ($emails) $data->title = DECODE_SPECIAL_CHARACTERS ? mb_decode_mimeheader($overview->subject) : $overview->subject; $data->type = "plain"; $data->order = -time(); + $body = $inbox->fetchMessageBody($emails[$j], 1.1); + if ($body == "") { + $body = $inbox->fetchMessageBody($emails[$j], 1); + } if(count($attachments)) { $data->attachments = $attNames; - $description = DECODE_SPECIAL_CHARACTERS ? quoted_printable_decode($inbox->fetchMessageBody($emails[$j], 1.1)) : $inbox->fetchMessageBody($emails[$j], 1.1); + $description = DECODE_SPECIAL_CHARACTERS ? quoted_printable_decode($body) : $body; } else { - $description = DECODE_SPECIAL_CHARACTERS ? quoted_printable_decode($inbox->fetchMessageBody($emails[$j], 1)) : $inbox->fetchMessageBody($emails[$j], 1); + $description = DECODE_SPECIAL_CHARACTERS ? quoted_printable_decode($body) : $body; } if($base64encode) { $description = base64_decode($description);