Giter Club home page Giter Club logo

letterparser's Issues

Handling of Multipart message fails

Hi,

If a send a simple multipart message and catch it with your micromta code - then pass it to letterparser It fails to decode the parts...

Here is the incoming multipart

{
  recipients: [ '[email protected]' ],
  sender: '[email protected]',
  message: 'Content-Type: multipart/mixed; boundary="--_NmP-79d22631bd047a69-Part_1"\r\n' +
    'From: [email protected]\r\n' +
    'To: [email protected]\r\n' +
    'Subject: New Subject\r\n' +
    'Message-ID: <[email protected]>\r\n' +
    'Date: Tue, 13 Oct 2020 19:12:21 +0000\r\n' +
    'MIME-Version: 1.0\r\n' +
    '\r\n' +
    '----_NmP-79d22631bd047a69-Part_1\r\n' +
    'Content-Type: text/plain; charset=utf-8\r\n' +
    'Content-Transfer-Encoding: 7bit\r\n' +
    '\r\n' +
    'More words I have an attachment\r\n' +
    '----_NmP-79d22631bd047a69-Part_1\r\n' +
    'Content-Type: text/plain; name="c:/temp/foo.txt"\r\n' +
    'Content-Transfer-Encoding: base64\r\n' +
    'Content-Disposition: attachment; filename="c:/temp/foo.txt"\r\n' +
    '\r\n' +
    'U29tZSBzbWFsbCB3b3JkcyB0byB0ZXN0IGF0dGFjaG1lbnQ=\r\n' +
    '----_NmP-79d22631bd047a69-Part_1--'
}

If I add some debug I can that for some reason in line 43 of parser.js you do

    var split = value
        .toLowerCase()

which then ends up with parameters['boundary'] being all lower case which for the message above you can see is not the case... so I'm not sure why you make it all lowercase ?

However If I remove that then I do get a return object with multiple "body"s - but they are both empty strings.... so something else is also not working...

Many thanks

PS the email above was generated using nodemailer, in case that matters.

Multipart type lacking boundary at line 1

While looking for an example of #8 I came across this issue.

I get the error Error: Multipart type lacking boundary at line 1 when parsing this email.

var letterparser = require("letterparser")

letterparser.extract(`MIME-Version: 1.0
Content-Type: multipart/alternative; boundary=mk-c744386e165c44ecbb696782a4f930f1; charset=UTF-8

--mk-c744386e165c44ecbb696782a4f930f1
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable


Hey, glad you're checking out Buttondown :)

Please let me know if you need any help getting set up, or have any questio=
ns or
feature requests!  I'd be more than happy to help =E2=80=94 I also offer co=
ncierge
onboarding, so if you need any help migrating back issues or existing
subscribers from Mailchimp/Tinyletter/whatever, I'd be happy to do that
free of charge.

Some stuff coming down the pipeline in the next month or so:

   - A new, cleaner writing interface
   - Improved accessibility
   - Internationalization

Also, if you wanna keep up to date with new features, feel free to [sign up=
 for our newsletter](https://newsletter.buttondown.email).

---

If you're interested in supporting Buttondown's development, please conside=
r:

- Signing up for our premium newsletter, [Weeknotes](https://weeknotes.butt=
ondown.email), for $4/month.
- Upgrading to **Buttondown for Professionals** for $29/month, which gives =
you access to custom domain support,
  custom URLs, removed branding, [and more](https://buttondown.email/pricin=
g).

(Don't worry, this is exactly the _only_ time I'll be obnoxious and ask for=
 money.)

---

Have a great rest of your day, and don't hesitate to reach out!

(Seriously, replies go straight to my inbox, and I love getting email.)



=E2=80=94 Justin from Buttondown

--mk-c744386e165c44ecbb696782a4f930f1
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<p>Hey, glad you're checking out Buttondown :)</p>
<p>Please let me know if you need any help getting set up, or have any ques=
tions or
feature requests!  I'd be more than happy to help =E2=80=94 I also offer co=
ncierge
onboarding, so if you need any help migrating back issues or existing
subscribers from Mailchimp/Tinyletter/whatever, I'd be happy to do that
free of charge.</p>
<p>Some stuff coming down the pipeline in the next month or so:</p>
<ul>
<li>A new, cleaner writing interface</li>
<li>Improved accessibility</li>
<li>Internationalization</li>
</ul>
<p>Also, if you wanna keep up to date with new features, feel free to <a hr=
ef=3D"https://click.pstmrk.it/2s/newsletter.buttondown.email/nIZRcCEN/bP1H/=
xUofLUDTvI">sign up for our newsletter</a>.</p>
<hr />
<p>If you're interested in supporting Buttondown's development, please cons=
ider:</p>
<ul>
<li>Signing up for our premium newsletter, <a href=3D"https://click.pstmrk.=
it/2s/weeknotes.buttondown.email/nYZRcCEN/bP1H/jcp5Gv4YsO">Weeknotes</a>, f=
or $4/month.</li>
<li>Upgrading to <strong>Buttondown for Professionals</strong> for $29/mont=
h, which gives you access to custom domain support,
  custom URLs, removed branding, <a href=3D"https://click.pstmrk.it/2s/butt=
ondown.email%2Fpricing/noZRcCEN/bP1H/blpKM8YX7W">and more</a>.</li>
</ul>
<p>(Don't worry, this is exactly the <em>only</em> time I'll be obnoxious a=
nd ask for money.)</p>
<hr />
<p>Have a great rest of your day, and don't hesitate to reach out!</p>
<p>(Seriously, replies go straight to my inbox, and I love getting email.)<=
/p>
<p>=E2=80=94 Justin from Buttondown</p><img src=3D"https://ea.pstmrk.it/ope=
n/v3_P-aeGHPIISH2BUXSOKKE4BZp-HanwtEbCgvz_6SycY51mHCcxUHOM85uyh6H9kTAY83tF7=
FcGzesFhWcsoQUxX_bkz657r-Mu7gf4s-H0h0ll32WCOvCfka8Z9HK28lEoeZ4rlqXLYj47t1rs=
F9NuM9DIzqXc-Ec4jIHY1Rzi_I3h0MFf0aGpRRrbnHrEuwtmkh-qj9HA1tE0rAa_RApixCXRjIt=
dTJVD00bhrsDEKw-Jv1WDsFIgAFS4ILlOpDagKNMk8GQ4mlvMN61Wh-irfULUNzsX2WvTI9fLy4=
8eRfLTkUPDzaT7uwbQmRGND9u4Ci2p9K4EHYw3sVp_flfID3Tr0oF-66UTW5JsoEc1xGihmDi9-=
XCyInt-k3dyb7thdztb9vlFYiTmPIyBj_dRkZe4o6SuV6wBcPeeL6V6vupwRITgKjS-otoDKWWj=
dbKkGdrktwpA97et4monhRmNQ" width=3D"1" height=3D"1" border=3D"0" alt=3D"" /=
>
--mk-c744386e165c44ecbb696782a4f930f1--`)

MultiPart message not parsing

Hi, got an odd one here. const result: LetterparserMail = extract(block.Data); is returning result.html wiith the data not being decoded.
e.g.
image

Here's the raw data in JSON:

{
    "Data": "Subject: =?iso-8859-1?Q?Resource_Scheduler:_Appointment_Reminder?=\r\nSender: \"sgmh\" <[email protected]>\r\nFrom: \"sgmh\" <[email protected]>\r\nDate: Thu, 18 Jan 2024 11:42:35 -0500\r\nTo: \"=?iso-8859-1?Q?xxx@xxx=2Eonmicrosoft=2Ecom?=\" <[email protected]>\r\nX-Priority: 3\r\nMIME-Version: 1.0\r\nX-Mailer: JMail 4.5 by Dimac\r\nContent-Type: text/HTML;\r\n\tboundary=\"--NEXT_BM_4AF3382FC1824F4089035FEF82BF1006\"\r\n\r\nThis is a multipart message in MIME format.\r\n----NEXT_BM_4AF3382FC1824F4089035FEF82BF1006\r\nContent-Type: text/html;\r\n\tcharset=\"iso-8859-1\"\r\nContent-Transfer-Encoding: Quoted-Printable\r\n\r\n<body=3EThis is a system reminder of the following scheduled event<br/=3E<br=\r\n/=3EReservation Title: marce cancelled<br/=3E<br/=3EFriday,&nbsp;January&nbs=\r\np;19,&nbsp;2024&nbsp;from&nbsp;5:00&nbsp;PM&nbsp;until&nbsp;5:30&nbsp;PM&nbs=\r\np;Bolivia<br/=3E<br/Location: Andreina; Exchange; ex148<br/=3E<br/=3E     Cu=\r\nrrent Resources: Exchange - ex148<br/=3E<br/=3E     Reservation Link: https:=\r\n//sgmh=2Exxx=2Ecom/ResourceScheduler/scheddtl=2Easp=3FID=3D-1999927282<=\r\nbr/=3E<br/=3E     Options:<br/=3E - No Options - <br/=3E<br/=3E     Thank yo=\r\nu,<br/=3E<br/=3E     Resource Scheduler<br/=3E<br/=3E     Copyright =A9 2000=\r\n-2023 rights reserved=2E</body=3E\r\n\r\n----NEXT_BM_4AF3382FC1824F4089035FEF82BF1006\r\nContent-Type: application/octet-stream; name=\"=?iso-8859-1?Q?Test=2Edocx?=\"\r\nContent-Transfer-Encoding: base64\r\nContent-Description: =?iso-8859-1?Q?Test=2Edocx?=\r\nContent-Disposition: attachment; filename=\"=?iso-8859-1?Q?Test=2Edocx?=\"\r\nContent-ID: <390879B749BA4BE49C72D69BED1D4F2E>\r\n\r\nUEsDBBQACAAIAKGNL1gAAAAAAAAAAAAAAAALAAAAX3JlbHMvLnJlbHONjzsO\r\nwjAQRK9ibU82UCCE4qRB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aZXZGmBv\r\nKpcX5Ykj56gMk/+ATFFx8Sbb6L9bYDk7wMtXWOdufLncS/cFUEsHCP9ia7rz\r\nAAAAXQIAAFBLAQItABQACAAIAKGNL1hPi908pgAAABwBAAALAAAAAAAAAAAA\r\nAAAAAAAAAABfcmVscy8ucmVsc1BLAQItABQACAAIAKGNL1jc8wDAtgAAAJYB\r\nAAAcAAAAAAAAAAAAAAAAAN8AAAB3b3JkL19yZWxzL2RvY3VtZW50LnhtbC5y\r\nZWxzUEsBAi0AFAAIAAgAoY0vWGdUNTGXAQAAbyAAABEAAAAAAAAAAAAAAAAA\r\n3wEAAHdvcmQvZG9jdW1lbnQueG1sUEsBAi0AFAAIAAgAoY0vWCwxv3F8AAAA\r\njQAAABIAAAAAAAAAAAAAAAAAtQMAAHdvcmQvbnVtYmVyaW5nLnhtbFBLAQIt\r\nABQACAAIAKGNL1ivU8hBeQAAAIoAAAAPAAAAAAAAAAAAAAAAAHEEAAB3b3Jk\r\nL3N0eWxlcy54bWxQSwECLQAUAAgACAChjS9Y/2JruvMAAABdAgAAEwAAAAAA\r\nAAAAAAAAAAAnBQAAW0NvbnRlbnRfVHlwZXNdLnhtbFBLBQYAAAAABgAGAIAB\r\nAABbBgAAAAA=\r\n\r\n\r\n----NEXT_BM_4AF3382FC1824F4089035FEF82BF1006--\r\n\r\n",
}

Unable to parse emails from outlook

I am unable to parse emails from outlook. This is the stack trace for the corresponding.
Error: Unexpected space at the beginning of line 51 at parseHeaders (/home/example/node_modules/letterparser/lib/parser.js:95:23) at Object.parseBody (/home/example/node_modules/letterparser/lib/parser.js:135:21) at parse (/home/example/node_modules/letterparser/lib/index.js:32:30)

Unable to parse emails from yahoo mail

Getting the below error while parsing email from yahoo.

TypeError: Cannot read property 'startsWith' of undefined at parseContentType (/home/arun/workspace/vidwaan-api/node_modules/letterparser/lib/parser.js:56:29) at Object.parseBody (/home/arun/workspace/vidwaan-api/node_modules/letterparser/lib/parser.js:136:22) at Object.parse (/home/arun/workspace/vidwaan-api/node_modules/letterparser/lib/index.js:32:30)

Content-Type "name" attribute not recognized

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/[email protected]/node_modules/letterparser/lib/esm/parser.js:133:15)
       at parseBody (/Users/samh/Sites/receipt-bot/node_modules/.pnpm/[email protected]/node_modules/letterparser/lib/esm/parser.js:172:51)
       at parse (/Users/samh/Sites/receipt-bot/node_modules/.pnpm/[email protected]/node_modules/letterparser/lib/esm/index.js:13:24)
       at extract (/Users/samh/Sites/receipt-bot/node_modules/.pnpm/[email protected]/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
...

Error when parsing strange Content-Type header

letterparser currently cannot parse this Content-Type:

Content-Type: text/plain; charset = "utf-8"

This Content-Type is found in email sent by QQ Mail SMTP server (but don't know how to trigger that exactly)

I checked the code and after const parameterSplit = parameter.split('=');, letterparser trimed the header name, but didn't trim the header value, causing the fail

Can letterparser be used on the frontend?

I'm looking for a solution that would enable email parsing on the client side. Is it possible with letterparser? Should I look elsewhere? Do you believe some additional work could enable it (which I would then be inclined to try to bring into the project)?

Thanks

Base-64 parsing error

Thanks for an interesting project.

I had trouble parsing a message with a base64-encoded attachment - it was throwing an exception about the length not being a multiple of 4. What worked for me as a quick hack was to strip line breaks from the string before decoding it.

diff --git a/node_modules/letterparser/lib/parser.js b/node_modules/letterparser/lib/parser.js
index 487ecd9..657f4ca 100644
--- a/node_modules/letterparser/lib/parser.js
+++ b/node_modules/letterparser/lib/parser.js
@@ -225,6 +225,9 @@ function parseBody(depth, lines, lineStartIdx, lineEndIdx, lookaheadBoundaryLine
                     case 'base64':
                         {
                             var decoder = new TextDecoder(parsedType.encoding);
+                            stringBody = stringBody.replace(/\r?\n|\r/, '')
                             body = decoder.decode(base64_js_1.toByteArray(stringBody));
                         }
                         break;
@@ -236,8 +239,10 @@ function parseBody(depth, lines, lineStartIdx, lineEndIdx, lookaheadBoundaryLine
             else {
                 switch (headers['Content-Transfer-Encoding'].toLowerCase()) {
                     case 'base64':
-                        body = base64_js_1.toByteArray(stringBody);
-                        break;
+                      stringBody = stringBody.replace(/\r?\n|\r/, '')
+                      body = base64_js_1.toByteArray(stringBody);
+
+                      break;
                     case 'quoted-printable':
                         body = lettercoder_1.decodeQuotedPrintable(stringBody, parsedType.encoding);
                         break;

That's probably not a full fix, so I've not created a PR, but perhaps it's helpful.

AMP for Email support

It'd be awesome to have native support for the text/x-amp-html mime part treated like text and HTML.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.