Add ability to also retrieve only specific headers and a body in addition to all headers and a body

fork
Brian White 12 years ago
parent 747f2c2122
commit 28e9965787

@ -239,6 +239,9 @@ ImapConnection.prototype.connect = function(loginCb) {
state.parser = new MIMEParser();
state.parser.on('header', function(name, val) {
name = name.toLowerCase();
if (requests[0]._headers
&& requests[0]._headers.indexOf(name) === -1)
return;
if (requests[0]._msg.headers[name] !== undefined)
requests[0]._msg.headers[name].push(val);
else
@ -799,13 +802,12 @@ ImapConnection.prototype._fetch = function(which, uids, options) {
headers: true,
body: false
}
}, toFetch, bodyRange, extensions, useParser, self = this;
}, toFetch, bodyRange, extensions, useParser, onlyHeaders, self = this;
if (typeof options !== 'object')
options = {};
utils.extend(true, opts, options);
if (!Array.isArray(opts.request.headers)) {
if (Array.isArray(opts.request.body)) {
var rangeInfo;
if (opts.request.body.length !== 2)
@ -818,13 +820,20 @@ ImapConnection.prototype._fetch = function(which, uids, options) {
+ parseInt(rangeInfo[2], 10) + '>';
opts.request.body = opts.request.body[0];
}
if (opts.request.headers === true && opts.request.body === true) {
// fetches the whole entire message (including the headers)
toFetch = '';
useParser = true;
} else if (opts.request.headers === true) {
// fetches headers only
toFetch = 'HEADER';
if (opts.request.headers !== false
&& typeof opts.request.body === 'boolean') {
if (Array.isArray(opts.request.headers))
onlyHeaders = opts.request.headers.join(' ').toUpperCase();
if (opts.request.body === true) {
// fetches the whole entire message (including some/all headers)
toFetch = '';
} else if (onlyHeaders) {
// fetch specific headers only
toFetch = 'HEADER.FIELDS (' + onlyHeaders + ')';
} else {
// fetches (all) headers only
toFetch = 'HEADER';
}
useParser = true;
} else if (opts.request.body === true) {
// fetches the whole entire message text (minus the headers), including
@ -841,12 +850,6 @@ ImapConnection.prototype._fetch = function(which, uids, options) {
} else
throw new Error("Invalid body partID format");
}
} else {
// fetch specific headers only
toFetch = 'HEADER.FIELDS (' + opts.request.headers.join(' ').toUpperCase()
+ ')';
useParser = true;
}
// always fetch GMail-specific bits of information when on GMail
if (this._serverSupports('X-GM-EXT-1'))
@ -885,6 +888,8 @@ ImapConnection.prototype._fetch = function(which, uids, options) {
req = this._state.requests[this._state.requests.length - 1];
req._fetcher = imapFetcher;
req._useParser = useParser;
if (Array.isArray(opts.request.headers))
req._headers = onlyHeaders.toLowerCase().split(' ');
return imapFetcher;
};

Loading…
Cancel
Save