Skip to content
Snippets Groups Projects
Commit c5ba9c16 authored by Zdravko Iliev's avatar Zdravko Iliev
Browse files

debugging extract message id

parent cd9bece8
No related branches found
No related tags found
1 merge request!71[VCL] Sign generated v-card upon using a profile
...@@ -61,7 +61,10 @@ function calculateParts(body, from, to, previousBondary) { ...@@ -61,7 +61,10 @@ function calculateParts(body, from, to, previousBondary) {
let boundary = findFirstBoundary(body, from, to); let boundary = findFirstBoundary(body, from, to);
if (boundary == null) { if (boundary == null) {
return [{ indices: { from: from, to: to }, boundary: previousBondary, leaf: true }]; return [{ indices: { from,
to },
boundary: previousBondary,
leaf: true }];
} }
const realBoundary = boundary; const realBoundary = boundary;
...@@ -74,12 +77,16 @@ function calculateParts(body, from, to, previousBondary) { ...@@ -74,12 +77,16 @@ function calculateParts(body, from, to, previousBondary) {
for (let i = 0; i < boundaryIndicesLength; i++) { for (let i = 0; i < boundaryIndicesLength; i++) {
const startBoundary = boundaryIndices[i]; const startBoundary = boundaryIndices[i];
const endBoundary = body.indexOf("\r\n", startBoundary); const endBoundary = body.indexOf("\r\n", startBoundary);
boundaryPairs.push({ start: startBoundary, end: endBoundary }); boundaryPairs.push({ start: startBoundary,
end: endBoundary });
} }
let bodies = []; let bodies = [];
if (previousBondary !== null) { if (previousBondary !== null) {
bodies.push({indices: {from: from, to: to}, boundary: previousBondary, leaf: false}); bodies.push({indices: {from,
to},
boundary: previousBondary,
leaf: false});
} }
for (let i = 0; i < boundaryIndicesLength - 1; i++) { for (let i = 0; i < boundaryIndicesLength - 1; i++) {
...@@ -123,29 +130,45 @@ export function fixNewLines(mime) { ...@@ -123,29 +130,45 @@ export function fixNewLines(mime) {
} }
export function extractMessageID(mime) { export function extractMessageID(mime) {
debugger;
if (mime.startsWith("\r\n")) { if (mime.startsWith("\r\n")) {
mime = mime.substring(2); //should not happen mime = mime.substring(2); //should not happen
} }
debugger;
const headersEndIndex = mime.indexOf("\r\n\r\n"); //the first empty line const headersEndIndex = mime.indexOf("\r\n\r\n"); //the first empty line
if (headersEndIndex < 0) { if (headersEndIndex < 0) {
return null; return null;
} }
debugger;
const mimeHeaders = mime.substring(0, headersEndIndex); const mimeHeaders = mime.substring(0, headersEndIndex);
debugger;
const headers = libmime.decodeHeaders(mimeHeaders); const headers = libmime.decodeHeaders(mimeHeaders);
debugger;
let messageId = headers["Message-ID"]; let messageId = headers["Message-ID"];
debugger;
if (Array.isArray(messageId) && messageId.length > 0) { if (Array.isArray(messageId) && messageId.length > 0) {
debugger;
messageId = messageId[0]; messageId = messageId[0];
} }
if (messageId && typeof messageId === "string") { if (messageId && typeof messageId === "string") {
messageId = messageId.replace(/^</, '').replace(/>$/, ''); messageId = messageId.replace(/^</, '').replace(/>$/, '');
debugger;
return messageId; return messageId;
} }
debugger;
return null; return null;
} }
export function parseMIME(mime) { export function parseMIME(mime) {
let mimeStart = 0; let mimeStart = 0;
let headersEnd = mime.indexOf("\r\n\r\n"); //the first empty line const headersEnd = mime.indexOf("\r\n\r\n"); //the first empty line
let mimeBody = ""; let mimeBody = "";
if (headersEnd < 0 && mime.startsWith("\r\n")) { if (headersEnd < 0 && mime.startsWith("\r\n")) {
mime = mime.substring(2); //should not happen mime = mime.substring(2); //should not happen
...@@ -156,9 +179,9 @@ export function parseMIME(mime) { ...@@ -156,9 +179,9 @@ export function parseMIME(mime) {
mimeStart = headersEnd + 4; mimeStart = headersEnd + 4;
} }
let headers = libmime.decodeHeaders(mime.substring(0, headersEnd)); const headers = libmime.decodeHeaders(mime.substring(0, headersEnd));
let indexOfSMIME = mimeBody.indexOf(SMIMEStart); const indexOfSMIME = mimeBody.indexOf(SMIMEStart);
if (indexOfSMIME >= 0) { if (indexOfSMIME >= 0) {
mimeBody = mimeBody.substring(indexOfSMIME + SMIMEStart.length); mimeBody = mimeBody.substring(indexOfSMIME + SMIMEStart.length);
...@@ -177,7 +200,9 @@ export function parseMIME(mime) { ...@@ -177,7 +200,9 @@ export function parseMIME(mime) {
} }
parts.push({ parts.push({
indices: { from: 0, to: mime.length, headersEnd: headersEnd }, indices: { from: 0,
to: mime.length,
headersEnd },
headers, headers,
boundary: "mimemessage", boundary: "mimemessage",
leaf: false leaf: false
...@@ -234,7 +259,7 @@ export function decodeMimeBody(descriptor, mimeString) { ...@@ -234,7 +259,7 @@ export function decodeMimeBody(descriptor, mimeString) {
let contentType = getHeaderValue("content-type", descriptor); let contentType = getHeaderValue("content-type", descriptor);
if (contentType) { if (contentType) {
contentType = contentType[0]; contentType = contentType[0];
let parsedContentType = libmime.parseHeaderValue(contentType); const parsedContentType = libmime.parseHeaderValue(contentType);
if ( if (
parsedContentType && parsedContentType &&
parsedContentType.params && parsedContentType.params &&
...@@ -251,10 +276,10 @@ export function decodeMimeBody(descriptor, mimeString) { ...@@ -251,10 +276,10 @@ export function decodeMimeBody(descriptor, mimeString) {
} }
if (contentTransferEncoding.toLowerCase() === "quoted-printable") { if (contentTransferEncoding.toLowerCase() === "quoted-printable") {
let buff = libqp.decode(mimeBody); const buff = libqp.decode(mimeBody);
return buff.toString(charset); return buff.toString(charset);
} else if (contentTransferEncoding.toLowerCase() === "base64") { } else if (contentTransferEncoding.toLowerCase() === "base64") {
let buff = Buffer.from(mimeBody, "base64"); const buff = Buffer.from(mimeBody, "base64");
return buff.toString(charset); return buff.toString(charset);
} }
...@@ -372,5 +397,6 @@ export function getAttachment(mime, part) { ...@@ -372,5 +397,6 @@ export function getAttachment(mime, part) {
base64 = window.btoa(body); base64 = window.btoa(body);
} }
return { contentType, base64 }; return { contentType,
base64 };
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment