COM Messages.ItemByDBID

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
palinka
Senior user
Senior user
Posts: 2475
Joined: 2017-09-12 17:57

COM Messages.ItemByDBID

Post by palinka » 2020-05-15 16:12

Is there a way to get to Messages.ItemByDBID without going through domain>account>imapfolders? I'm working on something where the message ID is known, but the rest is not.

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

Re: COM Messages.ItemByDBID

Post by mattg » 2020-05-16 09:35

How are you getting the message?
If from From a rule or built in event?
Or from a file in the data store?
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

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

Re: COM Messages.ItemByDBID

Post by palinka » 2020-05-16 13:27

mattg wrote:
2020-05-16 09:35
How are you getting the message?
If from From a rule or built in event?
Or from a file in the data store?
The idea behind it is some kind of bounce/ unsubscribe handling. Right now I'm working on the unsubscribe part.

The message ID gets inserted into a mailto link in a list-unsubscribe header at OnDeliveryStart. Then if the subscriber unsubscribes, the message id gets parsed from the to address to find the list so the from address can be deleted from the distribution list.

I sort of worked around the issue already by using the list name in the mailto instead of message ID. However, I stil think the exercise could be useful. I'm sure it will come in handy if it's possible.

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

Re: COM Messages.ItemByDBID

Post by palinka » 2020-05-16 14:07

Here's what I have for the insert.

Code: Select all

Sub OnDeliveryStart(oMessage)
	REM - Add List-Unsubscribe header if sending to distribution list
	Dim hMSCOM, sDomain, sDistList, sDistListRecip, IsDistList, vDomainName
	vDomainName = Split(oMessage.Recipients(0).OriginalAddress, "@")(1)

	Set hMSCOM = CreateObject("hMailServer.Application")
	Call hMSCOM.Authenticate(ADMIN, PASSWORD)
	Set sDomain = hMSCOM.Domains.ItemByName(vDomainName)
	Set sDistList = sDomain.DistributionLists.ItemByAddress(oMessage.Recipients(0).OriginalAddress)

	If oMessage.Recipients(0).OriginalAddress = sDistList.Address Then
		Dim vListName : vListName = Replace(oMessage.Recipients(0).OriginalAddress, "@", "=")
		oMessage.HeaderValue("List-Unsubscribe") = "<mailto:unsubscribe+" & oMessage.ID & "-" & vListName & "@mydomain.net>"
		oMessage.Save
	End If
End Sub
I have the address parsing and deleting from the distribution list worked out already. I prefer to use only the message ID if for no other reason than a bit more anonymity/randomness.

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

Re: COM Messages.ItemByDBID

Post by mattg » 2020-05-16 23:12

palinka wrote:
2020-05-16 13:27
The message ID gets inserted into a mailto link in a list-unsubscribe header at OnDeliveryStart. Then if the subscriber unsubscribes, the message id gets parsed from the to address to find the list so the from address can be deleted from the distribution list.
Won't the unsubscribe message come FROM that account that want's to be unsubscribed...

Otherwise someone else could unsubscribe for others by guessing original message IDs
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

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

Re: COM Messages.ItemByDBID

Post by palinka » 2020-05-16 23:31

mattg wrote:
2020-05-16 23:12
palinka wrote:
2020-05-16 13:27
The message ID gets inserted into a mailto link in a list-unsubscribe header at OnDeliveryStart. Then if the subscriber unsubscribes, the message id gets parsed from the to address to find the list so the from address can be deleted from the distribution list.
Won't the unsubscribe message come FROM that account that want's to be unsubscribed...

Otherwise someone else could unsubscribe for others by guessing original message IDs
I need a unique key of some kind. Message ID works as well as any. Could be any random string.

1) send unique identifier within list-unsubscribe mailto header plus www link also.
2) insert into body of message the www link (or mailto with instructions or something)
3) if recipient clicks link or sends unsubscribe message --> use unique identifier to find list and recipient in order to unsubscribe.

Message ID is not so important now since I discovered that hm_messages and hm_message_metadata do NOT contain the list recipient (member) address! Unbelievable! The list address is shown in column metadata_to for all list recipients.

Due to that, I guess I'll just use a random string and record it into a new database table along with the list name, recipient, etc. That can be retrieved when called by rule. I wanted to avoid setting up another database (makes sharing here just that much more complex), but it looks like there's no choice.
Last edited by palinka on 2020-05-16 23:41, edited 1 time in total.

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

Re: COM Messages.ItemByDBID

Post by palinka » 2020-05-16 23:39

One other thing. Minor but annoying. In order to see if the message recipient is a distribution list, I use this:

Code: Select all

Set hMSCOM = CreateObject("hMailServer.Application")
Call hMSCOM.Authenticate(ADMIN, PASSWORD)
Set sDomain = hMSCOM.Domains.ItemByName(vDomainName)
Set sDistList = sDomain.DistributionLists.ItemByAddress(oMessage.Recipients(0).OriginalAddress)

If oMessage.Recipients(0).OriginalAddress = sDistList.Address Then
This works fine, but throws an error when the recipient is NOT a distribution list: Subscript out of range.

I tried putting sDomain.DistributionLists.ItemByAddress(oMessage.Recipients(0).OriginalAddress) within an IF statement, but that didn't work. Is there a better way to mute these errors?

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

Re: COM Messages.ItemByDBID

Post by palinka » 2020-05-17 04:10

Well, the whole thing is up in the air. I need each message to distribution list recipients (members) to have a unique identifier but I don't believe there is a way to access individual messages from the distribution list to the distribution list MEMBERS. I can only access the message going to the distribution list from the original sender at OnDeliveryStart. I assume OnDeliverMessage is the same (haven't tried).

I guess this is why php mailing list software exists. :cry:

I can make the unsubscribe work this way (as it is above) with a mailto link in list-unsubscribe because the mailto link can contain the distribution list address and the unsubscribe from is obviously the list member. But no www unsubscribe unless I can insert a unique ID into each member's message.

Post Reply