chadxz / imap-simple

Wrapper over node-imap, providing a simpler api for common use cases
MIT License
245 stars 79 forks source link

Not returning anything -get subject lines #95

Closed krishna408 closed 3 years ago

krishna408 commented 3 years ago

`var imaps = require('imap-simple');

var config = { imap: { user: 'your@email.address', password: 'yourpassword', host: 'imap.gmail.com', port: 993, tls: true, authTimeout: 3000 } };

imaps.connect(config).then(function (connection) {

return connection.openBox('INBOX').then(function () {
    var searchCriteria = [
        'UNSEEN'
    ];

    var fetchOptions = {
        bodies: ['HEADER', 'TEXT'],
        markSeen: false
    };

    return connection.search(searchCriteria, fetchOptions).then(function (results) {
        var subjects = results.map(function (res) {
            return res.parts.filter(function (part) {
                return part.which === 'HEADER';
            })[0].body.subject[0];
        });

        console.log(subjects);
        // =>
        //   [ 'Hey Chad, long time no see!',
        //     'Your amazon.com monthly statement',
        //     'Hacker Newsletter Issue #445' ]
    });
});

});`