UNPKG

imap-mailbox

Version:

Simple library to use and watch IMAP mailboxes

96 lines (95 loc) 3.54 kB
import ImapConfig from './interfaces/ImapConfig.interface'; import Mailbox from './interfaces/Mailbox.interface'; import Mail from './Mail'; import UidsList from './interfaces/UidsList.interface'; export default class Imap { private readonly config; private readonly eventEmitter; private readonly logger; private readonly mailboxes; private client; /** * Await run() method before any action on this object * @param {ImapConfig} config Imap configuration */ constructor(config: ImapConfig); /** * Run IMAP service * You should await this method before any action on Imap object */ run(): Promise<void>; /** * Callback for on() method only for event 'deletedMail' * * @callback onCallbackNumber * @param {number} uid Uid of the mail that was deleted */ /** * Callback for on() method only for event 'newMail' and 'loadedMail' * * @callback onCallbackMail * @param {Mail} mail Mail that was emitted */ /** * Use callback when event is emitted * * @param {"deletedMail" | "newMail" | "loadedMail"} event Event to target * @param {onCallback | onCallbackMail} callback Callback to execute when event is emitted */ on(event: 'deletedMail', callback: (uid: number) => void): void; on(event: 'newMail' | 'loadedMail', callback: (mail: Mail) => void): void; /** * Delete mails from uids or mail objects * @param {string} mailboxPath Mailbox path where mails to delete are * @param {UidsList} toDelete Mails or uids of mails to delete * @returns {boolean} true if mails are deleted */ deleteMails(mailboxPath: string, toDelete: UidsList): Promise<boolean>; /** * Mark mails as seen from uids or mail object * @param {string} mailboxPath Mailbox path where mails to see are * @param {UidsList} toSee Mails or uids of mails to see * @returns {boolean} true if mails are marked seen */ seeMails(mailboxPath: string, toSee: UidsList): Promise<boolean>; /** * Mark mails as unseen from uids or mail object * @param {string} mailboxPath Mailbox path where mails to unsee are * @param {UidsList} toUnsee Mails or uids of mails to unsee * @returns {boolean} true if mails are marked unseen */ unseeMails(mailboxPath: string, toUnsee: UidsList): Promise<boolean>; /** * Get a list of unseen mails from a mailbox * @param {string} mailboxPath Path to mailbox (or name) * @returns {Mail[]} List of mails */ getUnseenMails(mailboxPath: string): Promise<Mail[]>; /** * Get a list of seen mails from a mailbox * @param {string} mailboxPath Path to mailbox (or name) * @returns {Mail[]} List of mails */ getSeenMails(mailboxPath: string): Promise<Mail[]>; /** * Get all the mails from a mailbox * @param {string} mailboxPath Path to mailbox (or name) * @returns {Mail[]} List of mails */ getAllMails(mailboxPath: string): Promise<Mail[]>; /** * Get list of mailboxes * @returns {Map<string, Mailbox>} Map of mailboxes */ getMailboxes(): Map<string, Mailbox>; private connect; private restart; private watchErrors; private loadMailboxes; private watchMailboxes; private watchMailbox; private getNewMail; private getLastUid; private getLastMails; private search; }