<<< Date Index >>>     <<< Thread Index >>>

[BUG/PATCH] MIME header parsing lenience



I've attached two message/rfc822 messages. The second is an exact copy
of the first, except that the second one contains an extra newline in
the message/rfc822 part, between the MIME header and the RFC822 message.
When mutt expands the attachment list for this message, the tree is
stunted; mutt does not parse into or beyond the inner rfc822 message. It
does for the first copy, without the extra newline.

The message is an inlined, rfc822-encapsulated forwarding of another
message with two attachments. Mutt should show this:
  I     1 <no description>                   [text/plain, 7bit, us-ascii, 0.3K] 
  I     2 inner rfc822                             [message/rfc822, 7bit, 2.6K]
  I     3 `-><no description>                       [multipa/mixed, 7bit, 0.6K]
  I     4   |-><no description>              [text/plain, 7bit, us-ascii, 0.2K]
  A     5   |->hostname.eri0                 [text/plain, 7bit, us-ascii, 0.1K]
  A     6   `->nodename                      [text/plain, 7bit, us-ascii, 0.1K]

The first message displays correctly. But on the second message, it
instead shows:
  I     1 <no description>                   [text/plain, 7bit, us-ascii, 0.3K] 
  I     2 <no description>                         [message/rfc822, 7bit, 2.6K]
  I     3 `-><no description>                [text/plain, 7bit, us-ascii, 2.6K]


Reading over RFC 1521, it's clear that the intention was for there to
be only one newline between the MIME header and the message/rfc822 data
(or between any other MIME header and body, for that matter). But it's
not clear that an implementation should not permit multiple blank lines
here. And this seems to be a common-enough occurrence: I see this
phenomenon in bounce replies from AOL, for instance.

I've attached a simple patch to make mutt a little more lenient in this
respect, but I'm not certain how much else this would affect. Thoughts?

If you look at the present list posting in the attachment view
currently, you will see this:
  I     1 <no description>                   [text/plain, 7bit, us-ascii, 1.9K]
  I     2 outer rfc822                             [message/rfc822, 7bit, 5.0K]
  I     3 `-><no description>                       [multipa/mixed, 7bit, 3.0K]
  I     4   |-><no description>              [text/plain, 7bit, us-ascii, 0.3K]
  I     5   `->inner rfc822                        [message/rfc822, 7bit, 2.6K]
  I     6     `-><no description>                   [multipa/mixed, 7bit, 0.6K]
  I     7       |-><no description>          [text/plain, 7bit, us-ascii, 0.2K]
  A     8       |->hostname.eri0             [text/plain, 7bit, us-ascii, 0.1K]
  A     9       `->nodename                  [text/plain, 7bit, us-ascii, 0.1K]
  I    10 outer rfc822                             [message/rfc822, 7bit, 5.0K]
  I    11 `-><no description>                       [multipa/mixed, 7bit, 3.0K]
  I    12   |-><no description>              [text/plain, 7bit, us-ascii, 0.3K]
  I    13   `-><no description>                    [message/rfc822, 7bit, 2.6K]
  I    14     `-><no description>            [text/plain, 7bit, us-ascii, 2.6K]
  A    15 patch-1.5.5.1.dgc.stunted822.1     [text/plain, 7bit, us-ascii, 0.6K]

whereas with the patch it more forgivingly becomes:
  I     1 <no description>                   [text/plain, 7bit, us-ascii, 1.9K]
  I     2 outer rfc822                             [message/rfc822, 7bit, 5.0K]
  I     3 `-><no description>                       [multipa/mixed, 7bit, 3.0K]
  I     4   |-><no description>              [text/plain, 7bit, us-ascii, 0.3K]
  I     5   `->inner rfc822                        [message/rfc822, 7bit, 2.6K]
  I     6     `-><no description>                   [multipa/mixed, 7bit, 0.6K]
  I     7       |-><no description>          [text/plain, 7bit, us-ascii, 0.2K]
  A     8       |->hostname.eri0             [text/plain, 7bit, us-ascii, 0.1K]
  A     9       `->nodename                  [text/plain, 7bit, us-ascii, 0.1K]
  I    10 outer rfc822                             [message/rfc822, 7bit, 5.0K]
  I    11 `-><no description>                       [multipa/mixed, 7bit, 3.0K]
  I    12   |-><no description>              [text/plain, 7bit, us-ascii, 0.3K]
  I    13   `->inner rfc822                        [message/rfc822, 7bit, 2.6K]
  I    14     `-><no description>                   [multipa/mixed, 7bit, 0.6K]
  I    15       |-><no description>          [text/plain, 7bit, us-ascii, 0.2K]
  A    16       |->hostname.eri0             [text/plain, 7bit, us-ascii, 0.1K]
  A    17       `->nodename                  [text/plain, 7bit, us-ascii, 0.1K]
  A    18 patch-1.5.5.1.dgc.stunted822.1     [text/plain, 7bit, us-ascii, 0.6K]


This caused me some trouble diagnosing my own MIME parser. :)

-- 
 -D.    dgc@xxxxxxxxxxxx   **   Enterprise Network Servers and Such
                           **   University of Chicago
 We are the robots.        **   North America's southernmost seasonal glacier
--- Begin Message ---
Contains a message/rfc822 message with two attachments.

-- 
 -D.    dgc@xxxxxxxxxxxx   **   Enterprise Network Servers and Such
                           **   University of Chicago
 We are the robots.        **   North America's southernmost seasonal glacier
--- Begin Message ---
message/rfc822 with attachments.

-- 
 -D.    dgc@xxxxxxxxxxxx   **   Enterprise Network Servers and Such
                           **   University of Chicago
 We are the robots.        **   North America's southernmost seasonal glacier
dust
dust

--- End Message ---

--- End Message ---
--- Begin Message ---
Contains a message/rfc822 message with two attachments.

-- 
 -D.    dgc@xxxxxxxxxxxx   **   Enterprise Network Servers and Such
                           **   University of Chicago
 We are the robots.        **   North America's southernmost seasonal glacier
--- Begin Message ---
Return-Path: <dgc@xxxxxxxxxxxx>
Received: from midway.uchicago.edu (midway.uchicago.edu [128.135.12.12])
        by dust.uchicago.edu (8.12.10/8.12.10) with ESMTP id i0RBQqch029407
        for <dgc@xxxxxxxxxxxxxxxxx>; Tue, 27 Jan 2004 05:26:52 -0600 (CST)
Received: (from daemon@localhost)
        by midway.uchicago.edu (8.12.10/8.12.9) id i0RBR2oN016671
        for dgc@xxxxxxxxxxxxxxxxx; Tue, 27 Jan 2004 05:27:02 -0600 (CST)
Received: from dust.uchicago.edu (dust.uchicago.edu [128.135.0.35])
        by midway.uchicago.edu (8.12.10/8.12.9) with ESMTP id i0RBR1O6016661
        for <dgc@xxxxxxxxxxxx>; Tue, 27 Jan 2004 05:27:01 -0600 (CST)
Received: from dust.uchicago.edu (localhost [127.0.0.1])
        by dust.uchicago.edu (8.12.10/8.12.10) with ESMTP id i0RBQpch029404
        for <dgc@xxxxxxxxxxxx>; Tue, 27 Jan 2004 05:26:51 -0600 (CST)
Received: (from dgc@localhost)
        by dust.uchicago.edu (8.12.10/8.12.10/Submit) id i0RBQpiq029403
        for dgc@xxxxxxxxxxxx; Tue, 27 Jan 2004 05:26:51 -0600 (CST)
X-Authentication-Warning: dust.uchicago.edu: dgc set sender to dgc@xxxxxxxxxxxx 
using -f
Date: Tue, 27 Jan 2004 05:26:51 -0600
X-PH: V4.4 (uchicago), $Revision: 1.61 $@midway
From: David Champion <dgc@xxxxxxxxxxxx>
To: David Champion <dgc@xxxxxxxxxxxx>
Subject: inner rfc822
Message-ID: <20040127112651.GC10209@xxxxxxxxxxxxxxxxx>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="fUYQa+Pmc3FrFX/N"
Content-Disposition: inline
X-Gouranga: Gouranga gouranga gouranga
X-Quote: There is nothing like free rum to set the imagination on fire.
User-Agent: Mutt/1.5.5.1i
X-SRS: srs-filter 0.3 dgc@dust ($Id: srs-filter,v 1.18 2003/01/08 
        21:37:52 dgc Exp $)
X-SRS-Probability: 0.001
X-SRS-Indicators: glacier(1 x 0.2), i0rbqpiq029403(1 x 0.2), 
        i0rbqqch029407(1 x 0.2), i0rbr1o6016661(1 x 0.2), nodename(1 x 0.2), 
        xquote(1 x 0.2), hostname(1 x 0.195), robots(1 x 0.195), 
        inner(1 x 0.094), xauthenticationwarning(1 x 0.037), 
        attachment(2 x 0.027), rfc822(2 x 0.007), 1281350(1 x 0.001), 
        51i(1 x 0.001), attachments(1 x 0.001)


--fUYQa+Pmc3FrFX/N
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

message/rfc822 with attachments.

-- 
 -D.    dgc@xxxxxxxxxxxx   **   Enterprise Network Servers and Such
                           **   University of Chicago
 We are the robots.        **   North America's southernmost seasonal glacier

--fUYQa+Pmc3FrFX/N
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="hostname.eri0"

dust

--fUYQa+Pmc3FrFX/N
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=nodename

dust

--fUYQa+Pmc3FrFX/N--

--- End Message ---

--- End Message ---
--- mutt-1.5.5.1-dist/parse.c   Wed Nov  5 03:41:33 2003
+++ mutt-1.5.5.1-dgc/parse.c    Tue Jan 27 06:03:30 2004
@@ -41,12 +41,18 @@
 
   FOREVER
   {
-    if (fgets (buf, *linelen - offset, f) == NULL ||   /* end of file or */
-       (ISSPACE (*line) && !offset))                   /* end of headers */ 
+    if (fgets (buf, *linelen - offset, f) == NULL)     /* end of file or */
     {
       *line = 0;
       return (line);
     }
+    if (ISSPACE (*line) && !offset)                    /* end of headers */ 
+    {
+      while ((ch = fgetc(f)) && (ch == '\n' || ch == '\r'));
+      ungetc(ch, f);
+      *line = 0;
+      return (line);
+    }
 
     buf += strlen (buf) - 1;
     if (*buf == '\n')