Pages: 1
RSS
%HEADER("Delivered-To")) is not working in filter
 
Hi. I need help with this problem.
I use the following filter to sort received emails:
Code
\\lk-lk\Data\Archiv-Sorted\acc_%ReplaceRegExp("[\.\+\-]","_",%ReplaceRegExp("@","_",%OTOADDR))\Incoming\%ODATE="yyyy"\%ReplaceRegExp("[\.\+\-]","_",%ReplaceRegExp(".*@","",%FromAddr))\%ReplaceRegExp("[\.\+\-]","_",%ReplaceRegExp("@.*","",%FromAddr))

but it causes the problem that "%OTOADDR" takes the email fr om the original recipient of the message. So when the message is forwarded, the original recipient is displayed.

Gradually I came to the point where I modified the filter like this:
Code
\\lk-lk\Data\Archiv-Sorted\acc_%ReplaceRegExp("[\.\+\-]","_",%ReplaceRegExp("@","_",%HEADER("Delivered-To")))\Incoming\%ODATE="yyyy"\%ReplaceRegExp("[\.\+\-]","_",%ReplaceRegExp(".*@","",%FromAddr))\%ReplaceRegExp("[\.\+\-]","_",%ReplaceRegExp("@.*","",%FromAddr))

Where should I replace "%HEADER("Delivered-To"))" with the real end recipient.

But for some reason it doesn't work. Or rather it doesn't work only in filters, because when I enter the same filter in the templates to test it, it displays correctly.

Wh ere am I making a mistake?

Tested on version 12.

I am attaching the header of the email I am trying to process (I have changed the delivery emails).
Code
Delivered-To: bbb@bbb.com
Received: by 2002:a05:651c:220e:b0:309:296f:4d77 with SMTP id y14csp1853758ljq;
        Mon, 24 Feb 2025 21:17:37 -0800 (PST)
X-Forwarded-Encrypted: i=2; AJvYcCWPci75EWUBAJrDy3i4GTGRZe0QdjIROf5XpaSYU8xqGhgknfvVz9v9Rk2Lv3k1yLydeR4X30uzIBjUuwzi@gmail.com
X-Google-Smtp-Source: AGHT+IHtqFyGewNARLkmbDmt5p7zNhMaZTVHlvuWHwH8lZlGI6QXHhrkxwjCr740pBMC7xO7uJSi
X-Received: by 2002:a17:902:ec81:b0:21f:7a9:48b2 with SMTP id d9443c01a7336-221a0001b5emr99181545ad.13.1740460656877;
        Mon, 24 Feb 2025 21:17:36 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1740460656; cv=none;
        d=google.com; s=arc-20240605;
        b=dyn92QFW9285ZoKxmOCl8H4zRqTe8/C6AY8eq03JQHkWjDAvzmc1Lod/IGI5gn/BIG
         hAXOKmHHvqsKxDeS4QU/lZh3hKbougsg1NP7hXcli+VNWzS+8fFSDS9XFlmEQT372fVt
         Mo/brRixXIWRkXVgFZ8Twj3P94ry6Krw4faGL7YUv8FNjDTJ8qucDf5CnWgcM/g9RwgD
         kNhUshvh4dCCg+EA7l4qfoBh88Jzl8X5MCg19gWxhxz/+RQmghonFuPa62g1ojO84II5
         zRrkC1HujmiviIIzwUxiyXmARzCLg5BBZ5sQSxYDHIaSgvgILyQXViqsORa9+pDPhMNT
         EOFg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605;
        h=message-id:reply-to:date:from:to:subject:content-description
         :content-transfer-encoding:mime-version;
        bh=UQ7cOzi/ad9EAdBlqUZ3wA9gj3u2LmyLIF3aL53mdBQ=;
        fh=swcM5vBf+iWe9L5Xi1TXM4duvvZqXxJGdHXGIHq6FVA=;
        b=hWU2ceQUQaWxd97XezGisDUKvYjjLwZMRvO680ydBUek393DEoMhbZzlr+CFO9nfb/
         JsLCH2Kto5wr26RnAQHmr71Jr9+uHbJANff08TRdoLRBr442OB8UIH3xVfkWWNpVF4c+
         JoEYdGM27CLdb4WK7WV9z3uFFdlR1Mvz9Qmjvi7yCzH4pmZbk4pT8oCrw0IOsIn4AKZq
         pbBSLA1Ab2TnCW4is/WxNFUroNurshjZC5IbkJGDkfMVC9uzU4VYxyMygZYBSq0b+Jw/
         p5+ZDbmSy5UNN1dYBiQHfMulAOoCtKsc+1mphyVm8cIR2FYFxqwS6X23jISmON3KwE6j
         uJkA==;
        dara=google.com
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: domain of chris@rackcorp.com designates 110.232.116.113 as permitted sender) smtp.mailfrom=chris@rackcorp.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=rackcorp.com
Return-Path: <chris@rackcorp.com>
Received: from au-gbl1-mail1.rackcorp.com (au-nsw-gbl1-mail2.rackcorp.com. [110.232.116.113])
        by mx.google.com with ESMTPS id d9443c01a7336-2230a09a4aesi13251065ad.424.2025.02.24.21.17.36
        for <bbb@bbb.com>
        (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
        Mon, 24 Feb 2025 21:17:36 -0800 (PST)
Received-SPF: pass (google.com: domain of chris@rackcorp.com designates 110.232.116.113 as permitted sender) client-ip=110.232.116.113;
Authentication-Results: mx.google.com;
       spf=pass (google.com: domain of chris@rackcorp.com designates 110.232.116.113 as permitted sender) smtp.mailfrom=chris@rackcorp.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=rackcorp.com
Received: by au-gbl1-mail1.rackcorp.com (Postfix, from userid 3000)
        id BD4598F5E7; Sun, 26 Jan 2025 05:37:41 +0000 (UTC)
Received: from au-gbl1-mail1.rackcorp.com (localhost [127.0.0.1])
        by au-gbl1-mail1.rackcorp.com (Postfix) with ESMTP id A94601C428;
        Fri, 24 Jan 2025 23:59:04 +0000 (UTC)
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on
        au-nsw-gbl1-mail2.rackcorp.com
X-Spam-Level: *
X-Spam-Status: No, score=1.6 required=8.0 tests=ALL_TRUSTED,
        FREEMAIL_FORGED_REPLYTO,LOTS_OF_MONEY,MISSING_MID autolearn=disabled
        version=3.4.1
Received: from [10.0.7.59] (unknown [104.248.141.96])
        (Authenticated sender: chris@rackcorp.com)
        by au-gbl1-mail1.rackcorp.com (Postfix) with ESMTPA;
        Fri, 24 Jan 2025 23:59:04 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Description: Mail message body
Subject: Re:subject
To: Recipients <chris@rackcorp.com>
From: "Iris Foundation" <chris@rackcorp.com>
Date: Fri, 24 Jan 2025 15:58:54 -0800
Reply-To: irischarityfoundation@gmail.com
X-Filtered: By RackCorp Filter
Message-Id: <20250126101316.BD4598F5E7@au-gbl1-mail1.rackcorp.com>
X-MailStore-Message-ID: <20250126101316.bd4598f5e7@au-gbl1-mail1.rackcorp.com>
X-MailStore-Header-Hash: f11fdef72f228f23fbed238c05cc23a2c4edd88a
X-MailStore-Date: 20250225051736
X-MailStore-ArcDate: 20251103090255
X-MailStore-Flags: 0
 
I'm afraid that I can't read these one-line filters.. My older version (v8.3) of The Bat puts filters in a more human-readable format when you copy/paste them.

Still, I can make a guess what they're doing. Apparently you want to archive messages as files in folders on a network drive, and the name of the folder must be the name of the recipient of the message. You said this goes wrong with 'forwarded' messages, but I think you meant 'redirected' (or 'auto-forwarded')  messages that have been redirected by the mail server (not by a user).. I can see how that would cause a problem with archiving to the proper folder.

When a message is saved in a wrongly named folder, and you view that message manually, is the 'Delivered-To:' line actually in it? I guess it's more likely that the line is there but your RegEx somehow doesn't catch it, but I am terrible with RegEx, so I can't tell you if you're doing anything wrong. I do have 2 thoughts, though:

1) You're cleaning up the folder name using RegEx, but wouldn't you rather use the %VALIDFILECHARS macro? It may catch a few more bad characters and it would simplify the filters. Maybe that would make it easier to find the problem, too.

2) Do you have a lot of mailboxes? If not, maybe you could make a filter for each one. It would test the recipient address and then export the message to a fixed folder name (so, the filter would not have to create a new folder that would possibly get the wrong name).

Good luck!
I volunteer as a moderator to help keep the forum tidy. I do not work for Ritlabs SRL.
 
Quote
True Friend wrote:
Where should I replace "%HEADER("Delivered-To"))" with the real end recipient.But for some reason it doesn't work. Or rather it doesn't work only in filters, because when I enter the same filter in the templates to test it, it displays correctly.
You make mistake in %HEADER macro syntax. The argument in this macro should be written without minus sign, i.e. the correct use should be %HEADER("DeliveredTo").
 
Quote
Zygmunt Wereszczyński wrote:
You make mistake in %HEADER macro syntax. The argument in this macro should be written without minus sign, i.e. the correct use should be   %HEADER("DeliveredTo")  .

That's weird. Where did you find this?

The online documentation (link) says:

%HEADER(header)
Inserts the text from the header field identified by the header parameter. The header parameter is the RFC-name of the header defined under "“Options -> Preferences -> Viewer/Editor -> Message Headers”"


Looking at the various header entities in “Options -> Preferences -> Viewer/Editor -> Message Headers”, I find "Delivered-To", not "DeliveredTo". Is this different in your version of TB?
I volunteer as a moderator to help keep the forum tidy. I do not work for Ritlabs SRL.
 
Quote
Daniel van Rooijen wrote:
That's weird. Where did you find this?
You are right, of course. Such syntax existed several years ago, as I remember. Now the names of the headers are the same as in original message.

Regarding errors in True Friend macros, I think he should use %OHEADER instead of %HEADER macro.
Pages: 1