{
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": false,
        "filters": {
          "readStatus": "unread"
        },
        "options": {
          "downloadAttachments": true
        }
      },
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.2,
      "position": [
        -960,
        680
      ],
      "id": "dc3aa025-1a0e-4521-abc3-7b6e839987b3",
      "name": "Gmail Trigger1",
      "credentials": {
        "gmailOAuth2": {
          "id": "hM6bQW0xBJblh1Tw",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "operation": "get",
        "messageId": "={{ $('Gmail Trigger1').item.json.id }}",
        "simple": false,
        "options": {
          "downloadAttachments": true
        }
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        -520,
        680
      ],
      "id": "2e79a39a-e1a6-4cb4-a2f4-b2f39ad4622a",
      "name": "Gmail1",
      "webhookId": "b7f54ce6-0bb8-45d3-970c-76fda0729899",
      "credentials": {
        "gmailOAuth2": {
          "id": "hM6bQW0xBJblh1Tw",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "resource": "draft",
        "subject": "=With JPG attachments – {{ $('Gmail1').item.json.subject }}",
        "emailType": "html",
        "message": "Hello,<br><br>The attachments contain JPG/JPEG files.<br><br>Best regards,",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {
                "property": "={{ $('Function – Filter by Extension Type').all().map(att => att.json.key).join(',') }}"
              }
            ]
          }
        }
      },
      "id": "df21cb1f-3474-40ac-bfa5-715fca99a358",
      "name": "Gmail – Create Draft ",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2,
      "position": [
        180,
        680
      ],
      "webhookId": "af45050c-6070-46a3-bd01-64f1510656ae",
      "credentials": {
        "gmailOAuth2": {
          "id": "hM6bQW0xBJblh1Tw",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const binaryData = items[0].binary || {};\nconst messageId = items[0].json.id || 'unknown';\nconst attachmentKeys = Object.keys(binaryData);\n\nconst attachmentsInfo = attachmentKeys.map(key => {\n  const file = binaryData[key];\n\n  return {\n    key,\n    fileName: file.fileName || key,\n    extension: file.fileName?.split('.').pop().toLowerCase() || '',\n    mimeType: file.mimeType || '',\n    fileSize: file.fileSize || file.data?.length || null,\n    messageId\n  };\n});\n\nreturn attachmentsInfo.map(info => ({\n  json: info,\n  binary: binaryData  // Passes all binary data along with each item\n}));\n"
      },
      "id": "4a0a33ed-f2e1-4244-a9c5-5e3c8c286c7b",
      "name": "Function – Attachment MetaData",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        -280,
        680
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "a9ea58b8-305b-4a36-9ae4-67144354a177",
              "leftValue": "={{ $('Gmail Trigger1').item.binary }}",
              "rightValue": "",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        -740,
        680
      ],
      "id": "203de072-d2a8-45d3-aba1-b236676c8dca",
      "name": "Filter emails with attachments only"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "1a065b12-9f0d-429d-bd68-33620b05e92d",
              "leftValue": "={{ $json.extension }}",
              "rightValue": "jpeg",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            },
            {
              "id": "d44de1d4-aaaf-41a5-9a7d-b2b2fac2542c",
              "leftValue": "={{ $json.extension }}",
              "rightValue": "jpg",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        -60,
        680
      ],
      "id": "0c6569d2-638c-4a05-9757-36e121d3542c",
      "name": "Function – Filter by Extension Type"
    }
  ],
  "connections": {
    "Gmail Trigger1": {
      "main": [
        [
          {
            "node": "Filter emails with attachments only",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail1": {
      "main": [
        [
          {
            "node": "Function – Attachment MetaData",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function – Attachment MetaData": {
      "main": [
        [
          {
            "node": "Function – Filter by Extension Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter emails with attachments only": {
      "main": [
        [
          {
            "node": "Gmail1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function – Filter by Extension Type": {
      "main": [
        [
          {
            "node": "Gmail – Create Draft ",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": ""
  }
}