Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base-64 parsing error #8

Closed
edwh opened this issue May 23, 2021 · 4 comments
Closed

Base-64 parsing error #8

edwh opened this issue May 23, 2021 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@edwh
Copy link

edwh commented May 23, 2021

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.

@avigoldman
Copy link
Contributor

I've run into a similar issue. I'll try to find an EML file to replicate this issue.

@mat-sz mat-sz self-assigned this May 24, 2021
@mat-sz mat-sz added the bug Something isn't working label May 24, 2021
@mat-sz mat-sz closed this as completed in c683bf9 May 24, 2021
@mat-sz
Copy link
Owner

mat-sz commented May 24, 2021

Thank you for your report, the issue has been resolved in c683bf9 and a new version will be released soon.

@edwh @avigoldman Please reopen if the issue is still present after update.

@mat-sz
Copy link
Owner

mat-sz commented May 24, 2021

Released with 0.0.8.

@edwh
Copy link
Author

edwh commented May 24, 2021

That seems to work for me. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants