You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
That's probably not a full fix, so I've not created a PR, but perhaps it's helpful.
The text was updated successfully, but these errors were encountered: