-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Connection.js #546
base: master
Are you sure you want to change the base?
Update Connection.js #546
Conversation
add some check on object _curReq and object box before use it It's fix some uncaugth error like : self._box.name = name; ^ TypeError: Cannot set property 'name' of undefined at Connection.<anonymous> (/root/thethingbox/node_modules/node-red/node_modules/node-red-node-email/node_modules/imap/lib/Connection.js:422:22) or var msg = self._curReq.fetchCache[info.seqno], toget; ^ TypeError: Cannot read property 'fetchCache' of undefined at Parser.<anonymous> (/root/thethingbox/node_modules/node-red/node_modules/node-red-node-email/node_modules/imap/lib/Connection.js:196:27)
I'd be more interested in knowing why there are |
I'm not sure what you want I debug, I added console.log(self) just after the parser.on('body', function (stream, info) { when the error come, I obtain this log : ( removing the mail adress and password) { domain: null,
_events: { error: [Function] },
_maxListeners: 10,
_config:
{ socket: undefined,
socketTimeout: 0,
host: 'smtp.gmail.com',
port: '993',
tls: true,
tlsOptions: { rejectUnauthorized: false },
autotls: undefined,
user: 'xxxxxxxxxxxxxxx@xxxxxxxxx',
password: 'xxxxxxxxxxxxxx',
xoauth: undefined,
xoauth2: undefined,
connTimeout: 7000,
authTimeout: 7000,
keepalive: true },
_sock:
{ _readableState:
{ highWaterMark: 16384,
buffer: [],
length: 0,
pipes: null,
pipesCount: 0,
flowing: false,
ended: false,
endEmitted: false,
reading: false,
calledRead: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: true,
objectMode: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: true,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events:
{ end: [Object],
sslOutEnd: [Function],
error: [Function],
timeout: [Function],
readable: [Function] },
_maxListeners: 10,
_writableState:
{ highWaterMark: 16384,
objectMode: false,
needDrain: false,
ending: true,
ended: true,
finished: true,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
sync: false,
bufferProcessing: false,
onwrite: [Function],
writecb: null,
writelen: 0,
buffer: [],
errorEmitted: false },
writable: false,
allowHalfOpen: true,
pair:
{ domain: null,
_events: [Object],
_maxListeners: 10,
server: undefined,
_secureEstablished: true,
_isServer: false,
_encWriteState: true,
_clearWriteState: true,
_doneFlag: false,
_destroying: false,
credentials: [Object],
_rejectUnauthorized: false,
_requestCert: true,
ssl: [Object],
servername: false,
cleartext: [Circular],
encrypted: [Object],
fd: undefined,
npnProtocol: undefined },
_pending: null,
_pendingEncoding: '',
_pendingCallback: null,
_doneFlag: false,
_retryAfterPartial: false,
_halfRead: false,
_sslOutCb: null,
_resumingSession: false,
_reading: true,
_destroyed: false,
_ended: false,
_finished: true,
_opposite:
{ _readableState: [Object],
readable: false,
domain: null,
_events: [Object],
_maxListeners: 10,
_writableState: [Object],
writable: true,
allowHalfOpen: true,
pair: [Object],
_pending: null,
_pendingEncoding: '',
_pendingCallback: null,
_doneFlag: true,
_retryAfterPartial: false,
_halfRead: false,
_sslOutCb: null,
_resumingSession: false,
_reading: true,
_destroyed: false,
_ended: true,
_finished: false,
_opposite: [Circular],
_buffer: [Object] },
_buffer:
{ isFull: false,
pool: <Buffer 4f 34 4e 43 53 71 73 56 6f 42 6b 46 5a 79 4b 0d 0a 55 2f 5a 69 66 78 2b 59 55 69 48 58 32 73 44 4d 38 42 45 36 6e 50 4a 47 46 2f 70 79 6c 6d 51 37 42 74 ...>,
offset: 7809569,
remaining: 2676191 },
_handle: { readStop: [Function], readStart: [Function] },
socket:
{ _connecting: false,
_handle: [Object],
_readableState: [Object],
readable: true,
domain: null,
_events: [Object],
_maxListeners: 10,
_writableState: [Object],
writable: false,
allowHalfOpen: false,
onend: null,
destroyed: false,
bytesRead: 4530834,
_bytesDispatched: 892,
_pendingData: null,
_pendingEncoding: '',
_idleNext: null,
_idlePrev: null,
_idleTimeout: -1,
read: [Function],
_consuming: true },
encrypted:
{ _readableState: [Object],
readable: false,
domain: null,
_events: [Object],
_maxListeners: 10,
_writableState: [Object],
writable: true,
allowHalfOpen: true,
pair: [Object],
_pending: null,
_pendingEncoding: '',
_pendingCallback: null,
_doneFlag: true,
_retryAfterPartial: false,
_halfRead: false,
_sslOutCb: null,
_resumingSession: false,
_reading: true,
_destroyed: false,
_ended: true,
_finished: false,
_opposite: [Circular],
_buffer: [Object] },
authorized: true,
_controlReleased: true,
npnProtocol: undefined },
_tagcount: 6,
_tmrConn:
{ _idleTimeout: -1,
_idlePrev: null,
_idleNext: null,
_idleStart: 1461162868479,
_monotonicStartTime: 399548,
_onTimeout: null,
_repeat: false,
ontimeout: null },
_tmrKeepalive: undefined,
_tmrAuth:
{ _idleTimeout: -1,
_idlePrev: null,
_idleNext: null,
_idleStart: 1461162868780,
_monotonicStartTime: 399849,
_onTimeout: null,
_repeat: false,
ontimeout: null },
_queue: [],
_box:
{ name: 'INBOX',
flags:
[ '\\Answered',
'\\Flagged',
'\\Draft',
'\\Deleted',
'\\Seen',
'$NotPhishing',
'$Phishing' ],
readOnly: false,
uidvalidity: 1,
uidnext: 1394,
permFlags: [ '\\Answered', '\\Flagged', '\\Draft', '\\Deleted', '\\Seen' ],
keywords: [ '$NotPhishing', '$Phishing' ],
newKeywords: true,
persistentUIDs: true,
nomodseq: false,
messages: { total: 1329, new: 0 },
highestmodseq: '247546' },
_idle: { started: undefined, enabled: false },
_parser:
{ domain: null,
_events:
{ untagged: [Function],
tagged: [Function],
body: [Function],
continue: [Function],
other: [Function] },
_maxListeners: 10,
_stream:
{ _readableState: [Object],
readable: true,
domain: null,
_events: [Object],
_maxListeners: 10,
_writableState: [Object],
writable: false,
allowHalfOpen: true,
pair: [Object],
_pending: null,
_pendingEncoding: '',
_pendingCallback: null,
_doneFlag: false,
_retryAfterPartial: false,
_halfRead: false,
_sslOutCb: null,
_resumingSession: false,
_reading: true,
_destroyed: false,
_ended: false,
_finished: true,
_opposite: [Object],
_buffer: [Object],
_handle: [Object],
socket: [Object],
encrypted: [Object],
authorized: true,
_controlReleased: true,
npnProtocol: undefined },
_body:
{ _readableState: [Object],
readable: true,
domain: null,
_events: {},
_maxListeners: 10,
_read: [Function] },
_literallen: 630,
_literals: [],
_buffer: '* 1329 FETCH (X-GM-THRID 1532140282143983147 X-GM-MSGID 1532140301053352759 X-GM-LABELS ("\\\\Important" "\\\\Sent") UID 1393 MODSEQ (247525) INTERNALDATE "20-Apr-2016 14:34:14 +0000" FLAGS (\\Seen) ',
_ignoreReadable: false,
debug: undefined,
_cbReadable: [Function] },
_curReq: undefined,
delimiter: '/',
namespaces: { personal: [ [Object] ], other: null, shared: null },
state: 'authenticated',
debug: undefined,
_onError: [Function],
_onSocketTimeout: [Function],
_caps:
[ 'IMAP4REV1',
'UNSELECT',
'IDLE',
'NAMESPACE',
'QUOTA',
'ID',
'XLIST',
'CHILDREN',
'X-GM-EXT-1',
'UIDPLUS',
'COMPRESS=DEFLATE',
'ENABLE',
'MOVE',
'CONDSTORE',
'ESEARCH',
'UTF8=ACCEPT',
'APPENDLIMIT=35882577',
'LIST-EXTENDED',
'LIST-STATUS' ] } |
Ok, so the parser still thinks it's parsing the results from a |
I set
|
Are you reusing client instances or? Can you show how you're using the module? |
It's come when I use the node mail of node-red so, each 10 seconds, this code is called : (line 180 of file 61-email.js) imap.once('ready', function() {
node.status({fill:"blue",shape:"dot",text:"email.status.fetching"});
var pay = {};
imap.openBox(node.box, false, function(err, box) {
if (err) {
node.status({fill:"red",shape:"ring",text:"email.status.foldererror"});
node.error(RED._("email.errors.fetchfail",{folder:node.box}),err);
}
else {
if (box.messages.total > 0) {
//var f = imap.seq.fetch(box.messages.total + ':*', { markSeen:true, bodies: ['HEADER.FIELDS (FROM SUBJECT DATE TO CC BCC)','TEXT'] });
var f = imap.seq.fetch(box.messages.total + ':*', { markSeen:true, bodies: ['HEADER','TEXT'] });
f.on('message', function(msg, seqno) {
node.log(RED._("email.status.message",{number:seqno}));
var prefix = '(#' + seqno + ') ';
msg.on('body', function(stream, info) {
var buffer = '';
stream.on('data', function(chunk) {
buffer += chunk.toString('utf8');
});
stream.on('end', function() {
if (info.which !== 'TEXT') {
var head = Imap.parseHeader(buffer);
if (head.hasOwnProperty("from")) { pay.from = head.from[0]; }
if (head.hasOwnProperty("subject")) { pay.topic = head.subject[0]; }
if (head.hasOwnProperty("date")) { pay.date = head.date[0]; }
pay.header = head;
} else {
var parts = buffer.split("Content-Type");
for (var p = 0; p < parts.length; p++) {
if (parts[p].indexOf("text/plain") >= 0) {
pay.payload = parts[p].split("\n").slice(1,-2).join("\n").trim();
}
else if (parts[p].indexOf("text/html") >= 0) {
pay.html = parts[p].split("\n").slice(1,-2).join("\n").trim();
} else {
pay.payload = parts[0];
}
}
//pay.body = buffer;
}
});
});
msg.on('end', function() {
//node.log('finished: '+prefix);
});
});
f.on('error', function(err) {
node.warn(RED._("email.errors.messageerror",{error:err}));
node.status({fill:"red",shape:"ring",text:"email.status.messageerror"});
});
f.on('end', function() {
delete(pay._msgid);
if (JSON.stringify(pay) !== oldmail) {
oldmail = JSON.stringify(pay);
node.send(pay);
node.log(RED._("email.status.newemail",{topic:pay.topic}));
}
else { node.log(RED._("email.status.duplicate",{topic:pay.topic})); }
//node.status({fill:"green",shape:"dot",text:"node-red:common.status.ok"});
node.status({});
});
}
else {
node.log(RED._("email.status.inboxzero"));
//node.status({fill:"green",shape:"dot",text:"node-red:common.status.ok"});
node.status({});
}
}
imap.end();
});
});
node.status({fill:"grey",shape:"dot",text:"node-red:common.status.connecting"});
imap.connect(); |
That looks relatively ok. Are you re-using |
this node-red module do |
Ok looking at the debug output again and with what you just told me, I think it makes sense now. I believe The underlying downstream problem still exists though, even with the aforementioned patch. A connection is being requested, but since the same instance is being reused, it's not waiting for the previous connection to be ready first (and possibly execute any So some possible suggestions for changes to the
|
@mscdex This seems to be related to #591. The suggested patch works, but it seemed like the request got stuck in like 1 of 10 attempts at first, thought it easily might have been something else. What do we do? Happy to work on the PR, but would appreciate some guidance – very new to the lib and the IMAP business. 👍 |
My particular issue appears my own fault – reconnecting on any status other than |
see PR mscdex#564 in original repo: mscdex#546 These crashes might result from user errors... but still it makes sense to not just crash because of accessing uninitialized variables.
add some check on object _curReq and object box before use it
It's fix some uncaugth error like :
or