Post new topic Reply to topic  [ 21 posts ] 
Author Message
 Post subject: header, LF & CRLF
PostPosted: 2005-09-21 01:53 
Normal user
User avatar

Joined: 2005-06-18 15:25
Posts: 74
Location: Paris
I know this topic has been the subject of 2 other topics, but no solution were found.

The problem is that with some web apps using the PHP mail function, the mails are returned to the server with this error :

Quote:
451 See smtplf.html.">http://pobox.com/~djb/docs/smtplf.html


I use 2 of those apps : Oscommerce 2.2MS2 and Gallery 1.5.1 RC1.

After hours of search in their forum, I found a solution for OScommerce. in the page general.php replace :

Code:
function tep_convert_linefeeds($from, $to, $string) {
if ((PHP_VERSION < "4.0.5") && is_array($from)) {
return ereg_replace('(' . implode('|', $from) . ')', $to, $string);
} else {
return str_replace($from, $to, $string);
}
}


with :

Code:
function tep_convert_linefeeds($from, $to, $string) {
// if ((PHP_VERSION < "4.0.5") && is_array($from)) {
return ereg_replace('(' . implode('|', $from) . ')', $to, $string);
// } else {
// return str_replace($from, $to, $string);
// }
}


That means this replacement is needed for PHP version under 4.0.5 and higher than 4.3.11 (or around that as I tried with 4.3.11 & 4.4).

But I haven't found a solution for Gallery and I'm sure this problem happens with other web apps.

My question is :

1st) can somebody explain what this LF storie is exactly ? what LF and CRLF means ? where are those famous /n/r and why, in OScommerce, whatever we choose LF or CRLF, it doesn't work anyway (except if you made the change I wrote).

2bd) Is it possible to create a script (now that Martin has enabled this since HMS v4) that would do that :

If sender is [email protected] (the mail adress you entered in apache conf)

check mail and correct the LF stuff
send mail.

Else do nothing.

Thank You

_________________
Apache 1.3.33 PHP Version 4.4 hMailServer 4.1-B136 OS : Win XP SP2 AV : ClamAV 0.86.1


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-21 07:49 
Developer
Developer

Joined: 2003-11-21 01:09
Posts: 6303
Location: Sweden
> But I haven't found a solution for Gallery and I'm sure this
> problem happens with other web apps.

Have you asked the authors of the software? What did they say?

> 1st) can somebody explain what this LF storie is exactly ?

CR = \n, ascii 13, carrige return
LF = \r, ascii 10, line feed

2) I don't think there's a easy way to do it. You would have to parse the entire file and fix where there's a missing LF in the end of the line.

Again, this isn't an hMailServer problem as I see it. If your email client sends the character A instead of B when you send email, it should be fixed in the client. This is pretty much the same thing.
Your email client creates messages that aren't valid and then sends them. A bugs should be fixed where it is. Creating a lot of workarounds for bugs all the times just makes applications go slower and use more resources.


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-21 14:23 
Normal user
User avatar

Joined: 2005-06-18 15:25
Posts: 74
Location: Paris
Hi Martin

Thanks for that quick reply. If you want to know what it is said about this on gallery forum, I quote :

Quote:
I understand that you'd like to think that Gallery is the issue, but it's just not possible.


That help a lot. I know the bug come from Gallery and I don't say that it's HMS falt. The issue is this problem exist with several web apps so I wanted to know if we could add a script in HMS to solve it. That would be easier than searching in all php pages of those apps to find what should be recode.

So, if I understand well, when we write a mail, the end of line is code with \r\n .
This error means there is à \r or a \n missing somewhere. That can be in header or in body or both ?

What happen if I create a script that just delete all \r and \n
Would I have the same prob if there is a \\n or \r\ or just a \ where I shoul have \r\n ???


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-21 16:12 
Senior user
Senior user

Joined: 2004-09-25 22:11
Posts: 550
Location: Atlanta, GA
You should be able to write a fairly simple script that uses a regular expression to find all instances of CR or LF without their corresponding partner and replace them.

Check for a CR without a LF: "\x13[^\x10]"
Check for a LF without a CR: "[^\x13]\x10"

See this reference on using the Regex Replace in VBScript
http://msdn.microsoft.com/library/defau ... eplace.asp


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-21 16:17 
Developer
Developer

Joined: 2003-11-21 01:09
Posts: 6303
Location: Sweden
FAWTS:
Could you give me the link to the forum so that I can ask the guys what they mean?
I can't see how it could be an hMailServer error. Email clients should not send improperly formatted messages...


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-21 19:12 
Normal user
User avatar

Joined: 2005-06-18 15:25
Posts: 74
Location: Paris
Mertin : here the link : http://gallery.menalto.com/node/15163

cmurphy54, I read your article.

Thanks a lot!!!

_________________
Apache 1.3.33 PHP Version 4.4 hMailServer 4.1-B136 OS : Win XP SP2 AV : ClamAV 0.86.1


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-21 20:44 
Developer
Developer

Joined: 2003-11-21 01:09
Posts: 6303
Location: Sweden
Looked on their web page but could not find anything obvious.

If you turn on the application and smtp log, and wait for that message to occur, then send the .eml file to me at [email protected] I can check what wrong. With the .EML-file it should be fairly easy to tell exactly where the problem is.

Are you using the scripting functionality in hMailServer today?


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-21 21:51 
Normal user
User avatar

Joined: 2005-06-18 15:25
Posts: 74
Location: Paris
Yes, since yesterday to add "analyse with ClamWin, no Virus found" at the end of the mail. But I had the problem before.


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-21 22:12 
Developer
Developer

Joined: 2003-11-21 01:09
Posts: 6303
Location: Sweden
Did you open/save that file in a text editor (such as notepad) before you sent it to me?

And about your other problem, mail not being showed properly in Thunderbird, does it work properly if scripting is turned off? Can you show what your script looks like?


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-21 22:35 
Normal user
User avatar

Joined: 2005-06-18 15:25
Posts: 74
Location: Paris
here the script :

Code:
   Sub OnClientConnect(oClient)
   End Sub

   Sub OnAcceptMessage(oClient, oMessage)
   call disclaimer(oMessage)
   End Sub

   Sub OnDeliverMessage(oMessage)
   End Sub

    'in onAcceptMessage

sub disclaimer(oMessage)
dim disclaim
disclaim=false
Dim oRecipients
Set oRecipients = oMessage.Recipients

For i = 0 To oRecipients.Count - 1
   if oRecipients(i).IsLocalUser = false Then disclaim = true
next

if disclaim=true then
   oMessage.Body=oMessage.Body & vbcrlf & vbcrlf & "----------------" & vbcrlf & "Ce mail a été contrôlé par ClamWin antivirus. Aucun virus trouvé."
   if oMessage.HTMLBody <> "" then
      oMessage.HTMLBody = oMessage.HTMLBody & "<br><br>----------------<br><h4>Ce mail a été contrôlé par ClamWin antivirus. Aucun virus trouvé.</h4>"
      end if
   oMessage.Save
   end if
end sub


I don't remember if I opened it before or after I sent U the .eml file. I make a new one I don't open.

_________________
Apache 1.3.33 PHP Version 4.4 hMailServer 4.1-B136 OS : Win XP SP2 AV : ClamAV 0.86.1


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-22 02:58 
Normal user
User avatar

Joined: 2005-06-18 15:25
Posts: 74
Location: Paris
I found a script that works very well at http://www.ericphelps.com/scripting/samples/LfToCrlf/.

I tried to adapt it to HMS doing something like that :

Code:
   Sub OnClientConnect(oClient)
   End Sub

   Sub OnAcceptMessage(oClient, oMessage)
   call disclaimer(oMessage)
   End Sub

   Sub OnDeliverMessage(oMessage)
   End Sub

   

sub disclaimer(oMessage)
dim disclaim
disclaim=false
Dim oRecipients
Set oRecipients = oMessage.Recipients

For i = 0 To oRecipients.Count - 1
   if oRecipients(i).IsLocalUser = false Then disclaim = true       
next

if disclaim=true then
   oMessage = Replace(oMessage, vbLf, vbCrLf)     
   
   oMessage.Save
   end if
end sub



I tried with oMessage.body, oMessage.HTMLBody with or without "" ... But nothing worked. There is no parse error, but nothing happens too...

BTW is somebody knows vbs (I discovered it yesterday with disclaimer) and can fix this script, you should do it in 2 steps :

1st) convert all CRLF into LF
Then convert LF to CRLF.

That might look stupid, but I saw that LF is always present and there is no CR without LF so if you don't do that, U'll get CRCRLF in some places.

The header and the body must be fixed (is header oMessage.header ?) and what is this o we found a bit everywhere in those scripts ???

Thank's a lot.

FAWTS

_________________
Apache 1.3.33 PHP Version 4.4 hMailServer 4.1-B136 OS : Win XP SP2 AV : ClamAV 0.86.1


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-22 08:02 
Developer
Developer

Joined: 2003-11-21 01:09
Posts: 6303
Location: Sweden
The above code doesn't really make any sense. You can't run Replace() on oMessage. oMessage is the message object.

Besides, you can't simply replace all vbLF with vbCRLF. By doing that, you'll replace the existing CRLF with CRCRLF which also is incorrect.

I think you should do the following:
1) Disable all scripts
2) Send a message from Gallery.
3) When it fails, _do not_ open the file in any editor, just send the .eml file to me.

Also, can you tell me which address you are trying to send the message to? Then I can try the same..


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-22 14:19 
Normal user
User avatar

Joined: 2005-06-18 15:25
Posts: 74
Location: Paris
For the adresse, all except local, for the rest, it is exactly what I did or said


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-22 16:33 
Normal user
User avatar

Joined: 2005-06-18 15:25
Posts: 74
Location: Paris
Why this :

Code:
   if oMessage.HTMLBody <> "" then
   oMessage.HTMLBody = Replace(oMessage.HTMLBody, vbCrLf, vbLf)
   oMessage.HTMLBody = Replace(oMessage.HTMLBody, vbLf, vbCrLf)
   end if

   oMessage.Save


Just delete body ?

What name should I used for Body, HTMLBody and Header or Mail ???


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-22 17:06 
Developer
Developer

Joined: 2003-11-21 01:09
Posts: 6303
Location: Sweden
I'm very confused by this thread. In my last post, i asked you to temporarly disable scripting to ensure that the problem is not in any way related to your scripts. Did you do this?

And what do you mean with the last post? "Just delete body?"?


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-22 18:27 
Developer
Developer

Joined: 2003-11-21 01:09
Posts: 6303
Location: Sweden
Try to replace it with

Code:
if oMessage.HasBodyType("text/html")  then
   oMessage.HTMLBody = Replace(oMessage.HTMLBody, vbCrLf, vbLf)
   oMessage.HTMLBody = Replace(oMessage.HTMLBody, vbLf, vbCrLf)
   end if


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-22 18:48 
Normal user
User avatar

Joined: 2005-06-18 15:25
Posts: 74
Location: Paris
same prob, the body is deleted


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-22 18:52 
Developer
Developer

Joined: 2003-11-21 01:09
Posts: 6303
Location: Sweden
I tested it myself and had no problems running it.

I think it would be helpful if you could do some troubleshooting yourself... For example, remove the Replace statements and see if the body still disappear.


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-22 23:25 
Normal user
User avatar

Joined: 2005-06-18 15:25
Posts: 74
Location: Paris
When I use this :

Code:
   Sub OnClientConnect(oClient)
   End Sub

   Sub OnAcceptMessage(oClient, oMessage)
   call disclaimer(oMessage)
   End Sub

   Sub OnDeliverMessage(oMessage)
   End Sub

sub disclaimer(oMessage)
if oMessage.HasBodyType("text/html")  then
   oMessage.HTMLBody = Replace(oMessage.HTMLBody, vbCrLf, vbLf)
   oMessage.HTMLBody = Replace(oMessage.HTMLBody, vbLf, vbCrLf)
   end if
   end sub


Nothing is change and I get the 451 See smtplf.html.">http://pobox.com/~djb/docs/smtplf.html error.

When I use this :

Code:
   Sub OnClientConnect(oClient)
   End Sub

   Sub OnAcceptMessage(oClient, oMessage)
   call disclaimer(oMessage)
   End Sub

   Sub OnDeliverMessage(oMessage)
   End Sub

sub disclaimer(oMessage)
if oMessage.HasBodyType("text/html")  then
   oMessage.HTMLBody = Replace(oMessage.HTMLBody, vbCrLf, vbLf)
   oMessage.HTMLBody = Replace(oMessage.HTMLBody, vbLf, vbCrLf)
   end if
   oMessage.Save
end sub


The message is sent without problem, but the body just disapear...

_________________
Apache 1.3.33 PHP Version 4.4 hMailServer 4.1-B136 OS : Win XP SP2 AV : ClamAV 0.86.1


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-22 23:44 
Normal user
User avatar

Joined: 2005-06-18 15:25
Posts: 74
Location: Paris
Is it possible to call another script as :

Sub OnAcceptMessage(oClient, oMessage)
call script.vbs(oMessage)
End Sub

???


Top
 Profile  
 
 Post subject:
PostPosted: 2005-09-23 12:47 
Developer
Developer

Joined: 2003-11-21 01:09
Posts: 6303
Location: Sweden
This is getting a bit ridicoulus now. :)

The reason your above HTMLBody replacement does not work is probably because technically there is no HTML body on that email. As you know the email message is improperly formatted, missing LF (or if it's CR) on every line). You can't expect that hMailServer should be able to parse email messages that are invalid formatted. :\

You can't call a script that way... There's no such thing as a global parameter to a vb script (as far as I know)..

Are you using any kind of email proxy that could be the cause of this? Does it _only_ happen to the messages created by Gallery?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ] 


Who is online

Users browsing this forum: No registered users and 11 guests



Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group