Modifying the Body before Forwarding

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

Modifying the Body before Forwarding

Post by gotspatel » 2021-03-12 11:15

Hi,

Need small help, I want to remove one line from the mail and forward it to a user.

Where I am making mistake.

Code: Select all

Sub Bankmail(oMessage)
	'custom event
	'uses globals:
	'called from: Rules	
    Dim txtMsg, aspMsg
		If oMessage.HeaderValue("X-hMailServer-LoopCount") = "" Then
			If oMessage.HasBodyType("text/plain") Then
				oMessage.Body = Replace(oMessage.body,^The Available Balance in your account is INR ([0-9]+(,[0-9]+)+)\.[0-9]+\.$,"..")
			End If
			If oMessage.HasBodyType("text/html") Then
				oMessage.HTMLBody = Replace(oMessage.HTMLBody,^The Available Balance in your account is INR ([0-9]+(,[0-9]+)+)\.[0-9]+\.$,"..")
			End If
			oMessage.save
		End If
End Sub

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

Re: Modifying the Body before Forwarding

Post by palinka » 2021-03-12 12:52

Try this instead. You can reuse the function for other things.

Code: Select all

Function oLookup(strRegEx, strMatch, bGlobal)
	If strRegEx = "" Then strRegEx = StrReverse(strMatch)
	With CreateObject("VBScript.RegExp")
		.Pattern = strRegEx
		.Global = bGlobal
		.MultiLine = True
		.IgnoreCase = True
		Set oLookup = .Execute(strMatch)
	End With
End Function

Sub Bankmail(oMessage)
	'custom event
	'uses globals:
	'called from: Rules	

	Dim strRegEx, Match, Matches
	
	If oMessage.HeaderValue("X-hMailServer-LoopCount") = "" Then

		If oMessage.HasBodyType("text/plain") Then

			strRegEx = "^The Available Balance in your account is INR ([0-9]+(,[0-9]+)+)\.[0-9]+\.$"
			Set Matches = oLookup(strRegEx, oMessage.Body, False)
			For Each Match In Matches
				oMessage.Body = Replace(oMessage.Body, Match.Value, "..")
			Next
			oMessage.Save
		End If

		If oMessage.HasBodyType("text/html") Then
			strRegEx = "^The Available Balance in your account is INR ([0-9]+(,[0-9]+)+)\.[0-9]+\.$"
			Set Matches = oLookup(strRegEx, oMessage.Body, False)
			For Each Match In Matches
				oMessage.HTMLBody = Replace(oMessage.Body, Match.Value, "..")
			Next
			oMessage.Save
		End If

	End If

End Sub

gotspatel
Normal user
Normal user
Posts: 110
Joined: 2013-10-08 05:42
Location: INDIA

Re: Modifying the Body before Forwarding

Post by gotspatel » 2021-03-12 13:00

palinka wrote:
2021-03-12 12:52
Try this instead. You can reuse the function for other things.

Code: Select all

Function oLookup(strRegEx, strMatch, bGlobal)
	If strRegEx = "" Then strRegEx = StrReverse(strMatch)
	With CreateObject("VBScript.RegExp")
		.Pattern = strRegEx
		.Global = bGlobal
		.MultiLine = True
		.IgnoreCase = True
		Set oLookup = .Execute(strMatch)
	End With
End Function

Sub Bankmail(oMessage)
	'custom event
	'uses globals:
	'called from: Rules	

	Dim strRegEx, Match, Matches
	
	If oMessage.HeaderValue("X-hMailServer-LoopCount") = "" Then

		If oMessage.HasBodyType("text/plain") Then

			strRegEx = "^The Available Balance in your account is INR ([0-9]+(,[0-9]+)+)\.[0-9]+\.$"
			Set Matches = oLookup(strRegEx, oMessage.Body, False)
			For Each Match In Matches
				oMessage.Body = Replace(oMessage.Body, Match.Value, "..")
			Next
			oMessage.Save
		End If

		If oMessage.HasBodyType("text/html") Then
			strRegEx = "^The Available Balance in your account is INR ([0-9]+(,[0-9]+)+)\.[0-9]+\.$"
			Set Matches = oLookup(strRegEx, oMessage.Body, False)
			For Each Match In Matches
				oMessage.HTMLBody = Replace(oMessage.Body, Match.Value, "..")
			Next
			oMessage.Save
		End If

	End If

End Sub

Thanks will try out. understood the OLookup also

gotspatel
Normal user
Normal user
Posts: 110
Joined: 2013-10-08 05:42
Location: INDIA

Re: Modifying the Body before Forwarding

Post by gotspatel » 2021-03-13 15:06

palinka wrote:
2021-03-12 12:52
Try this instead. You can reuse the function for other things.

Code: Select all

Function oLookup(strRegEx, strMatch, bGlobal)
	If strRegEx = "" Then strRegEx = StrReverse(strMatch)
	With CreateObject("VBScript.RegExp")
		.Pattern = strRegEx
		.Global = bGlobal
		.MultiLine = True
		.IgnoreCase = True
		Set oLookup = .Execute(strMatch)
	End With
End Function

Sub Bankmail(oMessage)
	'custom event
	'uses globals:
	'called from: Rules	

	Dim strRegEx, Match, Matches
	
	If oMessage.HeaderValue("X-hMailServer-LoopCount") = "" Then

		If oMessage.HasBodyType("text/plain") Then

			strRegEx = "^The Available Balance in your account is INR ([0-9]+(,[0-9]+)+)\.[0-9]+\.$"
			Set Matches = oLookup(strRegEx, oMessage.Body, False)
			For Each Match In Matches
				oMessage.Body = Replace(oMessage.Body, Match.Value, "..")
			Next
			oMessage.Save
		End If

		If oMessage.HasBodyType("text/html") Then
			strRegEx = "^The Available Balance in your account is INR ([0-9]+(,[0-9]+)+)\.[0-9]+\.$"
			Set Matches = oLookup(strRegEx, oMessage.Body, False)
			For Each Match In Matches
				oMessage.HTMLBody = Replace(oMessage.Body, Match.Value, "..")
			Next
			oMessage.Save
		End If

	End If

End Sub
How can I run this function for specific users only. It is working now for all users.

PS: I have currently set Global Rule

If From contains "bmail@bank.com"
Body Contains "Your ICICI Bank Account XX435 has been credited"

Run Function "Bankmail"
Forward to user1@domain.com
forward to user2@dmaoin.com

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

Re: Modifying the Body before Forwarding

Post by palinka » 2021-03-13 15:35

You can use an account rule.

Or if it's a long list of users you could put their addresses in an array and check against the array.

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

Re: Modifying the Body before Forwarding

Post by SorenR » 2021-03-13 19:32

This is an idea that just popped up...

Go to hMailAdmin.

Settings -> Protocols -> IMAP -> Groups ... Create a group called "test" and add some members.

I'm not really sure what else to use the "Groups" for ... :mrgreen:

Code: Select all

Option Explicit

'
'   COM authentication
'
Private Const ADMIN      = "administrator"
Private Const PASSWORD   = "Cosmic Secret Password"

Dim i, oApp : Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate(ADMIN, PASSWORD)

For i = 0 To oApp.Settings.Groups.ItemByName("test").Members.Count-1
    WScript.Echo oApp.Settings.Groups.ItemByName("test").Members.Item(i).Account.Address
Next

Set oApp = Nothing
SørenR.

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

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

Re: Modifying the Body before Forwarding

Post by mattg » 2021-03-14 03:22

SorenR wrote:
2021-03-13 19:32
I'm not really sure what else to use the "Groups" for ... :mrgreen:
Isn't that for Public folder permissions
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
SorenR
Senior user
Senior user
Posts: 4412
Joined: 2006-08-21 15:38
Location: Denmark

Re: Modifying the Body before Forwarding

Post by SorenR » 2021-03-14 15:20

mattg wrote:
2021-03-14 03:22
SorenR wrote:
2021-03-13 19:32
I'm not really sure what else to use the "Groups" for ... :mrgreen:
Isn't that for Public folder permissions
Yes - but not exclusively :mrgreen:
SørenR.

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

gotspatel
Normal user
Normal user
Posts: 110
Joined: 2013-10-08 05:42
Location: INDIA

Re: Modifying the Body before Forwarding

Post by gotspatel » 2021-03-16 11:09

SorenR wrote:
2021-03-14 15:20
mattg wrote:
2021-03-14 03:22
SorenR wrote:
2021-03-13 19:32
I'm not really sure what else to use the "Groups" for ... :mrgreen:
Isn't that for Public folder permissions
Yes - but not exclusively :mrgreen:
Am I on the right Track??

Code: Select all

Option Explicit

'
'   COM authentication
'
Private Const ADMIN      = "administrator"
Private Const PASSWORD   = "Cosmic Secret Password"

Function oLookup(strRegEx, strMatch, bGlobal)
	If strRegEx = "" Then strRegEx = StrReverse(strMatch)
	With CreateObject("VBScript.RegExp")
		.Pattern = strRegEx
		.Global = bGlobal
		.MultiLine = True
		.IgnoreCase = True
		Set oLookup = .Execute(strMatch)
	End With
End Function

Dim i, oApp : Set oApp = CreateObject("hMailServer.Application")
Dim strRegEx, Match, Matches
Call oApp.Authenticate(ADMIN, PASSWORD)

For i = 0 To oApp.Settings.Groups.ItemByName("test").Members.Count-1
    WScript.Echo oApp.Settings.Groups.ItemByName("test").Members.Item(i).Account.Address

	If oMessage.HeaderValue("X-hMailServer-LoopCount") = "" Then

		If oMessage.HasBodyType("text/plain") Then

			strRegEx = "^The Available Balance in your account is INR ([0-9]+(,[0-9]+)+)\.[0-9]+\.$"
			Set Matches = oLookup(strRegEx, oMessage.Body, False)
			For Each Match In Matches
				oMessage.Body = Replace(oMessage.Body, Match.Value, "..")
			Next
			oMessage.Save
		End If

		If oMessage.HasBodyType("text/html") Then
			strRegEx = "^The Available Balance in your account is INR ([0-9]+(,[0-9]+)+)\.[0-9]+\.$"
			Set Matches = oLookup(strRegEx, oMessage.Body, False)
			For Each Match In Matches
				oMessage.HTMLBody = Replace(oMessage.Body, Match.Value, "..")
			Next
			oMessage.Save
		End If

	End If
next

Set oApp = Nothing



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

Re: Modifying the Body before Forwarding

Post by SorenR » 2021-03-16 13:49

gotspatel wrote:
2021-03-16 11:09
SorenR wrote:
2021-03-14 15:20
mattg wrote:
2021-03-14 03:22

Isn't that for Public folder permissions
Yes - but not exclusively :mrgreen:
Am I on the right Track??
Nope, not even close!

1: It does not make sense to merge the two code pieces the way you've done.

2: You have not identified the account that "owns" the message so you can't do selective forward.

3: "WScript.Echo" will give an error as there is no default shell object in the hMailServer scripting engine.

4: My code piece is for checking if the recipient of the message to be forwarded is on the "safe to forward" list.
SørenR.

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

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

Re: Modifying the Body before Forwarding

Post by SorenR » 2021-03-16 14:00

Can you elaborate on the intended functionality?

Should the message be modified BEFORE forwarding - thus also modifying the original message? (your initial suggestion)
SørenR.

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

gotspatel
Normal user
Normal user
Posts: 110
Joined: 2013-10-08 05:42
Location: INDIA

Re: Modifying the Body before Forwarding

Post by gotspatel » 2021-03-16 14:04

SorenR wrote:
2021-03-16 14:00
Can you elaborate on the intended functionality?

Should the message be modified BEFORE forwarding - thus also modifying the original message? (your initial suggestion)
My intended use is as

We are getting mails from bank on email finance@mydomain.com

I want to forward copies to some users with the "BALANCE" portion redacted. user1@mydomain.com, user2@mydomain.com

Some users are getting full email copy without redaction by distribution group. fin_dist_list@mydoain.com >> (user4, user5, user10..)

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

Re: Modifying the Body before Forwarding

Post by palinka » 2021-03-16 14:12

I think that can all be done by rule.

If from finance

Action:
1) Forward unredacted to appropriate person
2) Run function to redact
3) Forward to distribution list

gotspatel
Normal user
Normal user
Posts: 110
Joined: 2013-10-08 05:42
Location: INDIA

Re: Modifying the Body before Forwarding

Post by gotspatel » 2021-03-16 14:18

palinka wrote:
2021-03-16 14:12
I think that can all be done by rule.

If from finance

Action:
1) Forward unredacted to appropriate person
2) Run function to redact
3) Forward to distribution list
Is this Possible / OR Viable

sorry for little confusion in my previous post.

mails come from bankmail@bank.com to finance@mydomain.com

Global Rule:

If
from contains bankmail@bank.com
body contains "BALANCE line to redact"
X-hMailServer-LoopCount < 1


Action:
1) Forward unredacted to distribution list No 1
2) Run function to redact
3) Forward to distribution list No 2

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

Re: Modifying the Body before Forwarding

Post by palinka » 2021-03-16 15:23

gotspatel wrote:
2021-03-16 14:18
palinka wrote:
2021-03-16 14:12
I think that can all be done by rule.

If from finance

Action:
1) Forward unredacted to appropriate person
2) Run function to redact
3) Forward to distribution list
Is this Possible / OR Viable

sorry for little confusion in my previous post.

mails come from bankmail@bank.com to finance@mydomain.com

Global Rule:

If
from contains bankmail@bank.com
body contains "BALANCE line to redact"
X-hMailServer-LoopCount < 1


Action:
1) Forward unredacted to distribution list No 1
2) Run function to redact
3) Forward to distribution list No 2
Looks good to me. You didn't mention they were going to distribution lists (originally). That greatly simplifies things, I think.

gotspatel
Normal user
Normal user
Posts: 110
Joined: 2013-10-08 05:42
Location: INDIA

Re: Modifying the Body before Forwarding

Post by gotspatel » 2021-03-16 15:30

One problem I found that even the finance@mydomain.com is getting the redacted mail :roll:

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

Re: Modifying the Body before Forwarding

Post by palinka » 2021-03-16 15:59

gotspatel wrote:
2021-03-16 15:30
One problem I found that even the finance@mydomain.com is getting the redacted mail :roll:
Naturally, since it was edited before delivery.

I guess one thing you could is set up an intermediate account. Create finance-temp@mydomain.com. Then:

Global Rule
If:
from contains bankmail@bank.com
body contains "BALANCE line to redact"
X-hMailServer-LoopCount < 1
Action:
Forward unredacted to finance-temp@mydomain.com


Account Rule on finance-temp@mydomain.com
If:
from contains bankmail@bank.com
body contains "BALANCE line to redact"
X-hMailServer-LoopCount < 1
Action:
1) Forward unredacted to distribution list No 1
2) Run function to redact
3) Forward to distribution list No 2
4) Delete message

gotspatel
Normal user
Normal user
Posts: 110
Joined: 2013-10-08 05:42
Location: INDIA

Re: Modifying the Body before Forwarding

Post by gotspatel » 2021-03-30 07:00

palinka wrote:
2021-03-16 15:59
gotspatel wrote:
2021-03-16 15:30

One problem I found that even the finance@mydomain.com is getting the redacted mail :roll:
Naturally, since it was edited before delivery.

I guess one thing you could is set up an intermediate account. Create finance-temp@mydomain.com. Then:

Global Rule
If:
from contains bankmail@bank.com
body contains "BALANCE line to redact"
X-hMailServer-LoopCount < 1
Action:
Forward unredacted to finance-temp@mydomain.com


Account Rule on finance-temp@mydomain.com
If:
from contains bankmail@bank.com
body contains "BALANCE line to redact"
X-hMailServer-LoopCount < 1
Action:
1) Forward unredacted to distribution list No 1
2) Run function to redact
3) Forward to distribution list No 2
4) Delete message
STILL NOT WORKING ANY HELP PLEASE, HERE IS THE SETUP I HAVE DONE

all the emails from the bank "alerts@mybank.com" are received in "finance@mydomain.com"

Code: Select all

finance@mydomain.com - with forwarding Enabled to distribution lists  >> "fin_dblist@Mydomain.com"
I have 2 distribution lists and other configs as below,

Code: Select all

fin_dblist@Mydomain.com - Public   - THIS LIST SHOULD GET "ORIGINAL EMAIL"
Members:
finnance-temp@mydomain.com
mitul.patel@mydomain.com
sagar.patel@mydomain.com

Code: Select all

ACCOUNT RULES for finance-temp@Domain1.com:

  1, FIN_TEMP_CR_LIST             Criteria:  Use AND
             Body                      Contains        Your ICICI Bank Account XX435 has been credited
     Custom: X-hMailServer-LoopCount   Less Than       1
                                  -----Actions-----
             Run Function                              Bankmail
             Forward                                   fin_cr_list@Domain1.com

Code: Select all

fin_cr_list@mydomain.com - Public - THIS LIST SHOULD GET "REDACTED EMAIL"
Members:
sales1@mydomain.com
sales2@mydomain.com
gautam.patel@mydomain.com

Code: Select all

Sub Bankmail(oMessage)
	'called from: Rules	
	Dim strRegEx, Match, Matches	
	If oMessage.HeaderValue("X-hMailServer-LoopCount") = "" Then
		If oMessage.HasBodyType("text/plain") Then
			strRegEx = "^The Available Balance in your account is INR ([0-9]+(,[0-9]+)+)\.[0-9]+\.$"
			Set Matches = oLookup(strRegEx, oMessage.Body, False)
			For Each Match In Matches
				oMessage.Body = Replace(oMessage.Body, Match.Value, "..")
			Next
			oMessage.Save
		End If
		If oMessage.HasBodyType("text/html") Then
			strRegEx = "^The Available Balance in your account is INR ([0-9]+(,[0-9]+)+)\.[0-9]+\.$"
			Set Matches = oLookup(strRegEx, oMessage.Body, False)
			For Each Match In Matches
				oMessage.HTMLBody = Replace(oMessage.Body, Match.Value, "..")
			Next
			oMessage.Save
		End If
	End If
End Sub




Code: Select all

[code]2021-03-30   Hmailserver: 5.6.8-B2538.29

DOMAINS

   "Domain1.com" - mexxxxxxxxxxx.com              Enabled: True

SIGNATURE         LIMITS                       DKIM               ADVANCED
  Enabled: False   Max size:                0   Enabled: False   
                   Max message size:        0                      Plus addressing: False
                   Max size of accounts:    0                    
                                                                   Greylisting:      True
-----------------------------------------------------------------------------------------------

GLOBAL RULES
  1, Mirror Stop                  Criteria:  Use AND
             Recipient List            Contains        mirror@Domain1.com
                                  -----Actions-----
             Stop Rule Processing
 ---------------------------------------------------------------------
  2, SPAM TO SPAM FOLDER          Criteria:  Use AND
     Custom: X-hMailServer-Spam        Equals          YES
     Custom: X-hMailServer-LoopCount   Less Than       1
     Custom: X-hMailServer-Reason-Sc   Greater Than    7
     Custom: Delivered-To              Not Contains    spambox@Domain1.com
                                  -----Actions-----
             Forward                                   spambox@Domain1.com
             Move To Folder                            Junk E-mail
 ---------------------------------------------------------------------
  3, CAUTION EXTERNAL MAIL        Criteria:  Use AND
             From                      Not Contains    @Domain1.com
                                  -----Actions-----
             Run Function                              Externalmail
 ---------------------------------------------------------------------
  4, Sales1 Sent FW to Sales      Criteria:  Use AND
             From                      Contains        sales1@Domain1.com
             Recipient List            Not Contains    sales@Domain1.com
     Custom: X-hMailServer-LoopCount   Less Than       1
                                  -----Actions-----
             Forward                                   sales@Domain1.com
 ---------------------------------------------------------------------
  5, Sales1 To FW to Sales        Criteria:  Use AND
             Recipient List            Contains        sales1@Domain1.com
             Recipient List            Not Equals      sales@Domain1.com
             From                      Not Equals      sales@Domain1.com
     Custom: X-hMailServer-LoopCount   Less Than       1
                                  -----Actions-----
             Forward                                   sales@Domain1.com
 ---------------------------------------------------------------------
  6, donotreply Sent FW           Criteria:  Use AND
             From                      Contains        donotreply@Domain1.com
     Custom: X-hMailServer-LoopCount   Less Than       1
                                  -----Actions-----
             Forward                                   sales@Domain1.com
 ---------------------------------------------------------------------
  7, mitul.patel Sent FW          Criteria:  Use AND
             From                      Contains        mitul.patel@Domain1.com
             Recipient List            Not Contains    gautam.patel@Domain1.com
     Custom: X-hMailServer-LoopCount   Less Than       1
                                  -----Actions-----
             Forward                                   gautam.patel@Domain1.com
 ---------------------------------------------------------------------
  8, sagar.patel Sent FW          Criteria:  Use AND
             From                      Contains        sagar.patel@Domain1.com
             Recipient List            Not Contains    gautam.patel@Domain1.com
     Custom: X-hMailServer-LoopCount   Less Than       1
                                  -----Actions-----
             Forward                                   gautam.patel@Domain1.com
-----------------------------------------------------------------------------------------------

ACCOUNT RULES for finance-temp@Domain1.com:

  1, FIN_TEMP_CR_LIST             Criteria:  Use AND
             Body                      Contains        Your ICICI Bank Account XX435 has been credited
     Custom: X-hMailServer-LoopCount   Less Than       1
                                  -----Actions-----
             Run Function                              Bankmail
             Forward                                   fin_cr_list@Domain1.com
-----------------------------------------------------------------------------------------------

IP RANGES

IP: 192.168.168.0 - 192.168.175.254     Priority: 25     Name: MML lan

  Allow connections                         Other
     SMTP:   True                              Antispam :   True
     POP3:   True                              Antivirus:   True !! ANTIVIRUS NOT CONFIGURED !!
     IMAP:   True                              SSL/TLS:     True

  Allow Deliveries from                     Require Authentication from
     Local To Local       -  True              Local To Local       -  True
     Local To External    -  True              Local To External    -  True
     External To Local    -  True              External To Local    -  True
     External To External -  True              External To External -  True


IP: 45.58.142.12 - 45.58.142.12     Priority: 20     Name: Suchan 45.58.142.12

  Allow connections                         Other
     SMTP:   True                              Antispam :   True
     POP3:   True                              Antivirus:   True !! ANTIVIRUS NOT CONFIGURED !!
     IMAP:   True                              SSL/TLS:    False

  Allow Deliveries from                     Require Authentication from
     Local To Local       -  True              Local To Local       -  True
     Local To External    -  True              Local To External    -  True
     External To Local    -  True              External To Local    -  True
     External To External -  True              External To External -  True


IP: 127.0.0.1 - 127.0.0.1     Priority: 15     Name: My computer

  Allow connections                         Other
     SMTP:   True                              Antispam :   True
     POP3:   True                              Antivirus:   True !! ANTIVIRUS NOT CONFIGURED !!
     IMAP:   True                              SSL/TLS:    False

  Allow Deliveries from                     Require Authentication from
     Local To Local       -  True              Local To Local       -  True
     Local To External    -  True              Local To External    -  True
     External To Local    -  True              External To Local    -  True
     External To External -  True              External To External -  True


IP: 0.0.0.0 - 255.255.255.255     Priority: 10     Name: Internet

  Allow connections                         Other
     SMTP:   True                              Antispam :   True
     POP3:   True                              Antivirus:   True !! ANTIVIRUS NOT CONFIGURED !!
     IMAP:   True                              SSL/TLS:     True

  Allow Deliveries from                     Require Authentication from
     Local To Local       -  True              Local To Local       -  True
     Local To External    -  True              Local To External    -  True
     External To Local    -  True           !! External To Local    -  True !!
       !! EXTERNAL INBOUND ON SUB IP RANGES OR EXTERNAL DOWNLOADS ONLY !!  
     External To External -  True              External To External -  True


   !!  Warning:  DEFAULT DOMAIN is SET  !! - "Domain1.com"
------------------------------------------------------
AUTOBANNED Local Addresses:
    No entries

-----------------------------------------------------------------------------------------------

AUTOBAN
  Autoban Enabled: True       Max invalid logon attempts:      5
                              Minutes Before Reset:         1500  (25.00 hours, 1.04 days)
                              Minutes to Autoban:          10140  (169.00 hours, 7.04 days)

No problems were found in the IP range configuration.
-----------------------------------------------------------------------------------------------

INCOMING RELAYS
   No entries
-----------------------------------------------------------------------------------------------

MIRRORING         mirror@Domain1.com
-----------------------------------------------------------------------------------------------

PROTOCOLS

SMTP
GENERAL             DELIVERY                  RFC COMPLIANCE            ADVANCED
No. Connections:  0  No Retries:  5 Mins:  3   Plain Text:        False  Bind: 
                     Host: EXTERNAL.TLD        Empty sender:       True  Batch recipients:   100
Max Msg Size: 20480  Relay:-                   Incorrect endings:  True  Use STARTTLS:      True
                  !! POINTS TO LOCAL DOMAIN !! Disc. on invalid:   True  Delivered-To hdr: False
                                               
                     Port: 465                 Max number commands:   5  Loop limit:           2
                     Req Auth: True *User Entered*                       Recipient hosts:      5
                     Con. Sec.: SSL/TLS
  Routes:
     No routes defined.

POP3
  No. Connections: 0

IMAP
 GENERAL                   PUBLIC FOLDERS                    ADVANCED
  No. Connections:   0      Public folder name: #Public       IMAP sort:  True
                                                              IMAP Quota: True
                                                              IMAP Idle:  True
                                                              IMAP ACL:   True
                                                              Delim: "."
-----------------------------------------------------------------------------------------------

ANTISPAM

GENERAL                              SPAM TESTS              Score   SPAMASSASSIN
  Spam Mark:                  5       Use SPF:            True - 3    Use Spamassassin:    True
  Add X-HmailServer-Spam:     True    Check HELO host:    True - 2    Hostname:       127.0.0.1
  Add X-HmailServer-Reason:   True    Check MX records:   True - 2    Port:                 783
  Add X-HmailServer-Subject:  True    Verify DKIM:        True - 5    Use SA score:        True
              Subject Text: "[SPAM HMS]"
  Spam delete threshold: 100         Maximum message size: 2048

DNSBL ENTRIES:
                  zen.spamhaus.org      Score: 3     Result: 127.0.0.*
                    bl.spamcop.net      Score: 3     Result: 127.0.0.*
                   dnsbl.njabl.org      Score: 1     Result: 127.0.0.*
                  psbl.surriel.com      Score: 1     Result: 127.0.0.*
                virbl.dnsbl.bit.nl      Score: 1     Result: 127.0.0.*
           bb.barracudacentral.org      Score: 2     Result: 127.0.0.*
               ix.dnsbl.manitu.net      Score: 5     Result: 127.0.0.*

SURBL ENTRIES:
                   multi.surbl.org      Score: 1

GREYLISTING:
  Greylisting:   True       Defer mins: 1       Days Unused: 15      Days Used: 36
                            Bypass SPF: True     Bypass A/MX: True

Greylist WHITELIST ENTRIES:
   No entries

Greylist DOMAINS enabled:
           Domain1.com

WHITELISTING
              0.0.0.0            to    255.255.255.255              mygmail[@t]gmail[dot]com
              0.0.0.0            to    255.255.255.255              eepcho[@t]eepcindia[dot]net
              45.58.142.12       to    45.58.142.12                 donotreply[@t]MYDOMAIN[dot]com
-----------------------------------------------------------------------------------------------

ANTIVIRUS:  No application configured.

  Block Attachments: True
               *.bat             Batch processing file
               *.cmd             Command file for Windows NT
               *.com             Command
               *.cpl             Windows Control Panel extension
               *.csh             CSH script
               *.exe             Executable file
               *.inf             Setup file
               *.lnk             Windows link file
               *.msi             Windows Installer file
               *.msp             Windows Installer patch
               *.pif             Program Information file
               *.reg             Registration key
               *.scf             Windows Explorer command
               *.scr             Windows Screen saver
-----------------------------------------------------------------------------------------------

SSL CERTIFICATES
   Domain1.com
       Certificate: C:\Program Files (x86)\hMailServer\Bin\SSL\Domain1.com.cert
       Private key: C:\Program Files (x86)\hMailServer\Bin\SSL\Domain1.com.key
-----------------------------------------------------------------------------------------------

SSL/TLS
             TLS 1.0 :  False
             TLS 1.1 :  False
             TLS 1.2 :   True
             TLS 1.3 :   True                Verify Remote SSL/TLS Certs:   True
SslCipherList  :

ECDHE-RSA-AES128-GCM-SHA256     - ECDHE-ECDSA-AES128-GCM-SHA256   - ECDHE-RSA-AES256-GCM-SHA384     
ECDHE-ECDSA-AES256-GCM-SHA384   - DHE-RSA-AES128-GCM-SHA256       - DHE-DSS-AES128-GCM-SHA256       
kEDH+AESGCM                     - ECDHE-RSA-AES128-SHA256         - ECDHE-ECDSA-AES128-SHA256       
ECDHE-RSA-AES128-SHA            - ECDHE-ECDSA-AES128-SHA          - ECDHE-RSA-AES256-SHA384         
ECDHE-ECDSA-AES256-SHA384       - ECDHE-RSA-AES256-SHA            - ECDHE-ECDSA-AES256-SHA          
DHE-RSA-AES128-SHA256           - DHE-RSA-AES128-SHA              - DHE-DSS-AES128-SHA256           
DHE-RSA-AES256-SHA256           - DHE-DSS-AES256-SHA              - DHE-RSA-AES256-SHA              
AES128-GCM-SHA256               - AES256-GCM-SHA384               - ECDHE-RSA-RC4-SHA               
ECDHE-ECDSA-RC4-SHA             - AES128                          - AES256                          
RC4-SHA                         - HIGH                            - !aNULL                          
!eNULL                          - !EXPORT                         - !DES                            
!3DES                           - !MD5                            - !PSK;                           
-----------------------------------------------------------------------------------------------

TCPIP PORTS                                         Connection Sec
               0.0.0.0         / 25    / SMTP   -   None                
               0.0.0.0         / 110   / POP3   -   None                
               0.0.0.0         / 143   / IMAP   -   None                
               0.0.0.0         / 465   / SMTP   -   SSL/TLS             Cert: Domain1.com
               0.0.0.0         / 587   / SMTP   -   None                
               0.0.0.0         / 993   / IMAP   -   SSL/TLS             Cert: Domain1.com
               0.0.0.0         / 995   / POP3   -   SSL/TLS             Cert: Domain1.com
-----------------------------------------------------------------------------------------------

LOGGING      Logging Enabled: True

  Paths:-
    Current:  C:\Program Files (x86)\hMailServer\Logs\hmailserver_2021-03-30.log
    Error:    C:\Program Files (x86)\hMailServer\Logs\ERROR_hmailserver_2021-03-30.log
    Event:    C:\Program Files (x86)\hMailServer\Logs\hmailserver_events.log - Last Event: 2021/03/30
    Awstats:  C:\Program Files (x86)\hMailServer\Logs\hmailserver_awstats.log
                        APPLICATION -    True
                        SMTP        -    True
                        POP3        -    True
                        IMAP        -    True
                        TCPIP       -    True
                        DEBUG       -    True
                        AWSTATS     -    True
-----------------------------------------------------------------------------------------------

SYSTEM TESTS

Database type: MySQL

IPv6 support is available in operating system.

Backup directory C:\hMail_Config_BKP is writable.

Relative message paths are stored in the database for all messages.

-----------------------------------------------------------------------------------------------

HMAILSERVER.INI

[Directories]
Program folder:  C:\Program Files (x86)\hMailServer\
Database folder: 
Data folder:     C:\Program Files (x86)\hMailServer\Data
Log folder:      C:\Program Files (x86)\hMailServer\Logs
Temp folder:     C:\Program Files (x86)\hMailServer\Temp
Event folder:    C:\Program Files (x86)\hMailServer\Events

[Database]
Type=              MYSQL
Username=          root
PasswordEncryption=1
Port=              3306
Server=            localhost
Internal=          0

[settings]
PreferredHashAlgorithm=1
BlockedIPHoldSeconds=10
SepSvcLogs=1
-----------------------------------------------------------------------------------------------

Generated by HMSSettingsDiagnostics v2.01, Hmailserver Forum.

[/code]

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

Re: Modifying the Body before Forwarding

Post by RvdH » 2021-04-01 11:43

If oMessage.HeaderValue("X-hMailServer-LoopCount") = "" Then

I don't think that header exists wehn it's empty.... oMessage.HeaderValue("X-hMailServer-LoopCount") only is added when loopcount > 0
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
jimimaseye
Moderator
Moderator
Posts: 8960
Joined: 2011-09-08 17:48

Re: Modifying the Body before Forwarding

Post by jimimaseye » 2021-04-01 11:46

RvdH wrote:
2021-04-01 11:43
If oMessage.HeaderValue("X-hMailServer-LoopCount") = "" Then

I don't think that header exists wehn it's empty.... oMessage.HeaderValue("X-hMailServer-LoopCount") only is added when loopcount > 0
+1


Better to say:

if oMessage.HeaderValue("X-hMailServer-LoopCount") < 1 then.....

as that would trigger the same even if it doesnt exist (the value is still Zero)
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

gotspatel
Normal user
Normal user
Posts: 110
Joined: 2013-10-08 05:42
Location: INDIA

Re: Modifying the Body before Forwarding

Post by gotspatel » 2021-04-01 11:46

RvdH wrote:
2021-04-01 11:43
If oMessage.HeaderValue("X-hMailServer-LoopCount") = "" Then

I don't think that header exists wehn it's empty.... oMessage.HeaderValue("X-hMailServer-LoopCount") only is added when loopcount > 0
Got that. Thanks. Already removed them but still figuring out the exact sequencing for achieve what I want.

:D

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

Re: Modifying the Body before Forwarding

Post by RvdH » 2021-04-01 11:52

jimimaseye wrote:
2021-04-01 11:46
RvdH wrote:
2021-04-01 11:43
If oMessage.HeaderValue("X-hMailServer-LoopCount") = "" Then

I don't think that header exists wehn it's empty.... oMessage.HeaderValue("X-hMailServer-LoopCount") only is added when loopcount > 0
+1


Better to say:

if oMessage.HeaderValue("X-hMailServer-LoopCount") < 1 then.....

as that would trigger the same even if it doesnt exist (the value is still Zero)
Nope.... X-hMailServer-LoopCount=0 is not a valid header, is it? So in that case you have to check if the X-hMailServer-LoopCount header exists at all

EDIT....you might be right
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
SorenR
Senior user
Senior user
Posts: 4412
Joined: 2006-08-21 15:38
Location: Denmark

Re: Modifying the Body before Forwarding

Post by SorenR » 2021-04-01 12:08

RvdH wrote:
2021-04-01 11:52
jimimaseye wrote:
2021-04-01 11:46
RvdH wrote:
2021-04-01 11:43
If oMessage.HeaderValue("X-hMailServer-LoopCount") = "" Then

I don't think that header exists wehn it's empty.... oMessage.HeaderValue("X-hMailServer-LoopCount") only is added when loopcount > 0
+1


Better to say:

if oMessage.HeaderValue("X-hMailServer-LoopCount") < 1 then.....

as that would trigger the same even if it doesnt exist (the value is still Zero)
Nope.... X-hMailServer-LoopCount=0 is not a valid header, is it? So in that case you have to check if the X-hMailServer-LoopCount header exists at all

EDIT....you might be right
Previous tests show the header does not exist until X-hMailServer-LoopCount > 0

The very first rule I have in my global list is:

If X-hMailServer-LoopCount > 0 then "Stop rule processing"

So I don't need to include it every time.
If I need to process something on a forwarded mail I just add the new rule above it.
SørenR.

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

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

Re: Modifying the Body before Forwarding

Post by jimimaseye » 2021-04-01 12:36

RvdH wrote:
2021-04-01 11:52
Nope.... X-hMailServer-LoopCount=0 is not a valid header, is it? So in that case you have to check if the X-hMailServer-LoopCount header exists at all

EDIT....you might be right
If it exists the test results will have a value of 1 or more depending on what the header value is.

If the header doesn't exist then the results of the test will be zero ('nothing' also becomes zero).

(As you have found out)

[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: 4412
Joined: 2006-08-21 15:38
Location: Denmark

Re: Modifying the Body before Forwarding

Post by SorenR » 2021-04-01 12:45

jimimaseye wrote:
2021-04-01 12:36
RvdH wrote:
2021-04-01 11:52
Nope.... X-hMailServer-LoopCount=0 is not a valid header, is it? So in that case you have to check if the X-hMailServer-LoopCount header exists at all

EDIT....you might be right
If it exists the test results will have a value of 1 or more depending on what the header value is.

If the header doesn't exist then the results of the test will be zero ('nothing' also becomes zero).

(As you have found out)

[Entered by mobile. Excuse my spelling.]
I run a function in my eventhandler to check for attachments but only on "original" emails...

Code: Select all

If (oMessage.HeaderValue("X-hMailServer-LoopCount") > "0") Then Exit Function
When a header does not exist oMessage.HeaderValue() returns "".
SørenR.

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

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

Re: Modifying the Body before Forwarding

Post by jimimaseye » 2021-04-01 14:07

Empty string ("") converted to a value will be Zero.
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: 4412
Joined: 2006-08-21 15:38
Location: Denmark

Re: Modifying the Body before Forwarding

Post by SorenR » 2021-04-01 17:41

jimimaseye wrote:
2021-04-01 14:07
Empty string ("") converted to a value will be Zero.
Well... Actually... No!

VBScript only have one data type: Variant

Code: Select all

Dim var1, var2

var1 = "1"
var2 = 2

Wscript.Echo var1 + var2
When run it should say 3

If you replace "1" with "" you get a runtime error.

It only becomes 0 if you CLng(var1) or CInt(var1) it...

EDIT: Well, not even then :wink:
SørenR.

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

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

Re: Modifying the Body before Forwarding

Post by RvdH » 2021-04-01 21:26

Code: Select all

EventLog.Write(oMessage.HeaderValue("X-hMailServer-LoopCount") < 1)
result: "Script Error: Source: Microsoft VBScript runtime error - Error: 800A000D - Description: Type mismatch: '[string: ""]'

Code: Select all

EventLog.Write(oMessage.HeaderValue("X-hMailServer-LoopCount") > 0)
result: "Script Error: Source: Microsoft VBScript runtime error - Error: 800A000D - Description: Type mismatch: '[string: ""]'

Code: Select all

EventLog.Write(oMessage.HeaderValue("X-hMailServer-LoopCount") > "0")
result: False

Safest in my opinion is to wrap it inside:

Non-Empty

Code: Select all

If oMessage.HeaderValue("X-hMailServer-LoopCount")<>"" Then
...
End If
or

Empty

Code: Select all

If Not oMessage.HeaderValue("X-hMailServer-LoopCount")<>"" Then
...
End If
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

gotspatel
Normal user
Normal user
Posts: 110
Joined: 2013-10-08 05:42
Location: INDIA

Re: Modifying the Body before Forwarding

Post by gotspatel » 2021-04-06 07:43

mails come from alerts@mybank.com to finance@mydomain.com

Global Rule:

If
from contains alerts@mybank.com
body contains "BALANCE line to redact"
X-hMailServer-LoopCount < 1


Action:
1) Forward unredacted to distribution list No 1
2) Run function to redact
3) Forward to distribution list No 2

Mails other then the rule should go to distribution list no. 1 only

Code: Select all

Sub Bankmail(oMessage)
	'called from: Rules	
	Dim strRegEx, Match, Matches	
		If oMessage.HasBodyType("text/plain") Then
			strRegEx = "^The Available Balance in your account is INR ([0-9]+(,[0-9]+)+)\.[0-9]+\.$"
			Set Matches = oLookup(strRegEx, oMessage.Body, False)
			For Each Match In Matches
				oMessage.Body = Replace(oMessage.Body, Match.Value, "..")
			Next
			oMessage.Save
		End If
		If oMessage.HasBodyType("text/html") Then
			strRegEx = "^The Available Balance in your account is INR ([0-9]+(,[0-9]+)+)\.[0-9]+\.$"
			Set Matches = oLookup(strRegEx, oMessage.Body, False)
			For Each Match In Matches
				oMessage.HTMLBody = Replace(oMessage.Body, Match.Value, "..")
			Next
			oMessage.Save
		End If
End Sub
Can any senior please assist I tried many variations but this is not working none of the distribution list is getting the mail. Please point out where I am getting it wrong. :oops:

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

Re: Modifying the Body before Forwarding

Post by SorenR » 2021-04-06 12:56

Second lookup where body is "text/html" you still refer to "oMessage.Body" in "oLookup" and "Replace".

I believe that should be "oMessage.HTMLBody" .

Also, your rule ... body contains "BALANCE line to redact" ... Again, this is "text/plain" only and does such a text exist in the email body?

Perhaps there is a specific text in the subject you can trigger on??

If you like me to have a look perhaps you can PM me a copy of the raw email?
It's fine to redact email addresses and names ... and bank account numbers :wink:
SørenR.

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

gotspatel
Normal user
Normal user
Posts: 110
Joined: 2013-10-08 05:42
Location: INDIA

Re: Modifying the Body before Forwarding

Post by gotspatel » 2021-04-07 05:43

SorenR wrote:
2021-04-06 12:56
Second lookup where body is "text/html" you still refer to "oMessage.Body" in "oLookup" and "Replace".

I believe that should be "oMessage.HTMLBody" .

Also, your rule ... body contains "BALANCE line to redact" ... Again, this is "text/plain" only and does such a text exist in the email body?

Perhaps there is a specific text in the subject you can trigger on??

If you like me to have a look perhaps you can PM me a copy of the raw email?
It's fine to redact email addresses and names ... and bank account numbers :wink:
Thank you for assistance.

.HTMLBody was a silly mistake I overlook changed it appropriately.

Rule body contains "BALANCE line to redact": the mails are mostly plain text, Sorry I don't know how to write html line to check in the rule.

Subject is always: "ALERT" so have to rely on the body of mail as there are many type of ALERT mails from bank, credit payment, debit payments, cheque clearance etc. etc. I want to process the credit related mails before giving them to sales persons.

PM of mail Sent for further assistance.

Post Reply