|
|
|
@ -25,7 +25,7 @@ Installation
|
|
|
|
|
Example
|
|
|
|
|
=======
|
|
|
|
|
|
|
|
|
|
* Fetch the 'date', 'from', 'to', 'subject' message headers and the message structure of all unread messages in the Inbox since May 20, 2010:
|
|
|
|
|
* Fetch the 'date', 'from', 'to', 'subject' message headers and the message structure of the first 3 messages in the Inbox:
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
var Imap = require('imap'),
|
|
|
|
@ -40,27 +40,17 @@ var imap = new Imap({
|
|
|
|
|
secureOptions: { rejectUnauthorized: false }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
imap.once('ready', function() {
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
imap.once('error', function(err) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
imap.once('end', function() {
|
|
|
|
|
console.log('Connection ended');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function openInbox(cb) {
|
|
|
|
|
imap.openBox('INBOX', true, cb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
imap.once('ready', function() {
|
|
|
|
|
openInbox(function(err, box) {
|
|
|
|
|
if (err) throw err;
|
|
|
|
|
imap.search([ 'UNSEEN', ['SINCE', 'May 20, 2010'] ], function(err, results) {
|
|
|
|
|
if (err) throw err;
|
|
|
|
|
var f = imap.fetch(results, { bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)' });
|
|
|
|
|
var f = imap.fetch('1:3', {
|
|
|
|
|
bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)',
|
|
|
|
|
struct: true
|
|
|
|
|
});
|
|
|
|
|
f.on('message', function(msg, seqno) {
|
|
|
|
|
console.log('Message #%d', seqno);
|
|
|
|
|
var prefix = '(#' + seqno + ') ';
|
|
|
|
@ -89,6 +79,16 @@ openInbox(function(err, box) {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
imap.once('error', function(err) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
imap.once('end', function() {
|
|
|
|
|
console.log('Connection ended');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
imap.connect();
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* Retrieve the 'from' header and buffer the entire body of the newest message:
|
|
|
|
@ -98,9 +98,7 @@ openInbox(function(err, box) {
|
|
|
|
|
|
|
|
|
|
openInbox(function(err, box) {
|
|
|
|
|
if (err) throw err;
|
|
|
|
|
imap.search([ 'UNSEEN', ['SINCE', 'May 20, 2010'] ], function(err, results) {
|
|
|
|
|
if (err) throw err;
|
|
|
|
|
var f = imap.fetch(results, { bodies: ['HEADER.FIELDS (FROM)','TEXT'] });
|
|
|
|
|
var f = imap.seq.fetch(box.messages.total + ':*', { bodies: ['HEADER.FIELDS (FROM)','TEXT'] });
|
|
|
|
|
f.on('message', function(msg, seqno) {
|
|
|
|
|
console.log('Message #%d', seqno);
|
|
|
|
|
var prefix = '(#' + seqno + ') ';
|
|
|
|
@ -136,7 +134,6 @@ openInbox(function(err, box) {
|
|
|
|
|
imap.end();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* Save raw unread emails since May 20, 2010 to files:
|
|
|
|
|