From 42871d12856137f281590f156489d29c4104595e Mon Sep 17 00:00:00 2001 From: Brian White Date: Thu, 3 Jan 2013 23:48:19 -0500 Subject: [PATCH] allow `headers` to be a string for fetch() --- README.md | 4 ++-- lib/imap.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 68e6bdb..7134f01 100644 --- a/README.md +++ b/README.md @@ -562,13 +562,13 @@ Valid `options` are: * **id** - < _mixed_ > - _integer_ or _string_ referencing a message part to use when retrieving headers and/or a body. **Default:** (root part/entire message) - * **headers** - < _mixed_ > - An _array_ of specific headers to retrieve, _boolean_ true to fetch all headers, or an _object_ of the form (**Default:** (no headers)): + * **headers** - < _mixed_ > - An _array_ of specific headers to retrieve, a _string_ containing a single header to retrieve, _boolean_ true to fetch all headers, or an _object_ of the form (**Default:** (no headers)): * **fields** - < _mixed_ > - An _array_ of specific headers to retrieve or _boolean_ true to fetch all headers. **Default:** (all headers) * **parse** - < _boolean_ > - Parse headers? **Default:** true - * **headersNot** - < _mixed_ > - An _array_ of specific headers to exclude or an _object_ of the form (**Default:** (no headers)): + * **headersNot** - < _mixed_ > - An _array_ of specific headers to exclude, a _string_ containing a single header to exclude, or an _object_ of the form (**Default:** (no headers)): * **fields** - < _mixed_ > - An _array_ of specific headers to exclude. **Default:** (all headers) diff --git a/lib/imap.js b/lib/imap.js index dd18f21..372317d 100644 --- a/lib/imap.js +++ b/lib/imap.js @@ -995,6 +995,8 @@ ImapConnection.prototype._fetch = function(which, uids, options, what, cb) { else { if (Array.isArray(wp.headers)) headers = wp.headers; + else if (typeof wp.headers === 'string') + headers = [wp.headers]; else if (typeof wp.headers === 'object') { if (wp.headers.fields === undefined) wp.headers.fields = true; @@ -1027,6 +1029,8 @@ ImapConnection.prototype._fetch = function(which, uids, options, what, cb) { else { if (Array.isArray(wp.headersNot)) headers = wp.headersNot; + else if (typeof wp.headersNot === 'string') + headers = [wp.headersNot]; else if (typeof wp.headersNot === 'object') { if (wp.headersNot.fields === undefined) wp.headersNot.fields = true;