postalsys / imapflow

IMAP Client library for EmailEngine Email API (https://emailengine.app)
https://imapflow.com
Other
364 stars 63 forks source link

Error: Unexpected char at position 8 #214

Closed dr460nf1r3 closed 2 months ago

dr460nf1r3 commented 2 months ago

Describe the bug

When establishing the connection to a mail server, parser-instance.js throws an error.

{"level":30,"time":1724139375986,"pid":20276,"hostname":"adm5","component":"imap-connection","cid":"dwrjymekm3hjl5fzae9y","src":"connection","msg":"Established secure TCP connection","cid":"dwrjymekm3hjl5fzae9y","secure":true,"host":"mail.somehost.net","servername":"mail.somehost.net","port":465,"address":"someip","localAddress":"10.2.131.10","localPort":57525,"authorized":true,"algo":"TLS_AES_256_GCM_SHA384","version":"TLSv1.3"}
{"level":50,"time":1724139376057,"pid":20276,"hostname":"adm5","component":"imap-connection","cid":"dwrjymekm3hjl5fzae9y","src":"s","msg":"220 mail.somehost.net ESMTP NO UCE","err":{"type":"Error","message":"Unexpected char at position 8 [E2: \".\"]","stack":"Error: Unexpected char at position 8 [E2: \".\"]\n    at ParserInstance.getElement (somepath\\node_modules\\imapflow\\lib\\handler\\parser-instance.js:102:29)\n    at ParserInstance.getCommand (somepath\\node_modules\\imapflow\\lib\\handler\\parser-instance.js:34:39)\n    at module.exports (somepath\\node_modules\\imapflow\\lib\\handler\\imap-parser.js:31:41)\nat processTicksAndRejections(node:internal/process/task_queues:95:5)\nat ImapFlow.reader (somepath\\node_modules\\imapflow\\lib\\imap-flow.js:478:26)","code":"ParserError2","parserContext":{"input":"220 mail.somehost.net ESMTP NO UCE","element":"mail.somehost.net","pos":4}},"cid":"dwrjymekm3hjl5fzae9y"}
{"level":50,"time":1724139391987,"pid":20276,"hostname":"adm5","component":"imap-connection","cid":"dwrjymekm3hjl5fzae9y","err":{"type":"Error","message":"Failed to receive greeting from server in required time","stack":"Error: Failed to receive greeting from server in required time\n    at Timeout._onTimeout (somepath\\node_modules\\imapflow\\lib\\imap-flow.js:1332:31)\n    at listOnTimeout (node:internal/timers:573:17)\n    at processTimers (node:internal/timers:514:7)","code":"GREEETING_TIMEOUT","details":{"greetingTimeout":16000}},"cid":"dwrjymekm3hjl5fzae9y","msg":"Failed to receive greeting from server in required time"}

To Reproduce Probably not easy to reproduce without connecting to the given server? The host is set up with https://gitlab.com/simple-nixos-mailserver/nixos-mailserver.

Expected behavior The connection succeeds.

Additional context Settings are:

{
  "secure": true,
  "auth": { "user": "test@somehost.org", "pass": "somepass" },
  "host": "mail.somehost.net",
  "port": 465,
  "logger": true
}
this.client = new ImapFlow(<ImapFlowOptions>this.settings.imapOptions);
await this.client.connect();

The problem occurs with Node.js 20.13.1 / imapflow library version 1.0.164.

andris9 commented 2 months ago

You are connecting an IMAP client to an SMTP server. Obviously, you will get syntax errors because the protocol is different.

dr460nf1r3 commented 2 months ago

Oops. Now that's hella embarrassing, sorry for bothering you with this Layer 8 problem.