Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

imap-client

Package Overview
Dependencies
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imap-client

High-level UMD module wrapper for [browserbox](https://github.com/whiteout-io/browserbox). This module encapsulates the most commonly used IMAP commands.

  • 0.6.0
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-63.64%
Maintainers
3
Weekly downloads
 
Created
Source

imap-client

High-level UMD module wrapper for browserbox. This module encapsulates the most commonly used IMAP commands.

API

Constructor

var ImapClient = require(‘imap-client’);
var imap = new ImapClient({
    port: 993, // the port to connect to
    host: ’imap.example.com’, // the host to connect to
    secure: true/false, // use SSL?
        ignoreTLS: true/false, // if true, do not call STARTTLS before authentication even if the host advertises support for it
        requireTLS: true/false, // if true, always use STARTTLS before authentication even if the host does not advertise it. If STARTTLS fails, do not try to authenticate the user
    auth.user: ’john.q@example.com’, // username of the user (also applies to oauth2)
    auth.pass: ‘examplepassword’, // password for the user
    auth.xoauth2: ‘EXAMPLEOAUTH2TOKEN’, // OAuth2 access token to be used instead of password
    ca: ‘PEM ENCODED CERT’,     // (optional, used only in conjunction with the TCPSocket shim) if you use TLS with forge, pin a PEM-encoded certificate as a string. Please refer to the [tcp-socket documentation](https://github.com/whiteout-io/tcp-socket) for more information!
    maxUpdateSize: 20 // (optional) the maximum number of messages you want to receive in one update from the server
});

#login(callback) and #logout(callback)

Log in to an IMAP Session. No-op if already logged in.

imap.login(function() {
    // yay, we’re logged in

        imap.logout(function() {
            // yay, we’re logged out
        });
});

#listenForChanges(callback) and #stopListeningForChanges(callback)

Set up a connection dedicated to listening for changes published by the IMAP server on one specific inbox.

imap.listenForChanges({
    path: ‘mailboxpath’
}, function() {
    // the audience is listening

        imap.stopListeningForChanges(function() {
                // we’re not listening anymore
        });
})

#listWellKnownFolders(callback)

Lists folders, grouped to folders that are in the following categories: Inbox, Drafts, All, Flagged, Sent, Trash, Junk, Archive, Other.

#search(options, callback)

Returns the uids of messages containing the search terms in the options.

imap.search({
        answered: true
        unread: true
}, function(error, uids) {
        console.log(‘uids: ‘ + uids.join(‘, ‘))
});

#listMessages(options, callback)

Lists messages in the mailbox based on their UID.

imap.listMessages({
        path: ‘path’, the folder's path
        firstUid: 15, (optional) the uid of the first messagem defaults to 1
        lastUid: 30 (optional) the uid of the last message, defaults to ‘*’
}, function(error, messages) {})

Messages have the following attributes:

  • uid: The UID in the mailbox
  • id: The Mesage-ID header (without "<>")
  • inReplyTo: The Message-ID that this message is a reply to
  • references: The Message-IDs that this message references
  • from, replyTo, to, cc, bcc: The Sender/Receivers
  • modseq: The MODSEQ number of this message
  • subject: The message's subject
  • sentDate: The date the message was sent
  • unread: The unread flag
  • answered: The answered flag
  • bodyParts: Array of message parts, simplified version of a MIME tree. Used by #getBodyParts

#getBodyParts()

Fetches parts of a message from the imap server

imap.getBodyParts({
path: 'foo/bar',
uid: someMessage.uid,
bodyParts: someMessage.bodyParts
}, function(err) {
    // all done, bodyparts can now be fed to the mailreader
})

#updateFlags(options, callback)

Marks a message as un-/read or un-/answered.

imap.updateFlags({
    path: 'foo/bar',
    uid: someMessage.uid,
    unread: true/false/undefined, // (optional) Marks the message as un-/read, no action if omitted
    answered: true/false/undefined // (optional) Marks the message as answered, no action if omitted
}, function (error, flags) {
    // all done, called the flags received from the server
});

#moveMessage(options, callback)

Moves a message from mailbox A to mailbox B.

imap.updateFlags({
    path: 'foo/bar', // the origin folder
    uid: someMessage.uid, // the message's uid
    destination: 'bla/bli' // the destination folder
}, function (error) {
    // all done
});

uploadMessage(options, callback)

Uploads a message to a folder

imap.updateFlags({
    path: 'foo/bar', // the target folder
    message: '...' // RFC-2822 compliant string
}, function (error) {
    // all done
});

#deleteMessage(options, callback)

Deletes a message from a folder

imap.updateFlags({
    path: 'foo/bar', // the folder from which to delete the message
    uid: someMessage.uid, // the message's uid
}, function (error) {
    // all done
});

#onSyncUpdate

If there are updates available for an IMAP folder, you will receive the changed UIDs in the #onSyncUpdate callback. The IMAP client invokes the callback if there are new/changes messages after a mailbox has been selected and on IMAP expunge/exists/fetch updates have been pushed from the server

var SYNC_TYPE_NEW = 'new';
var SYNC_TYPE_DELETED = 'deleted';
var SYNC_TYPE_MSGS = 'messages';    

imap.onSyncUpdate = function(options) {
        var updatedMesages = options.list,
        updatesMailbox = options.path
        
    if (options.type === SYNC_TYPE_NEW) {
        // new messages available on imap
                // updatedMesages is an array of the newly available UIDs
    } else if (options.type === SYNC_TYPE_DELETED) {
        // messages have been deleted
                // updatedMesages is an array of the deleted UIDs
    } else if (options.type === SYNC_TYPE_MSGS) {
        // NB! several possible reasons why this could be called.
                // updatedMesages is an array of objects
        // if an object in the array has uid value and flags array, it had a possible flag update
        }
};

Getting started

Run the following commands to get started:

npm install && grunt

License

The MIT License (MIT)

Copyright (c) 2014 Whiteout Networks GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

FAQs

Package last updated on 06 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc