Problem with obAttachment name

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Problem with obAttachment name

Post by GlenC » 2006-01-12 23:26

I'm using this in a script,

Code: Select all

		For s = 0 to oMessage.Attachments.Count -1
			Set obAttachment = oMessage.Attachments(s)
			mailfile = obAttachment.FileName
However, it appears to choke on certain attachments. The attachments are messages and usally take on the name from the subject of the message (I believe). Anyway, it is choking on this one in particular. It shows in TBird like this:

Code: Select all

Invitación
but looking at the source, it is actually this:

Code: Select all

=?iso-8859-1?Q?Invitaci=F3n?=
Is there any way around this? I have verified that the script runs with a normal subject line. It appears to me that hMail aborts the script before I even get a chance to strip out illegal characters.

User avatar
martin
Developer
Developer
Posts: 6834
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2006-01-13 00:28

Hmm. When you say choke, does that mean that the script stops executing?
Is there an error message in the hMailServer error log when it happens?

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-13 00:45

Strangley enough, it appears to skip right over the For loop. I thought it was aborting but there is no error in the log, the script seems to pick up after the For loop where I have a final "Result.Value=1" statement, and that gets logged, that the message was deleted.

I can tell the For loop is skipped because I setup a MsgBox test in there and the MsgBox is never activated.

It appears a I can duplicate it with similar messages 100% of the time.

User avatar
martin
Developer
Developer
Posts: 6834
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2006-01-13 00:58

Have to go to bed now, but I'll see if I can reproduce it myself in the weekend..

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-13 01:07

ok, let me know if you need the script or the message. Thanks!

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-14 18:06

I did a little more testing. Apparently it all boils down to having a valid filename. In addition to the illegal characters which apparently trip it up, subject lines which are too long will trip it up also. Remembering that the filename appears to be created from the subject line, which can contain just about anything, here is what I get in my testing:
  • Subject < 50 chars = ok
    Subject contains 52-55 chars = obAttachment.FileName returns a blank filename
    Subject contains > 55 chars = hmail will skip the for loop
I can't explain the difference between 52-55 and > 56... seems strange. At any rate I thought 256 chars was a valid filename so my theory might be off a little here.

User avatar
martin
Developer
Developer
Posts: 6834
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2006-01-15 12:45

Hi.

I've tested this now but I'm afraid i don't get the error. I've tested both to send email using Outlook Express and Thunderbird.

I created a new message and attached Notepad.exe. Then I set the subject to Invitación. The hMailServer script properly showed that the attachment name was notepad. I then created a new message, set the subject to InvitaciónInvitaciónInvitaciónInvitaciónInvitaciónInvitación. Still, the script showed the attachment name correctly.

The script I used looked like this:

Code: Select all

   Sub OnDeliverMessage(oMessage)
	For s = 0 to oMessage.Attachments.Count -1
         Set obAttachment = oMessage.Attachments(s)
         mailfile = obAttachment.FileName

	 msgbox mailfile
	next
   End Sub
(To be able to use MsgBox, you need to enable Allow desktop interaction in the service settings).

Is it possible for you to give me a hint? Perhaps an .eml file where you get the problem?
Have you created the messages yourself using Thunderbird?

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-15 13:43

Yeah, I keep that "interaction" setting enabled when I'm debugging, it helps me out a lot since I'm prone to typing errors :)

I will send you an email with 4 attachments (emails) that illustrate the four. One is an actual spam (Invitación) the other 3 with a subject line of 50, 52 and 60 chars. What I had to do was send myself the email, and then attach the received email to another email which (by virtue of the recipient) triggers the code above. Ill attach the eventhandlers file also (hopefully it's readable code to you :) )

CraigHarris
Senior user
Senior user
Posts: 886
Joined: 2005-11-28 11:43

Post by CraigHarris » 2006-01-15 13:52

Ah, so the problem gets triggered when the subject string you refer to is the name of an attachment? - hence it worked with martin's dll

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-15 13:58

That's what appears to be happening.

User avatar
martin
Developer
Developer
Posts: 6834
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2006-01-15 14:23

Thanks Glen. I've received the files and will run them in debug. I agree with you that something looks strange. Have to do some more testing though.

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-15 14:30

ok, Thanks Martin... I'll be out for a few hours today so if you need testing I'll have to do it later tonight. (9:30am here now).

User avatar
martin
Developer
Developer
Posts: 6834
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2006-01-15 14:34

I think I'll be able to sort it out from here, but thanks anyway!

User avatar
martin
Developer
Developer
Posts: 6834
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2006-01-15 18:21

Hi again,

Could you try this build and tell me whether it solves the problem for you?

http://dev.hmailserver.com/hMailServer- ... ld-189.exe

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-15 23:27

My initial tests show it's working perfectly. I'll stress it out a little more tomorrow but I don't anticiapate any problems. Excellent work!

Is the limit for the filename 256 chars now?

Post Reply