🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
16 messages
16 total messages Started by D. Stussy Thu, 22 Sep 2011 02:26
INN's mailpost script - requested change.
#84287
Author: D. Stussy
Date: Thu, 22 Sep 2011 02:26
29 lines
2172 bytes
"A single header field line is limited to 998 bytes."

I have noted that some mail headers (which always end up being added to the
"weird_mail_hdrs" variable) exceed this limit, especially those which
relate to headers added by spam detection (e.g. a list of spam rules which
fired).  Would it be possible to modify any header added to this variable
to truncate them at 995 bytes plus elipsis ("...")?

I know that detection of the case is easy.  About line 312:

    # Random unknown header.  Prepend 'X-' if it is not already there.
    $_ = "X-$_" unless /^X-/sio ;

+   If length($_) > 998 then ....

    $weird_mail_hdrs .= "$_\n";


However, my perl skills aren't extensive enough to know the proper way to
actually perform the truncation.
It should be something like:

    $_  = left($_,995) . "...";

I thought about considering alteration of ALL headers, but decided it was
only really important for those headers which as a news article would be
prefixed with "X-".

Re: INN's mailpost script - requested change.
#84359
Author: Russ Allbery
Date: Thu, 22 Sep 2011 02:40
17 lines
1845 bytes
"D. Stussy" <spam+newsgroups@bde-arc.ampr.org> writes:

> "A single header field line is limited to 998 bytes."

> I have noted that some mail headers (which always end up being added to
> the "weird_mail_hdrs" variable) exceed this limit, especially those
> which relate to headers added by spam detection (e.g. a list of spam
> rules which fired).  Would it be possible to modify any header added to
> this variable to truncate them at 995 bytes plus elipsis ("...")?

You should really fold them rather than truncating them if possible.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

          Please post questions rather than mailing me directly.
     <http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
Re: INN's mailpost script - requested change.
#84382
Author: D. Stussy
Date: Thu, 22 Sep 2011 02:58
17 lines
2011 bytes
"Russ Allbery" <rra@stanford.edu> wrote in message
news:87vcslti2y.fsf@windlord.stanford.edu...
> "D. Stussy" <spam+newsgroups@bde-arc.ampr.org> writes:
>
> > "A single header field line is limited to 998 bytes."
>
> > I have noted that some mail headers (which always end up being added to
> > the "weird_mail_hdrs" variable) exceed this limit, especially those
> > which relate to headers added by spam detection (e.g. a list of spam
> > rules which fired).  Would it be possible to modify any header added to
> > this variable to truncate them at 995 bytes plus elipsis ("...")?
>
> You should really fold them rather than truncating them if possible.

How would folding help?  The limit is the unfolded maximum, isn't it?

Re: INN's mailpost script - requested change.
#84383
Author: Russ Allbery
Date: Thu, 22 Sep 2011 03:13
62 lines
4109 bytes
"D. Stussy" <spam+newsgroups@bde-arc.ampr.org> writes:
> "Russ Allbery" <rra@stanford.edu> wrote:

>> You should really fold them rather than truncating them if possible.

> How would folding help?  The limit is the unfolded maximum, isn't it?

No, it's only the limit on the line length.  RFC 5322:

2.1.1.  Line Length Limits

   There are two limits that this specification places on the number of
   characters in a line.  Each line of characters MUST be no more than
   998 characters, and SHOULD be no more than 78 characters, excluding
   the CRLF.

   The 998 character limit is due to limitations in many implementations
   that send, receive, or store IMF messages which simply cannot handle
   more than 998 characters on a line.  Receiving implementations would
   do well to handle an arbitrarily large number of characters in a line
   for robustness sake.  However, there are so many implementations that
   (in compliance with the transport requirements of [RFC5321]) do not
   accept messages containing more than 1000 characters including the CR
   and LF per line, it is important for implementations not to create
   such messages.

[...]

2.2.3.  Long Header Fields

   Each header field is logically a single line of characters comprising
   the field name, the colon, and the field body.  For convenience
   however, and to deal with the 998/78 character limitations per line,
   the field body portion of a header field can be split into a
   multiple-line representation; this is called "folding".  The general
   rule is that wherever this specification allows for folding white
   space (not simply WSP characters), a CRLF may be inserted before any
   WSP.

and RFC 5536:

   o  Compliant software MUST NOT generate (but MAY accept) header field
      lines of more than 998 octets.  This is the only limit on the
      length of a header field line prescribed by this standard.
      However, specific rules to the contrary may apply in particular
      cases (for example, according to [RFC2047], lines of a header
      field containing encoded words are limited to 76 octets).
      [USEAGE] includes suggested limits for convenience of display by
      user agents.

         NOTE: As stated in [RFC5322], there is NO restriction on the
         number of lines into which a header field may be split, and
         hence there is NO restriction on the total length of a header
         field (in particular it may, by suitable folding, be made to
         exceed the 998-octet restriction pertaining to a single header
         field line).

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

          Please post questions rather than mailing me directly.
     <http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
Re: INN's mailpost script - requested change.
#84386
Author: D. Stussy
Date: Thu, 22 Sep 2011 07:32
86 lines
5364 bytes
"Russ Allbery" <rra@stanford.edu> wrote in message
news:87r539tgkk.fsf@windlord.stanford.edu...
> "D. Stussy" <spam+newsgroups@bde-arc.ampr.org> writes:
> > "Russ Allbery" <rra@stanford.edu> wrote:
>
> >> You should really fold them rather than truncating them if possible.
>
> > How would folding help?  The limit is the unfolded maximum, isn't it?
>
> No, it's only the limit on the line length.  RFC 5322:
>
> 2.1.1.  Line Length Limits
>
>    There are two limits that this specification places on the number of
>    characters in a line.  Each line of characters MUST be no more than
>    998 characters, and SHOULD be no more than 78 characters, excluding
>    the CRLF.
>
>    The 998 character limit is due to limitations in many implementations
>    that send, receive, or store IMF messages which simply cannot handle
>    more than 998 characters on a line.  Receiving implementations would
>    do well to handle an arbitrarily large number of characters in a line
>    for robustness sake.  However, there are so many implementations that
>    (in compliance with the transport requirements of [RFC5321]) do not
>    accept messages containing more than 1000 characters including the CR
>    and LF per line, it is important for implementations not to create
>    such messages.
>
> [...]
>
> 2.2.3.  Long Header Fields
>
>    Each header field is logically a single line of characters comprising
>    the field name, the colon, and the field body.  For convenience
>    however, and to deal with the 998/78 character limitations per line,
>    the field body portion of a header field can be split into a
>    multiple-line representation; this is called "folding".  The general
>    rule is that wherever this specification allows for folding white
>    space (not simply WSP characters), a CRLF may be inserted before any
>    WSP.
>
> and RFC 5536:
>
>    o  Compliant software MUST NOT generate (but MAY accept) header field
>       lines of more than 998 octets.  This is the only limit on the
>       length of a header field line prescribed by this standard.
>       However, specific rules to the contrary may apply in particular
>       cases (for example, according to [RFC2047], lines of a header
>       field containing encoded words are limited to 76 octets).
>       [USEAGE] includes suggested limits for convenience of display by
>       user agents.
>
>          NOTE: As stated in [RFC5322], there is NO restriction on the
>          number of lines into which a header field may be split, and
>          hence there is NO restriction on the total length of a header
>          field (in particular it may, by suitable folding, be made to
>          exceed the 998-octet restriction pertaining to a single header
>          field line).

And I read this as indicating that header fields (including the header
name) should not be longer than 998 bytes and should be folded into
multiple lines of 78 bytes (or less), thus implying that 998 is the
UNFOLDED maximum length.

If what you are saying is that FOLDED lines may not be longer than 998
bytes, then such implies that there is NO LIMIT on the length of unfolded
header data.  However, I'm not certain that a "note" in an RFC should be
controlling (as opposed to its normal text).

Regardless, when perl is manipulating header lines in mailpost, isn't it
dealing with unfolded lines?

Cf. Line 192's comment:  # Gather up a single header with possible
continuation lines into $line.

Cf. Line 266's comment:  # 986 = 998 (maximum per RFC 5536) -
length("References: ")
- Here' we're manipulating an UNFOLDED header.  Whoever wrote that comment
also believes that 998 bytes is the unfolded limit.

Regardless, as we have unfolded all headers while reading them, there is NO
CODE which re-folds them for submission to NNRPD (when written to TMPFILE
at lines 360-366).  That's a problem when folding is necessary due to
headers exceeding the limit....

Re: INN's mailpost script - requested change.
#84388
Author: Russ Allbery
Date: Thu, 22 Sep 2011 20:35
68 lines
4223 bytes
"D. Stussy" <spam+newsgroups@bde-arc.ampr.org> writes:
> "Russ Allbery" <rra@stanford.edu> wrote:

>> and RFC 5536:

>>    o  Compliant software MUST NOT generate (but MAY accept) header field
>>       lines of more than 998 octets.  This is the only limit on the
>>       length of a header field line prescribed by this standard.
>>       However, specific rules to the contrary may apply in particular
>>       cases (for example, according to [RFC2047], lines of a header
>>       field containing encoded words are limited to 76 octets).
>>       [USEAGE] includes suggested limits for convenience of display by
>>       user agents.

>>          NOTE: As stated in [RFC5322], there is NO restriction on the
>>          number of lines into which a header field may be split, and
>>          hence there is NO restriction on the total length of a header
>>          field (in particular it may, by suitable folding, be made to
>>          exceed the 998-octet restriction pertaining to a single header
>>          field line).

> And I read this as indicating that header fields (including the header
> name) should not be longer than 998 bytes and should be folded into
> multiple lines of 78 bytes (or less), thus implying that 998 is the
> UNFOLDED maximum length.

The NOTE above says directly and explicitly not to read things that way to
be sure that people don't read the text in a way other than what was
intended.  We verified the intended meaning with the DRUMS working group
at the time.

> If what you are saying is that FOLDED lines may not be longer than 998
> bytes, then such implies that there is NO LIMIT on the length of
> unfolded header data.

Correct.

> However, I'm not certain that a "note" in an RFC should be controlling
> (as opposed to its normal text).

The NOTE is trying to explain the intent of the text.  The word "line" in
the text refers to a folded line, not the unfolded header value.

> Regardless, when perl is manipulating header lines in mailpost, isn't it
> dealing with unfolded lines?

> Cf. Line 192's comment:  # Gather up a single header with possible
> continuation lines into $line.

> Cf. Line 266's comment:  # 986 = 998 (maximum per RFC 5536) -
> length("References: ")
> - Here' we're manipulating an UNFOLDED header.  Whoever wrote that comment
> also believes that 998 bytes is the unfolded limit.

The comment seems to be buggy, indeed.

> Regardless, as we have unfolded all headers while reading them, there is
> NO CODE which re-folds them for submission to NNRPD (when written to
> TMPFILE at lines 360-366).  That's a problem when folding is necessary
> due to headers exceeding the limit....

Yes.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

          Please post questions rather than mailing me directly.
     <http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
Re: INN's mailpost script - requested change.
#84389
Author: Julien ÉLIE
Date: Thu, 22 Sep 2011 20:56
44 lines
2682 bytes
Hi Dieter,

> Regardless, when perl is manipulating header lines in mailpost, isn't it
> dealing with unfolded lines?
> 
> Cf. Line 192's comment:  # Gather up a single header with possible
> continuation lines into $line.

Please read the whole code:

180	    # Gather up a single header with possible continuation lines into $line.
181	    if (/^\s+/) {
182	        if (! $line) {
183	            $msg = "First line with leading whitespace!" ;
184	            if ($use_syslog) {
185	                syslog("err", $msg) unless -t STDERR;
186	            }
187	            die "$msg\n" ;
188	        }           
189	
190	        $line .= "\n" . $_ ;
191	        next ;
192	    }

$line is folded because of line 190.
We're just getting the whole header field value in $line, still folded.



> Regardless, as we have unfolded all headers while reading them, there is NO
> CODE which re-folds them for submission to NNRPD (when written to TMPFILE
> at lines 360-366).

No.

$line is then put in $_; then we have:
  $real_news_hdrs .= "$_\n";
and $real_news_hdrs is written to TMPFILE.

-- 
Julien ÉLIE

« Ce serait un tunnel pour aller de la Gaule en Bretagne. »
  (Astérix)
Re: INN's mailpost script - requested change.
#84390
Author: Julien ÉLIE
Date: Thu, 22 Sep 2011 20:57
34 lines
2557 bytes
Hi Russ,

>> Cf. Line 266's comment:  # 986 = 998 (maximum per RFC 5536) -
>> length("References: ")
>>
>> - Here' we're manipulating an UNFOLDED header.  Whoever wrote that comment
>> also believes that 998 bytes is the unfolded limit.

No.


> The comment seems to be buggy, indeed.

Yep, the comment should mention "RFC 5537, Section 3.4.4" instead of 
"RFC 5536".

3.4.4.  Construction of the References Header Field

    If the resulting References header field would, after unfolding,
    exceed 998 characters in length (including its field name but not the
    final CRLF), it MUST be trimmed (and otherwise MAY be trimmed).
    Trimming means removing any number of message identifiers from its
    content, except that the first message identifier and the last two
    MUST NOT be removed.


As a message-ID is less than 250 bytes, three message-IDs can be stored 
in 998 bytes.

-- 
Julien ÉLIE

« Ce serait un tunnel pour aller de la Gaule en Bretagne. »
   (Astérix)
Re: INN's mailpost script - requested change.
#84391
Author: Russ Allbery
Date: Thu, 22 Sep 2011 21:09
11 lines
1756 bytes
Julien ÉLIE <iulius@nom-de-mon-site.com.invalid> writes:

> Please read the whole code:

Ah, whoops, I should have gone and actually looked at the code.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

          Please post questions rather than mailing me directly.
     <http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
Re: INN's mailpost script - requested change.
#84392
Author: Julien ÉLIE
Date: Thu, 22 Sep 2011 21:09
32 lines
2533 bytes
Hi Dieter,

> "A single header field line is limited to 998 bytes."
>
> I have noted that some mail headers (which always end up being added to the
> "weird_mail_hdrs" variable) exceed this limit, especially those which
> relate to headers added by spam detection (e.g. a list of spam rules which
> fired).  Would it be possible to modify any header added to this variable
> to truncate them at 995 bytes plus elipsis ("...")?

Are the mail headers you are speaking about composed of lines whose 
length exceeds 998 bytes between two consecutive CRLF?
If that is the case, then these mails have an invalid syntax and I would 
have thought you would have rejected them at first sight.  :-)


> I know that detection of the case is easy.  About line 312:
>
>      # Random unknown header.  Prepend 'X-' if it is not already there.
>      $_ = "X-$_" unless /^X-/sio ;
>
> +   If length($_) > 998 then ....
>
>      $weird_mail_hdrs .= "$_\n";

Why not just remove the invalid header?  (998 bytes without seeing any CRLF)

-- 
Julien ÉLIE

« Ce serait un tunnel pour aller de la Gaule en Bretagne. »
   (Astérix)
Re: INN's mailpost script - requested change.
#84394
Author: D. Stussy
Date: Thu, 22 Sep 2011 23:29
35 lines
2523 bytes
"Julien ÉLIE" <iulius@nom-de-mon-site.com.invalid> wrote in message
news:j5g860$9qe$1@news.trigofacile.com...
> > "A single header field line is limited to 998 bytes."
> >
> > I have noted that some mail headers (which always end up being added to
the
> > "weird_mail_hdrs" variable) exceed this limit, especially those which
> > relate to headers added by spam detection (e.g. a list of spam rules
which
> > fired).  Would it be possible to modify any header added to this
variable
> > to truncate them at 995 bytes plus elipsis ("...")?
>
> Are the mail headers you are speaking about composed of lines whose
> length exceeds 998 bytes between two consecutive CRLF?
> If that is the case, then these mails have an invalid syntax and I would
> have thought you would have rejected them at first sight.  :-)
>
>
> > I know that detection of the case is easy.  About line 312:
> >
> >      # Random unknown header.  Prepend 'X-' if it is not already there.
> >      $_ = "X-$_" unless /^X-/sio ;
> >
> > +   If length($_) > 998 then ....
> >
> >      $weird_mail_hdrs .= "$_\n";
>
> Why not just remove the invalid header?  (998 bytes without seeing any
CRLF)

That could be done, but I thought that the idea was to preserve as much as
possible from the original message....

Re: INN's mailpost script - requested change.
#84406
Author: Julien ÉLIE
Date: Tue, 27 Sep 2011 22:05
41 lines
2955 bytes
Hi Dieter,

>>> I have noted that some mail headers (which always end up being
>>> added to the "weird_mail_hdrs" variable) exceed this limit,
>>> especially those which relate to headers added by spam detection
>>> (e.g. a list of spam rules which fired). Would it be possible to
>>> modify any header added to this variable to truncate them at 995
>>> bytes plus elipsis ("...")?
>>
>> Why not just remove the invalid header? (998 bytes without seeing
>> any CRLF)
>
> That could be done, but I thought that the idea was to preserve as
> much as possible from the original message....

Sure, you're right.

Couldn't we use Text::Wrap, which is a Perl core module to achieve that?
It defaults to wrap to 76 columns, after a space ("\s"), with "\n" 
(which is fine because mailpost uses mere LF "\n" too).  If a word is 
more than 76 columns, then it is wrapped at multiples of its 76th chars 
(which is probably fine, even for base64-encoded headers).

I suggest to just call the function after a header field has been filled 
into $line.
$line is something like "Header: text\n text\n text".

     $line = Text::Wrap::wrap("", "\t", $line);


Maybe we should also remove lines containing only whitespace characters 
afterwards, just to be sure the header is valid?

     $line =~ s/\n[ \t]*\n/\n/g;
     $line =~ s/\n[ \t]*$//;

-- 
Julien ÉLIE

« – Où vous croyez-vous ici ?
   – Où je me trouve, je sais. » (Astérix)
Re: INN's mailpost script - requested change.
#84405
Author: D. Stussy
Date: Tue, 27 Sep 2011 23:55
41 lines
3040 bytes
"Julien ÉLIE" <iulius@nom-de-mon-site.com.invalid> wrote in message
news:j5thbn$7j6$1@news.trigofacile.com...
> >>> I have noted that some mail headers (which always end up being
> >>> added to the "weird_mail_hdrs" variable) exceed this limit,
> >>> especially those which relate to headers added by spam detection
> >>> (e.g. a list of spam rules which fired). Would it be possible to
> >>> modify any header added to this variable to truncate them at 995
> >>> bytes plus elipsis ("...")?
> >>
> >> Why not just remove the invalid header? (998 bytes without seeing
> >> any CRLF)
> >
> > That could be done, but I thought that the idea was to preserve as
> > much as possible from the original message....
>
> Sure, you're right.
>
> Couldn't we use Text::Wrap, which is a Perl core module to achieve that?
> It defaults to wrap to 76 columns, after a space ("\s"), with "\n"
> (which is fine because mailpost uses mere LF "\n" too).  If a word is
> more than 76 columns, then it is wrapped at multiples of its 76th chars
> (which is probably fine, even for base64-encoded headers).
>
> I suggest to just call the function after a header field has been filled
> into $line.
> $line is something like "Header: text\n text\n text".
>
>      $line = Text::Wrap::wrap("", "\t", $line);

I think that's the way to go.  We could also wrap at 998.

> Maybe we should also remove lines containing only whitespace characters
> afterwards, just to be sure the header is valid?
>
>      $line =~ s/\n[ \t]*\n/\n/g;
>      $line =~ s/\n[ \t]*$//;

A completely blank line separates headers from body....  Did you mean
trailing whitespace?

Re: INN's mailpost script - requested change.
#84408
Author: Julien ÉLIE
Date: Wed, 28 Sep 2011 17:34
43 lines
2654 bytes
Hi Dieter,

>> I suggest to just call the function after a header field has been filled
>> into $line.
>> $line is something like "Header: text\n text\n text".
>>
>>       $line = Text::Wrap::wrap("", "\t", $line);
>
> I think that's the way to go.  We could also wrap at 998.

We should indeed force a wrapping at 998.
(Message-IDs can contain up to 250 bytes -- a wrap at 76 would break them.)


>> Maybe we should also remove lines containing only whitespace characters
>> afterwards, just to be sure the header is valid?
>>
>>       $line =~ s/\n[ \t]*\n/\n/g;
>>       $line =~ s/\n[ \t]*$//;
>
> A completely blank line separates headers from body....  Did you mean
> trailing whitespace?

I mean blank lines (zero or more whitespace characters) in folded header 
fields like:

Subject: Test\n
  line 2\n
     \n
  line 4

(or with "\r\n" -- mailpost uses only "\n" internally)

The third line should be removed.  (I think using Text::Wrap might 
introduce such lines, in a few edge cases.)

I do not plan on altering the body with a wrap at 998.  Just headers.

-- 
Julien ÉLIE

« – Où vous croyez-vous ici ?
   – Où je me trouve, je sais. » (Astérix)
Re: INN's mailpost script - requested change.
#84427
Author: D. Stussy
Date: Thu, 29 Sep 2011 00:00
48 lines
2892 bytes
"Julien ÉLIE" <iulius@nom-de-mon-site.com.invalid> wrote in message
news:j5vlqk$4o0$1@news.trigofacile.com...
> >> I suggest to just call the function after a header field has been
filled
> >> into $line.
> >> $line is something like "Header: text\n text\n text".
> >>
> >>       $line = Text::Wrap::wrap("", "\t", $line);
> >
> > I think that's the way to go.  We could also wrap at 998.
>
> We should indeed force a wrapping at 998.
> (Message-IDs can contain up to 250 bytes -- a wrap at 76 would break
them.)
>
>
> >> Maybe we should also remove lines containing only whitespace
characters
> >> afterwards, just to be sure the header is valid?
> >>
> >>       $line =~ s/\n[ \t]*\n/\n/g;
> >>       $line =~ s/\n[ \t]*$//;
> >
> > A completely blank line separates headers from body....  Did you mean
> > trailing whitespace?
>
> I mean blank lines (zero or more whitespace characters) in folded header
> fields like:
>
> Subject: Test\n
>   line 2\n
>      \n
>   line 4
>
> (or with "\r\n" -- mailpost uses only "\n" internally)
>
> The third line should be removed.  (I think using Text::Wrap might
> introduce such lines, in a few edge cases.)
>
> I do not plan on altering the body with a wrap at 998.  Just headers.

Careful:  I would interpret the third line as the end of the header, and
the fourth line as part of the body, unless the relevant RFCs require
back-to-back CRLFs.

I didn't think I was suggesting altering the body at all....

Re: INN's mailpost script - requested change.
#84429
Author: Russ Allbery
Date: Thu, 29 Sep 2011 00:27
13 lines
1860 bytes
"D. Stussy" <spam+newsgroups@bde-arc.ampr.org> writes:

> Careful:  I would interpret the third line as the end of the header, and
> the fourth line as part of the body, unless the relevant RFCs require
> back-to-back CRLFs.

They do.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

          Please post questions rather than mailing me directly.
     <http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads