Set email header in OnSMTPData should rather fail

Use this forum if you want to discuss a problem or ask a question related to a hMailServer beta release.
estradis
Normal user
Normal user
Posts: 89
Joined: 2014-09-09 10:47

Set email header in OnSMTPData should rather fail

Postby estradis » 2017-08-04 18:23

Hi there,

due to an scripting issue in our company with an huge business impact, I figured out what happens when email headers will be set in OnSMTPData event.

In event OnSMTPData the oMessage object provides only the sender and all recipients but no email headers or contents. When a header will be set at this early point, hMailserver will create a raw mail and dump some basic headers there, including an empty line at the end. When the transmission continues with the real headers and contents as a part of DATA command, all will be interpreted as body part, including the headers. The recipient will now see the email source instead of the email content. The email is not readable by user and attachments won't be downloadable!

Therefore setting headers in event OnSMTPData should rather fail and result a scripting error.

e.g.:

Code: Select all

Sub OnSMTPData(oClient, oMessage)
   oMessage.HeaderValue("X-TestHeader") = "Testing headers in OnSMTPData which is a bad idea ..."
   oMessage.Save
End Sub

will result in:

Code: Select all

Return-Path: jane.doe@test.lab
Delivered-To: john.doe@test.lab
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Date: Fri, 4 Aug 2017 17:39:19 +0200

Received: from [10.x.y.z] (client.test.lab [10.x.y.z])
   by mx.test.lab with ESMTPSA
   (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128)
   ; Fri, 4 Aug 2017 17:39:19 +0200
From: Jane Doe <jane.doe@test.lab>
Subject: Test: Set headers in OnSMTPData event
To: "Doe, Jon" <john.doe@test.lab>
Message-ID: <7abcacf9-2f62-1f71-ea00-cdd472b493dd@test.lab>
Date: Fri, 4 Aug 2017 17:39:17 +0200
User-Agent: Mozilla/6.1 (Windows NT 10.0; WOW64; rv:54b.0) Gecko/20100101
 Thunderbird/54.6.1.3758b
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

This is the real body

The first 5 lines (including the empty line) will be set by event handler. All data afterwards will be interpreted as body.
Ironically, the header originally set in OnSMTPData is missing

Greetings

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

Re: Set email header in OnSMTPData should rather fail

Postby RvdH » 2017-08-04 20:51

Sounds pretty obvious to me as OnSmtpData is executed before the actual message is received

https://www.hmailserver.com/documentati ... onSMTPdata

OnSmtpData is called ONCE per message.

The following properties are the only ones populated at the point of OnSMTPData firing:

  • oMessage.Charset eg, utf-8
  • oMessage.Filename eg, e:\hMailData\{88ECA44E-D65A-4C8C-9797-EA1C3639D723}.eml
  • oMessage.FromAddress eg, user@domain.com
  • oMessage.recipients.item(j).address eg, touser@domain.com

That exactly why i suggested these documentation changes
Maybe the word populated isn't right in the OnSMTPData properties, and better should read 'only ones available/accessible'

Here is a similar finding on this subject
viewtopic.php?p=177511#p177511
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

estradis
Normal user
Normal user
Posts: 89
Joined: 2014-09-09 10:47

Re: Set email header in OnSMTPData should rather fail

Postby estradis » 2017-08-07 12:13

RvdH wrote:Sounds pretty obvious to me as OnSmtpData is executed before the actual message is received
[...]
That exactly why i suggested these documentation changes
Maybe the word populated isn't right in the OnSMTPData properties, and better should read 'only ones available/accessible'


A documentation change is necessary too, but not enough. It should definitifly be trapped by hMailserver! That is the reason why I posted it here. I hope it will arrive to Martin to be fixed in future releases.

The issue we had was an accidently set header in OnSMTPData while catching an exception. The mailserver was intended to send a SOS to postmaster. As this exception handler was tested in OnAcceptMessage only, it sets an important header to the original mail needed to be processed in OnAcceptMessage as well as in OnDeliveryStart.

By design the exception handler will be called in all events. Therefore in our scripts message headers will be set in a common function called SetMessageHeader(sName, sValue) instead of accessing it directly. If sValue is missing, the header given in sName will be deleted, otherwise the header will be set to sValue. Although the oMessage object is tested before, the oMessage.MessageHeaders object was forgotten to be tested eighter. Therefore the header was set in an invalid state. This error is now fixed.

According to murphy ("If shit can happen, it will be happen!") the problem described above appeared in a mass mailing to our customers after the script was running for more than one year without any issue. (Best example for murphys law ever!!! :twisted: )

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

Re: Set email header in OnSMTPData should rather fail

Postby RvdH » 2017-08-07 12:37

Better post it here....martin hardly visits/reads the forum
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

estradis
Normal user
Normal user
Posts: 89
Joined: 2014-09-09 10:47

Re: Set email header in OnSMTPData should rather fail

Postby estradis » 2017-08-07 13:15

RvdH wrote:Better post it here....martin hardly visits/reads the forum


Don't have an account. Can you forward it?

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

Re: Set email header in OnSMTPData should rather fail

Postby RvdH » 2017-08-07 13:47

No, as for me it is not a issue
like i said before, it is pretty obvious that is you're going to set headers on a message that isn't fully received/processed this is going to fail
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

estradis
Normal user
Normal user
Posts: 89
Joined: 2014-09-09 10:47

Re: Set email header in OnSMTPData should rather fail

Postby estradis » 2017-08-07 15:53

Created issue in https://github.com/hmailserver/hmailserver/issues/232. Let's see what Martin says ...


Return to “Development & alpha discussions”



Who is online

Users browsing this forum: No registered users and 5 guests