Skip to content
Snippets Groups Projects

[VCL] Sign generated v-card upon using a profile

Merged Damyan Mitev requested to merge 31-sign-generated-v-card-upon-using-a-profile into master
Files
3
@@ -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++) {
@@ -122,9 +129,34 @@ export function fixNewLines(mime) {
return mime.replace(newline, "\r\n");
}
export function extractMessageID(mime) {
if (mime.startsWith("\r\n")) {
mime = mime.substring(2); //should not happen
}
const headersEndIndex = mime.indexOf("\r\n\r\n"); //the first empty line
if (headersEndIndex < 0) {
return null;
}
const mimeHeaders = mime.substring(0, headersEndIndex);
const headers = libmime.decodeHeaders(mimeHeaders);
let messageId = headers["message-id"];
if (Array.isArray(messageId) && messageId.length > 0) {
messageId = messageId[0];
}
if (messageId && typeof messageId === "string") {
messageId = messageId.replace(/^</, '').replace(/>$/, '');
return messageId;
}
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
@@ -135,9 +167,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);
@@ -156,7 +188,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
@@ -213,7 +247,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 &&
@@ -230,10 +264,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);
}
@@ -351,5 +385,6 @@ export function getAttachment(mime, part) {
base64 = window.btoa(body);
}
return { contentType, base64 };
return { contentType,
base64 };
}
Loading