REGEX not working as expected?

Describe the issue/error/question

I am trying to setup an incoming email in AWS SES, to notify a topic in AWS SNS, and then pick that up with a code node, so that I can do other things with it. the way SNS works, it nests the raw email message as JSON inside of the message field. Since I am just trying to get the body of the email, I was trying to use REGEX to get all text between one string and another.

I have worked this out via regex101.com, and can get the item to work in the workflow when I declare the data as a string; However, if I refer to the transformed data from the AWS SNS Trigger (pinned), I get a null output.

I have not determined a method to compare the contents of the str and the data transformed from the SNS node.

What is the error message (if any)?

I am not getting any error messages, but the regex is returning null.

Please share the workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 0.213.0
  • Database you’re using (default: SQLite): SQLite
  • Running n8n with the execution process [own(default), main]: own
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: npm

Hey @kcwebby,

In theory it is just javascript so assuming the regex and in the input work you should be good to go. Have you tried it on a smaller scale like looking for a string in some json data?

Hi Jon, thanks for the response;
I have not; Since I can get it to work when the “same” text is declared as a string in the node, I figured that something was just different between what it was pulling in, and what I had declared as a string. My string declaration is essentially a JSON export from the AWS SNS Trigger node, so I assumed it would process the same as from inside the node itself.

There is a typo on the node I posted, but basically line 29 works, and line 30 is supposed to be
messageTXT = regex.exec(messageTXT).toString() //does not work - results in empty var.

When you comment out 29, and run 30 its null (I’ve tried also without the .toString() ); but 29 works as expected.

Hey @kcwebby,

I get other errors when trying, Is the value of str exactly what comes out of the SNS node or was that changed? When I try to use it as a pin it seems to be invalid which makes it tricky to test.

Yes, at least I think so;

I exported the output of the AWS SNS Trigger (pinned it, so I can provide also if you’d like).
The only thing I did before updating the nodes was to change domain names and my AWS account ID for privacy, but the replacement was in the same format. Nothing in the data is terribly private, I could share it directly if you think that might be affecting it, I can also include the pinned output from the AWS SNS Trigger as well (private edits).
basically I changed the sender domain to testemailtxdomain.com
the recieving domain to testemailrxdomain.com
and changed my aws ID to 000009110000

  {
    "Type": "Notification",
    "MessageId": "4d91d489-f9c4-52c3-a9da-88d573fd7b89",
    "TopicArn": "arn:aws:sns:us-east-1:000009110000:alertsmail",
    "Subject": "Amazon SES Email Receipt Notification",
    "Message": "{\"notificationType\":\"Received\",\"mail\":{\"timestamp\":\"2023-02-07T17:18:48.295Z\",\"source\":\"[email protected]\",\"messageId\":\"s4llmkn04p4dgq3shhs5t2ohss3bo7pn0qi3c201\",\"destination\":[\"[email protected]\"],\"headersTruncated\":false,\"headers\":[{\"name\":\"Return-Path\",\"value\":\"<[email protected]>\"},{\"name\":\"Received\",\"value\":\"from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) by inbound-smtp.us-east-1.amazonaws.com with SMTP id s4llmkn04p4dgq3shhs5t2ohss3bo7pn0qi3c201 for [email protected]; Tue, 07 Feb 2023 17:18:48 +0000 (UTC)\"},{\"name\":\"X-SES-Spam-Verdict\",\"value\":\"PASS\"},{\"name\":\"X-SES-Virus-Verdict\",\"value\":\"PASS\"},{\"name\":\"Received-SPF\",\"value\":\"none (spfCheck: 209.85.128.172 is neither permitted nor denied by domain of testemailtxdomain.com) client-ip=209.85.128.172; [email protected]; helo=mail-yw1-f172.google.com;\"},{\"name\":\"Authentication-Results\",\"value\":\"amazonses.com; spf=none (spfCheck: 209.85.128.172 is neither permitted nor denied by domain of testemailtxdomain.com) client-ip=209.85.128.172; [email protected]; helo=mail-yw1-f172.google.com; dkim=pass [email protected]; dmarc=none header.from=testemailtxdomain.com;\"},{\"name\":\"X-SES-RECEIPT\",\"value\":\"AEFBQUFBQUFBQUFGSU91V2k3eVU3MFdZNTZHWUZVaTRpR0h3QzVkWnJrLzR4K0NqQnZiT0graUI2SmxXMVQ4NkhhSk13UThud0dVaE1Zbmh5aDRvS3BtRDNjS2ltekluenVnb2czWE1IZGdSVWtiWjZOWWMwaUd5Q1h5a3dzdmxzZ2UyRVpaR3l6SndEb2JGWHo3b3haRHJDbHFNbzZ3enRvRkxINkp2MnFVT1hYYTBTMGllV2VKdGlpQlNaeWxHNFd2WGUyOXRkSk1TUUN0WnZZUXN0ejBJczJGallaUW83RkVkeXA5cTY3RDdjUm9pR3JUME94YTFrdkdNb0d1eUxhaCs3bU01OVhDMnNJNlBEcDQ5MlYwVmZxOWFtdktxSU8xUXQwWWxrNWhITGttRkRDNGoxN2c9PQ==\"},{\"name\":\"X-SES-DKIM-SIGNATURE\",\"value\":\"a=rsa-sha256; q=dns/txt; b=KrOrSVlr4UKF9KiGMbh7wppMfpMIUHqp+COR9IDhjoVD4I7jsrYwoAJEuAbzN98b8xsORNQw4+pSrLYVK4Sp2rn15JWE9BE6ZR0xwpogZdduUw0l7l1BzI2MemAPlEjX5kHVO+vi6yhV+tmDdwQp4uqmfUKqLKtQRzn5nVpqUCI=; c=relaxed/simple; s=6gbrjpgwjskckoa6a5zn6fwqkn67xbtw; d=amazonses.com; t=1675790328; v=1; bh=bTtrjy+s8vCLOfS3TwRaijDO11xe+YrRULcqxQzfoc8=; h=From:To:Cc:Bcc:Subject:Date:Message-ID:MIME-Version:Content-Type:X-SES-RECEIPT;\"},{\"name\":\"Received\",\"value\":\"by mail-yw1-f172.google.com with SMTP id 00721157ae682-527979e8670so117289057b3.10 for <[email protected]>; Tue, 07 Feb 2023 09:18:48 -0800 (PST)\"},{\"name\":\"DKIM-Signature\",\"value\":\"v=1; a=rsa-sha256; c=relaxed/relaxed; d=testemailtxdomain.com.20210112.gappssmtp.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version:from:to:cc:subject:date:message-id:reply-to; bh=K/vkpZAfqNfjE7VmBzfZwR5cj4TOi3l8JujyuO4K+a4=; b=JTTf474I6jKtd70yTKsoniuaVbZhPUeBh8iKk7VfMYfZhph9kDrxTn4SRC0ccbhS3fjbqkkFd3MHlzErtHYXE5lyCKBmnJLcGQvk6Io5Ingms86DZ6Jr2F0izI/XZLfy/Gk19agP7g8rXtaz4xc9dst+kP0f4fLOTav+hTP1s+f7W0GbhT/+DlwXIxBBLUJKiY1wqifKytkJiynMs2MTsiXEPtgikgA8tgMPJ0Gj9Nb+9LxvUd15sHWjC0cJ8L5UJHhJuZduFyJYVvirPXCiWaY2B5OAsZN/XisiPV5oIJTw0dnpGhG1pESAJsT0mftcT7T3UGkARfOhSEgx4+lxcw==\"},{\"name\":\"X-Google-DKIM-Signature\",\"value\":\"v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=K/vkpZAfqNfjE7VmBzfZwR5cj4TOi3l8JujyuO4K+a4=; b=cwsngK5L9EonoJhO4w1XqsLMxFmsxoGW9u37Zv8wC/jhatfybTZa9LSB6VGgOl58jJ 5ne4pI6T9/XFmL/FOLJ6bhwu5f4XSWTDTqA1mgDlFfPTj6OhbR8RFLk2JmF6UgfOrVpB oNXcjIx/Tm4ZTla4MBTFv//bpAdrtjjnXXKYvjdSPCl15v/uiEGq3nh5K9/gYXqPeKmc st20CkXkuMrBuJdMD8SRaBSi7rzDWaidE3rtsiiG73T4nHx1mrt7oS/t8SH6ur/uOhM4 vN+oV/7ymrp7CrHgacZaem1SpLnSdAk7UCW4QfhGk5BU7iWOGGXGqBM/38eTD7ipRm0w yrfA==\"},{\"name\":\"X-Gm-Message-State\",\"value\":\"AO0yUKU+4R7mOls9ftLFT8nWRGHmGhHeCd8P0VhAwdIRduS1RE6GoLbA 64TsE4DXQRSYAdwJQw5tEeppeQCaoWuRuJ6yZIzU21kBcWtyyA==\"},{\"name\":\"X-Google-Smtp-Source\",\"value\":\"AK7set9CJBb4rcWUAAdHRNWxkNJuNafCEl+cCG1bZRQ6nsy5OSSiw7h9x6CCLuOATHOQAvkMRyjKeHS6Ly6/08m4VnM=\"},{\"name\":\"X-Received\",\"value\":\"by 2002:a0d:dd8d:0:b0:52a:7aed:b634 with SMTP id g135-20020a0ddd8d000000b0052a7aedb634mr310584ywe.491.1675790327421; Tue, 07 Feb 2023 09:18:47 -0800 (PST)\"},{\"name\":\"MIME-Version\",\"value\":\"1.0\"},{\"name\":\"References\",\"value\":\"<[email protected]>\"},{\"name\":\"In-Reply-To\",\"value\":\"<[email protected]>\"},{\"name\":\"From\",\"value\":\"Brian M <[email protected]>\"},{\"name\":\"Date\",\"value\":\"Tue, 7 Feb 2023 12:18:36 -0500\"},{\"name\":\"Message-ID\",\"value\":\"<[email protected]om>\"},{\"name\":\"Subject\",\"value\":\"Fwd: Alarm CPU Usage Low on Virtual Machine : ap-jumphost1 is Critical\"},{\"name\":\"To\",\"value\":\"[email protected]\"},{\"name\":\"Content-Type\",\"value\":\"multipart/alternative; boundary=\\\"0000000000002f359505f41f5738\\\"\"}],\"commonHeaders\":{\"returnPath\":\"[email protected]\",\"from\":[\"Brian M <[email protected]>\"],\"date\":\"Tue, 7 Feb 2023 12:18:36 -0500\",\"to\":[\"[email protected]\"],\"messageId\":\"<[email protected]om>\",\"subject\":\"Fwd: Alarm CPU Usage Low on Virtual Machine : ap-jumphost1 is Critical\"}},\"receipt\":{\"timestamp\":\"2023-02-07T17:18:48.295Z\",\"processingTimeMillis\":722,\"recipients\":[\"[email protected]\"],\"spamVerdict\":{\"status\":\"PASS\"},\"virusVerdict\":{\"status\":\"PASS\"},\"spfVerdict\":{\"status\":\"GRAY\"},\"dkimVerdict\":{\"status\":\"GRAY\"},\"dmarcVerdict\":{\"status\":\"GRAY\"},\"action\":{\"type\":\"SNS\",\"topicArn\":\"arn:aws:sns:us-east-1:000009110000:alertsmail\",\"encoding\":\"UTF8\"}},\"content\":\"Return-Path: <[email protected]>\\r\\nReceived: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172])\\r\\n by inbound-smtp.us-east-1.amazonaws.com with SMTP id s4llmkn04p4dgq3shhs5t2ohss3bo7pn0qi3c201\\r\\n for [email protected];\\r\\n Tue, 07 Feb 2023 17:18:48 +0000 (UTC)\\r\\nX-SES-Spam-Verdict: PASS\\r\\nX-SES-Virus-Verdict: PASS\\r\\nReceived-SPF: none (spfCheck: 209.85.128.172 is neither permitted nor denied by domain of testemailtxdomain.com) client-ip=209.85.128.172; [email protected]; helo=mail-yw1-f172.google.com;\\r\\nAuthentication-Results: amazonses.com;\\r\\n spf=none (spfCheck: 209.85.128.172 is neither permitted nor denied by domain of testemailtxdomain.com) client-ip=209.85.128.172; [email protected]; helo=mail-yw1-f172.google.com;\\r\\n dkim=pass [email protected];\\r\\n dmarc=none header.from=testemailtxdomain.com;\\r\\nX-SES-RECEIPT: AEFBQUFBQUFBQUFGSU91V2k3eVU3MFdZNTZHWUZVaTRpR0h3QzVkWnJrLzR4K0NqQnZiT0graUI2SmxXMVQ4NkhhSk13UThud0dVaE1Zbmh5aDRvS3BtRDNjS2ltekluenVnb2czWE1IZGdSVWtiWjZOWWMwaUd5Q1h5a3dzdmxzZ2UyRVpaR3l6SndEb2JGWHo3b3haRHJDbHFNbzZ3enRvRkxINkp2MnFVT1hYYTBTMGllV2VKdGlpQlNaeWxHNFd2WGUyOXRkSk1TUUN0WnZZUXN0ejBJczJGallaUW83RkVkeXA5cTY3RDdjUm9pR3JUME94YTFrdkdNb0d1eUxhaCs3bU01OVhDMnNJNlBEcDQ5MlYwVmZxOWFtdktxSU8xUXQwWWxrNWhITGttRkRDNGoxN2c9PQ==\\r\\nX-SES-DKIM-SIGNATURE: a=rsa-sha256; q=dns/txt; b=KrOrSVlr4UKF9KiGMbh7wppMfpMIUHqp+COR9IDhjoVD4I7jsrYwoAJEuAbzN98b8xsORNQw4+pSrLYVK4Sp2rn15JWE9BE6ZR0xwpogZdduUw0l7l1BzI2MemAPlEjX5kHVO+vi6yhV+tmDdwQp4uqmfUKqLKtQRzn5nVpqUCI=; c=relaxed/simple; s=6gbrjpgwjskckoa6a5zn6fwqkn67xbtw; d=amazonses.com; t=1675790328; v=1; bh=bTtrjy+s8vCLOfS3TwRaijDO11xe+YrRULcqxQzfoc8=; h=From:To:Cc:Bcc:Subject:Date:Message-ID:MIME-Version:Content-Type:X-SES-RECEIPT;\\r\\nReceived: by mail-yw1-f172.google.com with SMTP id 00721157ae682-527979e8670so117289057b3.10\\r\\n        for <[email protected]>; Tue, 07 Feb 2023 09:18:48 -0800 (PST)\\r\\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\\r\\n        d=testemailtxdomain.com.20210112.gappssmtp.com; s=20210112;\\r\\n        h=to:subject:message-id:date:from:in-reply-to:references:mime-version\\r\\n         :from:to:cc:subject:date:message-id:reply-to;\\r\\n        bh=K/vkpZAfqNfjE7VmBzfZwR5cj4TOi3l8JujyuO4K+a4=;\\r\\n        b=JTTf474I6jKtd70yTKsoniuaVbZhPUeBh8iKk7VfMYfZhph9kDrxTn4SRC0ccbhS3f\\r\\n         jbqkkFd3MHlzErtHYXE5lyCKBmnJLcGQvk6Io5Ingms86DZ6Jr2F0izI/XZLfy/Gk19a\\r\\n         gP7g8rXtaz4xc9dst+kP0f4fLOTav+hTP1s+f7W0GbhT/+DlwXIxBBLUJKiY1wqifKyt\\r\\n         kJiynMs2MTsiXEPtgikgA8tgMPJ0Gj9Nb+9LxvUd15sHWjC0cJ8L5UJHhJuZduFyJYVv\\r\\n         irPXCiWaY2B5OAsZN/XisiPV5oIJTw0dnpGhG1pESAJsT0mftcT7T3UGkARfOhSEgx4+\\r\\n         lxcw==\\r\\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\\r\\n        d=1e100.net; s=20210112;\\r\\n        h=to:subject:message-id:date:from:in-reply-to:references:mime-version\\r\\n         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;\\r\\n        bh=K/vkpZAfqNfjE7VmBzfZwR5cj4TOi3l8JujyuO4K+a4=;\\r\\n        b=cwsngK5L9EonoJhO4w1XqsLMxFmsxoGW9u37Zv8wC/jhatfybTZa9LSB6VGgOl58jJ\\r\\n         5ne4pI6T9/XFmL/FOLJ6bhwu5f4XSWTDTqA1mgDlFfPTj6OhbR8RFLk2JmF6UgfOrVpB\\r\\n         oNXcjIx/Tm4ZTla4MBTFv//bpAdrtjjnXXKYvjdSPCl15v/uiEGq3nh5K9/gYXqPeKmc\\r\\n         st20CkXkuMrBuJdMD8SRaBSi7rzDWaidE3rtsiiG73T4nHx1mrt7oS/t8SH6ur/uOhM4\\r\\n         vN+oV/7ymrp7CrHgacZaem1SpLnSdAk7UCW4QfhGk5BU7iWOGGXGqBM/38eTD7ipRm0w\\r\\n         yrfA==\\r\\nX-Gm-Message-State: AO0yUKU+4R7mOls9ftLFT8nWRGHmGhHeCd8P0VhAwdIRduS1RE6GoLbA\\r\\n\\t64TsE4DXQRSYAdwJQw5tEeppeQCaoWuRuJ6yZIzU21kBcWtyyA==\\r\\nX-Google-Smtp-Source: AK7set9CJBb4rcWUAAdHRNWxkNJuNafCEl+cCG1bZRQ6nsy5OSSiw7h9x6CCLuOATHOQAvkMRyjKeHS6Ly6/08m4VnM=\\r\\nX-Received: by 2002:a0d:dd8d:0:b0:52a:7aed:b634 with SMTP id\\r\\n g135-20020a0ddd8d000000b0052a7aedb634mr310584ywe.491.1675790327421; Tue, 07\\r\\n Feb 2023 09:18:47 -0800 (PST)\\r\\nMIME-Version: 1.0\\r\\nReferences: <[email protected]>\\r\\nIn-Reply-To: <[email protected]>\\r\\nFrom: Brian M <[email protected]>\\r\\nDate: Tue, 7 Feb 2023 12:18:36 -0500\\r\\nMessage-ID: <[email protected]om>\\r\\nSubject: Fwd: Alarm CPU Usage Low on Virtual Machine : ap-jumphost1 is Critical\\r\\nTo: [email protected]\\r\\nContent-Type: multipart/alternative; boundary=\\\"0000000000002f359505f41f5738\\\"\\r\\n\\r\\n--0000000000002f359505f41f5738\\r\\nContent-Type: text/plain; charset=\\\"UTF-8\\\"\\r\\n\\r\\n*Brian Meinershagen*\\r\\n\\r\\n*Director of Information Systems*\\r\\nAlertpage, Inc.\\r\\nwww.testemailtxdomain.com\\r\\n\\r\\n\\r\\n---------- Forwarded message ---------\\r\\nFrom: <[email protected]>\\r\\nDate: Tue, Feb 7, 2023 at 11:38 AM\\r\\nSubject: Alarm CPU Usage Low on Virtual Machine : ap-jumphost1 is Critical\\r\\nTo: <[email protected]>, <[email protected]>, <\\r\\[email protected]>\\r\\n\\r\\n\\r\\nThis email is to notify you that an alarm has been triggered in your\\r\\nvCenter:\\r\\n\\r\\n*[Critical] Alarm CPU Usage Low on VM ap-jumphost1*because *VM Metric CPU\\r\\nUsage is equal to 0%.*\\r\\nAlarm name CPU Usage Low\\r\\nDescription\\r\\nTarget VM ap-jumphost1\\r\\nStatus Critical (previous status: Normal)\\r\\nTriggered time 02/07/2023 04:38:43 PM\\r\\n\\r\\n--0000000000002f359505f41f5738\\r\\nContent-Type: text/html; charset=\\\"UTF-8\\\"\\r\\nContent-Transfer-Encoding: quoted-printable\\r\\n\\r\\n<div dir=3D\\\"ltr\\\"><br clear=3D\\\"all\\\"><div><div dir=3D\\\"ltr\\\" class=3D\\\"gmail_sig=\\r\\nnature\\\" data-smartmail=3D\\\"gmail_signature\\\"><div dir=3D\\\"ltr\\\"><b>Brian Meiner=\\r\\nshagen</b><div><b>Director of Information Systems<br></b><div>Alertpage, In=\\r\\nc.</div><div><a href=3D\\\"http://www.testemailtxdomain.com/\\\" style=3D\\\"color:rgb(17,85=\\r\\n,204)\\\" target=3D\\\"_blank\\\">www.testemailtxdomain.com</a></div><div><img src=3D\\\"https:=\\r\\n//docs.google.com/uc?export=3Ddownload&amp;id=3D1quVfXRF9VMoqGZEJnRVjI_TOL-=\\r\\nK-pbqK&amp;revid=3D0B53X-9OUjjH6d212MCs4RnJKWFIzczFYYldPdUNsaG10Z2UwPQ\\\" wid=\\r\\nth=3D\\\"96\\\" height=3D\\\"22\\\"></div></div></div></div></div><br><br><div class=3D=\\r\\n\\\"gmail_quote\\\"><div dir=3D\\\"ltr\\\" class=3D\\\"gmail_attr\\\">---------- Forwarded me=\\r\\nssage ---------<br>From: <span dir=3D\\\"auto\\\">&lt;<a href=3D\\\"mailto:[email protected]=\\r\\ntestemailtxdomain.com\\\">[email protected]</a>&gt;</span><br>Date: Tue, Feb 7, 2=\\r\\n023 at 11:38 AM<br>Subject: Alarm CPU Usage Low on Virtual Machine : ap-jum=\\r\\nphost1 is Critical<br>To:  &lt;<a href=3D\\\"mailto:[email protected]\\\">jki=\\r\\[email protected]</a>&gt;,  &lt;<a href=3D\\\"mailto:[email protected]\\\">bri=\\r\\[email protected]</a>&gt;,  &lt;<a href=3D\\\"mailto:[email protected]=\\r\\ndr.com\\\">[email protected]</a>&gt;<br></div><br><br>This emai=\\r\\nl is to notify you that an alarm has been triggered in your vCenter:<br><b>=\\r\\n[Critical] Alarm CPU Usage Low on VM ap-jumphost1<br></b>because <b>VM Metr=\\r\\nic CPU Usage is equal to 0%.</b><br><table><tbody><tr><td>Alarm name</td><t=\\r\\nd>CPU Usage Low</td></tr><tr><td>Description</td><td></td></tr><tr><td>Targ=\\r\\net</td><td>VM ap-jumphost1</td></tr><tr><td>Status</td><td>Critical (previo=\\r\\nus status: Normal)</td></tr><tr><td>Triggered time</td><td>02/07/2023 04:38=\\r\\n:43 PM</td></tr></tbody></table><img src=3D\\\"http://url9931.testemailtxdomain.com/wf=\\r\\n/open?upn=3DOIlTlgJW10XUgPTQAICULMIFazrnCFT3e6BJCoNOjyFY9VHTfVK8ZXwX-2BcGF3=\\r\\nx-2Bi3ZG-2Fr31f-2Fbj-2BAqdgmZ5qqOuBMxkgyGulARJ6BiXfSE-2FOXitcXCF-2BbY7LW0Tx=\\r\\nSXUgxL85Uhroj03WwUHf4upryS-2BHf6pLVx6vtM8MDrlHn6Sm2FpdlsovOzv9keXAf7ZCIrB3a=\\r\\n8EuK13uwlh4ZlDCdoBdg7U0G53YxIbtqf9CkxI-3D\\\" alt=3D\\\"\\\" width=3D\\\"1\\\" height=3D\\\"1=\\r\\n\\\" border=3D\\\"0\\\" style=3D\\\"height:1px!important;width:1px!important;border-wid=\\r\\nth:0!important;margin-top:0!important;margin-bottom:0!important;margin-righ=\\r\\nt:0!important;margin-left:0!important;padding-top:0!important;padding-botto=\\r\\nm:0!important;padding-right:0!important;padding-left:0!important\\\"></div></d=\\r\\niv>\\r\\n\\r\\n--0000000000002f359505f41f5738--\\r\\n\"}",
    "Timestamp": "2023-02-07T17:18:49.028Z",
    "SignatureVersion": "1",
    "Signature": "ckMJjCuVUj5gWUMFMhAtsTh9uLqhy7MHnicoq8nPCxCI5g/vjKsN8nkNmilCBaeKHe84gMg2KcCE92J7A4Y9oacszbfhU+QHX+TwtroqNAvWlDoGg4OABQa26mWyWT2UeoRSDWnm7x1SKocvR7230c4R9pdFBTWrm4/xL/Tb93RvkE6XMQq5wHJVHAvnELN0JYLMNef9sglyPbs1x0ns48sO9N5KNqUUdFaFgNxIzMwduH7gYYX/4+6zLvj1J9tuz4PyWHHWH9MEkalAsK3hDm/stYTE3h348I5Izq4D3QrcFbbmZ7LxBvnYXelWG7s7b6tCipVQs9yptTwYBVuwTg==",
    "SigningCertURL": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-56e67fcb41f6fec09b0196692625d385.pem",
    "UnsubscribeURL": "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:000009110000:alertsmail:4ef1a96d-ee33-4bb5-a4db-1839877565f3"
  }
] ```

If you think it would be valuable to test, I can private message you the unedited version of the workflow and pinned trigger data.

Just the output there would be enough, It looks like the version in the code node had escaped slashes. It looks like using const messageTXT = regex.exec(JSON.stringify($input.item.json)) does the job.

Yes, thanks a ton! That seems to work; Anyway to get the code node from escaping the linefeeds? Even doing a regex for \n\r ?

Changing the code, its still escaped; I’m sure its for security reasons perhaps? But there should be a way to pass returns/linefeeds.
Here’s what I tried, which I executed twice just in case, since there were four \\ in some places.

 messageTXT = regex.exec(JSON.stringify($input.item.json))
console.log(messageTXT)
messageTXT = messageTXT.toString()
messageTXT = messageTXT.replace('\\','\\').replace('\\','\\') 

So while the solution to my original question works; Someone just pointed out that I could have done this with mailparser.
So I installed it, I have it in my environment variables to allow it to run, and I can run it without errors.
But it doesn’t return anything. Works fine if I run in a true javascript world.

I “stabbed” it into the working node, just to see what the result would look like; but the outputs are null.

Just to resolve my second issue with mailparser, in case anyone else runs into it.
The method I was running it, which is how it would work in regular JavaScript does not work in the code node, instead I had to use this:

const inputData = $json
const nestedJSON = JSON.parse(inputData.Message);
const mailData = nestedJSON.mail;
const simpleParser = require('mailparser').simpleParser;
let parsed = await simpleParser(nestedJSON.content);

An array is created in parsed() with the un-MIME’d version of the mail data. Works great.

Thanks to all!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.