Gmail "be careful with this message"

Use this forum if you have installed hMailServer and want to ask a question related to a production release of hMailServer. Before posting, please read the troubleshooting guide. A large part of all reported issues are already described in detail here.
michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-08 03:43

there wasn't even a "settings" section in the hmailserver.ini file. So I added it and I added the line to it. Yes it works but it's doing what I was talking about. In Outlook or Gmail, when your have your list of emails, instead of showing it's from me, it shows it's from the list. When you open the message up, the "on behalf of" is backwards. It says it's from "michaelj@vcn.com on behalf of abdx@abdx.org". Boy I will really confuse the list if I leave it this way. So what I'm looking for is for it to appear in the inbox as from me, not the list...and then on the inside saying from "abdx@abdx.org on behalf of michaelj@vcn.com" although the "on behalf of" is not that important. I am just thinking somehow that may help with the spf softfail. speaking of which, it's still having a softfail on SPF. Here's the portion of the header for you:

-----------------------------
Return-Path: <michaelj@vcn.com>
Received: from abdx.org (abdx.org. [65.38.140.167])
by mx.google.com with ESMTPS id a1si3003262jae.115.2021.01.07.17.18.53
for <michaeljwyo@gmail.com>
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 07 Jan 2021 17:18:53 -0800 (PST)
Received-SPF: softfail (google.com: domain of transitioning michaelj@vcn.com does not designate 65.38.140.167 as permitted sender) client-ip=65.38.140.167;
Authentication-Results: mx.google.com;
spf=softfail (google.com: domain of transitioning michaelj@vcn.com does not designate 65.38.140.167 as permitted sender) smtp.mailfrom=michaelj@vcn.com;
dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=abdx.org
------------------------------

So what to try next? Oh by the way, this is only your script with the rule. I haven't put in the revisions from Soren. I figured I'd try one thing at a time. I created a test list so that I can do all this testing and quit filling up 80 users' inboxes with test messages.

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-08 03:52

btw, pulled the "rule" and did the revisions from Soren. Does nothing except if you hit reply it replies to the originator and not to the list. Otherwise same SPF failing and as far as the look of the messages it looks like it always did (and should) with the originator's name in the email client.

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-08 04:07

From what I can see, hMailServer is using the post originator as the MAIL FROM envelope sender no matter what RewriteEnvelopeFromWhenForwarding is set to, and Gmail is looking up the SPF record based on the domain of the envelope sender.

The SPF record for vcn.com is:

Code: Select all

"v=spf1 ip4:209.193.72.0/23 ip4:184.164.96.0/28 ip4:66.198.195.100/30 ip6:2607:f498:4001::/64 include:spf.mandrillapp.com ~all"
Gmail sees the message coming from your server at 65.38.140.167, and this address is not in the SPF for vcn.com. The test softfails due to inclusion of ~all in the SPF record.

I don't see a another way to change hMailServers ditribution list behavior to force the MAIL FROM envelope sender to be abdx@abdx.org, which would then pass the SPF test based on abdx.org's SFP record of

Code: Select all

"v=spf1 include:_spf.google.com ip4:65.38.140.167 ~all"
So I think you are back to needing to consider using add-on mail list list software to generate the emails. There are a number of free open source options for Linux, but I don't know of any for Windows.

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-08 04:57

Is there something I can do to our spf record?
"v=spf1 include:_spf.google.com ip4:65.38.140.167 ~all"

I can change it in any way need be. This particular email happened to be sent to the list from my vcn.com account. People are sending from all their different accounts. I sent to the list from my gmail account. So google or whoever is always gonna try to spf with the sender, and not with the list. That's what you're saying right?

Don't know if it helps, but here's the header info from a user that sent to the list from his gmail account:

------------------------------------------------
ARC-Authentication-Results: i=1; mx.google.com;
dkim=pass header.i=@gmail.com header.s=20161025 header.b=j8BzAO+q;
spf=softfail (google.com: domain of transitioning wghauser@gmail.com does not designate 65.38.140.167 as permitted sender) smtp.mailfrom=wghauser@gmail.com;
dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
Return-Path: <wghauser@gmail.com>
Received: from abdx.org (abdx.org. [65.38.140.167])
by mx.google.com with ESMTPS id m4si4489898ilh.99.2021.01.07.09.54.17
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 07 Jan 2021 09:54:25 -0800 (PST)
Received-SPF: softfail (google.com: domain of transitioning wghauser@gmail.com does not designate 65.38.140.167 as permitted sender) client-ip=65.38.140.167;
Authentication-Results: mx.google.com;
dkim=pass header.i=@gmail.com header.s=20161025 header.b=j8BzAO+q;
spf=softfail (google.com: domain of transitioning wghauser@gmail.com does not designate 65.38.140.167 as permitted sender) smtp.mailfrom=wghauser@gmail.com;
dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
X-Spam-Checker-Version: SpamAssassin 3.4.2 (svnunknown) on mail-PC
X-Spam-Level:
X-Spam-Status: No, score=0.4 required=5.0 tests=DATE_IN_PAST_24_48,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2
Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by abdx.org with ESMTP ; Thu, 7 Jan 2021 10:54:15 -0700
Received: by mail-wr1-f45.google.com with SMTP id a12so6478059wrv.8
for <abdx@abdx.org>; Thu, 07 Jan 2021 09:54:13 -0800 (PST)

------------------------------------------------
Google always shows it as a softfail with our IP.

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

Re: Gmail "be careful with this message"

Post by SorenR » 2021-01-08 05:38

mikedibella wrote:
2021-01-08 04:07
From what I can see, hMailServer is using the post originator as the MAIL FROM envelope sender no matter what RewriteEnvelopeFromWhenForwarding is set to, and Gmail is looking up the SPF record based on the domain of the envelope sender.
It appear from the source that RewriteEnvelopeFromWhenForwarding is an "account" thing... I have not found the exact spot yet where distributionlists are sent... It could be the same spot in the code as it only checks for either " sender="" " => " mailerdaemon " or " pAccount & RewriteEnvelopeFromWhenForwarding " => " sender = pAccount.GetSenderAddress() "...

Anyways. If RewriteEnvelopeFromWhenForwarding=1 and an account is created called "mylist@domain.tld" and this account is set to forward the message to "list1@domain.tld" then the MAIL FROM would be rewritten to "mylist@domain.tld"...

I think...

Worth a try?
SørenR.

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

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-08 05:39

michaeljwyo wrote:
2021-01-08 04:57
Is there something I can do to our spf record?
You'd need to have your IP added to the SPF records for the domain's of every list member to solve the problem.

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-08 05:45

SorenR wrote:
2021-01-08 05:38
If RewriteEnvelopeFromWhenForwarding=1 and an account is created called "mylist@domain.tld" and this account is set to forward the message to "list1@domain.tld" then the MAIL FROM would be rewritten to "mylist@domain.tld"...
Hmmm...you reminded me I suggested something similar to solve a related distribution list program:

https://www.hmailserver.com/forum/viewt ... 49#p224355

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

Re: Gmail "be careful with this message"

Post by SorenR » 2021-01-08 06:05

mikedibella wrote:
2021-01-08 05:45
SorenR wrote:
2021-01-08 05:38
If RewriteEnvelopeFromWhenForwarding=1 and an account is created called "mylist@domain.tld" and this account is set to forward the message to "list1@domain.tld" then the MAIL FROM would be rewritten to "mylist@domain.tld"...
Hmmm...you reminded me I suggested something similar to solve a related distribution list program:

https://www.hmailserver.com/forum/viewt ... 49#p224355
Did it work?
SørenR.

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

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-08 06:09

SorenR wrote:
2021-01-08 06:05
Did it work?
OP never followed up.

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-08 23:50

Hmmm..I'd be willing to try it. So...the list name is abdx@abdx.org. In order for people to send something to the list they would have to email a different address...one that I set up to automatically forward to the abdx@abdx.org address. Do that using the method you described in your post...the one you linked to. Is that what we want to try? The potential problem I see is getting the OP's name to come up when it hits the list. when someone gets a post from the list, I don't want it to just have the list's address. Then we'll be getting many posts coming in to our inbox's not knowing who they are from unless we open them up and even then, if the person didn't sign their message we still might now know who sent it. Not sure if the actual name is in a different part of the envelope versus the address and it follows the forward.

Thoughts?

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-09 01:43

1. Change the MAIL FROM envelope sender from the post originator to the list address. The front-end account may be able to do that. You should create an account on the list's domain with the name you want to use as the list name. Configure this account Forwarding tab, Enabled, Forward to the distribution list address. Leave Keep original message unchecked.

2. Add this code to EventHandlers.vbs:

Code: Select all

Sub SaveOriginator(oMessage)
	oMessage.HeaderValue("X-Originator") = oMessage.FromAddress
	oMessage.Save
End Sub
3. Add an Account Rule to this account that fires SaveOriginator for all messages. Criteria such as To Contains proxy-account-address should work.

4. Add this code to EventHandlers.vbs (replacing the earlier function of the same name):

Code: Select all

Sub FixListPost(oMessage)
	oMessage.HeaderValue("Sender") = oMessage.HeaderValue("X-Originator")
	oMessage.HeaderValue("Reply-to") = oMessage.From
	oMessage.From = oMessage.HeaderValue("X-Originator")
	oMessage.Save
End Sub
5. Add or modify the Global Rule to fire this function using criteria To Contains distribution-list-alias-address.

Test and report.

@SorenR...can you review my logic?

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-09 02:46

Okay...another question. So what happens when people reply? Reply-to would need to be the address that everybody sends to. Is that where it's going to go?
For example: I create an actual distro list called "messages@abdx.org" with all the list members. Meanwhile abdx@abdx.org is the address that people will actually send to that will forward to messages@abdx.org. So when they hit "reply" will it reply to "messages@abdx.org" (since that's where it came from) ? If it does, then it will go directly out to the list bypassing the forwarding account...which of course will put it back in the same situation with SPF failures and so forth. I want to make sure before I start making modifications and creating a new list and so on.

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

Re: Gmail "be careful with this message"

Post by SorenR » 2021-01-09 03:14

mikedibella wrote:
2021-01-09 01:43
1. Change the MAIL FROM envelope sender from the post originator to the list address. The front-end account may be able to do that. You should create an account on the list's domain with the name you want to use as the list name. Configure this account Forwarding tab, Enabled, Forward to the distribution list address. Leave Keep original message unchecked.

2. Add this code to EventHandlers.vbs:

Code: Select all

Sub SaveOriginator(oMessage)
	oMessage.HeaderValue("X-Originator") = oMessage.FromAddress
	oMessage.Save
End Sub
3. Add an Account Rule to this account that fires SaveOriginator for all messages. Criteria such as To Contains proxy-account-address should work.

4. Add this code to EventHandlers.vbs (replacing the earlier function of the same name):

Code: Select all

Sub FixListPost(oMessage)
	oMessage.HeaderValue("Sender") = oMessage.HeaderValue("X-Originator")
	oMessage.HeaderValue("Reply-to") = oMessage.From
	oMessage.From = oMessage.HeaderValue("X-Originator")
	oMessage.Save
End Sub
5. Add or modify the Global Rule to fire this function using criteria To Contains distribution-list-alias-address.

Test and report.

@SorenR...can you review my logic?
Not quite sure that will work as "X-Envelope-From" aka "oMessage.FromAddress" usually is the account address.

@michaeljwyo

If you create a mailbox called abdx2@abdx.org and forward - deselect "Keep original message" - it to abdx2list@abdx.org (this is your distributionlist) and remember to put ...

Code: Select all

[Settings]
RewriteEnvelopeFromWhenForwarding=1
in your hmailserver.ini then the sender (MAIL FROM) of the list should be abdx2@abdx.org and "From:" in the message should be the original sender.

Perhaps !?! add the header "Sender" using a rule but I am not sure it is needed.

Hmm. Maybe I should play a bit with this tomorrow, I have a couple of servers and a GMail account so it's easy to see what is missing :mrgreen:
SørenR.

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

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-09 03:34

michaeljwyo wrote:
2021-01-09 02:46
So when they hit "reply" will it reply to "messages@abdx.org" (since that's where it came from) ?
Maybe:

Code: Select all

Sub SaveOriginator(oMessage)
	oMessage.HeaderValue("X-Originator") = oMessage.FromAddress
	oMessage.HeaderValue("X-Forwarded-To") = "list-forwarded-address"
	oMessage.Save
End Sub

Sub FixListPost(oMessage)
	oMessage.HeaderValue("Sender") = oMessage.HeaderValue("X-Originator")
	oMessage.HeaderValue("Reply-to") = oMessage.HeaderValue("X-Forwarded-To")
	oMessage.From = oMessage.HeaderValue("X-Originator")
	oMessage.Save
End Sub

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-09 05:23

This is simpler:

Code: Select all

Sub SaveOriginator(oMessage)
	oMessage.HeaderValue("X-Originator") = oMessage.FromAddress
	oMessage.Save
End Sub

Sub FixListPost(oMessage)
	oMessage.HeaderValue("Sender") = oMessage.HeaderValue("X-Originator")
	oMessage.HeaderValue("Reply-to") = oMessage.From
	oMessage.From = oMessage.HeaderValue("X-Originator")
	oMessage.Save
End Sub

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-09 05:45

Okay...some preliminary results.
Just making a forwarding account worked. Didn't adjust any scripts or anything. Didn't put in anything new. Only added the account that we would send to that automatically forwards to the list. Works good. Passes SPF perfectly. Original poster's name is there. Reply actually replies to the forwarding account and not the list. Everything we wanted.
Problems:
I had to leave the distribution list set as "public - anyone can post". If I set it to "private - only list members can post" (which is what we want) it doesn't work. Why? Well the forwarding account needs to have membership in order to be able to send to the posting list. If he has membership, then guess what? Infinite loop. Because he is a member, the message gets sent back to him and of course gets forwarded back to the list and then back to him and so forth. Like I said, if we leave the distribution list open to public, then the forwarding account can post to it without being a member. Not sure how to solve that. I wish there were a way in the distribution list to say "Okay...so this guy can post, but don't send the post back to him when he posts." That would solve that and then I could leave the distribution list as members only and put all the list members there as usual.

So if we can solve that then we're golden. Maybe a rule of some sort? Something like if the forwarding account gets an email message from the list, reject it. I don't know if individual email accounts can have their own "black list"

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-09 05:48

Ooops...spoke too soon. should have looked first. Yes, individual email accounts can have their own rules. Setting up a rule right now.

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-09 05:53

Set the list to Announcement, allow from the proxy address.

Add an Account Rule to the proxy account:

Criteria:
Use AND
From Not contains member1
From Not contains member2
etc

Action:
Delete e-mail

You'll have to maintain list membership in both places.

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-09 06:23

I sure wish we wouldn't have to do that, but I know that would work. I am still trying to solve the looping problem. I tried putting a rule in the proxy account using the custom header field. I figure a message coming back over to the proxy from the list (because the proxy has to be a member of the list in order to post there). Right now....proxy account is actually abdx@abdx.org . distro account is abdxlist@abdx.org.
So the rule says if the message has a "return-path:" of "<abdx@abdx.org>" then it needs to delete the message. So I guess maybe it does do that but AFTER it forwards it...not before. So we still get the looping. I also tried NOT using the forwarding tab and instead using another rule that says if the header field called "return-path:" does NOT contain <abdx@abdx.org> then forward it to abdxlist@abdx.org. It still loops. I am wondering if there is some other header field that I could try using...that maybe the rule doesn't like return-path.

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-09 07:00

Try:

Criteria:
X-hMailServer-Loop-Count greater then 0

Action:
Delete email

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-09 08:08

Thanks Mike. That didn't really do anything or stop the looping. It worked as far as just changing over to announce mode. In announce mode, the only one that can post is the proxy. Then it goes out to all the members. We are so close. I really wish there was some way to maintain a text file or something and a script that would check this text file every time someone sends mail to the proxy. So much easier than making 120 rules and making another rule every time we add another member. That's how many members we have.

I dunno...maybe Soren has some suggestions or something we can do with a script. I know at least if we make a rule and put a wildcard for the criteria, we can tell it to run a function. Let the function check a list and then if someone isn't on that list, then delete it otherwise forward it. I'm thinking along those lines but I don't know how to do it.

Am I really the only one using HMS to run a listserv like this? I mean, there have to be many many others. Are all of them just suffering through all the SPF failures and stuff? That's been the problem we were trying to fix for this whole thread...which using the proxy account finally DID fix. No one else has asked about this?

Anyways...hope to come up with some way to control who sends mail and who doesn't. Right now basically anyone can send mail to the list. Of course if it's spam, the spam software will grab it and it won't make the list but still we can't operate wide open like that. I am leaving it for a bit at least until we can (hopefully) come up with something.

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

Re: Gmail "be careful with this message"

Post by SorenR » 2021-01-09 13:01

michaeljwyo wrote:
2021-01-09 08:08
Thanks Mike. That didn't really do anything or stop the looping. It worked as far as just changing over to announce mode. In announce mode, the only one that can post is the proxy. Then it goes out to all the members. We are so close. I really wish there was some way to maintain a text file or something and a script that would check this text file every time someone sends mail to the proxy. So much easier than making 120 rules and making another rule every time we add another member. That's how many members we have.

I dunno...maybe Soren has some suggestions or something we can do with a script. I know at least if we make a rule and put a wildcard for the criteria, we can tell it to run a function. Let the function check a list and then if someone isn't on that list, then delete it otherwise forward it. I'm thinking along those lines but I don't know how to do it.

Am I really the only one using HMS to run a listserv like this? I mean, there have to be many many others. Are all of them just suffering through all the SPF failures and stuff? That's been the problem we were trying to fix for this whole thread...which using the proxy account finally DID fix. No one else has asked about this?

Anyways...hope to come up with some way to control who sends mail and who doesn't. Right now basically anyone can send mail to the list. Of course if it's spam, the spam software will grab it and it won't make the list but still we can't operate wide open like that. I am leaving it for a bit at least until we can (hopefully) come up with something.
Probably yes. There is a big difference in having distribution lists and being a Listserv...

Having said that ...

Palinka managed to secure one of the last versions of Brother.Gabriel's ListServ script...
https://github.com/palinkas-jo-reggelt/ ... ListServer

The superiors of Brother.Gabriel's church decided to "go Cloud" in 2015 ... Yes, I had a hard time staying on my seat reading that :mrgreen:
https://www.hmailserver.com/forum/viewt ... 54#p179754
SørenR.

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

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-09 21:08

michaeljwyo wrote:
2021-01-09 08:08
I dunno...maybe Soren has some suggestions or something we can do with a script. I know at least if we make a rule and put a wildcard for the criteria, we can tell it to run a function. Let the function check a list and then if someone isn't on that list, then delete it otherwise forward it. I'm thinking along those lines but I don't know how to do it.
All the pieces are there in the API to do. I'm thinking there is two rules. The first rule invokes a script Sub to tag the message with a custom header if the sender is a member of the list. The second rule delete the message if the header isn't present.

For the script, the pseudo-code looks like this:

1. Parse the recipient address without delimiters from the message To.
2. Parse the domain from the recipient address.
3. Get the Account object for that domain.
4. If the Account isn't forwarded, exit.
5. Get the forwarded address for the account.
6. Parse the list domain from the forwarded address.
7. Get the Domain object for the list domain.
8. Get the DistributionLists object for the list domain.
9. Get the DistributionList object by the forwarded address.
10. If the list doesn't exist exit.
11. Search the DistributionListRecipients for the message From address.
12. If the From address is a member, add the header X-Member-Of: or similar.

I'll try to look at the coding of this in coming days.

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-09 22:06

Thank you Mike. I know this has really turned into a project and a half! Throughout all of this I sure have learned a LOT about scripting and coding. But not enough to start writing. Just looking through the eventhandler script and trying to understand it all. Reminds me of when I learned BASIC some 35 years ago. Yeah I'm old. Trying to understand the commands and variables. Even messed around last night trying to figure out where it puts in the subject prefix...which I did find in one section but nothing I did made it work. So we've got that script controlling things plus the variables in the .hms files. But there are things in those files like global posters and allowed posters and the prefix....all there and have really never done anything.
Boy I tell ya, when we get this working I will need to save it.

I know listservs are going out of style these days especially with people just forming a facebook group instead. But my group has a good many "old farts". We "DX"....listen to AM radio and stuff trying to pick up distant signals and report what we find. It's a hobby. See www .abdx. org for more info. But a lot of these guys are in their 60s and 70s and prefer not to mess with Facebook. And I get it. A listserv is simple without a ton of "other things" involved. It's email. Everyone knows how to do email. As far as listservs, there's only one group out there that still does it. Groups.io . yahoogroups went away. Pretty sure GoogleGroups is not around anymore. And we don't want to use Groups.io because there are restrictions and stuff if you want a free account...like only so many users and so many messages. That's why I decided to do it on my own. But you need your own SMTP server to do it. There are no SMTP providers out there that like to handle 120 messages multiple times a day. At least not for free. There's always something and always hard to get a hold of anyone for any kind of support if any is even offered at all. Again, the reason why I wanted to do it all myself. So we're in control. I stumbled on to Hmailserver when looking for a way to run my own SMTP server. It has been a TON of work and I have learned a ton about all the external stuff that needs to go in the DNS...spf...dkim...etc etc. plus all the stuff internally we're working on. I know we are probably using HMS for something it wasn't intended to but honestly it is working and we're just about there.

Not that you needed to know, but that's my story! :)

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

Re: Gmail "be careful with this message"

Post by SorenR » 2021-01-10 02:52

As I posted earlier...

Some 11 years ago AndyP designed ListServ functionality for hMailServer.
viewtopic.php?f=20&t=15301&start=0

In 2013 Brother Gabriel-Marie, Society of Saint Prius X, made improvements to the script. Unfortunately we do not have the latest version 2.8. All @Palinka could secure was version 2.4.
viewtopic.php?f=20&t=15301&p=152599#p152599

Manual can be found here: https://listserver.dynu.net/

Code: https://github.com/palinkas-jo-reggelt/ ... master.zip

I was told later in 2015 by Brother Gabriel-Marie that his Superiors instructed him to use Office365 and "move it into the Cloud" ... :wink:
SørenR.

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

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

Re: Gmail "be careful with this message"

Post by palinka » 2021-01-10 03:18

Half the listserv functionality is the sending and receiving email bit. The other half is a web display of the list messages. That's been on my back burner list for a long time. Maybe I'll get working on that soon. I messed around with php IMAP stuff a while back and got a bare bones thing working, but it's a long way from being anything useful.

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-10 05:03

Lightly tested.

Add this to EventHandlers.vbs.

When triggered from an Account Rule, for an Account used as the forwarder for a distribution list, adds X-Member-Of-List: header with the address of the forwarded list if the sender is a member of the target list.

Make sure you change the placeholder credientials with an account with at least Server Administration level.

Code: Select all

function CleanAddress(sAddress)
  CleanAddress = Replace(Replace(sAddress, "<", ""), ">", "")
end function

function DomainFromAddress(sAddress)
	aTemp = Split(sAddress, "@")
	DomainFromAddress = aTemp(1)
end function

sub TagListMembers(oMessage)
	on error resume next
	bIsMember = false
	sMailUser = "accountname"
	sMailPass = "password"
	sProxyAddress = CleanAddress(oMessage.To)
	sPostOriginator = CleanAddress(oMessage.From)
	set oMailServer = CreateObject("hMailServer.Application")
	oMailServer.Authenticate sMailUser, sMailPass
	set oPostDomain = oMailServer.Domains.ItemByName(DomainFromAddress(sProxyAddress))
	if not IsNull(oPostDomain) then
		set oProxyAccount = oPostDomain.Accounts.ItemByAddress(sProxyAddress)
		if not IsNull(oProxyAccount) then
			if oProxyAccount.ForwardEnabled then
				sListAddress = oProxyAccount.ForwardAddress
				set oListDomain = oMailServer.Domains.ItemByName(DomainFromAddress(sListAddress))
				if not IsNull(oListDomain) then
					set oDistroList = oListDomain.DistributionLists.ItemByAddress(sListAddress)
					if not IsNull(oDistroList) then 
						for i = 0 to oDistroList.Recipients.Count - 1
							if oDistroList.Recipients(i).RecipientAddress = sPostOriginator then
								bIsMember = true
								exit for
							end if
						next
					end if
				end if
			end if
		end if
	end if
	if bIsMember then
		oMessage.HeaderValue("X-Member-Of-List") = sListAddress
		oMessage.Save
	end if
end sub

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-10 07:26

IMO, the hMailServer Distribution List feature is only appropriate for internal message distribution. That is, when it is necessary to distribute messages to multiple users hosted on the same server. The implementation appears to have been coded with that assumption. As long as all the list members are hosted on the same HMS instance, I think it will work well. When external members are added, the implementation breaks.

That said, the OP might still be able to achieve a satisfactory configuration for his use case. Time will tell.

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-10 23:31

Okay thank you guys. Sorry about the other really long post. TMI that nobody needed to know.
Thank you for coming up with something, Mike. Like I said I get lost in the scripts and variables - can you be more specific in what exactly I need to replace? smailuser and smailpass on lines 13 and 14? Is that it? Or are there more? Is there somewhere the address of the proxy account or mail account goes or something like that? What needs to go in the rule...

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-11 02:08

You need credentials from an account to use in the script. You can use the credentials from the proxy/front-end account, but make the Authorization level on the account Server. Use the mailbox address for sMailUser and the password for sMailPass.

Re-read my previous post for how to use. You need two Account rules in the proxy/front-end account.

The first rule's action invokes the TagListMembers sub. Set the criteria on that rule so that it fires for all messages. I used To contains mailbox-address in test. If configured correctly, messages passing this rule will have a new header added if they are members of the list specified as the mailbox forwarding address.

The second rule criteria is custom header X-Member-Of-List Not contains list-address; action Delete message. That way non-list members posts are distributed; they are black-holed.

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-11 07:24

Okay so I think I got everything right. The mailbox for smailuser = abdx@abdx.org and the smailpass= (the password) . And the account is indeed server level. It appears that the header is still not getting added to the message. Everytime I send a message through, I check the logging and it says :
"SMTPDeliverer - Message 2946: The message was not delivered to abdx@abdx.org. Delivery to this account was canceled by an account rule Rule name: check name, ID: 14."

The second rule is indeed titled "check name"...it's the one that checks for the x-member-of-list header and I don't think that is being put there. If it is, then the actual "list address" isn't being put there at that header. I disabled the "check name" rule...just so the message would go through. In that case I SHOULD be able to see the x-member-of-list header there, right? That is, if it was put there which it should be because I am sending from an account that is a list member. But if it was put there, then I should see it in the header when the message comes through.

Still combing through the script...I kinda understand what it's doing but I think something is missing.

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-11 07:38

I think I may have another clue - it looks like it's not even logging on to the account. All accounts will show "last login" and a time....and it doesn't show anything happening. So there is something there that's not quite right. Hope that helps

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

Re: Gmail "be careful with this message"

Post by SorenR » 2021-01-11 16:07

michaeljwyo wrote:
2021-01-11 07:38
I think I may have another clue - it looks like it's not even logging on to the account. All accounts will show "last login" and a time....and it doesn't show anything happening. So there is something there that's not quite right. Hope that helps
I would assume "logging on" and "authenticating" are two different things.
SørenR.

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

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-11 18:18

Start by commenting out the line that disables the built-in error handler, by putting an apostrophe before the line:

Code: Select all

sub TagListMembers(oMessage)
	'on error resume next
Test again and look at the logging. The logged error will have a line number relative to your entire EventHandler.vbs. Post the verbose error message and the line in the Sub referenced by line number.

My hypothesis is the problem is not in the Authenticate method call, but rather an unexpected format for one of the email addresses. I only coded to and test with the assumption that email addresses would be either bare "name@domain" or delimited "<name@domain>".

If the addresses are more complex "Display-name <name@domain>", I'll have to code a more sophisticated parser.

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-11 19:40

Improved parsing, error checking and event logging. Test and review the hmailserver_events.log if behavior is unexpected.

Code: Select all

function CleanAddress(sAddress)
  i = InStrRev(sAddress, "<")
  if i > 0 then
	sAddress = Mid(sAddress, i + 1)
	i = InStr(sAddress, ">")
	if i > 0 then
		sAddress = Mid(sAddress, 1, i - 1)
	end if
	sAddress = CleanAddress(sAddress)
  end if
  CleanAddress = lcase(sAddress)
end function

function DomainFromAddress(sAddress)
	aTemp = Split(sAddress, "@")
	if UBound(aTemp) > 0 then
		DomainFromAddress = aTemp(1)
	end if
end function

sub TagListMembers(oMessage)
	on error resume next
	bIsMember = false
	sMailUser = "account"
	sMailPass = "password"
	sProxyAddress = CleanAddress(oMessage.To)
	sPostOriginator = CleanAddress(oMessage.From)
	set oMailServer = CreateObject("hMailServer.Application")
	oMailServer.Authenticate sMailUser, sMailPass
	if Err.Number > 0 then
		EventLog.Write "TagListMembers failed to authenticate."
	else
		sProxyDomain = DomainFromAddress(sProxyAddress)
		set oPostDomain = oMailServer.Domains.ItemByName(sProxyDomain)
		if IsNull(oPostDomain) then
			EventLog.Write "Domain " & sProxyDomain & " is not a local domain."
		else 
			set oProxyAccount = oPostDomain.Accounts.ItemByAddress(sProxyAddress)
			if IsNull(oProxyAccount) then
				EventLog.Write "To address " & sProxyAddress & " is not a local account."
			else
				if oProxyAccount.ForwardEnabled then
					sListAddress = oProxyAccount.ForwardAddress
					set oListDomain = oMailServer.Domains.ItemByName(DomainFromAddress(sListAddress))
					if IsNull(oListDomain) then
						EventLog.Write "Address " & sListAddress & " is not a distribution list."
					else 
						set oDistroList = oListDomain.DistributionLists.ItemByAddress(sListAddress)
						if not IsNull(oDistroList) then 
							for i = 0 to oDistroList.Recipients.Count - 1
								sListMember = CleanAddress(oDistroList.Recipients(i).RecipientAddress)
								if sListMember = sPostOriginator then
									bIsMember = true
									exit for
								end if
							next
						end if
					end if
				end if
			end if
		end if
		if bIsMember = true then
			oMessage.HeaderValue("X-Member-Of-List") = sListAddress
			oMessage.Save
		end if
	end if
end sub

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-11 21:22

Opps...one logic error caught:

Code: Select all

function DomainFromAddress(sAddress)
	aTemp = Split(sAddress, "@")
	if UBound(aTemp) > 0 then
		DomainFromAddress = aTemp(1)
	else
		DomainFromAddress = sAddress
	end if
end function

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-12 01:34

OK, I was able to do a bit more testing with a variety of address formats. Along the way I tweeked the code slightly to provide clearer reporting of failures in the hmailserver_events.log file.

My test setup has the front-end account set for forwarding to the distro, and three rules:

1. If To contains front-end-address run sub TagListMembers.
2. If To contains front-end-address run sub FixListPost. Implement this if you want the on-behalf-of addressing in the distro msg.
3. If X-Member-Of-List not equals distro-address delete email.

Code: Select all

Sub FixListPost(oMessage)
	oMessage.From = oMessage.To
	oMessage.HeaderValue("Sender") = oMessage.FromAddress
	oMessage.Save
End Sub

function CleanAddress(sAddress)
  i = InStrRev(sAddress, "<")
  if i > 0 then
	sAddress = Mid(sAddress, i + 1)
	i = InStr(sAddress, ">")
	if i > 0 then
		sAddress = Mid(sAddress, 1, i - 1)
	end if
	sAddress = CleanAddress(sAddress)
  end if
  CleanAddress = lcase(sAddress)
end function

function DomainFromAddress(sAddress)
	aTemp = Split(sAddress, "@")
	if UBound(aTemp) > 0 then
		DomainFromAddress = aTemp(1)
	else
		DomainFromAddress = sAddress
	end if
end function

sub TagListMembers(oMessage)
	on error resume next
	bIsMember = false
	sMailUser = "account"
	sMailPass = "password"
	sProxyAddress = CleanAddress(oMessage.To)
	sPostOriginator = CleanAddress(oMessage.From)
	set oMailServer = CreateObject("hMailServer.Application")
	oMailServer.Authenticate sMailUser, sMailPass
	if Err.Number > 0 then
		EventLog.Write "TagListMembers: Failed to authenticate."
	else
		sProxyDomain = DomainFromAddress(sProxyAddress)
		set oPostDomain = oMailServer.Domains.ItemByName(sProxyDomain)
		if IsNull(oPostDomain) then
			EventLog.Write "TagListMembers: Domain " & sProxyDomain & " is not a local domain."
		else 
			set oProxyAccount = oPostDomain.Accounts.ItemByAddress(sProxyAddress)
			if IsNull(oProxyAccount) then
				EventLog.Write "TagListMembers: To address " & sProxyAddress & " is not a local account."
			else
				if oProxyAccount.ForwardEnabled then
					sListAddress = oProxyAccount.ForwardAddress
					set oListDomain = oMailServer.Domains.ItemByName(DomainFromAddress(sListAddress))
					if IsNull(oListDomain) then
						EventLog.Write "TagListMembers: Domain " & sProxyDomain & " is not a local domain."
					else 
						set oDistroList = oListDomain.DistributionLists.ItemByAddress(sListAddress)
						if IsNull(oDistroList) then 
							EventLog.Write "TagListMembers: Address " & sListAddress & " is not a distribution list."
						else
							for i = 0 to oDistroList.Recipients.Count - 1
								sListMember = CleanAddress(oDistroList.Recipients(i).RecipientAddress)
								if sListMember = sPostOriginator then
									bIsMember = true
									exit for
								end if
							next
						end if
					end if
				end if
			end if
		end if
		if bIsMember = true then
			oMessage.HeaderValue("X-Member-Of-List") = sListAddress
			oMessage.Save
		end if
	end if
end sub

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-12 05:51

Thanks again for your time, Mike. Okay so I actually got an ERROR_hmailserver log. I think that might be what we're looking for. Here's what we got upon me sending my test email:

"ERROR" 11544 "2021-01-11 08:33:58.667" "Script Error: Source: Microsoft VBScript runtime error - Error: 800A0046 - Description: Permission denied - Line: 1783 Column: 3 - Code: (null)"
"ERROR" 3276 "2021-01-11 08:35:01.057" "Script Error: Source: Microsoft VBScript runtime error - Error: 800A0046 - Description: Permission denied - Line: 1786 Column: 3 - Code: (null)"
"ERROR" 11544 "2021-01-11 08:37:05.838" "Script Error: Source: Microsoft VBScript runtime error - Error: 800A0046 - Description: Permission denied - Line: 1786 Column: 3 - Code: (null)"
"ERROR" 11544 "2021-01-11 08:37:05.869" "Severity: 3 (Medium), Code: HM5064, Source: RuleApplier::ApplyAction_Forward, Description: Could not forward message. Maximum rule loop count reached."
"ERROR" 3276 "2021-01-11 08:38:08.291" "Severity: 3 (Medium), Code: HM5064, Source: RuleApplier::ApplyAction_Forward, Description: Could not forward message. Maximum rule loop count reached."
"ERROR" 7304 "2021-01-11 20:36:59.828" "Script Error: Source: Microsoft VBScript runtime error - Error: 800A01F4 - Description: Variable is undefined: 'bIsMember' - Line: 149 Column: 1 - Code: (null)"

I don't know why it says it's undefined. Not sure what the loop count is either. Wondering if the "permission denied" has anything to do with the authentication.

Here is the logging from the regular logs:

"ERROR" 7304 "2021-01-11 20:36:59.828" "Script Error: Source: Microsoft VBScript runtime error - Error: 800A01F4 - Description: Variable is undefined: 'bIsMember' - Line: 149 Column: 1 - Code: (null)"
"APPLICATION" 7304 "2021-01-11 20:36:59.849" "SMTPDeliverer - Message 3006: The message was not delivered to abdx@abdx.org. Delivery to this account was canceled by an account rule Rule name: X-Member, ID: 16."
"APPLICATION" 7304 "2021-01-11 20:36:59.859" "SMTPDeliverer - Message 3006: Message delivery thread completed."

X-member is the 2nd rule. Right now I am not using the "fix post" sub so no rule on that one. So the second rule is the one with if NOT EQUALS in it.

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-12 06:02

Couple of things to try.

Make your password for the account complex but with only upper/lowercase letter and numbers in case the script engine treats one of the special characters as a delimiter.

Try again using the last version of the code, with the default error handler disabled (don't add the apostrophe), and test again, then post the hmailserver_events.log contents.

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-12 11:51

Hi Mike
So I tried changing the password. You were right in that yes it contained an @ symbol. Still didn't make much difference. I thought what I would try to do is disable the 2nd rule...the one that looks for the "x-member-of-list" header. That way that rule couldn't kick it out. So with only the first rule in effect...the one that actually runs the function that is supposed to tag the message with that header....it should get delivered. Which it did. I figured if the function is working then I should be able to look at the message headers and see that x-member-of-list header there. It's not. I've checked several times before and it's not there. So something in the script it just not getting in to alter the message and add that header to it.
The only thing in the logs that's any different is that same error as the last time:

"ERROR" 1732 "2021-01-12 02:41:43.586" "Script Error: Source: Microsoft VBScript runtime error - Error: 800A01F4 - Description: Variable is undefined: 'bIsMember' - Line: 149 Column: 1 - Code: (null)"

So what's that tell you?

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

Re: Gmail "be careful with this message"

Post by SorenR » 2021-01-12 17:16

michaeljwyo wrote:
2021-01-12 11:51
Hi Mike
So I tried changing the password. You were right in that yes it contained an @ symbol. Still didn't make much difference. I thought what I would try to do is disable the 2nd rule...the one that looks for the "x-member-of-list" header. That way that rule couldn't kick it out. So with only the first rule in effect...the one that actually runs the function that is supposed to tag the message with that header....it should get delivered. Which it did. I figured if the function is working then I should be able to look at the message headers and see that x-member-of-list header there. It's not. I've checked several times before and it's not there. So something in the script it just not getting in to alter the message and add that header to it.
The only thing in the logs that's any different is that same error as the last time:

"ERROR" 1732 "2021-01-12 02:41:43.586" "Script Error: Source: Microsoft VBScript runtime error - Error: 800A01F4 - Description: Variable is undefined: 'bIsMember' - Line: 149 Column: 1 - Code: (null)"

So what's that tell you?
Could you try something for me?

"testlist@abdx.org" is a distribution list requiring membership but NO authentication.

Add a test account from your domain and a GMail test account to the list
Add the code below to your EventHandlers.vbs and send a mail to "testlist@abdx.org"

It is important that this list do not match any of the lists you and Mike work on.

Code: Select all

Sub OnDeliveryStart(oMessage)

    If InStr(oMessage.To, "testlist@abdx.org") Then
        oMessage.FromAddress = "testlist@abdx.org"
        oMessage.HeaderValue("Reply-To") = Chr(34) & "TEST maillist" & Chr(34) & " <" & "testlist@abdx.org" & ">"
        oMessage.Save
    End If

End Sub
I have a test domain "acme.inc" and when I create a list on my normal domain with members from acme.inc and gmail I get SPF and DKIM error on gmail if sender is @acme.inc. "acme.inc" do not exist on the Interweb. :mrgreen:

Adding the 5 lines of code made gmail check SPF and DKIM of my "listserv domain" - not senders domain - and flag message as clean.
SørenR.

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

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-12 18:33

SorenR wrote:
2021-01-12 17:16
Could you try something for me?
I like the simplicity of this approach. While you are testing it, here's my comments on my more complex approach:
michaeljwyo wrote:
2021-01-12 11:51
"ERROR" 1732 "2021-01-12 02:41:43.586" "Script Error: Source: Microsoft VBScript runtime error - Error: 800A01F4 - Description: Variable is undefined: 'bIsMember' - Line: 149 Column: 1 - Code: (null)"
Variable is undefined error usually occurs then the script code references a variable for the first time and explicit variable declaration is enabled. In VBScript this is done with the option explicit statement. I don't have that statement in my script code, but it may be activated elsewhere. If you are comfortable, post the entire EventHandlers.vbs, with passwords redacted but no line-break changes, and I'll look over all your script code.

Also post the contents of hmailserver_events.log to show the in-line event logging output in my script. If the problem is caused by formatting of the To or From addresses, it will show up there and the parser can be adjusted to compensate.

Another point to remember. Any script changes will not be recognized until to press the Settings | Advanced | Scripts | Reload scripts button.

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

Re: Gmail "be careful with this message"

Post by SorenR » 2021-01-12 18:46

mikedibella wrote:
2021-01-12 18:33
Variable is undefined error usually occurs then the script code references a variable for the first time and explicit variable declaration is enabled. In VBScript this is done with the option explicit statement. I don't have that statement in my script code, but it may be activated elsewhere. If you are comfortable, post the entire EventHandlers.vbs, with passwords redacted but no line-break changes, and I'll look over all your script code.

Also post the contents of hmailserver_events.log to show the in-line event logging output in my script. If the problem is caused by formatting of the To or From addresses, it will show up there and the parser can be adjusted to compensate.

Another point to remember. Any script changes will not be recognized until to press the Settings | Advanced | Scripts | Reload scripts button.
Just add a "Dim bIsMember" somewhere in the code before first use. It's no big deal.
I Always Dim my variables, eat my vegetables and Set [object] = Nothing when I'm done using them. It's just a "thing" :mrgreen:
SørenR.

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

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-12 19:20

Here the code with explicit declaration and deallocation:

Code: Select all

function CleanAddress(sAddress)
	dim i
  i = InStrRev(sAddress, "<")
  if i > 0 then
	sAddress = Mid(sAddress, i + 1)
	i = InStr(sAddress, ">")
	if i > 0 then
		sAddress = Mid(sAddress, 1, i - 1)
	end if
	sAddress = CleanAddress(sAddress)
  end if
  CleanAddress = lcase(sAddress)
end function

function DomainFromAddress(sAddress)
	dim aTemp
	aTemp = Split(sAddress, "@")
	if UBound(aTemp) > 0 then
		DomainFromAddress = aTemp(1)
	else
		DomainFromAddress = sAddress
	end if
end function

sub TagListMembers(oMessage)
	dim bIsMember, sMailUser, sMailPass, sProxyAddress, sPostOriginator, sProxyDomain, sListAddress, sListMember, i
	dim oMailServer, oPostDomain, oProxyAccount, oListDomain, oDistroList
	on error resume next
	bIsMember = false
	sMailUser = "account"
	sMailPass = "password"
	sProxyAddress = CleanAddress(oMessage.To)
	sPostOriginator = CleanAddress(oMessage.From)
	set oMailServer = CreateObject("hMailServer.Application")
	oMailServer.Authenticate sMailUser, sMailPass
	if Err.Number > 0 then
		EventLog.Write "TagListMembers: Failed to authenticate."
	else
		sProxyDomain = DomainFromAddress(sProxyAddress)
		set oPostDomain = oMailServer.Domains.ItemByName(sProxyDomain)
		if IsNull(oPostDomain) then
			EventLog.Write "TagListMembers: Domain " & sProxyDomain & " is not a local domain."
		else 
			set oProxyAccount = oPostDomain.Accounts.ItemByAddress(sProxyAddress)
			if IsNull(oProxyAccount) then
				EventLog.Write "TagListMembers: To address " & sProxyAddress & " is not a local account."
			else
				if oProxyAccount.ForwardEnabled then
					sListAddress = oProxyAccount.ForwardAddress
					set oListDomain = oMailServer.Domains.ItemByName(DomainFromAddress(sListAddress))
					if IsNull(oListDomain) then
						EventLog.Write "TagListMembers: Domain " & sProxyDomain & " is not a local domain."
					else 
						set oDistroList = oListDomain.DistributionLists.ItemByAddress(sListAddress)
						if IsNull(oDistroList) then 
							EventLog.Write "TagListMembers: Address " & sListAddress & " is not a distribution list."
						else
							for i = 0 to oDistroList.Recipients.Count - 1
								sListMember = CleanAddress(oDistroList.Recipients(i).RecipientAddress)
								if sListMember = sPostOriginator then
									bIsMember = true
									exit for
								end if
							next
						end if
						set oDistroList = nothing
					end if
					set oListDomain = nothing
				end if
			end if
			set oProxyAccount	= nothing
		end if
		set oPostDomain = nothing
		if bIsMember = true then
			oMessage.HeaderValue("X-Member-Of-List") = sListAddress
			oMessage.Save
		end if
	end if
	set oMailServer = nothing
end sub

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

Re: Gmail "be careful with this message"

Post by SorenR » 2021-01-12 19:49

Well... :mrgreen:

File: ReloadScript.vbs

Code: Select all

Option Explicit

'
' ReloadScript.vbs Version 0.01 PRE-Alpha
'

Private Const ADMIN = "Administrator"
Private Const PASSWORD = "SUPER SECRET PASSWORD"

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

If Len(oApp.Settings.Scripting.CheckSyntax) = 0 Then
    If Len(oApp.Settings.Scripting.Reload) = 0 Then
        MsgBox("EventHandlers.vbs reloaded!")
    Else
        MsgBox("EventHandlers.vbs NOT reloaded!")
    End If
Else
    MsgBox("EventHandlers.vbs syntax wrong!")
End If
Add file to C:\hMailserver\Events and drag a shortcut to your desktop. Settings = run minimized.

The IP address is for DCOM, my server is headless, you can remove it or change it to "127.0.0.1" if you are using server as workstation.

oApp.Settings.Scripting.CheckSyntax does actually return the message that the Admin GUI show in a messagebox.

One could speculate adding the above to Sub OnError(iSeverity, iCode, sSource, sDescription) :mrgreen:
SørenR.

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

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-12 20:08

Soren - thank you for all YOUR help...problem no longer isn't any kind of spam flagging and so forth. We got that solved by using the proxy account to forward to the list. Works perfectly...no spam problems at all. Problem we were trying to solve here was to get it to check the distribution list members so that people NOT on that list can not post.

Mike - I think we got it...finally. I sent one message from a member account and it went through. Checked its headers and stuff and sure enough there it is. X-Member-Of-List: abdxlist@abdx.org . Sent one from my yahoo account, which is NOT a member, and it got rejected and did so because of the "x-member" rule doing what it's supposed to do.
Wow! You're a scripting pro!

That being said, one more thing I am curious about and Soren maybe you can help with this too. I and my members really miss having the subject prefix. [abdx] used to be on every message that came from the list. I remember going through trying to solve the spam problem, and I think we determined one thing causing spam was when the original message was altered. Adding the subject prefix did indeed alter the original message and boom, it got flagged. Now that we are using the proxy account, can we maybe put the prefix back, and how? I have tried using what's there in the script....something I think Soren gave me a long time ago. i don't remember how we disabled it but it's not working.

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

Re: Gmail "be careful with this message"

Post by SorenR » 2021-01-12 20:19

Probably add something like this to your code...

Code: Select all

If Not InStr(oMessage.Subject, "[list]") Then oMessage.Subject = "[list] " & oMessage.Subject
SørenR.

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

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-12 20:21

How about this:

1. Add Rule after TagListMembers, criteria To contains list-address Action run sub TagSubject:

Code: Select all

sub TagSubject(oMessage)
	sListAddress = oMessage.HeaderValue("X-Member-Of-List") 
	if sListAddress <> "" then
		oMessage.Subject = "[" & sListAddress & "] " & oMessage.Subject
		oMessage.Save
	end if
end sub
If you'd rather have an arbitrary tag, change:

Code: Select all

sListAddress = oMessage.HeaderValue("X-Member-Of-List") 
to

Code: Select all

sListAddress = "arbitrary"

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-12 21:02

Thanks guys. Mike, I tried what you said. No errors, but it just doesn't work.
Soren - I think the code you sent looks very similar to the sub that's already there:

Sub AddMLPrefixToSubjectIfMissing ( prefix, listAdress, message)
If InStr(1,LCase(message.To),LCase(listAdress),1)>0 Then
If NOT InStr(1,LCase(message.Subject),LCase(prefix),1)>0 Then
message.Subject = prefix & " " & message.Subject
message.Save()
End If
End If
End Sub

That code's always been there but I don't think it does anything. I want to say I looked at messages and it was around the 15th of December when we were trying to solve spam problems that I took off the subject prefix. I just don't remember what I did. Don't know if it's a setting in eventhandlers script, or if it's maybe over in the .hms file.

One thing I know for sure is that it grabbed the prefix from the .hms file. Both lists (I also have my testing list) have their own subject prefixes and there's only one eventhandler file. It used to work perfectly. So there's something in the eventhandlers file that isn't grabbing anymore.

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-12 21:41

michaeljwyo wrote:
2021-01-12 21:02
Mike, I tried what you said. No errors, but it just doesn't work.
Like this:
Untitled.png
Remember that after adding the new Sub to EventHandlers.vbs, you have to Reload Scripts.

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-12 21:55

Yep. That's how I have it. And nope. Still no prefix :(

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-12 22:19

Working fine here. Double check your criteria. Make sure your operator is "Contains", not "Equals", with the operand just the email@address.

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-12 22:26

Is there somewhere in the script where I actually put the subject prefix? You have brackets in quotes and list address. Should I change that?

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-12 22:44

Okay so here is a good chunk of my eventhandlers script...most of the top part where all the subs are. I got nothing. The rule still isn't working. We changed something around the 18th of december. If you look back at the thread there is a mention where I said "there used to be a prefix before the subject. We can live without it but I am curious....." Before that, for both lists it was just taking from the .hms files for whatever list and putting the prefix that's in the .hms file . All automatic. No rules no nothing. Anyways, here ya go.

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

' Sub OnClientConnect(oClient)
' End Sub

' Sub OnAcceptMessage(oClient, oMessage)
' End Sub

' Sub OnDeliveryStart(oMessage)
' End Sub

' Sub OnDeliverMessage(oMessage)
' End Sub

' Sub OnBackupFailed(sReason)
' End Sub

' Sub OnBackupCompleted()
' End Sub

' Sub OnError(iSeverity, iCode, sSource, sDescription)
' End Sub

' Sub OnDeliveryFailed(oMessage, sRecipient, sErrorMessage)
' End Sub

' Sub OnExternalAccountDownload(oMessage, sRemoteUID)
' End Sub


'--------History------------------------------------------
'ListServer Script Version 2.4 - Sunday, March 03, 2013
'See accompanying documentation at http://www.sspxusa.org/goodies/hMailSer ... manual.htm

'Original Listserver Script written by AndyP
'modifications by Peter Hyde and Brother Gabriel-Marie


'Note that if your list config contains email_subscription=false then it won't check to see whether the poster is valid.

'------------------------------------------------------------------
' Global variables and settings
'Make sure to adjust these to match your configuration
'The rest of the script should not need any adjustment
'------------------------------------------------------------------

option explicit 'this means that all variables must be defined before they can be used; this prevents silly typos

Public obApp
Public domain_buffer
Public configpaths
Public procode
Public configbuffer(2,50)
Public configbuffer_nr
Public logspath
public configfile_standard_settings
Public generalposterslist
Public general_allowed_list
Public SMTP_log_position ' internal storage file
Public msg_from
Public msg_fromaddress

Public Const RootDir = "C:\program files (x86)\hmailserver\" 'ends with backslash
Public Const ipslocalhost = "127.0.0.1#65.38.140.167" 'separated by #
Public Const user = "admin"
Public Const pw = "ppq@9791D"
Public Const using_v5 = true
Public Const serveradmin = "admin@abdx.org"
Public Const write_log_active = true
Public Const mail_configuration_active = true
Public Const apply_std_sett_lists_without_cf = true
Public Const apply_std_sett_accounts_without_cf = false
Public Const apply_standard_settings_file = "" 'if empty or not found, standards will be for all. Each address in a new line.
Public Const apply_standard_settings_file_negate = false
Public Const subject_help="help" ' Commands for subscription via email
Public Const subject_list="list"
Public Const subject_subscription="subscribe"
Public Const subject_subscription_address="subscribeaddress"
Public Const subject_subscription_list="subscribelist"
Public Const subject_unsubscription="unsubscribe"
Public Const subject_unsubscription_address="unsubscribeaddress"
Public Const subject_unsubscription_list="unsubscribelist"
Public Const delta_pos_log = 100000 ' 100000 for small installations, 1000000 for large installations
Public Const smtp_log_search_string = "SENT: 220 mail.anotherplace.org ESMTP"
public const configfileextension = ".hms" 'don't leave off the dot!

'msg_from = "ABDX" ' PeterWeb defined these two for messages sent FROM the listserver; BGM substituted the domain tokens
'msg_fromaddress = "abdx@abdx.org" ' they were left empty in original script!

'Spacers and tokens for logging
Public Const s0 = "~" 'logging base level
Public Const s1 = " " 'logging level 1
Public Const s2 = " " 'logging level 2
public const a1 = "-->" 'notice. Use this when an integral action is performed
Public Const e1 = "===ERROR===>" 'error
Public const w1 = "===WARNING=>" 'warning
Public Const d1 = "-------------------------" 'divider



'addresses who can post to ALL domains go here.
Public Const globally_allowed_list = "big_h00pla@yahoo.com#smoakrc@yahoo.com#martinfoltz@cox.net#kg4lac@yahoo.com" ' separated by #
general_allowed_list = globally_allowed_list

'file containing list of generally allowed posters for specified domain (should be in the domain's directory)
'It is okay if the file doesn't exist.
'the domain token will get replaced in the script below
generalposterslist = RootDir & "data\%domain%\domainposters.txt"

logspath = RootDir & "Logs\" 'ends with a backslash
configpaths = RootDir & "config\#" & RootDir & "config\%domain%\" ' separated by #, ending with \, %domain% will be replaced by the domain of the list
configfile_standard_settings = RootDir & "config\config.txt" 'if empty, standard settings in function get_config_string
SMTP_log_position = RootDir & "Events\smtplogposition.txt"



'------------------------------------------------------------------
' Hmailserver Eventhandlers
'------------------------------------------------------------------

sub TagSubject(oMessage)
sListAddress = oMessage.HeaderValue("X-Member-Of-List")
if sListAddress <> "" then
oMessage.Subject = "[abdx.org] " & oMessage.Subject
oMessage.Save
end if
end sub

Sub FixListPost(oMessage)
oMessage.From = oMessage.To
oMessage.HeaderValue("Sender") = oMessage.FromAddress
oMessage.Save
End Sub

function CleanAddress(sAddress)
dim i
i = InStrRev(sAddress, "<")
if i > 0 then
sAddress = Mid(sAddress, i + 1)
i = InStr(sAddress, ">")
if i > 0 then
sAddress = Mid(sAddress, 1, i - 1)
end if
sAddress = CleanAddress(sAddress)
end if
CleanAddress = lcase(sAddress)
end function

function DomainFromAddress(sAddress)
dim aTemp
aTemp = Split(sAddress, "@")
if UBound(aTemp) > 0 then
DomainFromAddress = aTemp(1)
else
DomainFromAddress = sAddress
end if
end function

sub TagListMembers(oMessage)
dim bIsMember, sMailUser, sMailPass, sProxyAddress, sPostOriginator, sProxyDomain, sListAddress, sListMember, i
dim oMailServer, oPostDomain, oProxyAccount, oListDomain, oDistroList
on error resume next
bIsMember = false
sMailUser = "abdx"
sMailPass = "ppq9791D"
sProxyAddress = CleanAddress(oMessage.To)
sPostOriginator = CleanAddress(oMessage.From)
set oMailServer = CreateObject("hMailServer.Application")
oMailServer.Authenticate sMailUser, sMailPass
if Err.Number > 0 then
EventLog.Write "TagListMembers: Failed to authenticate."
else
sProxyDomain = DomainFromAddress(sProxyAddress)
set oPostDomain = oMailServer.Domains.ItemByName(sProxyDomain)
if IsNull(oPostDomain) then
EventLog.Write "TagListMembers: Domain " & sProxyDomain & " is not a local domain."
else
set oProxyAccount = oPostDomain.Accounts.ItemByAddress(sProxyAddress)
if IsNull(oProxyAccount) then
EventLog.Write "TagListMembers: To address " & sProxyAddress & " is not a local account."
else
if oProxyAccount.ForwardEnabled then
sListAddress = oProxyAccount.ForwardAddress
set oListDomain = oMailServer.Domains.ItemByName(DomainFromAddress(sListAddress))
if IsNull(oListDomain) then
EventLog.Write "TagListMembers: Domain " & sProxyDomain & " is not a local domain."
else
set oDistroList = oListDomain.DistributionLists.ItemByAddress(sListAddress)
if IsNull(oDistroList) then
EventLog.Write "TagListMembers: Address " & sListAddress & " is not a distribution list."
else
for i = 0 to oDistroList.Recipients.Count - 1
sListMember = CleanAddress(oDistroList.Recipients(i).RecipientAddress)
if sListMember = sPostOriginator then
bIsMember = true
exit for
end if
next
end if
set oDistroList = nothing
end if
set oListDomain = nothing
end if
end if
set oProxyAccount = nothing
end if
set oPostDomain = nothing
if bIsMember = true then
oMessage.HeaderValue("X-Member-Of-List") = sListAddress
oMessage.Save
end if
end if
set oMailServer = nothing
end sub

Sub OnAcceptMessage(oClient, oMessage)

' Dim strDist : strDist = "abdx@abdx.org.tld, testing@abdx.org.tld"
' Dim i, j
' For i = 0 To oMessage.Recipients.Count-1
' j = InStr(strDist, oMessage.Recipients(i).OriginalAddress)
' If j > 0 Then
' oMessage.HeaderValue("Sender") = Mid(strDist, j, InStr(j, strDist, ",", 1) - j)
' oMessage.Save
' EventLog.Write( "Sender: " & oMessage.HeaderValue("Sender") )
' Exit For
' End If
' Next

Dim strSender : strSender = "abdx@abdx.org.TLS"
Dim i, strTo, strOriginalTo
For i = 0 To oMessage.Recipients.Count-1
If (i = 0) Then
strTo = oMessage.Recipients(i).Address
strOriginalTo = oMessage.Recipients(i).OriginalAddress
Else
strTo = strTo & ", " & oMessage.Recipients(i).Address
strOriginalTo = strOriginalTo & ", " & oMessage.Recipients(i).OriginalAddress
End If
Next
If InStr(1, strTo, strSender, 1) > 0 Then oMessage.HeaderValue("Sender") = strSender
oMessage.HeaderValue("X-Envelope-To") = strTo
oMessage.HeaderValue("X-Envelope-OriginalTo") = strOriginalTo
oMessage.HeaderValue("X-Envelope-From") = oMessage.FromAddress
oMessage.Save

End Sub

Sub AddMLPrefixToSubjectIfMissing ( prefix, listAdress, message)
If InStr(1,LCase(message.To),LCase(listAdress),1)>0 Then
If NOT InStr(1,LCase(message.Subject),LCase(prefix),1)>0 Then
message.Subject = prefix & " " & message.Subject
End If
End If
End Sub

Sub OnDeliveryStart(oMessage)
write_log (d1 & " OnDeliveryStart Event " & d1)
Set obApp = CreateObject("hMailServer.Application")
Call obApp.Authenticate(user, pw)

'write_log("Client IP: " & Client.IPAddress)
write_log (s0 & "Mail FromAddress: " & oMessage.FromAddress)
write_log (s0 & "Mail From: " & oMessage.From)
write_log (s0 & "Mail To: " & oMessage.To)
write_log (s0 & "Subject: " & oMessage.Subject)
If mail_configuration_active then
write_log (s0 & a1 & "Starting mail configuration check")
Result.Value = process_mailconfiguration (oMessage)
End If
End Sub

Sub OnDeliverMessage(oMessage)
' Check if the message is to the list
If IsMessageToList(oMessage, "abdx@abdx.org") Then
' Yes, the message is to the list, update the Reply-To header and save the changes
oMessage.HeaderValue("Reply-To") = "abdx@abdx.org"
oMessage.Save
End If
End Sub

Function IsMessageToList(oMessage, sList)
IsMessageToList = (InStr(1, oMessage.To, sList, 1) > 0 Or InStr(1, oMessage.CC, sList,1) > 0)
End Function

'Sub OnSMTPData(oClient, oMessage)
' Result.Value = Spammy(oClient, oMessage)
'End Sub





'------------------------------------------------------------------
' Check mail configuration / ListServer
'------------------------------------------------------------------


Function add_client_info(oClient, oMessage)
oMessage.HeaderValue("oclient") = oClient.IPAddress & "#" & oClient.Username & "#" & oClient.Port
write_log (s1 & "Adding oclient header: " & oClient.IPAddress & "#" & oClient.Username & "#" & oClient.Port)
oMessage.save
End Function

'PROCESS MAIL CONFIGURATION
'return 1 for failure and 0 for success
function process_mailconfiguration(oMessage)
process_mailconfiguration = 0
Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim fs
Set fs = CreateObject("scripting.filesystemobject")

Dim mailfrom
Dim mailto
Dim rgh(500)
Dim addr(500)
Dim lcl(500)
Dim cmd(500)
Dim fnd
Dim arr
Dim add_admin
Dim recipientnr
Dim ipaddr
dim usern
Dim smtprec 'smtp recipient
Dim smtprecarr 'smtp recipient array
Dim noneconfigured 'flag for whether the list is configured
Dim headerto
Dim tmpMessage
Dim msgcontent
Dim temp
Dim configfile


smtprec = ""
If oMessage.HeaderValue("oclient") <> "" then
arr = Split(oMessage.HeaderValue("oclient"),"#")
If UBound(arr) = 2 then
ipaddr = arr(0)
usern = arr(1)
smtprec = LCase(get_smtp_recipient(oMessage, ipaddr))
Else
write_log (s1 & "Cannot read oclient header in email.")
End If
Else
write_log (s1 & "No oclient header in email. Internal Mail!")
' I had to remove these lines of Peter's because they were causing an infinite loop in the message cycle. I had to kill hMailserver.exe to clear the queue.
' Here was his proposal (I am not concerned with version 4)
' write_log (" No oclient header in email. Internal Mail! Adding workaround defaults") ' workaround text PeterWeb, plus 3 lines below
' ipaddr = "127.0.0.1"
' usern = ""
' smtprec=LCase(get_smtp_recipient(oMessage, ipaddr)) ' in v5 the ipaddr isn't used in this call anyway, but maybe below...
End If

If smtprec <> "" then
mailfrom = oMessage.FromAddress
smtprecarr = Split(smtprec,"#")
noneconfigured = True
configbuffer_nr = 0

Dim k
For k = 1 To UBound(smtprecarr) + 1
addr(k) = smtprecarr(k - 1)
rgh(k) = True
cmd(k) = false
mailto = addr(k)

write_log (s1 & "Recipient: " & addr(k))

If update_config_buffer(mailto) Then
print_config_string mailto, "write"
If get_config_string(mailto, "email_subscription") = "true" Then
write_log (s1 & "Subscription via email activated.")
cmd(k) = do_emailsubscription (mailto, mailfrom, oMessage)
End If

If Not cmd(k) then
If has_client_authenticated_man(ipaddr,usern) And get_config_string(mailto, "allow_authenticated_users") = "true" Then
rgh(k) = True
Else
rgh(k) = check_recipient(mailto, mailfrom, oMessage)
End If
Else
rgh(k) = False
End If

noneconfigured = false
Else
write_log (s2 & a1 & "No config file found; Either this isn't a mailing list, or it isn't configured.")
End If
Next

If noneconfigured = false then
recipientnr = UBound(smtprecarr) + 1
Dim g
For g = 0 To oMessage.headers.count -1 ' added "- 1" PeterWeb
If oMessage.headers(g).name = "oclient" Then
oMessage.headers(g).delete
g = oMessage.headers.count + 1
End if
Next
headerto = oMessage.to
oMessage.ClearRecipients
msgcontent = msg_file_content_read(oMessage)
write_log (s1 & "Changing recipients")

dim thistodo 'fetch the todo setting from the config file
thistodo = get_config_string(mailto, "todo")

Dim i
For i = 1 To recipientnr
add_admin = False
If rgh(i) = true And cmd(k) = False Then
write_log (s1 & "Recipient " & addr(i) & " is accepted")
If is_local_list(addr(i)) then 'the recipient is the mailing list itself
write_log (s2 & "Generating new mail for " & addr(i))
Set tmpMessage = CreateObject("hMailServer.Message")
msg_file_content_write tmpMessage, msgcontent
write_log (s2 & "Copying finished.")

tmpMessage.FromAddress = addr(i)
tmpMessage.AddRecipient addr(i), addr(i)

write_log (s1 & "Adding available header and footer")
attach_header_footer tmpMessage, addr(i), mailfrom
write_log (s1 & "Modifiying message")
modify_msg tmpMessage, addr(i), mailfrom

tmpMessage.HeaderValue("To") = headerto
tmpMessage.HeaderValue("oclient") = ""
write_log (s2 & a1 & "Generation finished. Now saving to queue")
tmpMessage.Save
else
oMessage.AddRecipient addr(i), addr(i)
End If

write_notification True, mailfrom, mailto 'BGM add

ElseIf cmd(i) = True Then
write_log (s1 & "Subscription via email command " & addr(i) & " detected. Deleting recipient.")
if get_config_string(mailto, "email_subscription_admin_notification") = "true" then
add_admin = true
write_log (s2 & "Sending a copy to admin.")
end if
ElseIf thistodo = "delete" Then
write_notification False, mailfrom, mailto 'BGM add
write_log (s1 & "Recipient " & addr(i) & " has been deleted")
ElseIf thistodo = "nothing" Then
write_log (s1 & "Recipient " & addr(i) & " has todo nothing. Adding the recipient.")
oMessage.AddRecipient addr(i), addr(i)
ElseIf thistodo = "redirect" then
add_admin = true
write_log (s1 & "Recipient " & addr(i) & " has been redirected to admin")
Else
write_log (e1 & "Recipient " & addr(i) & " has not been processed. No valid command found. Script error.")
End If

check_list_setting(addr(i))

dim thisadmin 'fetch the admin setting from the config file
thisadmin = get_config_string(mailto, "admin")
thisadmin = ReplaceTokens(temp, mailto, mailfrom)
Dim n
'If admin is already in the list of recipients, don't add it again
For n = 0 to omessage.recipients.count - 1
if omessage.recipients(n).Address = thisadmin then
add_admin = false
n = omessage.recipients.count
write_log(s2 & "Admin is already a member.")
end if
next
'if admin isn't already a recipient, and the setting is true, add him to the list
If add_admin = True then
write_log (s1 & "Adding admin email address.")
oMessage.AddRecipient thisadmin, thisadmin
End If
Next

oMessage.HeaderValue("To") = headerto
If oMessage.Recipients.count = 0 Then
process_mailconfiguration = 1
End If
Else
write_log (s1 & "No recipient configured")
End If
oMessage.Subject = Replace(oMessage.Subject, get_pw(oMessage.Subject, mailto),"")
oMessage.save
End If
End function



'MODIFY THE MESSAGE HEADERS AND ATTACHMENTS
Sub modify_msg(oMessage, mailto, mailfrom)
write_log(s0 & "MODIFYING MESSAGE")
Dim temp
Dim temp1
Dim i
Dim ts
Dim del
write_log(s1 & "Removing possible pws")
oMessage.Subject = Replace(oMessage.Subject, get_pw(oMessage.Subject, mailto),"")
oMessage.Subject = Replace(oMessage.Subject, create_pw(mailto),"")

dim thisadmin 'fetch the admin setting from the config file
thisadmin = get_config_string(mailto, "admin")
thisadmin = ReplaceTokens(temp, mailto, mailfrom)

'ADD SENDER HEADER
temp = get_config_string(mailto, "addsenderheader")
temp = ReplaceTokens(temp, mailto, mailfrom) 'BGM Friday, March 01, 2013
If temp = "list" Then
oMessage.HeaderValue("Sender") = mailto
write_log (s2 & "Changing header Sender to " & mailto)
elseIf temp <> "" Then
oMessage.HeaderValue("Sender") = temp
write_log (s2 & "Changing header Sender to " & temp)
End If

'ADD REPLY-TO HEADER
temp = get_config_string(mailto, "addreplytoheader")
temp = ReplaceTokens(temp, mailto, mailfrom) 'BGM Friday, March 01, 2013
If temp = "list" Then
oMessage.HeaderValue("Reply-To") = mailto
write_log (s2 & "Changing header Reply-To to " & mailto)
elseIf temp <> "" Then
oMessage.HeaderValue("Reply-To") = temp
write_log (s2 & "Changing header Reply-To to " & temp)
elseIf Len(oMessage.HeaderValue("Reply-To")) < 3 Then
oMessage.HeaderValue("Reply-To") = mailfrom
write_log (s2 & "Changing empty header Reply-To to " & mailfrom)
'write_log (s1 & a1 & "Header Reply-To is empty")
End If

'ADD RETURN-PATH HEADER
temp = get_config_string(mailto, "addreturnpathheader")
temp = ReplaceTokens(temp, mailto, mailfrom) 'BGM Friday, March 01, 2013
If temp = "list" Then
oMessage.HeaderValue("Return-Path") = mailto
write_log (s2 & "Changing header Return-Path to " & mailto)
elseIf temp <> "" Then
oMessage.HeaderValue("Return-Path") = temp
write_log (s2 & "Changing header Return-Path to " & temp)
End If

'ADD SMTP-FROM HEADER
temp = get_config_string(mailto, "smtpmailfrom")
temp = ReplaceTokens(temp, mailto, mailfrom) 'BGM Friday, March 01, 2013
If temp = "admin" then
oMessage.FromAddress = thisadmin
write_log (s2 & "Changing mail from in smtp session to " & thisadmin)
ElseIf temp = "list" then
oMessage.FromAddress = mailto
write_log (s2 & "Changing mail from in smtp session to " & temp = "list")
ElseIf Len(temp) > 5 then
oMessage.FromAddress = temp
write_log (s2 & "Changing mail from in smtp session to " & temp)
ElseIf Len(temp1) > 5 then
oMessage.FromAddress = thisadmin
write_log (s2 & "Changing mail from in smtp session to " & thisadmin)
End If

'ADD SUBJECT PREFIX
temp = get_config_string(mailto, "subjectprefix")
temp = ReplaceTokens(temp, mailto, mailfrom)
If temp <> "" Then
oMessage.Subject = temp & oMessage.Subject
write_log (s2 & "Adding prefix to subject " & temp)
End If

'ADJUST THE ATTACHMENTS
write_log (s1 & a1 & "Checking attachments")
Dim thisext
Dim att_temp
Dim ats_temp
Dim atws_temp
dim atn_temp
att_temp = get_config_string(mailto, "allowed_attachments")
att_temp = ReplaceTokens(att_temp, mailto, mailfrom)

atn_temp = get_config_string(mailto, "disallowed_attachments")
atn_temp = ReplaceTokens(atn_temp, mailto, mailfrom)

ats_temp = get_config_string(mailto, "allowed_attachment_size") 'this must be numeric, so don't do token replacement
atws_temp = get_config_string(mailto, "allowed_attachments_total_size") 'this must be numeric, so don't do token replacement

If att_temp = "none" Then
write_log (s2 & a1 & "Removing all attachments")
oMessage.Attachments.clear
Else
ts = CLng(0)
i = oMessage.Attachments.count
write_log (s1 & "There are " & i & " attachments.")
Do While i > 0
i = i - 1
del = false
thisext = get_file_suffix(oMessage.Attachments(i).Filename)

'then see if this file is amoungst the disallowed_attachments
'Once we've removed all the disallowed ones, we can rest easy.
If InStr(1," #" & atn_temp & "#", "#" & thisext & "#") > 0 Then 'if the extension IS found, delete it
write_log (s2 & a1 & "Removing disallowed extension: " & thisext)
del = true
End If

'Are all attachments allowed?
If att_temp = "*" Or att_temp = "" Then
'don't do anything!
'Is this file amoungst the allowed_attachments? If not, delete it.
ElseIf InStr(1," #" & att_temp & "#", "#" & thisext & "#") = 0 Then
write_log(s2 & a1 & "Removing unapproved extension: " & thisext)
del = true
End If

'Now lets work on the size of the attachments.
If ats_temp = "" then
ElseIf Not IsNumeric(ats_temp) Then
write_log (e1 & "allowed_attachment_size is not numeric, cannot be converted to long")
Else
If oMessage.Attachments(i).size > CLng(Trim(ats_temp)) * CLng(1000) then
write_log (s2 & a1 & "Removing too large file: " & thisext & " Size: " & oMessage.Attachments(i).size)
del = true
End If
End If
If del Then
oMessage.Attachments(i).delete
Else
ts = ts + oMessage.Attachments(i).size
End if
loop
If atws_temp = "" then
ElseIf Not IsNumeric(atws_temp) Then
write_log (e1 & "allowed_attachments_total_size is not numeric, cannot be converted to long")
Else
If CLng(ts) > CLng(Trim(atws_temp)) * CLng(1000) then
write_log (s1 & a1 & "Total size of: " & ts & " exceeded.")
write_log (s2 & a1 & "Removing all attachments.")
oMessage.Attachments.clear
End If
End If
End If
End sub

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

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-12 22:58

michaeljwyo wrote:
2021-01-12 22:26
Is there somewhere in the script where I actually put the subject prefix? You have brackets in quotes and list address. Should I change that?
Well, I recognized that the original script sub was putting he actual distro list address there ,not the proxy address, so I changed here in the test to:

Code: Select all

sub TagSubject(oMessage)
	sListAddress = CleanAddress(oMessage.To)
	if sListAddress <> "" then
		oMessage.Subject = "[" & sListAddress & "] " & oMessage.Subject
		oMessage.Save
	end if
end sub
Remember that this sub has to be below the CleanAddress function declaration or you'll get an error.

If you just want an arbitrary value you could go with:

Code: Select all

sub TagSubject(oMessage)
	oMessage.Subject = "[subject-tag] " & oMessage.Subject
	oMessage.Save
end sub
I've been doing a lot of testing tweaking the To, From, Sender, and Reply-to addresses and I can not get Yahoo to accept a message where the To and From are the same. Maybe that a good thing because hMailServer does sent posts back out to the originator, and maybe that superfluous.

But it does cause a permanant error from Yahoo:

Code: Select all

554 5.7.9 Message not accepted for policy reasons. See https://postmaster.verizonmedia.com/error-codes
Which then causes hMailServer to generate an NDR for that post, but the NDR From address is empty ("<>"), so the Delete Non-members rule just consumes it.

Still, this shows just how tricky this has become.

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-12 23:59

Okay...it's working! :)
Two problems. You were right. I did NOT have it below the "cleanaddress" sub...it was above. So I moved it.
2nd problem - In the rule, you had said it needed to look for "To:" and criteria "list address." I changed it so it looks for the PROXY address. Now it works. I think the PROXY address is what is in the "to" field and not the list address. So anyway....the prefix is there now. Now we have to watch and make sure that we don't have spam flagging again because of it. I don't think we will since the proxy address fixed that. However if we, it's really easy to turn off the rule and just live with no prefix. Looks like we are all good for now. Thanks you guys again for all your massive help! Will open it up and let it run now and see what happens.

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Gmail "be careful with this message"

Post by mikedibella » 2021-01-13 03:58

Depending on the mail client, the X-Member-Of-List header may get copied into a reply to that post. If the member is recently removed from the list, this might allow the post to be distributed. The risk is small, but to mitigate it, I've added an additional action to the Tag List Members rule to set the header to "No". This action fires before the Run function TagListMembers action.
Untitled.png
Untitled.png (4.59 KiB) Viewed 6613 times

michaeljwyo
Normal user
Normal user
Posts: 61
Joined: 2020-02-11 19:02
Location: Evanston, WY
Contact:

Re: Gmail "be careful with this message"

Post by michaeljwyo » 2021-01-15 03:46

Thank you Mike. Good point. Probably pretty rare but worth putting in as well...especially if something turns really ugly with a member and we boot him...it'd keep them from replying to the message and "retaliating" on-list.

Post Reply