Processing Incoming Read Receipts

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
gotspatel
Senior user
Senior user
Posts: 347
Joined: 2013-10-08 05:42
Location: INDIA

Processing Incoming Read Receipts

Post by gotspatel » 2021-07-25 10:48

Is there a way to find that whether the email is a "Read Receipt" of the mail sent and not an Email?

so as a custom Header can be sent to it "X-Hmailserver-ReadReceipt" via Script.

TIA
GP

User avatar
katip
Senior user
Senior user
Posts: 1158
Joined: 2006-12-22 07:58
Location: Istanbul

Re: Processing Incoming Read Receipts

Post by katip » 2021-07-25 14:01

have you tried checking Content-Type header?
it contains ...report-type=disposition-notification...
and ...delivery-status... for DSNs
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8

gotspatel
Senior user
Senior user
Posts: 347
Joined: 2013-10-08 05:42
Location: INDIA

Re: Processing Incoming Read Receipts

Post by gotspatel » 2021-07-26 11:10

Thanks for the tip. Found them as below

READ RECEIPTS

Code: Select all



Content-Type: multipart/mixed;
	report-type=disposition-notification;
	boundary="----=_NextPart_000_001C_01D77E1B.8A0ACF60"

Content-Type: multipart/mixed;
	boundary="_000_CWXP265MB4570857051E368A1F4FF04DB9DE19CWXP265MB4570GBRP_";
	report-type=disposition-notification	

Content-Type: multipart/mixed;
	boundary="----=_NextPart_000_001E_01D77BE4.A5B39A50";
	report-type=disposition-notification


EMAILS

Code: Select all


Content-Type: multipart/mixed; boundary="000000000000397b9905c78afd89"

Content-Type: multipart/related; boundary="00000000000045677305c735d933"

Content-Type: multipart/alternative; boundary="----=_NextPart_000_000F_01D775B4.F2F82230"

Content-Type: multipart/alternative;  boundary="----=_Part_1043721_120166650.1622528055318"

Content-Type: multipart/mixed;
	boundary="----=_NextPart_000_0033_01D7820B.94097D60"
	
Content-Type: multipart/related;
	boundary="----=_NextPart_000_0015_01D78135.A018F940"
Now is this GLOBAL rule right?

IF (USE AND)

Custom Header field: Content-Type

Contains: report-type=disposition-notification

THEN

Run Script: My processing plan

User avatar
katip
Senior user
Senior user
Posts: 1158
Joined: 2006-12-22 07:58
Location: Istanbul

Re: Processing Incoming Read Receipts

Post by katip » 2021-07-26 11:29

gotspatel wrote:
2021-07-26 11:10

Now is this GLOBAL rule right?

IF (USE AND)

Custom Header field: Content-Type

Contains: report-type=disposition-notification

THEN

Run Script: My processing plan
looks good. give it a try
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8

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

Re: Processing Incoming Read Receipts

Post by SorenR » 2021-07-26 11:36

You cannot use a rule for that other than to launch a script...

Rule will look for first instance of string (top down) and use that. You need to process message line by line.

Something like this:

Code: Select all

For i = 0 To oMessage.Headers.Count-1
    If (oMessage.Headers(i).Name = "Content-Type") Then
        ....
        If InStr(1, oMessage.Headers(i).Value, "disposition-notification", 1) > 0 Then
            ....
            Do Stuff
            ....
            Exit For    ' Found it, no need to look further.
        End If
        ....
    End If
Next
SørenR.

Woke is Marxism advancing through Maoist cultural revolution.

gotspatel
Senior user
Senior user
Posts: 347
Joined: 2013-10-08 05:42
Location: INDIA

Re: Processing Incoming Read Receipts

Post by gotspatel » 2021-07-26 11:44

SorenR wrote:
2021-07-26 11:36
You cannot use a rule for that other than to launch a script...

Rule will look for first instance of string (top down) and use that. You need to process message line by line.

Something like this:

Code: Select all

For i = 0 To oMessage.Headers.Count-1
    If (oMessage.Headers(i).Name = "Content-Type") Then
        ....
        If InStr(1, oMessage.Headers(i).Value, "disposition-notification", 1) > 0 Then
            ....
            Do Stuff
            ....
            Exit For    ' Found it, no need to look further.
        End If
        ....
    End If
Next
:oops:

MY actual Intention is that if it is a read receipt or DSN then I don't want to apply the rule "External Email", (this rule appends a Header to email originating from outside the organization.

User avatar
katip
Senior user
Senior user
Posts: 1158
Joined: 2006-12-22 07:58
Location: Istanbul

Re: Processing Incoming Read Receipts

Post by katip » 2021-07-26 12:17

SorenR wrote:
2021-07-26 11:36
You cannot use a rule for that other than to launch a script...

Rule will look for first instance of string (top down) and use that. You need to process message line by line.
do you mean a Read Receipt may contain multiple Content-Type headers?
just checked 20 recent, received from different sources. all with unique Content-Type header.
i use similar rule and don't remember to have missed any of them.
but who knows, we see something new every day.. :wink:
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8

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

Re: Processing Incoming Read Receipts

Post by SorenR » 2021-07-26 12:25

I use the same logic to process every message arriving either direct or via my BackupMX to extract the original sender IP and greeting...

I need the IP address of the original sender to check if a banned server send to me via my BackupMX and the EHLO greeting to verify it is RFC compliant.

Code: Select all

Function setEnvelope(oClient, oMessage)
    Dim i, a, strTo, strOriginalTo, strIP, strRegEx, oMatch, oMatchCollection
    If Lookup("from " & BACKUPMX, oMessage.HeaderValue("Received")) Then
        '
        '   Received from BackupMX ?
        '
        For i = 0 To oMessage.Headers.Count-1
            '
            '   Process all "Received" headers
            '
            If (oMessage.Headers(i).Name = "Received") Then
                If Lookup("by " & BACKUPMX & " with", oMessage.Headers(i).Value) Then
                    '
                    '   Received from BackupMX !
                    '
                    a = Split( oMessage.Headers(i).Value, " " )
                    oMessage.HeaderValue("X-Envelope-HELO") = Trim(a(1))
                    strRegEx = "(?:\[)((?:[0-9]{1,3}\.){3}[0-9]{1,3})(?:\])"
                    Set oMatchCollection = oLookup(strRegEx, oMessage.Headers(i).Value, False)
                    For Each oMatch In oMatchCollection
                        If oMatch.SubMatches.Count > 0 Then
                            oMessage.HeaderValue("X-Envelope-IP") = oMatch.SubMatches(0)
                        Else
                            '
                            '   Oops, something went wrong ...
                            '
                            oMessage.HeaderValue("X-Envelope-IP") = ""
                        End If
                    Next
                    '
                    '   Mission accomplished !
                    '
                    Exit For
                '
                '   No dice - NEXT
                '
                End If
            End If
        Next
    Else
        '
        '   Nope, delivered directly
        '
        oMessage.HeaderValue("X-Envelope-HELO") = Trim(oClient.HELO)
        oMessage.HeaderValue("X-Envelope-IP") = Trim(oClient.IPAddress)
    End If
    oMessage.Save
    Set oMatch = Nothing
    Set oMatchCollection = Nothing
End Function
SørenR.

Woke is Marxism advancing through Maoist cultural revolution.

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

Re: Processing Incoming Read Receipts

Post by SorenR » 2021-07-26 12:29

katip wrote:
2021-07-26 12:17
SorenR wrote:
2021-07-26 11:36
You cannot use a rule for that other than to launch a script...

Rule will look for first instance of string (top down) and use that. You need to process message line by line.
do you mean a Read Receipt may contain multiple Content-Type headers?
just checked 20 recent, received from different sources. all with unique Content-Type header.
i use similar rule and don't remember to have missed any of them.
but who knows, we see something new every day.. :wink:
In theory it can contain multiple "Content-Type" headers. I have never investigated it.

In Theory There Is No Difference Between Theory and Practice, In Practice There Is :mrgreen:
SørenR.

Woke is Marxism advancing through Maoist cultural revolution.

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

Re: Processing Incoming Read Receipts

Post by SorenR » 2021-07-26 16:10

katip wrote:
2021-07-26 12:17
SorenR wrote:
2021-07-26 11:36
You cannot use a rule for that other than to launch a script...

Rule will look for first instance of string (top down) and use that. You need to process message line by line.
do you mean a Read Receipt may contain multiple Content-Type headers?
just checked 20 recent, received from different sources. all with unique Content-Type header.
i use similar rule and don't remember to have missed any of them.
but who knows, we see something new every day.. :wink:
OK, I have been tracking "Content-Type" on a couple of incoming emails.

This is one of the first things I do in OnAcceptMessage()

Code: Select all

    '
    '   Testing "Content-Type"
    '
    EventLog.Write( "From: " & oMessage.From & "  To: " & oMessage.To )
    EventLog.Write( "Subject: " & oMessage.Subject )
    For i = 0 To oMessage.Headers.Count-1
        If oMessage.Headers(i).Name = "Content-Type" Then
            EventLog.Write( "Content-Type: " & oMessage.Headers(i).Value )
        End If
    Next
    EventLog.Write( "." )
And...

Code: Select all

1912	"2021-07-26 14:28:06.583"	"From: blabla@somewhere>  To: unknown@nowhere"
1912	"2021-07-26 14:28:06.583"	"Subject: Servicemeddelelse fra Gjensidige"
1912	"2021-07-26 14:28:06.583"	"Content-Type: text/html; charset=UTF-8"
1912	"2021-07-26 14:28:06.583"	"."
1544	"2021-07-26 15:04:46.488"	"From: Lavinia Medium <lavinia@laviniaspoh.com>  To: "
1544	"2021-07-26 15:04:46.488"	"Subject: I have important information to transmit to you !"
1544	"2021-07-26 15:04:46.488"	"Content-Type: text/html; charset=UTF-8"
1544	"2021-07-26 15:04:46.488"	"."
1912	"2021-07-26 15:13:26.429"	"From: Melitta Isabel <melisabelmo@outlook.com>  To: "
1912	"2021-07-26 15:13:26.429"	"Subject: Kan du se længslen i mine øjne?"
1912	"2021-07-26 15:13:26.429"	"Content-Type: multipart/related; boundary="_005_BLAPR19MB4308497F35ED21DE83EF26B1AAE89BLAPR19MB4308namp_"; type="multipart/alternative""
1912	"2021-07-26 15:13:26.429"	"."
3512	"2021-07-26 15:13:34.507"	"From: Kathyrn Kletschka <kathyrnf6nyk@outlook.com>  To: "
3512	"2021-07-26 15:13:34.507"	"Subject: Kan du se længslen i mine øjne?"
3512	"2021-07-26 15:13:34.507"	"Content-Type: multipart/related; boundary="_005_DM5PR16MB175551F1A718DA73C3826B1A83E89DM5PR16MB1755namp_"; type="multipart/alternative""
3512	"2021-07-26 15:13:34.507"	"."
1912	"2021-07-26 15:36:05.937"	"From: "Web Camera Pro" <sb@web-camera.pro>  To: unknown@nowhere"
1912	"2021-07-26 15:36:05.937"	"Subject: Web Camera Pro:  Free software download link"
1912	"2021-07-26 15:36:05.937"	"Content-Type: multipart/mixed; boundary="MW04MGx6LWxSYWRMYy1NbA==""
1912	"2021-07-26 15:36:05.937"	"."
3512	"2021-07-26 15:36:43.813"	"From: "Web Camera Pro" <sb@web-camera.pro>  To: unknown@nowhere"
3512	"2021-07-26 15:36:43.813"	"Subject: Web Camera Pro - Download link for SorenR"
3512	"2021-07-26 15:36:43.813"	"Content-Type: multipart/mixed; boundary="MW04MG1mLVBDOEVEYy1NbA==""
3512	"2021-07-26 15:36:43.813"	"."
Only ONE "Content-Type" before mail body begins - and there are several "Content-Type" in the mail body when you look at the source ...

So I guess you are correct in assuming the first occurance is sufficient.
SørenR.

Woke is Marxism advancing through Maoist cultural revolution.

User avatar
katip
Senior user
Senior user
Posts: 1158
Joined: 2006-12-22 07:58
Location: Istanbul

Re: Processing Incoming Read Receipts

Post by katip » 2021-07-26 17:25

SorenR wrote:
2021-07-26 16:10
Only ONE "Content-Type" before mail body begins - and there are several "Content-Type" in the mail body when you look at the source ...
ok, alles klar.

now this made me recall something different. do your remember this : viewtopic.php?f=10&t=36903#p231060
mattg made a remark:
the .tmp has some CRLFs that are changed to spaces in the main file as currently saved in the data directory (domain / account path)
in my cases (today twice again) it's always the same sender site, exactly with this symptom. isn't <... blah>CRLF + CRLF<blah...> illegal in headers? if so how does HMS react in such case?
if you mean this is something worth to investigate, i'll open a topic with full source of one of that .tmp file. this is something still unresolved.
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8

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

Re: Processing Incoming Read Receipts

Post by SorenR » 2021-07-26 19:12

RFC 2047

Section 8 ...
Bottom page 12

Code: Select all

   encoded form                                displayed as
   ---------------------------------------------------------------------
   (=?ISO-8859-1?Q?a?=)                        (a)

   (=?ISO-8859-1?Q?a?= b)                      (a b)

           Within a 'comment', white space MUST appear between an
           'encoded-word' and surrounding text.  [Section 5,
           paragraph (2)].  However, white space is not needed between
           the initial "(" that begins the 'comment', and the
           'encoded-word'.


   (=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)     (ab)

           White space between adjacent 'encoded-word's is not
           displayed.

   (=?ISO-8859-1?Q?a?=  =?ISO-8859-1?Q?b?=)    (ab)

        Even multiple SPACEs between 'encoded-word's are ignored
        for the purpose of display.

   (=?ISO-8859-1?Q?a?=                         (ab)
       =?ISO-8859-1?Q?b?=)

           Any amount of linear-space-white between 'encoded-word's,
           even if it includes a CRLF followed by one or more SPACEs,
           is ignored for the purposes of display.

   (=?ISO-8859-1?Q?a_b?=)                      (a b)

           In order to cause a SPACE to be displayed within a portion
           of encoded text, the SPACE MUST be encoded as part of the
           'encoded-word'.

   (=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?=)    (a b)

           In order to cause a SPACE to be displayed between two strings
           of encoded text, the SPACE MAY be encoded as part of one of
           the 'encoded-word's.
Any amount of linear-space-white between 'encoded-word's,
even if it includes a CRLF followed by one or more SPACEs,
is ignored for the purposes of display.
Ehm... The MIME translated message SHOULD exclude CRLF and SPACE'es in hMailServer.
SørenR.

Woke is Marxism advancing through Maoist cultural revolution.

gotspatel
Senior user
Senior user
Posts: 347
Joined: 2013-10-08 05:42
Location: INDIA

Re: Processing Incoming Read Receipts

Post by gotspatel » 2021-07-29 08:32

This is what I did

Created a Global rule

IF

Content-Type:

Contains

report-type=disposition-notification

THEN

Set header Value

X-hmailserver-ReadReceipt

YES

and it is working as of now.


And regarding the Function Setenvelope()

I tried implementation as is and called it first thing in Sub onacceptmessage.

It works BUT FOR OUTGOING MAILS (I sent mail from Hmail to outside and verified)

How to implement it to work On the INCOMING MAIL.

shall I call the function in Sub onexternaldownload ??

gotspatel
Senior user
Senior user
Posts: 347
Joined: 2013-10-08 05:42
Location: INDIA

Re: Processing Incoming Read Receipts

Post by gotspatel » 2021-08-10 15:30

gotspatel wrote:
2021-07-29 08:32

How to implement it to work On the INCOMING MAIL.

shall I call the function in Sub onexternaldownload ??
Is this even Possible?? :oops:

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

Re: Processing Incoming Read Receipts

Post by mattg » 2021-08-11 08:56

Global rule

If recipient includes *@example.com

AND
rest of your global rule

With action to run function
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