lib/imapSimple.js
function getParts(struct, parts) {
    parts = parts || [];
    for (var i = 0; i < struct.length; i++) {
        if (Array.isArray(struct[i])) {
            getParts(struct[i], parts);
        } else if (struct[i].partID) {
            parts.push(struct[i]);
        }
    }
    return parts;
}
function getParts(struct, parts) {
    parts = parts || [];
    for (var i = 0; i < struct.length; i++) {
        if (Array.isArray(struct[i])) {
            getParts(struct[i], parts);
        } else if (struct[i].partID) {
            parts.push(struct[i]);
        }
    }
    return parts;
}
function getParts ( struct , parts ) { parts = parts || [ ] ; for ( var i = 0 ; i < struct . length ; i ++ ) { if ( Array . isArray ( struct [ i ] ) ) { getParts ( struct [ i ] , parts ) ; } else if ( struct [ i ] . partID ) { parts . push ( struct [ i ] ) ; } } return parts ; }
Given the `message.attributes.struct`, retrieve a flattened array of `parts` objects that describe the structure of
the different parts of the message's body. Useful for getting a simple list to iterate for the purposes of,
for example, finding all attachments.

Code taken from http://stackoverflow.com/questions/25247207/how-to-read-and-save-attachments-using-node-imap

@param {Array} struct The `message.attributes.struct` value from the message you wish to retrieve parts for.
@param {Array} [parts] The list of parts to push to.
@returns {Array} a flattened array of `parts` objects that describe the structure of the different parts of the
message's body
Given the message . attributes . struct retrieve a flattened array of parts objects that describe the structure of the different parts of the message s body . Useful for getting a simple list to iterate for the purposes of for example finding all attachments .