umanamente / n8n-nodes-imap

This is an n8n community node that adds support for IMAP email servers.
MIT License
10 stars 1 forks source link

Cannot read properties of undefined (reading 'filename') #1

Closed lamarios closed 6 months ago

lamarios commented 6 months ago

Hi,

I'm getting the following error:

NodeApiError: Cannot read properties of undefined (reading 'filename')
    at Object.execute (/home/node/.n8n/nodes/node_modules/n8n-nodes-imap/nodes/Imap/Imap.node.ts:74:15)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:696:19)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:656:53

When trying to retrieved attached file from gmail. Heres the json input :

[
    {
        "seq": 545,
        "emailId": "1787316242905259322",
        "uid": 50766,
        "modseq": "7824950",
        "envelope": {
            "date": "2024-01-06T05:06:24.000Z",
            "subject": "test attachment",
            "from": [
                {
                    "name": "xxxxxx",
                    "address": "xxxxx"
                }
            ],
            "sender": [
                {
                    "name": "xxxxx",
                    "address": "xxxxxx"
                }
            ],
            "replyTo": [
                {
                    "name": "xxxxx",
                    "address": "xxxxx"
                }
            ],
            "to": [
                {
                    "name": "xxxx",
                    "address": "xxxx"
                }
            ],
            "messageId": ""
        },
        "bodyStructure": {
            "childNodes": [
                {
                    "part": "1",
                    "childNodes": [
                        {
                            "part": "1.1",
                            "type": "text/plain",
                            "parameters": {
                                "charset": "utf-8"
                            },
                            "encoding": "base64",
                            "size": 22,
                            "lineCount": 1
                        },
                        {
                            "part": "1.2",
                            "type": "text/html",
                            "parameters": {
                                "charset": "utf-8"
                            },
                            "encoding": "base64",
                            "size": 36,
                            "lineCount": 1
                        }
                    ],
                    "type": "multipart/alternative",
                    "parameters": {
                        "boundary": "b2_gBUGeS4c5Ygk7HcLjeocfuB7HRnVs3Qx3ag1WJGA"
                    }
                },
                {
                    "part": "2",
                    "type": "image/jpeg",
                    "parameters": {
                        "name": "Fan_4-Pin_PWM_Connector_Male_to_2-Pin_CB-32D_Connector_Female_(5cm)_(2)__07913_zoom.jpg"
                    },
                    "encoding": "base64",
                    "size": 53538,
                    "disposition": "attachment",
                    "dispositionParameters": {
                        "filename": "Fan_4-Pin_PWM_Connector_Male_to_2-Pin_CB-32D_Connector_Female_(5cm)_(2)__07913_zoom.jpg"
                    }
                }
            ],
            "type": "multipart/mixed",
            "parameters": {
                "boundary": "b1_gBUGeS4c5Ygk7HcLjeocfuB7HRnVs3Qx3ag1WJGA"
            }
        },
        "id": "1787316242905259322",
        "attachmentsInfo": [
            {
                "partId": "2",
                "filename": "Fan_4-Pin_PWM_Connector_Male_to_2-Pin_CB-32D_Connector_Female_(5cm)_(2)__07913_zoom.jpg",
                "type": "image/jpeg",
                "encoding": "base64",
                "size": 53538
            }
        ],
        "path": "/tmp/test/2024-01"
    }
]
umanamente commented 6 months ago

I was able to reproduce this problem, but unfortunately this is a Gmail specific issue, when Gmail IMAP server responds with "Some messages could not be FETCHed (Failure)" when it couldn't provide the specific email part (attachment). I only got this error when specified "1.1" or "1.2" as "Attachment Part ID" instead of "2". Please check if you specify correct attachment part number (usually starts from 2).

I also updated the node (v1.1.1), so it will display IMAP server errors in the error description.

lamarios commented 6 months ago

yeah I specified the part id properly, from the attachmentInfo data:

image

image

Edit: I updated the node, but the error is the same. Do i need to restart or something ? I'm fairly new to n8n

umanamente commented 6 months ago

Edit: I updated the node, but the error is the same. Do i need to restart or something ? I'm fairly new to n8n

Yes, you need to restart n8n after updating community nodes

lamarios commented 6 months ago

i'm getting this:

NodeApiError: IMAP server has not returned attachment info
    at Object.executeImapAction (/home/node/.n8n/nodes/node_modules/n8n-nodes-imap/nodes/Imap/operations/email/functions/EmailDownloadAttachment.ts:63:10)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Object.execute (/home/node/.n8n/nodes/node_modules/n8n-nodes-imap/nodes/Imap/Imap.node.ts:75:24)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:696:19)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:656:53

same email as above.

umanamente commented 6 months ago

Does it show the IMAP server response? It should be in the error description.

lamarios commented 6 months ago

owh i think i know why. I was using the wrong credentials, I didn't realize that downloading attachments required credentials. i thought it would know where to get from based on the inputs. Meanwhile i switched to use the gmail nodes directly, I'll try again with your node and see.

lamarios commented 6 months ago

Yeah all working, sorry for the trouble, it was my issue from the beginning. Great project though, thanks :)

umanamente commented 6 months ago

Yeah all working, sorry for the trouble, it was my issue from the beginning. Great project though, thanks :)

Glad to hear! Also your input helped identify a minor bug, which is now fixed (correctly handling empty/bad response from server).