gmail-mbox-stats
Version:
Nice tool to analyze Gmail MBOX file
143 lines (140 loc) • 4.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.processParsedMail = exports.scanHeaders = void 0;
const gloAccu_1 = require("../gloAccu");
const sweetUtils_1 = require("./sweetUtils");
const statsBuilder_1 = require("./statsBuilder");
const scanHeaders = (headersMap) => {
const headers = headersMap;
const init_From = headers.get("from");
const init_To = headers.get("to");
// const init_deliveredTo = headers.get("delivered-to");
const init_cc = headers.get("cc");
const init_bcc = headers.get("bcc");
//
const init_date = headers.get("date");
const init_messageId = headers.get("message-id");
// for testing:
/*
if ([7, 14].includes(step.v)) {
init_From?.value?.forEach((val, index) => {
// @ts-ignore
val.address = `hidden${index}${step.v}`;
});
}
if ([21].includes(step.v)) {
init_From = undefined;
}
if ([29, 30].includes(step.v)) {
init_From?.value?.forEach((val) => {
// @ts-ignore
val.address = ``;
// val.name = ``;
});
}
*/
// if (
// init_messageId ===
// "<CAA_p-vxkKrYGM+QcZMbjvTkxQ6biC+6zdH4Mcp+bmAYzBXaxfQ@mail.gmail.com>"
// ) {
// console.log("baaa", JSON.stringify([...headers]));
// }
const initialMainInfoForThisMail = {
from: init_From,
to: init_To,
// "delivered-to": init_deliveredTo,
cc: init_cc,
bcc: init_bcc,
//
date: init_date,
["message-id"]: init_messageId,
};
return initialMainInfoForThisMail;
// if (step.v === 23) {
// const rrr = initialMainInfoForThisMail.to?.value;
// if (rrr) {
// rrr.forEach((x) => {
// x.address = undefined;
// });
// }
// const rrr2 = initialMainInfoForThisMail["delivered-to"]?.value;
// if (rrr2) {
// rrr2.forEach((x) => {
// x.address = undefined;
// });
// }
// console.log(initialMainInfoForThisMail["message-id"]);
// }
};
exports.scanHeaders = scanHeaders;
const processParsedMail = (theParsedMail) => {
const initialMainInfoForThisMail = (0, exports.scanHeaders)(theParsedMail.headers);
// MB => million bytes
const sumOfSizesOfAttachmentsOfOneMail = theParsedMail.attachments.reduce((accu, curr) => accu + curr.size, 0) /
1000000;
const countOfAttachmentsInThisMail = theParsedMail.attachments.length;
const zenMainInfoForThisMail = {
from: (0, sweetUtils_1.getZenParticipantsFromFamily)({
family: initialMainInfoForThisMail.from,
step: gloAccu_1.step.succeededV,
familyKind: "from",
messageId: initialMainInfoForThisMail["message-id"],
fromCombiner: false,
}),
// zenTo: combineTwoFamiliesIntoZenArr({
// step: step.v,
// messageId: initialMainInfoForThisMail["message-id"],
// twoFamilies: [
// {
// familyKind: "to",
// participationInfo: initialMainInfoForThisMail.to,
// },
// {
// familyKind: "delivered-to",
// participationInfo: initialMainInfoForThisMail["delivered-to"],
// },
// ],
// }),
zenTo: (0, sweetUtils_1.getZenParticipantsFromFamily)({
family: initialMainInfoForThisMail.to,
step: gloAccu_1.step.succeededV,
familyKind: "to",
messageId: initialMainInfoForThisMail["message-id"],
fromCombiner: false,
}),
cc: (0, sweetUtils_1.getZenParticipantsFromFamily)({
family: initialMainInfoForThisMail.cc,
step: gloAccu_1.step.succeededV,
familyKind: "cc",
messageId: initialMainInfoForThisMail["message-id"],
fromCombiner: false,
}),
bcc: (0, sweetUtils_1.getZenParticipantsFromFamily)({
family: initialMainInfoForThisMail.bcc,
step: gloAccu_1.step.succeededV,
familyKind: "bcc",
messageId: initialMainInfoForThisMail["message-id"],
fromCombiner: false,
}),
//
date: initialMainInfoForThisMail.date,
"message-id": initialMainInfoForThisMail["message-id"],
};
// TODO: maybe for future
/*
handleOneLineOfMailboxIndex({
stepV: step.v,
zenMainInfoForThisMail,
});
*/
//
// maybe more logical for "addOneMailInfoToStats" to be here:
(0, statsBuilder_1.addOneMailInfoToStats)({
oneMail: zenMainInfoForThisMail,
stepN: gloAccu_1.step.succeededV,
//
sumOfSizesOfAttachmentsOfOneMail,
countOfAttachmentsInThisMail,
});
};
exports.processParsedMail = processParsedMail;