How to replace 00 at Hexadecimal

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
glenluo
Normal user
Normal user
Posts: 209
Joined: 2011-07-03 12:10

How to replace 00 at Hexadecimal

Post by glenluo » 2022-01-08 14:35

I got some email with strange end as attachec pic,how to replace the 00 in Hexadecimal with vbscript?
001.jpg
002.jpg

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

Re: How to replace 00 at Hexadecimal

Post by SorenR » 2022-01-08 15:45

https://social.msdn.microsoft.com/Forum ... vblanguage

Code: Select all

strTemp = Replace(strTemp, &H00, "")
SørenR.

There are only two difficult problems in computer science: naming things, cache invalidation and off-by-one errors.

glenluo
Normal user
Normal user
Posts: 209
Joined: 2011-07-03 12:10

Re: How to replace 00 at Hexadecimal

Post by glenluo » 2022-01-08 16:38

Thanks so much,SorenR!!

I make it working as below script,as only one compay's emails have such issue to me:

Sub OnAcceptMessage(oClient, oMessage)

If instr(oMessage.FromAddress,"@XXXXX")>0 Then
oMessage.Body = Replace(oMessage.Body,&H00,"")
oMessage.Save
End If

End Sub

glenluo
Normal user
Normal user
Posts: 209
Joined: 2011-07-03 12:10

Re: How to replace 00 at Hexadecimal

Post by glenluo » 2022-01-13 11:08

Still have some other problem,some normal emails body will be empty.

Content-Type: text/html;charset=UTF-8
Content-Transfer-Encoding: quoted-printable

glenluo
Normal user
Normal user
Posts: 209
Joined: 2011-07-03 12:10

Re: How to replace 00 at Hexadecimal

Post by glenluo » 2022-01-13 12:04

oMessage.Body change to be oMessage.HTMLBody,then all works fine at the moment

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

Re: How to replace 00 at Hexadecimal

Post by palinka » 2022-01-13 14:17

Maybe something like this?

Code: Select all

Sub OnAcceptMessage(oClient, oMessage)
	If instr(oMessage.FromAddress,"@XXXXX")>0 Then
		If oMessage.Body = Empty Then
			oMessage.HTMLBody = Replace(oMessage.Body,&H00,"")
		Else
			oMessage.Body = Replace(oMessage.Body,&H00,"")
		End If
		oMessage.Save
	End If
End Sub

glenluo
Normal user
Normal user
Posts: 209
Joined: 2011-07-03 12:10

Re: How to replace 00 at Hexadecimal

Post by glenluo » 2022-01-13 15:22

I mean some email that is not base64 encoding,if used oMessage.Body,then the body will be cleared and to be empty,need to use oMessage.HTMLBody,then it show correctly show the body content.

glenluo
Normal user
Normal user
Posts: 209
Joined: 2011-07-03 12:10

Re: How to replace 00 at Hexadecimal

Post by glenluo » 2022-01-13 15:32

@palinka
Your script is good,i use eventlog to check,the oMessage.Body is really empty.

glenluo
Normal user
Normal user
Posts: 209
Joined: 2011-07-03 12:10

Re: How to replace 00 at Hexadecimal

Post by glenluo » 2022-01-13 15:43

Final version:

Sub OnAcceptMessage(oClient, oMessage)
If instr(oMessage.FromAddress,"@XXXXX")>0 Then
If oMessage.Body = Empty Then
oMessage.HTMLBody = Replace(oMessage.HTMLBody,&H00,"")
Else
oMessage.Body = Replace(oMessage.Body,&H00,"")
End If
oMessage.Save
End If
End Sub

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

Re: How to replace 00 at Hexadecimal

Post by palinka » 2022-01-13 17:52

glenluo wrote:
2022-01-13 15:43
Final version:

Sub OnAcceptMessage(oClient, oMessage)
If instr(oMessage.FromAddress,"@XXXXX")>0 Then
If oMessage.Body = Empty Then
oMessage.HTMLBody = Replace(oMessage.HTMLBody,&H00,"")
Else
oMessage.Body = Replace(oMessage.Body,&H00,"")
End If
oMessage.Save
End If
End Sub
:oops:

I did say *something* like that. :lol:

Post Reply