{
  "name": "Nodbot - Email IMAP Gmail parser with attachments",
  "nodes": [
    {
      "parameters": {
        "path": "integration-email-imap-gmail-n8n-parser",
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "id": "2c2d9122-f417-4c80-954f-b73beaa00f33",
      "name": "Email or Gmail Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const src = $json.body ?? $json;\nconst headers = src.headers ?? {};\nconst messageId = String(src.message_id ?? headers['message-id'] ?? src.id ?? '').trim();\nif (!messageId) throw new Error('No email Message-ID or provider id');\nconst from = String(src.from ?? '').toLowerCase();\nconst subject = String(src.subject ?? '').trim();\nconst body = String(src.body_text ?? src.text ?? '').trim();\nconst ignored = /(auto.?reply|out of office|delivery status|mailer-daemon|no-reply)/i;\nif (ignored.test(from) || ignored.test(subject)) {\n  return [{ json: { action: 'ignore', reason: 'auto_or_system_email', from, subject } }];\n}\nconst attachments = Array.isArray(src.attachments) ? src.attachments.filter(a => {\n  const size = Number(a.size_bytes ?? 0);\n  const name = String(a.filename ?? '').toLowerCase();\n  return size > 0 && size < 25 * 1024 * 1024 && !name.endsWith('.exe');\n}) : [];\nconst intent = /счет|invoice|оплат/i.test(subject + ' ' + body) ? 'invoice' : /договор|contract/i.test(subject + ' ' + body) ? 'contract' : 'support_request';\nreturn [{ json: {\n  action: 'create_task_or_ticket',\n  idempotency_key: `email:${src.mailbox ?? 'default'}:${messageId}`.toLowerCase(),\n  from, subject, intent,\n  body_preview: body.slice(0, 600),\n  attachment_count: attachments.length,\n  attachments,\n  received_at: src.received_at ?? new Date().toISOString()\n}}];"
      },
      "id": "589310a4-43e0-4c09-bd21-1a09681c5524",
      "name": "Normalize message",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const src = $json.body ?? $json;\nconst headers = src.headers ?? {};\nconst messageId = String(src.message_id ?? headers['message-id'] ?? src.id ?? '').trim();\nif (!messageId) throw new Error('No email Message-ID or provider id');\nconst from = String(src.from ?? '').toLowerCase();\nconst subject = String(src.subject ?? '').trim();\nconst body = String(src.body_text ?? src.text ?? '').trim();\nconst ignored = /(auto.?reply|out of office|delivery status|mailer-daemon|no-reply)/i;\nif (ignored.test(from) || ignored.test(subject)) {\n  return [{ json: { action: 'ignore', reason: 'auto_or_system_email', from, subject } }];\n}\nconst attachments = Array.isArray(src.attachments) ? src.attachments.filter(a => {\n  const size = Number(a.size_bytes ?? 0);\n  const name = String(a.filename ?? '').toLowerCase();\n  return size > 0 && size < 25 * 1024 * 1024 && !name.endsWith('.exe');\n}) : [];\nconst intent = /счет|invoice|оплат/i.test(subject + ' ' + body) ? 'invoice' : /договор|contract/i.test(subject + ' ' + body) ? 'contract' : 'support_request';\nreturn [{ json: {\n  action: 'create_task_or_ticket',\n  idempotency_key: `email:${src.mailbox ?? 'default'}:${messageId}`.toLowerCase(),\n  from, subject, intent,\n  body_preview: body.slice(0, 600),\n  attachment_count: attachments.length,\n  attachments,\n  received_at: src.received_at ?? new Date().toISOString()\n}}];"
      },
      "id": "7d682c17-5596-4eee-86c9-e749930686b0",
      "name": "Classify email intent",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        560,
        260
      ]
    },
    {
      "parameters": {},
      "id": "803b77f7-6d65-40ca-96d0-0eb8061531a8",
      "name": "Check Message-ID dedupe",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2,
      "position": [
        840,
        260
      ]
    },
    {
      "parameters": {},
      "id": "dc773d8c-dac3-46a2-98c6-99f4e7a4edf2",
      "name": "Save attachments",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        1120,
        260
      ]
    },
    {
      "parameters": {},
      "id": "88cc601e-1664-417f-bd6e-23ac27dd12b0",
      "name": "Create task or ticket",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        1400,
        260
      ]
    }
  ],
  "connections": {
    "Email or Gmail Trigger": {
      "main": [
        [
          {
            "node": "Normalize message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize message": {
      "main": [
        [
          {
            "node": "Classify email intent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify email intent": {
      "main": [
        [
          {
            "node": "Check Message-ID dedupe",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Message-ID dedupe": {
      "main": [
        [
          {
            "node": "Save attachments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save attachments": {
      "main": [
        [
          {
            "node": "Create task or ticket",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "nodbot",
    "integration",
    "production"
  ],
  "triggerCount": 1,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "2c55f935-bc45-46cb-a05b-9b099832c6ee",
  "meta": {
    "templateCredsSetupCompleted": false
  }
}