Problem with Delivered-To rule..

Use this forum if you have installed hMailServer and want to ask a question related to a production release of hMailServer. Before posting, please read the troubleshooting guide. A large part of all reported issues are already described in detail here.
Post Reply
User avatar
tbrg78_hm
Normal user
Normal user
Posts: 53
Joined: 2013-12-17 19:58
Location: Berlin/Germany

Problem with Delivered-To rule..

Post by tbrg78_hm » 2020-05-12 21:32

Hi folks! o)

I use plus addressing and "_" as separator quite successfully for some years. Occasionally, a mail address gets into the hand of spammers and I will receive odd mail from that point on. I normally simply add such an address to an existing rule, which looks at the "To" field, then deletes the mail. Now I have an address I cannot seem to filter/delete this way, it does not contain a "To" field, it has "Delivered-To" (instead?).

This is how the headers of these mails look:

Code: Select all

Return-Path: ufafbixtw@0861vodacom.co.za
Delivered-To: mail_foobar@mydomain.net
Received: from 0861vodacom-co-za.mail.protection.outlook.com (Unknown [195.24.61.7]) by mail.mydomain.net with ESMTP ; Tue, 12 May 2020 18:44:58 +0200
Received: from apache by m6MB2yd-1zPM.0861vodacom.co.za with local (Exim 4.84_2) (envelope-from <ufafbixtw@0861vodacom.co.za>) id zMF04X-CLXY65-Oz for mail_foobar@mydomain.net; Tue, 12 May 2020 16:44:57 -0800
Subject: [Spam?]: Amirah love to suck.
X-PHP-Originating-Script: 502:PHPMailer.php
Date: Tue, 12 May 2020 16:44:57 -0800
From: "Katharina" <ufafbixtw@0861vodacom.co.za>
Reply-To: <ufafbixtw@0861vodacom.co.za>
Message-ID: <ISMUc_z2P4QWxeIiM4v58NZ_62NQq_s1@3053.0861vodacom.co.za>
X-Priority: 3
X-Mailer: PHPMailer 5.2.9 (https://github.com/PHPMailer/PHPMailer/)
MIME-Version: 1.0
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64
X-hMailServer-Spam: YES
X-hMailServer-Reason-1: Rejected by SpamCop. - (Score: 3)
X-hMailServer-Reason-2: Blocked by SPF () - (Score: 3)
X-hMailServer-Reason-3: Rejected by Spamhaus. - (Score: 3)
X-hMailServer-Reason-4: The host name specified in HELO does not match IP address. - (Score: 2)
X-hMailServer-Reason-Score: 11
The new rule I created for the domain looks like this:
hmailserver-rule.png
hmailserver-rule.png (2.01 KiB) Viewed 1865 times
Do you see anything obvious I don't see? It seems the rule won't trigger for some reason,
although I think it should and I just can't find an error in the configuration.

Any feedback appreciated, thank you in advance! o)

tbrg

palinka
Senior user
Senior user
Posts: 1968
Joined: 2017-09-12 17:57

Re: Problem with Delivered-To rule..

Post by palinka » 2020-05-12 22:27

I don't know the answer to your question, but isn't a spam score of 11 high enough to delete automatically? My delete threshold is much lower than that. That message is bona fide spam and should be deleted. It's not worthy of sending to a spam folder for review.

User avatar
jimimaseye
Moderator
Moderator
Posts: 8646
Joined: 2011-09-08 17:48

Re: Problem with Delivered-To rule..

Post by jimimaseye » 2020-05-12 22:47

+1

....and....

I believe 'delivered to' is not added until the message is delivered (funnily enough). And it is delivered AFTER rules have been run.

You might like this: https://www.hmailserver.com/forum/viewt ... 20&t=29306

You can carry on using (replacing) your plus addressing and use a 'black list' to setup abused addresses instead of writing a rule (which, as you see, has restrictions).

[Entered by mobile. Excuse my spelling.]
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

User avatar
SorenR
Senior user
Senior user
Posts: 3623
Joined: 2006-08-21 15:38
Location: Denmark

Re: Problem with Delivered-To rule..

Post by SorenR » 2020-05-13 01:24

in OnAcceptMessage() add this code

Code: Select all

    For i = 0 To oMessage.Recipients.Count-1
        If (i = 0) Then
            strTo = oMessage.Recipients(i).Address
            strOriginalTo = oMessage.Recipients(i).OriginalAddress
        Else
            strTo = strTo & ", " & oMessage.Recipients(i).Address
            strOriginalTo = strOriginalTo & ", " & oMessage.Recipients(i).OriginalAddress
        End If
    Next
    oMessage.HeaderValue("X-Envelope-To") = strTo
    oMessage.HeaderValue("X-Envelope-OriginalTo") = strOriginalTo
    oMessage.HeaderValue("X-Envelope-From") = oMessage.FromAddress
    oMessage.Save
The new Header "X-Envelope-To" will now contain the SMTP RCPT TO xxxx@yyyy from your SMTP log.

Addressing an email is like addressing a handwritten letter... "To" is the "Dear John" in the top of letter and the name/address on the envelope is the RCPT TO from your logfile.

In your rule use: Custom header field "X-Envelope-To" contains "target_addr@mydomain.tld"
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

User avatar
tbrg78_hm
Normal user
Normal user
Posts: 53
Joined: 2013-12-17 19:58
Location: Berlin/Germany

Re: Problem with Delivered-To rule..

Post by tbrg78_hm » 2020-05-14 12:58

@palinka
Well, yes. These mails are meant to be deleted automatically. o) I don't use the spam score, I have issues with it (too many false positives, need more time researching).
I also don't have to, the delete rule for compromised addresses does the job quite well. It's just this specific one, which is missing the "To" header giving a little headache.

@jimimaseye
Thanks for the delivered-to header hint, if it's inserted after delivery, its quite obvious that my rule fails. o)
I looked into the link you posted, quite a heavy solution, but it helped thinking on how to solve with script code.

@SorenR
Thank you, I tried around with the same idea and similar code. The hard part was to find a code snippet for setting a header. I always looked for a method on the headers collection, but nah, it's on the message object. I would have thanked you earlier, I did not get a post notification this time though. Anyway, big thank you for taking the time! o)

I like your "envelope" header naming approach. I use X-Recipient<n> right now and tested for some days. I noticed that every outgoing email is affected by this as well, even for mails using BCC. Is there a way around that? I need to think about that for a little. This is surely a privacy issue and would render using BCC useless.

Thank you all! o)

User avatar
jimimaseye
Moderator
Moderator
Posts: 8646
Joined: 2011-09-08 17:48

Re: Problem with Delivered-To rule..

Post by jimimaseye » 2020-05-14 13:50

tbrg78_hm wrote:
2020-05-14 12:58
@jimimaseye
I looked into the link you posted, quite a heavy solution, but it helped thinking on how to solve with script code.
Define "Heavy". Big script? Yes. But its all there (Ive done the heavy work). You just need to paste in and configure according to instructions. Then reap the benefits. :D
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

User avatar
SorenR
Senior user
Senior user
Posts: 3623
Joined: 2006-08-21 15:38
Location: Denmark

Re: Problem with Delivered-To rule..

Post by SorenR » 2020-05-14 14:26

tbrg78_hm wrote:
2020-05-14 12:58
I noticed that every outgoing email is affected by this as well, even for mails using BCC. Is there a way around that? I need to think about that for a little. This is surely a privacy issue and would render using BCC useless.
How about ... If (oClient.Username = "") Then :mrgreen:
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

User avatar
RvdH
Senior user
Senior user
Posts: 1085
Joined: 2008-06-27 14:42
Location: Netherlands

Re: Problem with Delivered-To rule..

Post by RvdH » 2020-05-14 14:49

SorenR wrote:
2020-05-14 14:26
tbrg78_hm wrote:
2020-05-14 12:58
I noticed that every outgoing email is affected by this as well, even for mails using BCC. Is there a way around that? I need to think about that for a little. This is surely a privacy issue and would render using BCC useless.
How about ... If (oClient.Username = "") Then :mrgreen:
or (if on 5.7, custom 5.6.x build)

Code: Select all

If Not oClient.Authenticated Then
:mrgreen:
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

User avatar
tbrg78_hm
Normal user
Normal user
Posts: 53
Joined: 2013-12-17 19:58
Location: Berlin/Germany

Re: Problem with Delivered-To rule..

Post by tbrg78_hm » 2020-05-19 13:52

Ok, thank you, I get your point. o) So now I test for auth/username before adding the headers.
This prevents headers from being added for outgoing mail successfully, but I still have a problem to solve:

The strOriginalTo seems to aggregate addresses for the same domain, which is not an issue for regular To-type mails I guess.
But if mail was send with receivers in BCC only, like mail to 3 local accounts on 2 domains -> usr1@AAA.net, usr2@AAA.net, usr3@BBB.net.
The resulting X-Envelope-OriginalTo header for usr1 + usr2 on same domain would look like this (unwanted multiple addresses (exposed BCC addresses)):

Code: Select all

X-Envelope-OriginalTo: usr1@AAA.net, usr2@AAA.net
While a single usr3 on BBB.net domain would receive (expected):

Code: Select all

X-Envelope-OriginalTo: usr3@BBB.net
The BCC information is gone, at the time the mail arrives, right? I noticed however, that the To header seems generally missing for BCC recipients.
Could this be my BCC "indicator"? But then, how to set custom Original-To header on a single mail for multiple recipients so they don't see each other?
In case you have an opinion on this, I appreciate any further input. Thx! o)

User avatar
SorenR
Senior user
Senior user
Posts: 3623
Joined: 2006-08-21 15:38
Location: Denmark

Re: Problem with Delivered-To rule..

Post by SorenR » 2020-05-19 14:13

tbrg78_hm wrote:
2020-05-19 13:52
Ok, thank you, I get your point. o) So now I test for auth/username before adding the headers.
This prevents headers from being added for outgoing mail successfully, but I still have a problem to solve:

The strOriginalTo seems to aggregate addresses for the same domain, which is not an issue for regular To-type mails I guess.
But if mail was send with receivers in BCC only, like mail to 3 local accounts on 2 domains -> usr1@AAA.net, usr2@AAA.net, usr3@BBB.net.
The resulting X-Envelope-OriginalTo header for usr1 + usr2 on same domain would look like this (unwanted multiple addresses (exposed BCC addresses)):

Code: Select all

X-Envelope-OriginalTo: usr1@AAA.net, usr2@AAA.net
While a single usr3 on BBB.net domain would receive (expected):

Code: Select all

X-Envelope-OriginalTo: usr3@BBB.net
The BCC information is gone, at the time the mail arrives, right? I noticed however, that the To header seems generally missing for BCC recipients.
Could this be my BCC "indicator"? But then, how to set custom Original-To header on a single mail for multiple recipients so they don't see each other?
In case you have an opinion on this, I appreciate any further input. Thx! o)
The BCC = Blind Carbon Copy header only exists in your SENT MAIL folder...

But yes, as a rule if the recipient exists in "X-Envelope-OriginalTo" and not in "To" the recpient most likely is BCC'ed on the message.

HOWEVER !! Mime headers can be spoofed and/or doctored to the extreme so you can never be 100% sure :mrgreen:
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

User avatar
tbrg78_hm
Normal user
Normal user
Posts: 53
Joined: 2013-12-17 19:58
Location: Berlin/Germany

Re: Problem with Delivered-To rule..

Post by tbrg78_hm » 2020-05-19 14:26

Ok, but technically.. how to solve this, if it is solvable at all.

In OnAcceptMessage() I have a single message for multiple accounts, which I assume to be "BCC"ed to my server, because the "To" header is empty.
It seems I would need to drop the message and send individual copies to be able to set different Original-To header for all recipients, so BCCed addresses don't get exposed.
Does this make sense, is it possible in OnAcceptMessage() at all?
I already have a script/method in place which creates copies of mails and re-sends them (because of the internal forwarding delay of 1 minute). Could I do the same here?

User avatar
SorenR
Senior user
Senior user
Posts: 3623
Joined: 2006-08-21 15:38
Location: Denmark

Re: Problem with Delivered-To rule..

Post by SorenR » 2020-05-19 15:29

tbrg78_hm wrote:
2020-05-19 14:26
Ok, but technically.. how to solve this, if it is solvable at all.

In OnAcceptMessage() I have a single message for multiple accounts, which I assume to be "BCC"ed to my server, because the "To" header is empty.
It seems I would need to drop the message and send individual copies to be able to set different Original-To header for all recipients, so BCCed addresses don't get exposed.
Does this make sense, is it possible in OnAcceptMessage() at all?
I already have a script/method in place which creates copies of mails and re-sends them (because of the internal forwarding delay of 1 minute). Could I do the same here?
Ah yes... Who's looking at headers anyways :oops: I'm not really getting many BCC'ed mails :mrgreen:

You could do some manipulating during "Sub OnDeliverMessage(oMessage)"

oMessage.Headers.ItemByName("X-Envelope-To").Delete
oMessage.Headers.ItemByName("X-Envelope-OriginalTo").Delete
oMessage.Save
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

User avatar
tbrg78_hm
Normal user
Normal user
Posts: 53
Joined: 2013-12-17 19:58
Location: Berlin/Germany

Re: Problem with Delivered-To rule..

Post by tbrg78_hm » 2020-05-19 15:52

Aha.. so I could use the custom header to run it against domain level rules..
And then get rid of the header, once I don't need it anymore. "Temporary headers" so to speak?!

That sounds like a reasonable approach..
I will try and be back.. o)

User avatar
tbrg78_hm
Normal user
Normal user
Posts: 53
Joined: 2013-12-17 19:58
Location: Berlin/Germany

Re: Problem with Delivered-To rule..

Post by tbrg78_hm » 2020-05-20 12:58

Mhh, it seems I cannot run something after an account level rule? There is no event for that?
I could move my anti spam rule from account level to global, but not so nice.

More problematic is this, this code won't remove my temporary headers, the TESTXXX header in this example.
The event log prints "DELETED TESTXXX", but when I dump all headers with an account level rule (run function) they are still there.
Can you imagine why? I was so close! o)

Code: Select all

Sub OnDeliverMessage(oMessage)
	..
	If Not IsNull(oMessage.Headers.ItemByName("TESTXXX")) Then
		oMessage.Headers.ItemByName("TESTXXX").Delete
		EventLog.Write("DELETED TESTXXX")
		oMessage.Save
	End If 
	..

User avatar
SorenR
Senior user
Senior user
Posts: 3623
Joined: 2006-08-21 15:38
Location: Denmark

Re: Problem with Delivered-To rule..

Post by SorenR » 2020-05-20 13:32

Rule name: "Sub Test(oMessage)"

Criteria: If "Message size" greater than "0"

Action: Run function "test"

Code: Select all

Sub Test(oMessage)
    Rem Do Stuff
    If Not IsNull(oMessage.Headers.ItemByName("TESTXXX")) Then
        oMessage.Headers.ItemByName("TESTXXX").Delete
        EventLog.Write("DELETED TESTXXX")
        oMessage.Save
    End If 
End Sub
Alternative

Code: Select all

Sub Test(oMessage)
    Rem Do Stuff
    If oMessage.HeaderValue("TESTXXX") <> "" Then
        oMessage.Headers.ItemByName("TESTXXX").Delete
        EventLog.Write("DELETED TESTXXX")
        oMessage.Save
    End If 
End Sub
Job done 8)
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

User avatar
mattg
Moderator
Moderator
Posts: 20898
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Problem with Delivered-To rule..

Post by mattg » 2020-05-21 01:07

I actually found some messages report as 0 size
I use >-1 (greater than negative 1)

I don't get any 'misses' then
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
tbrg78_hm
Normal user
Normal user
Posts: 53
Joined: 2013-12-17 19:58
Location: Berlin/Germany

Re: Problem with Delivered-To rule..

Post by tbrg78_hm » 2020-05-22 02:10

Thanks guys, my current problem was not about getting the rule to execute the function, it was deleting the header. I got that covered now (see down below for details).
I think this problem is very near a possible solution. There is drawback though. I need to use a global rule for deleting/filtering these type of messages instead of an account level rule.

Let's recap:
My initial goal was to delete/filter incoming mail without "To" header (because BCC sent). Incoming mail address to filter uses plus-addressing scheme (<account>_<plusaddressing>@<domain>). At first, the "Delivered-To" header looked like it could be used to delete/filter these mails, as it stored the plus address email address just fine. This failed though, because "Delivered-To" is not available until all events and as last step, the account level rules were executed.

We then tried to save all original recipient email addresses to temporary custom headers in OnAcceptMessage() and use these headers instead of the "Delivered-To" header, which is added much too late. This worked ok, headers were also added to outgoing mail though and thereby exposed BCC information, not good. We chose to test for absent of authorization, so temporary headers will only be added for incoming mail from external (most likely) by adding If (oClient.Username = "")..

Further we noticed, that for a BCC type mail coming in, you can't really tell it was BCC sent. The empty "To" header is an indicator though. A problem came up. If a BCC type mail comes in and is about to be delivered to accounts sharing the same domain, hMailserver will "combine" the delivery to accounts on affected domain and recipients will receive the very same email, added custom header would list all the targeted addresses, exposing BCC information again. Not good. Notice that recipients on different domains will receive "individual" mail, not including recipients of other domains.

To get around exposing BCC information, we would delete the custom headers in OnDeliverMessage(), so any receiving account would not see other receivers on the same domain in the custom header. We had some trouble finding the right syntax and preventing script errors if our custom headers were not present for deletion. We also noticed that there is no event available to run after account level rules (and delete the custom header). So the filtering and testing on custom header has to be done in a global rule, which runs before OnDeliverMessage() -> last point for script control.

Findings for further discussion if time and motivation allows. In another thread. o)
-> Why is "BBC mail" delivery between domains separated, but for recipients on same domain it is not (sharing same mail object -> same headers)?
-> Would it make sense to have an event after account level rules are done? (I have to use global rule, since there is no way to remove the temporary header later, but for domain level users this means, that it's not possible to add filter rules there, so this custom "BCC" mail filtering is available to me as a system admin only).

Thank you! o)

Last step:
Deleting the mail via rule function instead of the builtin "Delete" operation. This is to add info about deleted mail to a log file. It seems the Message object does not have a Delete() method though. I found DeleteByDBID(long lDBID) in the docs, would this work? I would need to create a hmailserver object I guess, adding user/password to the script right? Not sure I'd like to do this.

Hope to read you about this last piece.. o)
cya..

Header existence check section:
Both approaches shown here did not work for me, testing for header existence fails if header does not exist, with:
"Script Error: Source: Microsoft VBScript runtime error - Error: 800A01B6 - Description: Object doesn't support this property or method - Line: xxx Column: y - Code: (null)"

Code: Select all

If Not IsNull(oMessage.Headers.ItemByName("TESTXXX")) Then..
If oMessage.HeaderValue("TESTXXX") <> "" Then
I went for a HeaderExists() function, to get around the "On Error Resume Next" bloat.
So, just for reference..

Code: Select all

Sub OnDeliverMessage(oMessage)
	..
	If HeaderExists(oMessage, "TESTXXX") Then 
		oMessage.Headers.ItemByName("TESTXXX").Delete
		EventLog.Write("DELETED TESTXXX")
	End If 
	..
End Sub

Function HeaderExists( msgIn, headerName)
    HeaderExists = False
    Dim headerIndex
    For headerIndex = 0 to msgIn.Headers.Count-1
        If headerName = msgIn.Headers(headerIndex).Name Then
            HeaderExists = True
            Exit function
        End If 
    Next
End Function

User avatar
SorenR
Senior user
Senior user
Posts: 3623
Joined: 2006-08-21 15:38
Location: Denmark

Re: Problem with Delivered-To rule..

Post by SorenR » 2020-05-22 14:44

tbrg78_hm wrote:
2020-05-22 02:10
Thanks guys, my current problem was not about getting the rule to execute the function, it was deleting the header. I got that covered now (see down below for details).
I think this problem is very near a possible solution. There is drawback though. I need to use a global rule for deleting/filtering these type of messages instead of an account level rule.

...
...
...

Last step:
Deleting the mail via rule function instead of the builtin "Delete" operation. This is to add info about deleted mail to a log file. It seems the Message object does not have a Delete() method though. I found DeleteByDBID(long lDBID) in the docs, would this work? I would need to create a hmailserver object I guess, adding user/password to the script right? Not sure I'd like to do this.

Hope to read you about this last piece.. o)
cya..

Header existence check section:
Both approaches shown here did not work for me, testing for header existence fails if header does not exist, with:
"Script Error: Source: Microsoft VBScript runtime error - Error: 800A01B6 - Description: Object doesn't support this property or method - Line: xxx Column: y - Code: (null)"

Code: Select all

If Not IsNull(oMessage.Headers.ItemByName("TESTXXX")) Then..
If oMessage.HeaderValue("TESTXXX") <> "" Then
I went for a HeaderExists() function, to get around the "On Error Resume Next" bloat.
So, just for reference..

Code: Select all

Sub OnDeliverMessage(oMessage)
	..
	If HeaderExists(oMessage, "TESTXXX") Then 
		oMessage.Headers.ItemByName("TESTXXX").Delete
		EventLog.Write("DELETED TESTXXX")
	End If 
	..
End Sub

Function HeaderExists( msgIn, headerName)
    HeaderExists = False
    Dim headerIndex
    For headerIndex = 0 to msgIn.Headers.Count-1
        If headerName = msgIn.Headers(headerIndex).Name Then
            HeaderExists = True
            Exit function
        End If 
    Next
End Function
Hmm... Do you read our answers at all?

The last post I made here about the Rule "Sub Test(oMessage)" ... If you add this rule as the last Account rule it WILL delete the header before the mail is delivered to the user. It was to show you a way to run a script function/subroutine using a rule AFTER the last hMailServer script event.

Also ... Why the "HeaderExist()" function when you can do this (I actually posted similar code in my last post):

Code: Select all

Sub OnDeliverMessage(oMessage)
    ..
    If oMessage.HeaderValue("TESTXXX") <> "" Then oMessage.Headers.ItemByName("TESTXXX").Delete
    ..
End Sub
HINT: IF you delete the custom "X-Envelope..." headers before delivering the message you DO NOT need to split the message into multiple recipients. Normal mail clients DO NOT have access to "oMessage.Recipients(i)".

Limiting new headers to incoming mails only is easy PROVIDED your clients are required to log on to send mails (and they SHOULD!)

Code: Select all

If oClient.Username <> "" Then
    REM OUTGOING MAIL
Else
    REM INCOMING MAIL
End If
Oh and by the way the "Delivered-To" header is exactly that... Delivered To... but not until the email is delivered into the INBOX.
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

User avatar
jimimaseye
Moderator
Moderator
Posts: 8646
Joined: 2011-09-08 17:48

Re: Problem with Delivered-To rule..

Post by jimimaseye » 2020-05-22 21:17

SorenR wrote:
2020-05-22 14:44
Oh and by the way the "Delivered-To" header is exactly that... Delivered To... but not until the email is delivered into the INBOX.
Told him that already. It seems it doesn't seem to be acknowledged.
jimimaseye wrote:
2020-05-12 22:47
I believe 'delivered to' is not added until the message is delivered (funnily enough). And it is delivered AFTER rules have been run.
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

User avatar
tbrg78_hm
Normal user
Normal user
Posts: 53
Joined: 2013-12-17 19:58
Location: Berlin/Germany

Re: Problem with Delivered-To rule..

Post by tbrg78_hm » 2020-05-25 10:44

Dear Sirs.. o) No, I don't read your answers -> I study them and learn them by heart! o)
Seriously, I actually read them multiple times and try to keep track of what I learned and tried with your help.

Regarding the "Delivered-To" header, in 1st paragraph of the recap I wrote:
tbrg78_hm wrote:At first, the "Delivered-To" header looked like it could be used to delete/filter these mails, as it stored the plus address email address just fine. This failed though, because "Delivered-To" is not available until all events and as last step, the account level rules were executed.
SorenR, you asked why the HeaderExists() function, this is because I tried and..
tbrg78_hm wrote:Both approaches shown here did not work for me, testing for header existence fails if header does not exist, with:
"Script Error: Source: Microsoft VBScript runtime error - Error: 800A01B6 - Description: Object doesn't support this property or method - Line: xxx Column: y - Code: (null)"

Code: Select all

If Not IsNull(oMessage.Headers.ItemByName("TESTXXX")) Then..
If oMessage.HeaderValue("TESTXXX") <> "" Then
Regarding limiting headers to incoming mail, yes, I learned and use:
tbrg78_hm wrote:We chose to test for absent of authorization, so temporary headers will only be added for incoming mail from external (most likely) by adding If (oClient.Username = "")..
I'm not sure why you got the impression I would not read your posts?! I clearly "clevered-up" by your input! o)
If I still missed a crucial detail, please knock my head into it again.

If you're still here, I'd like to continue the quest. o)
In the meantime, my impression is more like, "Really? Is this the way to go if I want to filter mail by incoming address if sent via BCC?"
Isn't that some kind of a basic thing to do? And why is there even a difference on the receiving side, it should not matter whether mail was sent by BCC or To?
Just thinking, I'm not exactly sure yet.

User avatar
mattg
Moderator
Moderator
Posts: 20898
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Problem with Delivered-To rule..

Post by mattg » 2020-05-25 17:22

Rules work with SMTP Envelope TO, not the message header to

The only sure way to get the SMTP Envelope TO is to check the logs, or do something like this

Code: Select all

Sub OnAcceptMessage(oClient, oMessage)
	Call XEnvelope(oMessage)
End Sub

Sub XEnvelope(oMessage)
   Dim i, strEnvelope1, strEnvelope2
   For i = 0 To oMessage.Recipients.Count-1
      If (i = 0) Then
         strEnvelope1 = oMessage.Recipients(i).Address
         strEnvelope2 = oMessage.Recipients(i).OriginalAddress
      Else
         strEnvelope1 = strEnvelope1 & ", " & oMessage.Recipients(i).Address
         strEnvelope2 = strEnvelope2 & ", " & oMessage.Recipients(i).OriginalAddress
      End If
   Next
   oMessage.HeaderValue("X-Envelope-To") = strEnvelope1
   oMessage.HeaderValue("X-Envelope-OriginalTo") = strEnvelope2
   oMessage.HeaderValue("X-Envelope-From") = oMessage.FromAddress
   oMessage.Save
End Sub
Now that you have the right address, you can add that to your Global rules, and next time message will be actioned as per global rules (includes reject or delete)
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
tbrg78_hm
Normal user
Normal user
Posts: 53
Joined: 2013-12-17 19:58
Location: Berlin/Germany

Re: Problem with Delivered-To rule..

Post by tbrg78_hm » 2020-05-25 19:01

Yes, I read up on BCC-mail and how addresses are handled in envelope and message headers.

The RFC concept seems fine as long as you don't use plus addressing or other weird things. With regular accounts and no plus addressing, you know where the mail was originally sent to, since your account will match that address automatically (it seems). With plus addressing though and being a simple user/account, you have difficulties getting hands on the targeted address.

But then, you added the Delivered-To header and it contains the right address! *trumpets*.. o)
Only problem is, it is added so lately. Why is it added after running the account rules?

User avatar
jimimaseye
Moderator
Moderator
Posts: 8646
Joined: 2011-09-08 17:48

Re: Problem with Delivered-To rule..

Post by jimimaseye » 2020-05-25 21:22

tbrg78_hm wrote:
2020-05-25 19:01
Only problem is, it is added so lately. Why is it added after running the account rules?
Oh boy. Again:
jimimaseye wrote:
2020-05-22 21:17
SorenR wrote:
2020-05-22 14:44
Oh and by the way the "Delivered-To" header is exactly that... Delivered To... but not until the email is delivered into the INBOX.
jimimaseye wrote:
2020-05-12 22:47
I believe 'delivered to' is not added until the message is delivered (funnily enough). And it is delivered AFTER rules have been run.
Rules cannot be run after delivery... in case the rule says delete/do not deliver.

[Entered by mobile. Excuse my spelling.]
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

User avatar
mattg
Moderator
Moderator
Posts: 20898
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Problem with Delivered-To rule..

Post by mattg » 2020-05-26 01:36

tbrg78_hm wrote:
2020-05-25 19:01
But then, you added the Delivered-To header and it contains the right address! *trumpets*.. o)
My script adds the 'SMTP Envelope TO'

This may in fact be different to 'Delivered to'

Especially if you use a catchall or forward mail or use an alias etc
Delivered TO is exactly what it says - WHICH ACCOUNT the mail was delivered to.

That doesn't help you fight SPAM

For a rule to trigger you need to use the 'SMTP Envelope TO'
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
tbrg78_hm
Normal user
Normal user
Posts: 53
Joined: 2013-12-17 19:58
Location: Berlin/Germany

Re: Problem with Delivered-To rule..

Post by tbrg78_hm » 2020-05-26 02:02

Thanks jimimaseye, I do remember that the Delivered-To header is added after running the account rules, but I wanted to know why that is! o)

I was just thinking: If the mail comes in, is routed and the account level rules are run, the targeted account is obviously known. The mail seems to be "some kind of delivered" at that point. If the Delivered-To header would be added at this point (before running the account level rules), it would not hurt, even if a rule is about to delete that email.
Am I wrong with this?

Some seems to apply to forward/copy etc, the forwarded/copied mail would hop on to another account and the Delivered-To header would be overridden at arrival "there".

I don't necessarily want to run rules after what you call delivery, but anyway, I don't want to bug you with this. If you don't feel motivated to explain, I live with that.
I would be a bit disappointed though! o) Just trying to get behind the magic of this, thank you and good night. o)

User avatar
tbrg78_hm
Normal user
Normal user
Posts: 53
Joined: 2013-12-17 19:58
Location: Berlin/Germany

Re: Problem with Delivered-To rule..

Post by tbrg78_hm » 2020-05-26 02:36

@mattg
Maybe we focus to hard on this Delivered-To header, which is no nice, since it contains the address I like to use for filtering (the plus address), but cannot. o)
Maybe we need another header "Will-Be-Delivered-To-If-Account-Rules-Wont-Delete" and which is to provide the same value. o)

Ok, seriously. o)
It just seems a bit hard to understand, that I cannot use the account level rules to act on header information, which is added later/available/not going to change if there is no further rule messing with it. There was no technical reason mentioned yet, account level rules which "might" delete is questionable from my (very naive) point of view. o)

Keep in mind, this is related to BBC mail (empty To) and plus addressing. Unfortunately you did not respond on my finding in this regard. But anyway, if there is and will be no HM-"native" way for an account to filter on the email address which the sender used, so be it. The solution we were working on, using global rules to add headers seems good so far, suggested account level rules to clear these temporary headers is a problem though. If an account removes this rule, multiple BCC recipients would be exposed.

I will try to delete original incoming BCC mail and will try to resend these mails with separate headers, so deleting on account level is not necessary.
Filtering should work fine this way, as the header with the correct address is there before the account level rules can run.

Man, I never thought this was going to be that deep of a dive! Thank you. o)

User avatar
mattg
Moderator
Moderator
Posts: 20898
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Problem with Delivered-To rule..

Post by mattg » 2020-05-26 03:28

tbrg78_hm wrote:
2020-05-26 02:02
Thanks jimimaseye, I do remember that the Delivered-To header is added after running the account rules, but I wanted to know why that is!
In case there are account forwards, or a rule that deletes the message, in which case the message IS NOT DELIVERED. Delivered TO header is ONLY added when delivery occurs

Perhaps this misunderstanding is a language thing. What is your native language?


Clearly the 'Delivered To' is not very useful unless you use plus addressing or a catchall account
All it shows is the final account that the message WAS DELIVERED to

If you want a header of 'ADDRESSED TO' use the SMPT Envelope TO as per my script above
These can be different things (due to rules, forwards, rejections and more)

As you want to use a rule to reject based on a header, you need NOT to use 'delivered To', but instead use 'SMTP Envelope TO' which means 'addressed to'.

Even BCC mail is picked up by using the SMTP Envelope TO

You are asking for something that will not solve your issue, and are rejecting a solution.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

Post Reply