gmail-mbox-stats
Version:
Nice tool to analyze Gmail MBOX file
109 lines (108 loc) • 3.56 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.processOneMail = exports.parseOneMail = void 0;
const mailparser_1 = require("mailparser");
const mailHeadersUtils_1 = require("./mailHeadersUtils");
const gloAccu_1 = require("../gloAccu");
const print000SuccessCount = () => {
// just for CLI visualization:
const curr = gloAccu_1.step.succeededV;
const asStr = String(curr);
const le = asStr.length;
if (asStr.slice(le - 3) === "000") {
console.log(curr);
}
};
const parseOneMail = (rawMail) => __awaiter(void 0, void 0, void 0, function* () {
const parsedMail = yield (0, mailparser_1.simpleParser)(rawMail, {});
return parsedMail;
/*
simpleParser(rawMail, {}).then((parsed) => {
const attt = parsed.attachments;
const fullSize = attt.reduce<number>((accu, item) => {
return accu + item.size;
}, 0);
if (fullSize === 0) {
return;
}
console.log(
"sttt:",
step.v,
"size:",
fullSize,
"id",
parsed.headers.get("message-id"),
);
});
*/
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
// low level class, but problematic with reading file-sizes of attachments
/*
const mailparser = new MailParser({
// streamAttachments: true
});
mailparser.on("headers", scanHeaders);
// mailparser.on("data", (data: AttachmentStream | MessageText) => {
// if (data.type === "attachment") {
// const attData = data as AttachmentStream;
// console.log(
// "data.filename:",
// attData.filename,
// "attData.size:",
// attData.size,
// attData.headers,
// );
// // attData.content.pipe(process.stdout);
// attData.content.on("end", () => attData.release());
// }
// });
mailparser.write(rawMail);
mailparser.end(() => {
console.log("mail ===========================");
});
*/
});
exports.parseOneMail = parseOneMail;
const processOneMail = (rawMail) => __awaiter(void 0, void 0, void 0, function* () {
const parsedMail = yield (0, exports.parseOneMail)(rawMail);
// const allZ = parsedMail.headers.get('x-gmail-labels');
(0, mailHeadersUtils_1.processParsedMail)(parsedMail);
// const attArr = parsedMail.attachments;
// if (attArr.length !== 0) {
// console.log(
// "attArr.len--",
// attArr.length,
// attArr[0]?.size,
// attArr[0]?.filename,
// );
// }
//
//
//
gloAccu_1.step.succeededV += 1; // count of mails which are processed successfully
print000SuccessCount();
});
exports.processOneMail = processOneMail;