catchall mailbox + eventHandler

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
Peyre
New user
New user
Posts: 7
Joined: 2021-06-17 12:38

catchall mailbox + eventHandler

Post by Peyre » 2021-06-17 13:40

Hi all,

I set up a catchall mailbox for a domain in order to catch all mails sent to unknown addresses (typo, former user, spammer educated guess, etc.)
I also set up an event handler script to list those unknown addresses.

At first I was a happy camper with it but... when multiples unknown addresses are present in the mail, the oMessage.Recipients only contains an unique recipient, as if the hMailServer resolved all unknown addresses to the catchall mailbox and removed duplicates from the resolved recipients list before firing the event handler.

I tried with onDeliverMessage and onAcceptMessage, both behave the same.

Is there a way to have the event handler know all the addresses present in the SMTP envelope, even if at the end of the day, they all resolve to the unknown mailbox?

Code: Select all

Sub OnAcceptMessage(oClient, oMessage)
	EventLog.Write("entering OnAcceptMessage")
	for i = 0 to oMessage.recipients.count -1
		EventLog.Write("OnAcceptMessage:recipient: " & oMessage.Recipients.Item(i).OriginalAddress)
	next  
	EventLog.Write("exiting OnAcceptMessage")
	Result.Value = 0
End Sub

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

Re: catchall mailbox + eventHandler

Post by jimimaseye » 2021-06-17 13:46

This sounds like a limitation that has already been identified (and logged for review in gitbub). However, if you look at the methods used in the script found here you may find a way round. That said, you may find (and I recomend) this script a more useful adaptation for handling Catchall anyway: viewtopic.php?f=20&t=29306 (effectively gives you catchall functionality with blacklisting in case any of them become a nuisance).
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

Peyre
New user
New user
Posts: 7
Joined: 2021-06-17 12:38

Re: catchall mailbox + eventHandler

Post by Peyre » 2021-06-17 16:25

jimimaseye wrote:
2021-06-17 13:46
This sounds like a limitation that has already been identified (and logged for review in gitbub). However, if you look at the methods used in the script found here you may find a way round. That said, you may find (and I recomend) this script a more useful adaptation for handling Catchall anyway: viewtopic.php?f=20&t=29306 (effectively gives you catchall functionality with blacklisting in case any of them become a nuisance).
nice piece of code. it's just a bit weird to modify the variable R that contains the end of the main loop within the loop. it seems that VBS handles it nicely by reading R once and not taking into account any modification but it remains weird.

Peyre
New user
New user
Posts: 7
Joined: 2021-06-17 12:38

Re: catchall mailbox + eventHandler

Post by Peyre » 2021-06-17 17:07

Peyre wrote:
2021-06-17 13:40
I tried with onDeliverMessage and onAcceptMessage, both behave the same.
I also tried with onSMTPData and foud the same behavior. it's quite weird as at that time, IMHO the recipients list should be the ones on the SMTP enveloppe, unresolved... :(

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

Re: catchall mailbox + eventHandler

Post by jimimaseye » 2021-06-17 17:12

again....

its an issue already identified (a 'bug' if you like) so you wil be getting the same results.

Why not just implement the script I gave you?
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

Peyre
New user
New user
Posts: 7
Joined: 2021-06-17 12:38

Re: catchall mailbox + eventHandler

Post by Peyre » 2021-06-17 17:52

jimimaseye wrote:
2021-06-17 17:12
its an issue already identified (a 'bug' if you like) so you wil be getting the same results.
an undocumented feature as a former colleague call them :wink:
jimimaseye wrote:
2021-06-17 17:12
Why not just implement the script I gave you?
the script is very interresting and powerfull but does not implement what I need, that is, list all the unknown addresses in a text file. I will use ideas from it to build my own. thanks a lot for the share :)

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

Re: catchall mailbox + eventHandler

Post by SorenR » 2021-06-17 18:02

Peyre wrote:
2021-06-17 17:07
Peyre wrote:
2021-06-17 13:40
I tried with onDeliverMessage and onAcceptMessage, both behave the same.
I also tried with onSMTPData and foud the same behavior. it's quite weird as at that time, IMHO the recipients list should be the ones on the SMTP enveloppe, unresolved... :(
:roll:

https://github.com/hmailserver/hmailserver/issues/214
SørenR.

Algorithm (noun.)
Word used by programmers when they do not want to explain what they did.

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

Re: catchall mailbox + eventHandler

Post by jimimaseye » 2021-06-17 18:06

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
jimimaseye
Moderator
Moderator
Posts: 9187
Joined: 2011-09-08 17:48

Re: catchall mailbox + eventHandler

Post by jimimaseye » 2021-06-17 18:09

Peyre wrote:
2021-06-17 17:52
jimimaseye wrote:
2021-06-17 17:12
its an issue already identified (a 'bug' if you like) so you wil be getting the same results.
an undocumented feature as a former colleague call them :wink:
jimimaseye wrote:
2021-06-17 17:12
Why not just implement the script I gave you?
the script is very interresting and powerfull but does not implement what I need, that is, list all the unknown addresses in a text file. I will use ideas from it to build my own. thanks a lot for the share :)
Try it before dismissing it. I say this because.....

.... I think that the recipient count (always) = 1 is because of it being a CATCHALL account (and possibly the HMS code gets screwed by always counting the destination catchall account exclusivity and therefore always being the 1 and the same).

However, my script isnt using 'hmailserver catchall' functionality and therefore the receipient list IS being seen correctly and counted correctly. Thus I believe you will be able to log the original recipient addresses as you wish. It already logs the recipient in this line:

Code: Select all

eventlog.write(now() & " SMTP - CATCHALL BLACKLIST mail blocked to " & oMessage.recipients.item(j).address & " from " & oMessage.fromaddress )
if it is on the blacklist.
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: 4712
Joined: 2006-08-21 15:38
Location: Denmark

Re: catchall mailbox + eventHandler

Post by SorenR » 2021-06-17 18:32

SørenR.

Algorithm (noun.)
Word used by programmers when they do not want to explain what they did.

Post Reply