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.
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)
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)
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
If HeaderExists(oMessage, "TESTXXX") Then
Function HeaderExists( msgIn, headerName)
HeaderExists = False
For headerIndex = 0 to msgIn.Headers.Count-1
If headerName = msgIn.Headers(headerIndex).Name Then
HeaderExists = True