node.js - node-imap module fetch gmail list folders(labels) -


i'm trying fetch gmail folders list(labels actually). i'm using node js , module : https://github.com/mscdex/node-imap

i want fetch folders , sub folders. documentation author left not bright.

any idea this?

finally after hard working found answer, how folders not google every email system use imap standards

after connection imap server folders function.

function getfolders(username, callback) {  var folders = []; if (connection[username]) {      connection[username].once('ready', function() {          connection[username].getboxes(function (err, boxes) {               if (err) {                  // todo : parse error here              } else {                  folders = imapnestedfolders(boxes);              }              return callback(err, folders);         });     });  } else {      return framework.httperror(500, self); } } 

the parse folder pretty nested tree json object function

function imapnestedfolders(folders) {  var folders = []; var folder  = {};  (var key in folders) {      if (folders[key].attribs.indexof('\\haschildren') > -1) {          var children = imapnestedfolders(folders[key].children);          folder = {             name        : key,             children    : children         };      } else {          folder = {             name        : key,             children    : null         };     }      folders.push(folder);  } return folders; } 

you might change connection variable wanted. these functions work multiple connection because of connection variable array can read more here, wrote how use multiple connection in node imap here

how can handle multiple imap connections in node.js?


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -