Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4260564
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:56:13+00:00 2026-05-21T05:56:13+00:00

function die(err) { console.log(‘Uh oh: ‘ + err); process.exit(1); } var box, cmds, next

  • 0
function die(err) {
  console.log('Uh oh: ' + err);
  process.exit(1);
}

var box, cmds, next = 0, cb = function(err) {
  if (err)
    die(err);
  else if (next < cmds.length)
    cmds[next++].apply(this, Array.prototype.slice.call(arguments).slice(1));
};

cmds = [
  function() { imap.connect(cb); },
  function() { imap.openBox('INBOX', false, cb); },
  function(result) { box = result; imap.search([ 'UNSEEN', ['SINCE', 'April 5, 2011'] ], cb); },
  function(results) {
    var msgCache = {},
        fetch = imap.fetch(results, { request: { headers: ['from', 'to', 'subject', 'date'] } });
    console.log('Now fetching headers!');
    fetch.on('message', function(msg) {
      msg.on('end', function() {
        msgCache[msg.id] = { headers: msg.headers };
      });
    });
    fetch.on('end', function() {
      console.log('Done fetching headers!');
      console.log('Now fetching bodies!');
      fetch = imap.fetch(results, { request: { headers: false, body: '1' } });
      fetch.on('message', function(msg) {
        msg.data = '';
        msg.on('data', function(chunk) {
          msg.data += chunk;
        });
        msg.on('end', function() {
          msgCache[msg.id].body = msg.data;
        });
      });
      fetch.on('end', function() {
        console.log('Done fetching bodies!');
        cb(msgCache);
      });
    });
  },
  function(msgs) {
    // Do something here with msgs, which contains the headers and
    // body (parts) of all the messages you fetched
    console.log("HERE");
    imap.logout(cb);    
    
  }
];
cb();

I’m using that code to get the headers and the body of an e-mail. However, when I try to pass the result (msgCache) it gets an error.

What am I missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:56:14+00:00Added an answer on May 21, 2026 at 5:56 am

    It seems like you are calling cb(msgCache) in your fetch on end callback, and cb takes the first argument err. If err is a valid non empty object, then it will call your error handler and die, so it is calling the error handler even with a valid msgCache.

    Why not call console.log(msgCache) instead of cb(msgCache) and see if you get through to the end ok.

    Or am I missing the point where the error occurs?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to simulate N-sided biased die? def roll(N,bias): '''this function rolls N dimensional
HI, I am using the following code request.js var request; function runAjax(JSONstring) { //
The jquery function that I'm using is: $.getJSON(rpc2.php?queryString= +inputString+, function(data) { if(data.length >0) {
Consider the following functions: function debug() { $args = func_get_args(); // process $args }
I'd like to be able to catch die() and exit() messages. Is this possible?
I need to overload the die() function. For example, I want to pass an
function tableOne() { $query = mysql_query(SELECT valor FROM grafico) or die(mysql_error()); $i = 0;
function returnsAnArray () { return array ('test'); } echo returnsAnArray ()[0]; generates a syntax
Function FillAdminAccount() As Boolean FillAdminAccount = True Try SQLconn.ConnectionString = connect timeout=9999999; & _
function Submit_click() { if (!bValidateFields()) return; } function bValidateFields() { /// <summary>Validation rules</summary> ///

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.