缺少默认的“已发送邮件”IMAP文件夹

时间:2014-02-25 00:30:27

标签: node.js imap

我正在使用优秀的inbox node.js库,对于某些电子邮件帐户,我没有看到某些默认邮箱,例如“已发送邮件”。我几乎使用OAUTH2的示例代码;

client = inbox.createConnection(false, "imap.gmail.com", {
    secureConnection: true,
    auth: {
        XOAuth2: {
            user: account.email,
            clientId: Settings.googleApp.clientId,
            clientSecret: Settings.googleApp.secretId,
            refreshToken: refreshToken,
            accessToken: accessToken,
            timeout: expires
        }
    }
});

client.connect();

client.on("connect", function() {

    Logger.debug("Opening mailbox " + mailbox);

    self.getMailboxes(function(err, boxes){
        var boxNames = _.pluck(boxes, 'name');
        Logger.info(boxNames);
    });
}

我有点难过......

1 个答案:

答案 0 :(得分:0)

谢谢,所以我最终使用了类型(type ='Sent')并遍历所有子邮箱以提取所有已发送邮箱,这允许邮箱的区域设置特定名称。这是代码;

        client.listMailboxes(function(error, mailboxes){

            var _findSent = function(mailbox, callback){

                if(mailbox.hasChildren){

                    mailbox.listChildren(function(error, children){

                        var sent = [];

                        for(var i=0; i < children.length; i++){

                            if (children[i].type == 'Sent'){
                                sent.push(children[i]);
                            }
                        }

                        callback(null, sent);

                    });

                }
                else {

                    var sent = [];

                    if (mailbox.type == 'Sent'){
                        sent.push(mailbox);
                    }

                    callback(null, sent);
                }

            }


            async.map(mailboxes, _findSent, function(err, results){
                onGotSentMailboxes(_.flatten(results));
            });

        });