readme: fix/modify examples

fork
mscdex 11 years ago
parent 10f65e4d2a
commit 4208cbb952

@ -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'),
@ -38,29 +38,19 @@ var imap = new Imap({
port: 993,
secure: true,
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);
}
openInbox(function(err, box) {
if (err) throw err;
imap.search([ 'UNSEEN', ['SINCE', 'May 20, 2010'] ], function(err, results) {
imap.once('ready', function() {
openInbox(function(err, box) {
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 + ') ';
@ -135,7 +133,6 @@ openInbox(function(err, box) {
console.log('Done fetching all messages!');
imap.end();
});
});
});
```

Loading…
Cancel
Save