### Example Object Structure for getQuotaRoot Response - JavaScript Source: https://github.com/mscdex/node-imap/blob/master/README.md Explains the structure of the `info` object returned by the `getQuotaRoot` function. It is keyed by quota root names, with values being objects containing resource usage and limit details (e.g., storage, message). This structure helps users understand how to access the quota information. ```javascript { '': { storage: { usage: 20480, limit: 102400 } }, foo: { storage: { usage: 1024, limit: 4096 }, message: { usage: 14, limit: 9001 } } } ``` -------------------------------- ### Example: Structure of Mailbox List Object in node-imap Javascript Source: https://github.com/mscdex/node-imap/blob/master/README.md This snippet shows the structure of the object returned by the `getBoxes` and `getSubscribedBoxes` methods. It illustrates how mailbox names, attributes, delimiters, and nested children/parent references are represented, including special cases like Gmail's structure. ```javascript { INBOX: // mailbox name { attribs: [], // mailbox attributes. An attribute of 'NOSELECT' indicates the mailbox cannot // be opened delimiter: '/', // hierarchy delimiter for accessing this mailbox's direct children. children: null, // an object containing another structure similar in format to this top level, // otherwise null if no children parent: null // pointer to parent mailbox, null if at the top level }, Work: { attribs: [], delimiter: '/', children: null, parent: null }, '[Gmail]': { attribs: [ '\\NOSELECT' ], delimiter: '/', children: { 'All Mail': { attribs: [ '\\All' ], delimiter: '/', children: null, parent: [Circular] }, Drafts: { attribs: [ '\\Drafts' ], delimiter: '/', children: null, parent: [Circular] }, Important: { attribs: [ '\\Important' ], delimiter: '/', children: null, parent: [Circular] }, 'Sent Mail': { attribs: [ '\\Sent' ], delimiter: '/', children: null, parent: [Circular] }, Spam: { attribs: [ '\\Junk' ], delimiter: '/', children: null, parent: [Circular] }, Starred: { attribs: [ '\\Flagged' ], delimiter: '/', children: null, parent: [Circular] }, Trash: { attribs: [ '\\Trash' ], delimiter: '/', children: null, parent: [Circular] } }, parent: null } } ``` -------------------------------- ### Fetching Headers and Structure - node-imap JavaScript Source: https://github.com/mscdex/node-imap/blob/master/README.md Demonstrates connecting to an IMAP server, opening the inbox, and fetching specific headers (FROM, TO, SUBJECT, DATE) and the message structure for the first three messages. It shows how to handle connection, fetch, and message events to process the retrieved data. ```javascript var Imap = require('imap'),\n inspect = require('util').inspect;\n\nvar imap = new Imap({\n user: 'mygmailname@gmail.com',\n password: 'mygmailpassword',\n host: 'imap.gmail.com',\n port: 993,\n tls: true\n});\n\nfunction openInbox(cb) {\n imap.openBox('INBOX', true, cb);\n}\n\nimap.once('ready', function() {\n openInbox(function(err, box) {\n if (err) throw err;\n var f = imap.seq.fetch('1:3', {\n bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)',\n struct: true\n });\n f.on('message', function(msg, seqno) {\n console.log('Message #%d', seqno);\n var prefix = '(#' + seqno + ') ';\n msg.on('body', function(stream, info) {\n var buffer = '';\n stream.on('data', function(chunk) {\n buffer += chunk.toString('utf8');\n });\n stream.once('end', function() {\n console.log(prefix + 'Parsed header: %s', inspect(Imap.parseHeader(buffer)));\n });\n });\n msg.once('attributes', function(attrs) {\n console.log(prefix + 'Attributes: %s', inspect(attrs, false, 8));\n });\n msg.once('end', function() {\n console.log(prefix + 'Finished');\n });\n });\n f.once('error', function(err) {\n console.log('Fetch error: ' + err);\n });\n f.once('end', function() {\n console.log('Done fetching all messages!');\n imap.end();\n });\n });\n});\n\nimap.once('error', function(err) {\n console.log(err);\n});\n\nimap.once('end', function() {\n console.log('Connection ended');\n});\n\nimap.connect(); ``` -------------------------------- ### Representing Single-Part Message Structure (node-imap) - JavaScript Source: https://github.com/mscdex/node-imap/blob/master/README.md This snippet shows the simpler structure object returned by fetch() for an email message consisting of only a single body part. It demonstrates the basic format of a single part object. ```javascript [ { partID: '1', type: 'text', subtype: 'plain', params: { charset: 'ISO-8859-1' }, id: null, description: null, encoding: '7BIT', size: 935, lines: 46, md5: null, disposition: null, language: null } ] ``` -------------------------------- ### Representing Namespace Object Structure (node-imap) - JavaScript Source: https://github.com/mscdex/node-imap/blob/master/README.md This snippet illustrates the structure of objects found within the personal, other, or shared arrays of the Connection's namespaces property. It details the prefix, delimiter, and optional extensions for a namespace. ```javascript { prefix: '', // A string containing the prefix to use to access mailboxes in this namespace delimiter: '/', // A string containing the hierarchy delimiter for this namespace, or boolean false // for a flat namespace with no hierarchy extensions: [ // An array of namespace extensions supported by this namespace, or null if none // are specified { name: 'X-FOO-BAR', // A string indicating the extension name params: [ 'BAZ' ] // An array of strings containing the parameters for this extension, // or null if none are specified } ] } ``` -------------------------------- ### Searching and Saving Raw Emails - node-imap JavaScript Source: https://github.com/mscdex/node-imap/blob/master/README.md Illustrates how to search for messages matching specific criteria (unread since a certain date) and fetch their complete raw content. It demonstrates piping the raw email body stream directly to a file using the Node.js 'fs' module. ```javascript // using the functions and variables already defined in the first example ...\n\nvar fs = require('fs'), fileStream;\n\nopenInbox(function(err, box) {\n if (err) throw err;\n imap.search([ 'UNSEEN', ['SINCE', 'May 20, 2010'] ], function(err, results) { if (err) throw err;\n var f = imap.fetch(results, { bodies: '' });\n f.on('message', function(msg, seqno) {\n console.log('Message #%d', seqno);\n var prefix = '(#' + seqno + ') ';\n msg.on('body', function(stream, info) {\n console.log(prefix + 'Body');\n stream.pipe(fs.createWriteStream('msg-' + seqno + '-body.txt'));\n });\n msg.once('attributes', function(attrs) {\n console.log(prefix + 'Attributes: %s', inspect(attrs, false, 8));\n });\n msg.once('end', function() {\n console.log(prefix + 'Finished');\n });\n });\n f.once('error', function(err) {\n console.log('Fetch error: ' + err);\n });\n f.once('end', function() {\n console.log('Done fetching all messages!');\n imap.end();\n });\n });\n}); ``` -------------------------------- ### Fetching Specific Header and Body - node-imap JavaScript Source: https://github.com/mscdex/node-imap/blob/master/README.md Shows how to fetch specific parts of the latest message in the inbox, specifically the 'FROM' header and the entire 'TEXT' body. It illustrates how to target specific message parts during the fetch operation and handle their respective body streams. ```javascript // using the functions and variables already defined in the first example ...\n\nopenInbox(function(err, box) {\n if (err) throw err;\n var f = imap.seq.fetch(box.messages.total + ':*', { bodies: ['HEADER.FIELDS (FROM)','TEXT'] });\n f.on('message', function(msg, seqno) {\n console.log('Message #%d', seqno);\n var prefix = '(#' + seqno + ') ';\n msg.on('body', function(stream, info) {\n if (info.which === 'TEXT')\n console.log(prefix + 'Body [%s] found, %d total bytes', inspect(info.which), info.size);\n var buffer = '', count = 0;\n stream.on('data', function(chunk) {\n count += chunk.length;\n buffer += chunk.toString('utf8');\n if (info.which === 'TEXT')\n console.log(prefix + 'Body [%s] (%d/%d)', inspect(info.which), count, info.size);\n });\n stream.once('end', function() {\n if (info.which !== 'TEXT')\n console.log(prefix + 'Parsed header: %s', inspect(Imap.parseHeader(buffer)));\n else\n console.log(prefix + 'Body [%s] Finished', inspect(info.which));\n });\n });\n msg.once('attributes', function(attrs) {\n console.log(prefix + 'Attributes: %s', inspect(attrs, false, 8));\n });\n msg.once('end', function() {\n console.log(prefix + 'Finished');\n });\n });\n f.once('error', function(err) {\n console.log('Fetch error: ' + err);\n });\n f.once('end', function() {\n console.log('Done fetching all messages!');\n imap.end();\n });\n}); ``` -------------------------------- ### Representing Multi-Part Message Structure (node-imap) - JavaScript Source: https://github.com/mscdex/node-imap/blob/master/README.md This snippet illustrates the structure object returned by fetch() for an email message containing multiple parts, such as alternative text/html bodies and attachments. Each part is represented by an object, and nested parts are represented by nested arrays. ```javascript [ { type: 'mixed', params: { boundary: '000e0cd294e80dc84c0475bf339d' }, disposition: null, language: null, location: null }, [ { type: 'alternative', params: { boundary: '000e0cd294e80dc83c0475bf339b' }, disposition: null, language: null }, [ { partID: '1.1', type: 'text', subtype: 'plain', params: { charset: 'ISO-8859-1' }, id: null, description: null, encoding: '7BIT', size: 935, lines: 46, md5: null, disposition: null, language: null } ], [ { partID: '1.2', type: 'text', subtype: 'html', params: { charset: 'ISO-8859-1' }, id: null, description: null, encoding: 'QUOTED-PRINTABLE', size: 1962, lines: 33, md5: null, disposition: null, language: null } ] ], [ { partID: '2', type: 'application', subtype: 'octet-stream', params: { name: 'somefile' }, id: null, description: null, encoding: 'BASE64', size: 98, lines: null, md5: null, disposition: { type: 'attachment', params: { filename: 'somefile' } }, language: null, location: null } ] ] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.