Newbie help :-)

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
thierry_b
New user
New user
Posts: 19
Joined: 2021-05-12 11:00

Newbie help :-)

Post by thierry_b » 2021-05-12 12:05

Hello,
Sorry for my bad English, I'm French and I just discover hMailServer. Great soft !!

I use below script to save Attachement.
How can I find Account name of "oMessage" ? I want to save attachements relative to account names.

Thanks!

Sub SaveAttachments(oMessage)
' this routine saves file attachments that have the specified
' FileExtensions.
Dim PFolder


Dim SaveFolder 'where to store attachments. This folder must already exist.
SaveFolder = "c:\path_to_folder\" ' trailing slash is required

Dim SavedFile

Dim FileExtensions ' set to the file attachment extensions you want to save
FileExtensions = "(pdf|doc|xml|png|jpg|xls|xlsx|tif)"

Dim oAttachment
Dim oRegExp
Set oRegExp = new RegExp
For oAttachment = 0 to oMessage.Attachments.Count-1
' Test for specified attachments
with oRegExp
.Pattern = "^.*\."& FileExtensions & "$"
.IgnoreCase = True
.Global = False
end with
if (oRegExp.test(oMessage.Attachments(oAttachment).Filename)) Then Sauvegarde toutes les pièces jointes

SavedFile = SaveFolder & Left(Right(oMessage.Filename,42),38) & "." & oAttachment & "." & oMessage.Attachments(oAttachment).Filename
oMessage.Attachments(oAttachment).SaveAs(SavedFile)
' uncomment below to Delete Attachment from message
'oMessage.Attachments(oAttachment).Delete
End If
Next
Set oRegExp = nothing

End Sub

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

Re: Newbie help :-)

Post by RvdH » 2021-05-12 12:22

You probably have to loop trough all recipients and then (most likely) only save those attachments for local users, eg:

Code: Select all

For oRecipient = 0 to oMessage.Recipients.Count-1
	If oMessage.Recipients(oRecipient).IsLocalUser Then
	

	accountname = oMessage.Recipients(oRecipient).Address
	
	
	End if
Next
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

thierry_b
New user
New user
Posts: 19
Joined: 2021-05-12 11:00

Re: Newbie help :-)

Post by thierry_b » 2021-05-12 12:27

Thanks
I'll try this.

Regards
Thierry

thierry_b
New user
New user
Posts: 19
Joined: 2021-05-12 11:00

Re: Newbie help :-)

Post by thierry_b » 2021-05-12 12:47

RvdH wrote:
2021-05-12 12:22
You probably have to loop trough all recipients and then (most likely) only save those attachments for local users, eg:

Code: Select all

For oRecipient = 0 to oMessage.Recipients.Count-1
	If oMessage.Recipients(oRecipient).IsLocalUser Then
	

	accountname = oMessage.Recipients(oRecipient).Address
	
	
	End if
Next

That's TOP :-)

Question : is it possible to change Attachements name before forwarding (list forwarding) ?

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

Re: Newbie help :-)

Post by RvdH » 2021-05-12 13:43

Renaming, probably not...but i think it might be possible to save & rename the attachment, next delete the attachment and then re-attach the saved and renamed attachment
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

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

Re: Newbie help :-)

Post by SorenR » 2021-05-12 14:34

RvdH wrote:
2021-05-12 12:22
You probably have to loop trough all recipients and then (most likely) only save those attachments for local users, eg:

Code: Select all

For oRecipient = 0 to oMessage.Recipients.Count-1
	If oMessage.Recipients(oRecipient).IsLocalUser Then
	

	accountname = oMessage.Recipients(oRecipient).Address
	
	
	End if
Next
Is the account name and domain not part of the file path in oMessage.Filename ??
SørenR.

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

thierry_b
New user
New user
Posts: 19
Joined: 2021-05-12 11:00

Re: Newbie help :-)

Post by thierry_b » 2021-05-13 00:34

RvdH wrote:
2021-05-12 13:43
Renaming, probably not...but i think it might be possible to save & rename the attachment, next delete the attachment and then re-attach the saved and renamed attachment
Ok, I will try this
Thanks

Post Reply