chadxz / imap-simple

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

Possible bug (?) #80

Closed mihha closed 3 years ago

mihha commented 4 years ago

Hi guys!

I apologise for opening an issue here if it really is not an issue but didn't know how to reach you otherwise

I wonder if you could help me with one small issue

Let me try to explain the situation. I am using one node application which is implementing your module

I have the following setup:

When you start this application normally, you will see the following error

node --trace-warnings /usr/bin/n8n
n8n ready on 0.0.0.0, port 5678
Version: 0.74.0

================================
Start Active Workflows:
================================
- Arburoža
ADD ID (active): 1
(node:12687) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
at getAllowUnauthorized (internal/options.js:21:13)
at Object.connect (_tls_wrap.js:1561:29)
at Connection.connect (/usr/lib/node_modules/n8n/node_modules/imap/lib/Connection.js:128:22)
at /usr/lib/node_modules/n8n/node_modules/imap-simple/lib/imapSimple.js:584:14
at new Promise (<anonymous>)
at Object.connect (/usr/lib/node_modules/n8n/node_modules/imap-simple/lib/imapSimple.js:532:12)
at Object.trigger (/usr/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/EmailReadImap.node.js:211:42)
at Workflow.runTrigger (/usr/lib/node_modules/n8n/node_modules/n8n-workflow/dist/src/Workflow.js:498:37)
at ActiveWorkflows.add (/usr/lib/node_modules/n8n/node_modules/n8n-core/dist/src/ActiveWorkflows.js:24:46)
at ActiveWorkflowRunner.add (/usr/lib/node_modules/n8n/dist/src/ActiveWorkflowRunner.js:240:44)
 => Started
- Slobodna djelatnost - uplate
ADD ID (active): 2
 => Started

Editor is now accessible via:
https://localhost:5678/

Press "o" to open in Browser.
(node:12687) UnhandledPromiseRejectionWarning: Error: Got 0 parts, should get 1
at /usr/lib/node_modules/n8n/node_modules/imap-simple/lib/imapSimple.js:206:28
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
at processPromiseRejections (internal/process/promises.js:247:11)
at processTicksAndRejections (internal/process/task_queues.js:94:32)
(node:12687) Error: Got 0 parts, should get 1
at /usr/lib/node_modules/n8n/node_modules/imap-simple/lib/imapSimple.js:206:28
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:12687) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
at emitDeprecationWarning (internal/process/promises.js:180:11)
at processPromiseRejections (internal/process/promises.js:249:13)
at processTicksAndRejections (internal/process/task_queues.js:94:32)

If I set NODE_TLS_REJECT_UNAUTHORIZED=1 the application throws the following error image

It seems that your module is throwing an error but I don't know how to let it know that I have LetsEncrypt certificate which it should use?

Guys who are developers of n8n application claims that the issue is within imap-simple module and because of that, they don't plan to fix it in their application

Would you have a possible hint on how to solve this issue?

Thank you in advance!

Regards, Igor

izwerg commented 4 years ago

This is missing SNI. See this issue for details. A workaround is to set imap.tlsOptions.servername to imap.gmail.com in your config. E.g.:

const config = {
  imap: {
    host: 'imap.gmail.com',
    port: 993,
    tls: true,
    user: 'youraccount@gmail.com',
    password: 'yourpassword,
    tlsOptions: { servername: 'imap.gmail.com' }
  }
};