Hi,
I am trying to get attachments from emails on a imap server and upload it to a paperless-ngx server.
So far, I managed to succeed in uploading a file located on the file system.
The attachments collection seems also to work.
The only part were I am stuck is from the "Read File" node which apparently does not find the msg.filename provided by the previous node.
Debug windows show that filename and content are correctly defined in the msg.
If someone has any suggestions, it will be appreciated. Thanks in advance for your help and support.
[
{
"id": "64c93503f2327cd7",
"type": "e-mail in",
"z": "adeefda291ab9373",
"name": "MyImapServer",
"protocol": "IMAP",
"server": "imap.mail.me.com",
"useSSL": true,
"autotls": "required",
"port": "993",
"authtype": "NONE",
"saslformat": true,
"token": "oauth2Response.access_token",
"box": "INBOX",
"disposition": "None",
"criteria": "ALL",
"repeat": "3000",
"fetch": "trigger",
"inputs": 1,
"x": 460,
"y": 700,
"wires": [
[
"aeabc6efaf7a7c89"
]
]
},
{
"id": "b9bed3ec8db3952a",
"type": "switch",
"z": "adeefda291ab9373",
"name": "Attachment?",
"property": "attachments.length",
"propertyType": "msg",
"rules": [
{
"t": "gt",
"v": "0",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 450,
"y": 820,
"wires": [
[
"1ccff38aff25a8cf"
],
[]
]
},
{
"id": "8a5eea56edea6da8",
"type": "inject",
"z": "adeefda291ab9373",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 440,
"y": 640,
"wires": [
[
"64c93503f2327cd7"
]
]
},
{
"id": "aeabc6efaf7a7c89",
"type": "switch",
"z": "adeefda291ab9373",
"name": "From?",
"property": "from",
"propertyType": "msg",
"rules": [
{
"t": "cont",
"v": "assur",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 470,
"y": 760,
"wires": [
[
"b9bed3ec8db3952a"
]
]
},
{
"id": "584ac1ace6ce7951",
"type": "debug",
"z": "adeefda291ab9373",
"name": "debug 28",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1160,
"y": 700,
"wires": []
},
{
"id": "1ccff38aff25a8cf",
"type": "change",
"z": "adeefda291ab9373",
"name": "Payload=Attachment",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "attachments",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 480,
"y": 880,
"wires": [
[
"5a250fcdcde156c0"
]
]
},
{
"id": "5a250fcdcde156c0",
"type": "split",
"z": "adeefda291ab9373",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"property": "payload",
"x": 690,
"y": 880,
"wires": [
[
"da71c49223f130df"
]
]
},
{
"id": "afc0a63c35b78298",
"type": "change",
"z": "adeefda291ab9373",
"name": "Filename + Content",
"rules": [
{
"t": "set",
"p": "filename",
"pt": "msg",
"to": "payload.filename",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.content",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1110,
"y": 880,
"wires": [
[
"9a4b632eac1d8c45",
"44c785bef9307991"
]
]
},
{
"id": "9a4b632eac1d8c45",
"type": "file in",
"z": "adeefda291ab9373",
"name": "Email Attach",
"filename": "filename",
"filenameType": "msg",
"format": "",
"chunk": false,
"sendError": false,
"encoding": "none",
"allProps": false,
"x": 555,
"y": 939,
"wires": [
[
"ae7a1daf9ddff457"
]
]
},
{
"id": "ae7a1daf9ddff457",
"type": "function",
"z": "adeefda291ab9373",
"name": "Prepare Upload",
"func": "const apiToken = \"MY_TOKEN\"; // Replace with your token\nconst apiURL = \"https://my.paperless.url/api/documents/post_document/\";\n\nvar fileData = msg.payload;\nvar fileName = msg.filename;\n\n// Prepare HTTP headers\nmsg.headers = {\n \"Authorization\": \"Token \" + apiToken,\n \"Content-Type\": \"multipart/form-data\"\n};\n\n\n// Attach file content as form data\nmsg.method = \"POST\";\nmsg.payload = {\n document: {\n value: fileData, // The file content from the File node\n options: {\n filename: fileName, // Modify the filename if needed\n contentType: \"multipart/form-data\", // Replace with correct MIME type\n tags: \"inbox\"\n }\n }\n};\n\n// Set the API URL\nmsg.url = apiURL;\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 756,
"y": 941,
"wires": [
[
"9e1e658d9fbaa605"
]
]
},
{
"id": "9e1e658d9fbaa605",
"type": "http request",
"z": "adeefda291ab9373",
"name": "",
"method": "use",
"ret": "txt",
"paytoqs": "ignore",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 950,
"y": 949,
"wires": [
[
"90896371fc8b61b8"
]
]
},
{
"id": "90896371fc8b61b8",
"type": "debug",
"z": "adeefda291ab9373",
"name": "debug 29",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1120,
"y": 960,
"wires": []
},
{
"id": "da71c49223f130df",
"type": "switch",
"z": "adeefda291ab9373",
"name": "Pdf?",
"property": "payload.contentType",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "application/pdf",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 890,
"y": 880,
"wires": [
[
"afc0a63c35b78298",
"584ac1ace6ce7951"
]
]
},
{
"id": "44c785bef9307991",
"type": "debug",
"z": "adeefda291ab9373",
"name": "debug 30",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1380,
"y": 780,
"wires": []
}
]
Denis