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) {
let boundary = findFirstBoundary(body, from, to);
if (boundary == null) {
return [{ indices: { from: from, to: to }, boundary: previousBondary, leaf: true }];
return [{ indices: { from,
to },
boundary: previousBondary,
leaf: true }];
}
const realBoundary = boundary;
......@@ -74,12 +77,16 @@ function calculateParts(body, from, to, previousBondary) {
for (let i = 0; i < boundaryIndicesLength; i++) {
const startBoundary = boundaryIndices[i];
const endBoundary = body.indexOf("\r\n", startBoundary);
boundaryPairs.push({ start: startBoundary, end: endBoundary });
boundaryPairs.push({ start: startBoundary,
end: endBoundary });
}
let bodies = [];
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++) {
......@@ -123,29 +130,45 @@ export function fixNewLines(mime) {
}
export function extractMessageID(mime) {
debugger;
if (mime.startsWith("\r\n")) {
mime = mime.substring(2); //should not happen
}
debugger;
const headersEndIndex = mime.indexOf("\r\n\r\n"); //the first empty line
if (headersEndIndex < 0) {
return null;
}
debugger;
const mimeHeaders = mime.substring(0, headersEndIndex);
debugger;
const headers = libmime.decodeHeaders(mimeHeaders);
debugger;
let messageId = headers["Message-ID"];
debugger;
if (Array.isArray(messageId) && messageId.length > 0) {
debugger;
messageId = messageId[0];
}
if (messageId && typeof messageId === "string") {
messageId = messageId.replace(/^</, '').replace(/>$/, '');
debugger;
return messageId;
}
debugger;
return null;
}
export function parseMIME(mime) {
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 = "";
if (headersEnd < 0 && mime.startsWith("\r\n")) {
mime = mime.substring(2); //should not happen
......@@ -156,9 +179,9 @@ export function parseMIME(mime) {
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) {
mimeBody = mimeBody.substring(indexOfSMIME + SMIMEStart.length);
......@@ -177,7 +200,9 @@ export function parseMIME(mime) {
}
parts.push({
indices: { from: 0, to: mime.length, headersEnd: headersEnd },
indices: { from: 0,
to: mime.length,
headersEnd },
headers,
boundary: "mimemessage",
leaf: false
......@@ -234,7 +259,7 @@ export function decodeMimeBody(descriptor, mimeString) {
let contentType = getHeaderValue("content-type", descriptor);
if (contentType) {
contentType = contentType[0];
let parsedContentType = libmime.parseHeaderValue(contentType);
const parsedContentType = libmime.parseHeaderValue(contentType);
if (
parsedContentType &&
parsedContentType.params &&
......@@ -251,10 +276,10 @@ export function decodeMimeBody(descriptor, mimeString) {
}
if (contentTransferEncoding.toLowerCase() === "quoted-printable") {
let buff = libqp.decode(mimeBody);
const buff = libqp.decode(mimeBody);
return buff.toString(charset);
} else if (contentTransferEncoding.toLowerCase() === "base64") {
let buff = Buffer.from(mimeBody, "base64");
const buff = Buffer.from(mimeBody, "base64");
return buff.toString(charset);
}
......@@ -372,5 +397,6 @@ export function getAttachment(mime, part) {
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.
Finish editing this message first!
Please register or to comment