mat-sz / letterparser

✉️ Isomorphic e-mail parser (with MIME support) written in TypeScript.
BSD 3-Clause Clear License
34 stars 4 forks source link

Content-Type "name" attribute not recognized #13

Closed ffxsam closed 7 months ago

ffxsam commented 7 months ago

I received the following error while my app tried to parse an email sent via Gmail:

|  Error: Invalid content type "application/pdf; name="Hulick, Sam_AFPS Fee.pdf"" at line 76
       at parseBody (/Users/samh/Sites/receipt-bot/node_modules/.pnpm/letterparser@0.1.2/node_modules/letterparser/lib/esm/parser.js:133:15)
       at parseBody (/Users/samh/Sites/receipt-bot/node_modules/.pnpm/letterparser@0.1.2/node_modules/letterparser/lib/esm/parser.js:172:51)
       at parse (/Users/samh/Sites/receipt-bot/node_modules/.pnpm/letterparser@0.1.2/node_modules/letterparser/lib/esm/index.js:13:24)
       at extract (/Users/samh/Sites/receipt-bot/node_modules/.pnpm/letterparser@0.1.2/node_modules/letterparser/lib/esm/index.js:5:28)

This is the relevant portion of that raw email:

[headers removed]
MIME-Version: 1.0
From: ...
Date: Mon, 18 Dec 2023 17:19:09 -0600
Message-ID: ...
Subject: test
To: ...
Content-Type: multipart/mixed; boundary="000000000000cb03f1060cd0fa16"

--000000000000cb03f1060cd0fa16
Content-Type: multipart/alternative; boundary="000000000000cb03ee060cd0fa14"

--000000000000cb03ee060cd0fa14
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: base64

4ZCnDQo=
--000000000000cb03ee060cd0fa14
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br></div><div hspace=3D"streak-pt-mark" style=3D"max-heig=
ht:1px"><img alt=3D"" style=3D"width:0px;max-height:0px;overflow:hidden" sr=
c=3D"https://mailfoogae.appspot.com/t?sender=3Dac2FtaEByZWVsY3JhZnRlci5jb20=
%3D&amp;type=3Dzerocontent&amp;guid=3D3ced9fdb-c786-46c9-bb39-9604d4f643ed"=
><font color=3D"#ffffff" size=3D"1">=E1=90=A7</font></div>

--000000000000cb03ee060cd0fa14--
--000000000000cb03f1060cd0fa16
Content-Type: application/pdf; name="Hulick, Sam_AFPS Fee.pdf"
Content-Disposition: attachment; filename="Hulick, Sam_AFPS Fee.pdf"
Content-Transfer-Encoding: base64
Content-ID: <f_lqbjfg490>
X-Attachment-Id: f_lqbjfg490

JVBERi0xLjcNJeLjz9MNCjI0IDAgb2JqCjw8L0ZpbHRlci9GbGF0ZURlY29kZS9GaXJzdCAxNi9M
ZW5ndGggMjE2L04gMy9UeXBlL09ialN0bT4+c3RyZWFtDQpo3qxP0QqCQBD8lf2C9k4tFcKHjCAi
...
mat-sz commented 7 months ago

Resolved in v0.1.3

ffxsam commented 7 months ago

Thanks, @mat-sz, that fix came faster than I'd expected!

Also, now I'm immortalized in the unit tests. 😂