How to check empty messages?

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
User avatar
Rainer
Normal user
Normal user
Posts: 166
Joined: 2007-06-21 13:40
Location: Zweibrücken - Germany

How to check empty messages?

Post by Rainer » 2009-07-22 13:35

Hello friends of HMS,

is the following code correct, to check and reject empty messages?

Sub OnAcceptMessage(oClient, oMessage)
....If (Len(oMessage.Body) = 0) And (oMessage.Attachments.Count = 0) Then
........MyResultMessage = "message rejecteced because empty!"
........MyResultValue = 2
....MyMessageBlocked = True
....End If
End Sub

Kind regards :D
Rainer Noa

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: How to check empty messages?

Post by ^DooM^ » 2009-07-22 14:21

Code: Select all

Sub OnAcceptMessage(oClient, oMessage)
    If (Len(oMessage.Body) <= 0) And (oMessage.Attachments.Count <= 0) Then
        Result.Message = "message rejecteced because empty!"
        Result.Value = 2
    End If
End Sub
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

User avatar
Rainer
Normal user
Normal user
Posts: 166
Joined: 2007-06-21 13:40
Location: Zweibrücken - Germany

Re: How to check empty messages?

Post by Rainer » 2009-07-22 16:10

Hello DooM, we get every day a lot of empty messages; no subject and no text in body.

Kind regards :)
Rainer Noa

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: How to check empty messages?

Post by ^DooM^ » 2009-07-22 17:28

Tweaked the script. Does it work?
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

User avatar
Rainer
Normal user
Normal user
Posts: 166
Joined: 2007-06-21 13:40
Location: Zweibrücken - Germany

Re: How to check empty messages?

Post by Rainer » 2009-07-22 17:52

Hello Doom, now I'm at Home.

My first try only with: If (Len(oMessage.Body) = 0) won't work.
Messages with body-text was rejected! :?

Tomorrow I will test it with <= 0 :P

Kind regards :shock:
Rainer Noa

DeanoX
Senior user
Senior user
Posts: 480
Joined: 2005-11-05 00:07
Location: Michigan

Re: How to check empty messages?

Post by DeanoX » 2009-07-22 18:57

Rainer,

Are you using Spamassassin?

Curious.


-Dean

User avatar
Rainer
Normal user
Normal user
Posts: 166
Joined: 2007-06-21 13:40
Location: Zweibrücken - Germany

Re: How to check empty messages?

Post by Rainer » 2009-07-23 07:32

Good Morning DeanoX, Spamassassin is not used.

Kind regards :)
Rainer Noa

User avatar
Rainer
Normal user
Normal user
Posts: 166
Joined: 2007-06-21 13:40
Location: Zweibrücken - Germany

Re: How to check empty messages?

Post by Rainer » 2009-07-23 07:39

@^DooM^ , the script won't work. Messages with content will be rejected too! :cry:

Any ideas?

Kind regards :)
Rainer Noa

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: How to check empty messages?

Post by ^DooM^ » 2009-07-23 10:21

Not without debugging.

Stick this line in and see what is contained in the vars you are checking.

EventLog.Write(oMessage.Body)
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

User avatar
Rainer
Normal user
Normal user
Posts: 166
Joined: 2007-06-21 13:40
Location: Zweibrücken - Germany

Re: How to check empty messages?

Post by Rainer » 2009-07-23 10:24

Hello ^DooM^, maby this helps:

If IsNull(oMessage.Body) Then
...
ElseIf Len(oMessage.Body) <= 0 Then
...
End If

Kind regards :)
Rainer Noa

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: How to check empty messages?

Post by ^DooM^ » 2009-07-23 10:39

I don't see how that would help. If IsNULL is the same s LEN <= 0 seeing as they would both be empty. I'm not a VB scripter though I mainly code in PHP

I would use if( empty( $oMessage->Body ) ) Like i say you will have to do some debugging, search through old posts in the scripting forum and user contributed sections. :)
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

User avatar
Rainer
Normal user
Normal user
Posts: 166
Joined: 2007-06-21 13:40
Location: Zweibrücken - Germany

Re: How to check empty messages?

Post by Rainer » 2009-07-23 10:44

Hello ^DooM^, IsNull(oMessage.Body) ist not the same like Is Len(oMessage.Body) <= 0.

Len-0 = "" (empty string)
IsNull = nothing

If you work with databases you will know this!

Kind regards :)
Rainer Noa

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: How to check empty messages?

Post by ^DooM^ » 2009-07-23 11:16

Ok "technically" they are different but in this regard they are the same and would do the same thing. And I work with MySQL all day every day ;)
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

Post Reply