npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

imap-manager

v0.2.1

Published

Provides abstraction on some of the more difficult imap server functions.

Readme

imap-manager

Node Module to manage an IMAP server

Using the package

To start using the package you will need to provide a server configuration to connect to and then require the package:

// Create a configuration object
var config = {
    host: 'imap.gmail.com',
    port: 993, // This is the default
    tls: true, // This is the default
    authTimeout: 10000,
    connTimeout: 20000
};

// Create our manager
var mailserver = require('imap-manager')(config);

Now we can start managing our imap server!

Examples

Here are two examples. The callback and promise versions of them are provided - depending on how your asynchronous coding style is you may use either. (These examples assume you have done the above setup)

Get all Folders

To get a list of all folders for an imap account perform the following steps:

// getFolders using a callback
mailserver.getFolders('[email protected]', 'pa$$word1', function(err, result) {
    if (err) {
        console.log('The following error occurred: ' + err);
    }
    else {
        console.log('Folders: ' + JSON.stringify(result));
    }
});

// getFolders using a promise
mailserver.getFolders('[email protected]', 'pa$$word1').then(result => {
    console.log('Folders: ' + JSON.stringify(result);
}).catch(error => {
    console.log('The following error occurred: ' + err);
});

// Result
{
    Archive: [Object],
    Drafts: [Object],
    INBOX: [Object],
    ...
}

List of Emails

To list off all of the emails in a specific folder, you can use getEmails:

// getEmails using a callback
mailserver.getEmails('[email protected]', 'pa$$word1', 'Inbox', function(err, result) {
    if (err) {
        console.log('The following error occurred: ' + err);
    }
    else {
        console.log('Emails: ' + JSON.stringify(result));
    }
});

// getEmails using a promise
mailserver.getEmails('[email protected]', 'pa$$word1', 'Inbox').then(result => {
    console.log('Emails: ' + JSON.stringify(result));
}).catch(error => {
    console.log('The following error occurred: ' + err);
});

// Result
[
    // Example email
    {
        attributes: {
            date: 'Sat, 02 Dec 2017 22:40:56 -0500',
            flags: [
                '\Seen'
            ],
            ...
        },
        content: {
            raw: ..., // Raw may be deprecated in the future to reduce network usage
            text: {
                plain: 'Example email content',
                html: '<strong>Example</strong> email content'
            },
            attachments: [
                {
                    partID: '2',
                    type: 'image',
                    subtype: 'png',
                    encoding: 'base64',
                    data: 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACx%0Ajwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAHKSURBVDhPpZO/axNhHIefa/ODXLxe2rRNYmLP%0AHFYoZFAQdHQRB0tdXDo6WBeLqODgJtKlIoUO/RNcVIogig7qIIolQYSKBNO0RIXYltJG0ySXH69v%0AvDM1tIKYB15uuOf7ed/P8Z4iJHRAl/P8bzoO2LPCs0cPSS285dSZMVY+pUm/T1JpKIyfn2AkkXAs%0Am10BqVSS21cu4PH5CPVqbFQUtjY3OTDQw7e6n7sP5h3TZleFm5MTnDxxhENxA78epPijgCW3UPfJ%0AgMwiy0sZx7RpC5ibucPxhEmwN0C90aBP7WLbqiKqFRY+ZKh1e5ieuuXYNm0VTh8dZiAUQvOrJNMr%0AhPt0wgFZ43sRq1bD5fLy6vUbvhQqeL2eXzOtE2SzWfJr6xRKFp/zq3KtcXAwQL+u4nZ1E9Q13qWX%0AMOLx1nCTVoBpmoyeG8cql/BJ4dhhg4+5VbL5DdxutxQFsaDG6NhZZ8KmrcLLF8+ZvTGJR5PfoN6g%0AKo/9dX0LRVEoli0U6Sxmlm35N82AP7l+7aoI9/jEyFBExAb7hRmLCHN/SER0VeRyOcfaYc+L1OTp%0Ak8fM379HubTNkGFw8dJlotGo83aHvwb8Kx3/Cx0GwE9hjclg65ielwAAAABJRU5ErkJggg==',
                    ...
                }
            ]
        },
        header: {
            date: ['Sat, 02 Dec 2017 22:40:56 -0500'],
            from: ['[email protected]'],
            subject: ['Example Email'],
            to: ['[email protected]']
        }
    },
    ...
]

Move an Email

To move an email from a parent folder to target folder, you can use the command: 'moveEmail'

// moveEmail using a callback
mailserver.moveEmail('[email protected]', 'pa$$word1', 'Inbox', 'Archive', 41, function(err) {
    if (err) {
        console.log('The following error occurred: ' + err);
    }
    else {
        console.log('Moved email with uid 41 from folder Inbox to folder Archive');
    }
});

// moveEmail using a promise
mailserver.moveEmail('[email protected]', 'pa$$word1', 'Inbox', 'Archive', 41).then(result => {
    console.log('Moved email with uid 41 from folder Inbox to folder Archive');
}).catch(err => {
    console.log('The following error occurred: ' + err);
});

Update an Email's Flags

To set the flags on an email, you can use the command: 'setFlags'

// For the following examples please assume we have access to an array called 'flags' that is defined as follows:
var flags = [
    'Seen',
    'Flagged'
];

// setFlags using a callback (Adding the flags)
mailserver.setFlags('[email protected]', 'pa$$word1', 'Inbox', 41, true, flags, function(err) {
    if (err) {
        console.log('The following error occurred: ' + err);
    }
    else {
        console.log('Successfully updated flags for email with uid 41!');
    }
});

// setFlags using a promise (Removing the flags)
mailserver.setFlags('[email protected]', 'pa$$word1', 'Inbox', 41, false, flags).then(result => {
    console.log('Successfully updated flags for email with uid 41!');
}).catch(err => {
    console.log('The following error occurred: ' + err);
});