1

I'm using the node-imap meteor package to retrieve an email, then use that email to find a guest in a Guests collection. I get the "can't wait without a fiber error" when I include the Guest.findOne code. Here's the code

        function openInbox(cb) {             
            imap.openBox('INBOX', true, cb);              
        }
        imap.once('ready', function() {
         openInbox(function(err, box) {
          if (err) throw err;
          var f = imap.seq.fetch(box.messages.total + ':*', { bodies: ['HEADER.FIELDS (FROM SUBJECT DATE)','TEXT'] });
          f.on('message', function(msg, seqno) {
            console.log('Message #%d', seqno);
            var prefix = '(#' + seqno + ') ';
            msg.on('body', function(stream, info) {
              if (info.which === 'TEXT')
                console.log(prefix + 'Body [%s] found, %d total bytes', (info.which), info.size);
              var buffer = '', count = 0;
              stream.on('data', function(chunk) {
                count += chunk.length;
                buffer += chunk.toString('utf8');
                if (info.which === 'TEXT')
                  console.log(prefix + 'Body [%s] (%d/%d)', (info.which), count, info.size);
              });
              stream.once('end', function() {
                if (info.which !== 'TEXT') {
                  console.log(prefix + 'Parsed header: ');
                  var header = Imap.parseHeader(buffer); 
                  var from = header.from;
                  email = from[0].slice(from[0].indexOf('<')+1, from[0].indexOf('>'));
                  fetched = true;
                }
                else
                  console.log(prefix + 'Body [%s] Finished', (info.which));
              });
            });
            msg.once('attributes', function(attrs) {
              console.log(prefix + 'Attributes: %s', (attrs, false, 8));
            });
            msg.once('end', function() {
              console.log(prefix + 'Finished');
            });
          });
          f.once('error', function(err) {
            console.log('Fetch error: ' + err);
          });
          f.once('end', function() {
            console.log('Done fetching all messages!');
            imap.end();
             if(fetched){
                  var guest = Guests.findOne({email: email}, {reactive: false}); // <-- this code causes the error
                  if(guest){
                    console.log(guest)
                  }
                }
          });
        });
      });
      imap.once('error', function(err) {
        console.log(err);
      });
      imap.once('end', function() {
        console.log('Connection ended');
      });
      imap.connect();

So I tried to do a Meteor.bindEnvironment based on Future.wait() can't wait without a fiber (while waiting on another future in Meteor.method)

    function openInbox(cb) {
        imap.openBox('INBOX', true, Meteor.bindEnvironment(cb));
    }

And get the error message "Cannot read property '_meteor_dynamics' of undefined". So there is no Fiber to bind to? I am still fairly new to Meteor so don't really know where to go from here. An explanation on what is going on and a solution would be great. Any help is appreciated.

4

0 回答 0