UNPKG

imap-mailbox

Version:

Simple library to use and watch IMAP mailboxes

55 lines (54 loc) 2.19 kB
"use strict"; 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 }); class Mail { constructor(imap, mailboxPath, msg, parsedMail) { this.imap = imap; this.uid = msg.uid; this.seq = msg.seq; this.subject = parsedMail.subject || ''; this.from = parsedMail.from; this.content = this.parseContent(parsedMail.text || ''); this.mailboxPath = mailboxPath; this.parsedMail = parsedMail; } delete() { return __awaiter(this, void 0, void 0, function* () { this.imap.deleteMails(this.mailboxPath, { uids: [this.uid] }); }); } see() { return __awaiter(this, void 0, void 0, function* () { this.imap.seeMails(this.mailboxPath, { uids: [this.uid] }); }); } unsee() { return __awaiter(this, void 0, void 0, function* () { this.imap.unseeMails(this.mailboxPath, { uids: [this.uid] }); }); } parseContent(content) { try { if (content !== undefined) { const textLines = content.split('\n'); textLines.pop(); const separator = textLines[textLines.length - 1].slice(0, -2); const separatedText = content.split(separator)[0]; return separatedText.trim(); } } catch (e) { return ''; } return ''; } } exports.default = Mail;