Bad SMTP Headers? Seems to be a Template.pm bug

Hello,

I have had from a long time some errors like:
Bad RFC822 field name ’ Script And Config File’
in the RT log file. As I’ve seen in the mailing list archives, I’m not
alone.

After some debugging, it appears that the file Template.pm seems not to
be RFC822 compliant (correct me if I’m wrong) regarding the folding of
the headers.
In fact, the RFC822 (and also do so the RFC2822 that obsolets the 822)
says, in chapter 3.1.1:

 3.1.1.  LONG HEADER FIELDS

    Each header field can be viewed as a single, logical  line  of
    ASCII  characters,  comprising  a field-name and a field-body.
    For convenience, the field-body  portion  of  this  conceptual
    entity  can be split into a multiple-line representation; this
    is called "folding".  The general rule is that wherever  there
    may  be  linear-white-space  (NOT  simply  LWSP-chars), a CRLF
    immediately followed by AT LEAST one LWSP-char may instead  be
    inserted.  Thus, the single line


    can be represented as:

                JJV@BBN

Note that the RFC 2822 is a little more clear.

I made a very little change in Template.pm that corrected the problem
(tested since 2 weeks). The diff is based on Template.pm v1.2 (as per
what the file header says:

$Header: /raid/cvsroot/rt/lib/RT/Template.pm,v 1.2 2001/11/06 23:04:14

jesse Exp $).

Here is the diff:

[root@zorro RT]# diff -C 4 Template.pm.orig Template.pm
*** Template.pm.orig Wed Mar 6 11:12:35 2002
Template.pm Mon Mar 18 11:31:10 2002
*** 288,295 ****
— 288,296 ----

$self->{'MIMEObj'}->attach(Data => $body);

if ($headers) {
  • $headers =~ s/\n[ \t]//mg;
    foreach $header (split(/\n/,$headers)) {
      (my $key, my $value) = (split(/: /,$header,2));
      chomp $key;
      chomp $value;
    

So, I just remove any carriage return followed by a tab or space. This
is, from my point of view, RFC2822 compliant, which says about
unfolding:

The process of moving from this folded multiple-line representation
of a header field to its single line representation is called
"unfolding". Unfolding is accomplished by simply removing any CRLF
that is immediately followed by WSP.

Hope it helps, and sorry if I’m wrong, but I’m not an SMTP specialist…

Rafael

You might want to look at RT 2.0.12, which solved this problem
in the “right” way, by moving over to using the MIME parser
we use elsewhere, rather than the broken code that was there
before.

-jOn Mon, Mar 18, 2002 at 12:02:23PM +0100, Rafael Corvalan wrote:

Hello,

I have had from a long time some errors like:
Bad RFC822 field name ’ Script And Config File’
in the RT log file. As I’ve seen in the mailing list archives, I’m not
alone.

After some debugging, it appears that the file Template.pm seems not to
be RFC822 compliant (correct me if I’m wrong) regarding the folding of
the headers.
In fact, the RFC822 (and also do so the RFC2822 that obsolets the 822)
says, in chapter 3.1.1:

=====================================
3.1.1. LONG HEADER FIELDS

    Each header field can be viewed as a single, logical  line  of
    ASCII  characters,  comprising  a field-name and a field-body.
    For convenience, the field-body  portion  of  this  conceptual
    entity  can be split into a multiple-line representation; this
    is called "folding".  The general rule is that wherever  there
    may  be  linear-white-space  (NOT  simply  LWSP-chars), a CRLF
    immediately followed by AT LEAST one LWSP-char may instead  be
    inserted.  Thus, the single line

        To:  "Joe & J. Harvey" <ddd @Org>, JJV @ BBN

    can be represented as:

        To:  "Joe & J. Harvey" <ddd @ Org>,
                JJV@BBN

=====================================

Note that the RFC 2822 is a little more clear.

I made a very little change in Template.pm that corrected the problem
(tested since 2 weeks). The diff is based on Template.pm v1.2 (as per
what the file header says:

$Header: /raid/cvsroot/rt/lib/RT/Template.pm,v 1.2 2001/11/06 23:04:14

jesse Exp $).

Here is the diff:

[root@zorro RT]# diff -C 4 Template.pm.orig Template.pm
*** Template.pm.orig Wed Mar 6 11:12:35 2002
Template.pm Mon Mar 18 11:31:10 2002


*** 288,295 ****
— 288,296 ----

$self->{'MIMEObj'}->attach(Data => $body);

if ($headers) {
  • $headers =~ s/\n[ \t]//mg;
    foreach $header (split(/\n/,$headers)) {
      (my $key, my $value) = (split(/: /,$header,2));
      chomp $key;
      chomp $value;
    

============================

So, I just remove any carriage return followed by a tab or space. This
is, from my point of view, RFC2822 compliant, which says about
unfolding:

The process of moving from this folded multiple-line representation
of a header field to its single line representation is called
"unfolding". Unfolding is accomplished by simply removing any CRLF
that is immediately followed by WSP.

Hope it helps, and sorry if I’m wrong, but I’m not an SMTP specialist…

Rafael

http://www.bestpractical.com/products/rt – Trouble Ticketing. Free.

Has 2.0.12 been officially released? I didn’t see any announcement on this
list, so I’m just making sure.

Thanks,

John DeBerry

Thanks for the responses. Hmm. I didn’t get the announcement at all! How
odd. :slight_smile: