mail() - message lines <= 70 chars
mail() - message lines <= 70 chars
am 22.11.2007 17:09:47 von matthew
I'm using PHP version 4.4.3.
The manual page for PHP's mail() function (URL below) says that for the
message (IE. email body) "Each line should be separated with a LF (\n).
Lines should not be larger than 70 characters."
http://uk2.php.net/manual/en/function.mail.php
To see what happened I just sent an email using mail() with one of its
lines exactly 100 chars. It was sent perfectly by sendmail as a line of
100 chars and no newline. PHP did not seem to mind at all.
Why the limitation of <= 70 chars per line, and why does my version of PHP
not seem to care?
Thanks all.
Re: mail() - message lines <= 70 chars
am 22.11.2007 17:47:52 von John Dunlop
Matthew:
> The manual page for PHP's mail() function (URL below) says that for the
> message (IE. email body) "Each line should be separated with a LF (\n).
Should be CRLF.
http://www.apps.ietf.org/rfc/rfc2822.html#sec-2.1
> Lines should not be larger than 70 characters."
Should be 78.
http://www.apps.ietf.org/rfc/rfc2822.html#sec-2.1.1
--
Jock
Re: mail() - message lines <= 70 chars
am 22.11.2007 18:13:52 von matthew
John Dunlop emailed this:
> Matthew:
>
>> The manual page for PHP's mail() function (URL below) says that for the
>> message (IE. email body) "Each line should be separated with a LF (\n).
>
> Should be CRLF.
>
> http://www.apps.ietf.org/rfc/rfc2822.html#sec-2.1
>
>> Lines should not be larger than 70 characters."
>
> Should be 78.
>
> http://www.apps.ietf.org/rfc/rfc2822.html#sec-2.1.1
>
> --
> Jock
Thanks.
Why do the long lines of 100 chars work for me anyway?
Re: mail() - message lines <= 70 chars
am 22.11.2007 18:26:44 von luiheidsgoeroe
On Thu, 22 Nov 2007 18:13:52 +0100, Matthew wrote:
> John Dunlop emailed this:
>> Matthew:
>>> The manual page for PHP's mail() function (URL below) says that for the
>>> message (IE. email body) "Each line should be separated with a LF (\n).
>> Should be CRLF.
>> http://www.apps.ietf.org/rfc/rfc2822.html#sec-2.1
>>
>>> Lines should not be larger than 70 characters."
>> Should be 78.
>> http://www.apps.ietf.org/rfc/rfc2822.html#sec-2.1.1
>
> Why do the long lines of 100 chars work for me anyway?
1. PHP doesn't check it: you, as the programmer, should take care of it.
2. Most email clients/servers ar robust enough to handle more characters.
The fact that almost all can is still not a reason to let the number of
characters slide though.
--
Rik Wasmus
Re: mail() - message lines <= 70 chars
am 22.11.2007 18:42:31 von matthew
Rik Wasmus emailed this:
> On Thu, 22 Nov 2007 18:13:52 +0100, Matthew wrote:
>> John Dunlop emailed this:
>>> Matthew:
>>>> The manual page for PHP's mail() function (URL below) says that for the
>>>> message (IE. email body) "Each line should be separated with a LF (\n).
>>> Should be CRLF.
>>> http://www.apps.ietf.org/rfc/rfc2822.html#sec-2.1
>>>
>>>> Lines should not be larger than 70 characters."
>>> Should be 78.
>>> http://www.apps.ietf.org/rfc/rfc2822.html#sec-2.1.1
>>
>> Why do the long lines of 100 chars work for me anyway?
>
> 1. PHP doesn't check it: you, as the programmer, should take care of it.
> 2. Most email clients/servers ar robust enough to handle more
> characters. The fact that almost all can is still not a reason to let
> the number of characters slide though.
Thanks Rik. I'll just add a newline every 70 chars then.
Re: mail() - message lines <= 70 chars
am 23.11.2007 13:55:55 von Toby A Inkster
Matthew wrote:
> Thanks Rik. I'll just add a newline every 70 chars then.
PHP has a function called wordwrap() that may be useful for you.
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 17:53.]
It'll be in the Last Place You Look
http://tobyinkster.co.uk/blog/2007/11/21/no2id/
Re: mail() - message lines <= 70 chars
am 23.11.2007 14:18:16 von colin.mckinnon
On 22 Nov, 16:47, John Dunlop wrote:
> Matthew:
>
> > The manual page for PHP's mail() function (URL below) says that for the
> > message (IE. email body) "Each line should be separated with a LF (\n).
>
> Should be CRLF.
>
> http://www.apps.ietf.org/rfc/rfc2822.html#sec-2.1
>
> > Lines should not be larger than 70 characters."
>
> Should be 78.
>
> http://www.apps.ietf.org/rfc/rfc2822.html#sec-2.1.1
>
> --
> Jock
No - that's SMTP which is a specific transport mechanism for email
(actually its a whole family of protocols but lets not go there) its
up to the MUA ('mail' command on Unix or the SMTP implementation
within PHP for |MSWin) to **convert** the message to a suitable format
for the MTA, which may in turn encode the message in a different
format depending on the carrier protocol.
Perhaps historically the SMTP implementation in PHP couldn't
accomodate this.
If you sniff the SMTP connection you'll see that long lines do get
wrapped - but the original message is restored when it comes out the
MUA at the other end.
C.
Re: mail() - message lines <= 70 chars
am 24.11.2007 10:35:49 von John Dunlop
C. (http://symcbean.blogspot.com/):
> No - that's SMTP which is a specific transport mechanism for email
> (actually its a whole family of protocols but lets not go there) its
> up to the MUA ('mail' command on Unix or the SMTP implementation
> within PHP for |MSWin) to **convert** the message to a suitable format
> for the MTA, which may in turn encode the message in a different
> format depending on the carrier protocol.
Right.
> Perhaps historically the SMTP implementation in PHP couldn't
> accomodate this.
>
> If you sniff the SMTP connection you'll see that long lines do get
> wrapped - but the original message is restored when it comes out the
> MUA at the other end.
I wonder where PHP's figure 70 came from? If long lines do get
wrapped but you still recommended a limit, would you not recommend
78, in line with the transfer protocol?
On the other note, line endings seem a bit messy: \n for the message
body but \r\n for headers, whereas the transfer protocol demands \r\n
across the board. Then, I suppose, the whole business of line ending
conventions is messy.
--
Jock
Re: mail() - message lines <= 70 chars
am 24.11.2007 13:54:44 von matthew
Toby A Inkster emailed this:
> Matthew wrote:
>
>> Thanks Rik. I'll just add a newline every 70 chars then.
>
> PHP has a function called wordwrap() that may be useful for you.
Thanks Toby. I already found it looking through the string functions in
the manual for an appropriate function to use.
Cheers.
Re: mail() - message lines <= 70 chars
am 24.11.2007 14:34:21 von matthew
John Dunlop emailed this:
> C. (http://symcbean.blogspot.com/):
>
>> No - that's SMTP which is a specific transport mechanism for email
>> (actually its a whole family of protocols but lets not go there) its
>> up to the MUA ('mail' command on Unix or the SMTP implementation
>> within PHP for |MSWin) to **convert** the message to a suitable format
>> for the MTA, which may in turn encode the message in a different
>> format depending on the carrier protocol.
>
> Right.
>
>> Perhaps historically the SMTP implementation in PHP couldn't
>> accomodate this.
>>
>> If you sniff the SMTP connection you'll see that long lines do get
>> wrapped - but the original message is restored when it comes out the
>> MUA at the other end.
>
> I wonder where PHP's figure 70 came from? If long lines do get
> wrapped but you still recommended a limit, would you not recommend
> 78, in line with the transfer protocol?
>
> On the other note, line endings seem a bit messy: \n for the message
> body but \r\n for headers, whereas the transfer protocol demands \r\n
> across the board. Then, I suppose, the whole business of line ending
> conventions is messy.
It seems a strange for PHP to place an extra limitation like this on line
lengths. It's not really a problem as line wrapping at 70 chars looks
perfectly neat in all email clients I've ever used. As it happens between
70 and 75 chars are the settings I've always used when manually setting
word wrap in my email client's options.
My question was why PHP places this restriction at all. It's not even
sending the mail itself anyway, just passing the email to 'sendmail',
surely then it should simply be concerned with whatever line length
restrictions 'sendmail' imposes.
I've just looked in the sendmail manual which says it conforms to RFC 821,
this is the SMTP standard, URL - http://www.ietf.org/rfc/rfc0821.txt
The relevant bit of the RFC 821 SMTP standard says:
"Text Line - The maximum total length of a text line including the
is 1000 characters (but not counting the leading dot duplicated for
transparency)."
AFAICT SMTP does not place any further restrictions on message body line
lengths (though other fields do have text length restrictions such as the
reply line being a max. of 512 chars). I can't find any reference in the
protocol to message body lines (or any other lines) being further limited
to either 70 or 78 characters.
With that said, why is PHP concerned with further limits? Why not just let
the user enter their own newlines, the programmer add a CRLF at 998 chars
if necessary, and let the recipient's email client handle line wrapping as
per it's own settings/user options?
Any comments?
Regards, etc..
Matthew
Re: mail() - message lines <= 70 chars
am 24.11.2007 15:03:20 von luiheidsgoeroe
On Sat, 24 Nov 2007 14:34:21 +0100, Matthew wro=
te:
> John Dunlop emailed this:
>> C. (http://symcbean.blogspot.com/):
>>> No - that's SMTP which is a specific transport mechanism for email
>>> (actually its a whole family of protocols but lets not go there) its=
>>> up to the MUA ('mail' command on Unix or the SMTP implementation
>>> within PHP for |MSWin) to **convert** the message to a suitable form=
at
>>> for the MTA, which may in turn encode the message in a different
>>> format depending on the carrier protocol.
>> Right.
>>
>>> Perhaps historically the SMTP implementation in PHP couldn't
>>> accomodate this.
>>>
>>> If you sniff the SMTP connection you'll see that long lines do get
>>> wrapped - but the original message is restored when it comes out the=
>>> MUA at the other end.
>> I wonder where PHP's figure 70 came from? If long lines do get
>> wrapped but you still recommended a limit, would you not recommend
>> 78, in line with the transfer protocol?
>> On the other note, line endings seem a bit messy: \n for the message=
>> body but \r\n for headers, whereas the transfer protocol demands \r\n=
>> across the board. Then, I suppose, the whole business of line ending=
>> conventions is messy.
>
> It seems a strange for PHP to place an extra limitation like this on =
> line lengths.
PHP doesn't. PHP informs you of a limitation older clients/servers may =
have.
> It's not really a problem as line wrapping at 70 chars looks perfectly=
=
> neat in all email clients I've ever used. As it happens between 70 and=
=
> 75 chars are the settings I've always used when manually setting word =
=
> wrap in my email client's options.
>
> My question was why PHP places this restriction at all. It's not even =
=
> sending the mail itself anyway, just passing the email to 'sendmail',
Euhm, mostly passing it to sendmail. Others are possible, and under =
Windows an external SMTP server.
> surely then it should simply be concerned with whatever line length =
> restrictions 'sendmail' imposes.
>
> I've just looked in the sendmail manual which says it conforms to RFC =
=
> 821, this is the SMTP standard, URL - http://www.ietf.org/rfc/rfc0821.=
txt
>
> The relevant bit of the RFC 821 SMTP standard says:
>
> "Text Line - The maximum total length of a text line including the =
> is 1000 characters (but not counting the leading dot duplicated=
=
> for transparency)."
>
> AFAICT SMTP does not place any further restrictions on message body li=
ne =
> lengths (though other fields do have text length restrictions such as =
=
> the reply line being a max. of 512 chars). I can't find any reference =
in =
> the protocol to message body lines (or any other lines) being further =
=
> limited to either 70 or 78 characters.
RF2822 states:
'Each line of characters MUST be no more than 998 characters, and SHOULD=
=
be no more than 78 characters, excluding the CRLF'
It's the difference between MUST and SHOULD.
'The more conservative 78 character recommendation is to accommodate the=
=
many implementations of user interfaces that display these messages whic=
h =
may truncate, or disastrously wrap, the display of more than 78 characte=
rs =
per line, in spite of the fact that such implementations are =
non-conformant to the intent of this
specification (and that of [RFC2821] if they actually cause information =
to =
be lost). Again, even though this limitation is put on messages, it is =
encumbant upon implementations which display messages to handle an =
arbitrarily large number of characters in a line (certainly at least up =
to =
the 998 character limit) for the sake of robustness.'
So, there may be applications out there that can't handle long lines ver=
y =
well, they should try though. So most email applications are robust enou=
gh =
to handle longer lines, yes.
I've had buggy POP3 servers in the past (that's over no thankfully), I =
remember using Windows and telnetting to a POP3 server to check =
email/check queue-busting messages. So not a slick GUI at all, just a =
console. The wrapping is very welcome then, certainly because I can use =
a =
'TOP msg# #lines' command, where #lines are the number of lines to =
display. I'd really hate it when I just want to see the first 5 lines to=
=
check the message, and it turns out that's 5000 characters.
> With that said, why is PHP concerned with further limits?
It isn't try to send ridiculously long lines. PHP will not complain. The=
=
writers of the manual were kind enough to inform you about conventions. =
=
Afaik, it's not enforced in any way.
> Why not just let the user enter their own newlines, the programmer add=
a =
> CRLF at 998 chars if necessary, and let the recipient's email client =
> handle line wrapping as per it's own settings/user options?
For this kind of thing, we have the format=3Dflowed property =
(). Compliant readers will 'reflow'=
=
the message according to 'soft' (i.e. wrapped) and 'hard' linebreaks. Th=
is =
is especially great on usenet, as it often can and will 'reflow' quotes =
=
(check the example in the txt-file linked above). So, you can have the =
=
best of both worlds: a reasonable human readable limit of characters on =
a =
line as raw source/non-compliant readers/console reading, and a nice =
reflow of text in compliant readers with or without GUI's. All without =
resorting to long lines or HTML as mime type :)
-- =
Rik Wasmus
Re: mail() - message lines <= 70 chars
am 24.11.2007 20:17:22 von unknown
Post removed (X-No-Archive: yes)