Probable bug in handling message/rfc822

Bob Rogers <[email protected]> Wed, 6 Jan 2010 15:49:47 -0500
Newsgroups gmane.mail.spam.tmda.devel
Message-ID <[email protected]>
--RXcn4LjWyw
Content-Type: text/plain; charset=us-ascii
Content-Description: message body text
Content-Transfer-Encoding: 7bit

   The _handle_message method in tmda/TMDA/pythonlib/email/generator.py
starts with the following comment:

         # The payload of a message/rfc822 part should be a multipart sequence
         # of length 1.  The zeroth element of the list should be the Message
         # object for the subpart . . .

But I think this is confusing message/* with multipart/digest; I see no
hint in RFC 2046 [1] that message/rfc822 bodies contain any internal
structure (other than whatever may be in the message itself, of course).

   And I have a counterexample:  I forwarded a message to myself using
VM [2], without adding any text in the body, and I got a top-level
Content-Type of "message/rfc822" with no multipart structure [first
attachment].  Passing this message through TMDA fails in the following
way:

    Uncaught Python 2.5.2 Exception (Wed Jan  6 12:33:04 2010):
    -----------------------------------------------------------
    Traceback (most recent call last):
      File "/usr/bin/tmda-filter", line 53, in <module>
	execfile(os.path.join(execdir, 'tmda-rfilter'))
      File "/usr/bin/tmda-rfilter", line 213, in <module>
	orig_msgin_as_string = Util.msg_as_string(msgin)
      File "/usr/lib64/python2.5/site-packages/TMDA/Util.py", line 552, in msg_as_string
	g.flatten(msg, unixfrom=unixfrom)
      File "/usr/lib/python2.5/site-packages/TMDA/pythonlib/email/generator.py", line 84, in flatten
	self._write(msg)
      File "/usr/lib/python2.5/site-packages/TMDA/pythonlib/email/generator.py", line 109, in _write
	self._dispatch(msg)
      File "/usr/lib/python2.5/site-packages/TMDA/pythonlib/email/generator.py", line 135, in _dispatch
	meth(msg)
      File "/usr/lib/python2.5/site-packages/TMDA/pythonlib/email/generator.py", line 266, in _handle_message
	g.flatten(msg.get_payload(0), unixfrom=False)
      File "/usr/lib/python2.5/site-packages/TMDA/pythonlib/email/message.py", line 185, in get_payload
	raise TypeError('Expected list, got %s' % type(self._payload))
    TypeError: Expected list, got <type 'str'>

The patch in the second attachment seems to fix the immediate symptom,
though at the cost of breaking the message "payload" abstraction.  I
can't recommend this patch, but something needs to be done, especially
if (as I suspect) this is valid MIME.

   TIA,

					-- Bob Rogers
					   http://www.rgrjr.com/

[1]  http://www.rfc-editor.org/rfc/rfc2046.txt, especially p.28.

[2]  http://www.nongnu.org/viewmail/


--RXcn4LjWyw
Content-Type: text/plain; name="forwarded-message.msg"
Content-Description: Test case
Content-Disposition: inline;
	filename="forwarded-message.msg"
Content-Transfer-Encoding: 7bit

Received: from rome.modulargenetics.com (rome.modulargenetics.com [192.168.23.56])
	by send.modulargenetics.com (Postfix on SuSE Linux) with ESMTP id EF9EA10EBED
	for <[email protected]>; Mon,  4 Jan 2010 22:55:07 -0500 (EST)
X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on
	rome.modulargenetics.com
X-Spam-Level: ***
X-Spam-Status: No, score=3.4 required=5.0 tests=FH_DATE_PAST_20XX autolearn=no
	version=3.2.4
Received: from rgrjr.com (rgrjr.com [216.146.47.5])
	by rome.modulargenetics.com (Postfix on SuSE Linux) with ESMTP id 610371AC24
	for <[email protected]>; Mon,  4 Jan 2010 22:55:07 -0500 (EST)
Received: from rgrjr.dyndns.org (c-66-30-196-77.hsd1.ma.comcast.net [66.30.196.77])
	by rgrjr.com (Postfix on CentOS) with ESMTP id A8C081601A6
	for <[email protected]>; Tue,  5 Jan 2010 03:55:05 +0000 (UTC)
Received: (qmail 23029 invoked by uid 89); 5 Jan 2010 03:55:05 -0000
Received: from unknown (HELO rgr.rgrjr.com) (192.168.57.1)
  by home with SMTP; 5 Jan 2010 03:55:05 -0000
Received: by rgr.rgrjr.com (Postfix, from userid 500)
	id 49E69484D4; Mon,  4 Jan 2010 22:55:04 -0500 (EST)
MIME-Version: 1.0
Content-Type: message/rfc822
Content-Description: forwarded message
Content-Transfer-Encoding: 7bit
Message-ID: <[email protected]>
Date: Mon, 4 Jan 2010 22:55:03 -0500
From: Bob Rogers <[email protected]>
To: Bob Rogers <[email protected]>
Subject: [Chong Yidong: Emacs 23.1.91 pretest]
X-Mailer: VM viewmail-600 under 23.1.50.1 (i686-pc-linux-gnu)

MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Return-Path: <[email protected]>
Delivered-To: [email protected]
Received: (qmail 693 invoked by uid 89); 31 Dec 2009 11:40:25 -0000
Received: from unknown (HELO rgrjr.com) (216.146.47.5)
  by home with SMTP; 31 Dec 2009 11:40:25 -0000
Received: from rgrjr.com (localhost [127.0.0.1])
	by rgrjr.com (Postfix on CentOS) with ESMTP id 7E1231601AF
	for <[email protected]>; Thu, 31 Dec 2009 11:40:21 +0000 (UTC)
X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on rgrjr.com
X-Spam-Level: 
X-Spam-Status: No, score=-2.1 required=5.0 tests=DATE_IN_PAST_06_12,
	RCVD_IN_DNSWL_MED autolearn=failed version=3.2.4
Received: from lists.gnu.org (lists.gnu.org [199.232.76.165])
	by rgrjr.com (Postfix on CentOS) with ESMTP id 684C2160180
	for <[email protected]>; Thu, 31 Dec 2009 11:40:21 +0000 (UTC)
Received: from localhost ([127.0.0.1]:40445 helo=lists.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43)
	id 1NQJO9-0005Kc-5X
	for [email protected]; Thu, 31 Dec 2009 06:40:21 -0500
Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43)
	id 1NQJNU-0005KO-IK
	for [email protected]; Thu, 31 Dec 2009 06:39:40 -0500
Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43)
	id 1NQJNQ-0005Jw-4L
	for [email protected]; Thu, 31 Dec 2009 06:39:40 -0500
Received: from [199.232.76.173] (port=44085 helo=monty-python.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1NQJNP-0005Jt-Up
	for [email protected]; Thu, 31 Dec 2009 06:39:35 -0500
Received: from pantheon-po19.its.yale.edu ([130.132.50.75]:40386)
	by monty-python.gnu.org with esmtps
	(TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60)
	(envelope-from <[email protected]>)
	id 1NQJNN-0003qC-L0; Thu, 31 Dec 2009 06:39:33 -0500
Received: from furry (adsl-99-75-106-169.dsl.wlfrct.sbcglobal.net
	[99.75.106.169]) (authenticated bits=0)
	by pantheon-po19.its.yale.edu (8.12.11.20060308/8.12.11) with ESMTP id
	nBVBYXLj008595
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT);
	Thu, 31 Dec 2009 06:34:35 -0500
Received: by furry (Postfix, from userid 1000)
	id F046FC05D; Wed, 30 Dec 2009 21:54:27 -0500 (EST)
Message-ID: <[email protected]>
X-YaleITSMailFilter: Version 1.2c (attachment(s) not renamed)
X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6
X-BeenThere: [email protected]
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: "Emacs development discussions." <emacs-devel.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/emacs-devel>,
	<mailto:[email protected]?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/pipermail/emacs-devel>
List-Post: <mailto:[email protected]>
List-Help: <mailto:[email protected]?subject=help>
List-Subscribe: <http://lists.gnu.org/mailman/listinfo/emacs-devel>,
	<mailto:[email protected]?subject=subscribe>
Errors-To: [email protected]
From: Chong Yidong <[email protected]>
Sender: [email protected]
To: [email protected]
Subject: Emacs 23.1.91 pretest
Date: Wed, 30 Dec 2009 21:54:27 -0500

Emacs pretest 23.1.91 is now available for download via FTP, at the
following location:

  ftp://alpha.gnu.org/gnu/emacs/pretest/emacs-23.1.91.tar.gz

The xdelta against the Emacs 23.1.90 pretest is here:

  ftp://alpha.gnu.org/gnu/emacs/pretest/emacs-23.1.90-23.1.91.xdelta

This is the second pretest for what will be the Emacs 23.2 release.

In particular, note that we have reverted the GDB-UI package back to
gdb-ui.el.  This is the same code-base as Emacs 23.1, with extensions
for reverse debugging and displaying STL collections.  The GDB-MI
package will be postphoned to a future version (either 23.3 or 24).

Pretesters: please send me an email reporting success or failure on your
build platform.  Report bugs via M-x report-emacs-bugs, or email
[email protected].  For questions, email [email protected].

Thanks.

--RXcn4LjWyw
Content-Type: text/plain; name="handle-top-level-message-rfc822.patch"
Content-Description: Patch
Content-Disposition: inline; filename="handle-top-level-message-rfc822.patch"
Content-Transfer-Encoding: 7bit

diff -u /usr/lib/python2.5/site-packages/TMDA/pythonlib/email/generator.py /usr/lib/python2.5/site-packages/TMDA/pythonlib/email/generator.py.\~1\~
--- /usr/lib/python2.5/site-packages/TMDA/pythonlib/email/generator.py	2010-01-06 12:59:54.000000000 -0500
+++ /usr/lib/python2.5/site-packages/TMDA/pythonlib/email/generator.py.~1~	2009-01-22 11:04:41.000000000 -0500
@@ -257,18 +257,14 @@
         self._fp.write(NL.join(blocks))
 
     def _handle_message(self, msg):
+        s = StringIO()
+        g = self.clone(s)
         # The payload of a message/rfc822 part should be a multipart sequence
         # of length 1.  The zeroth element of the list should be the Message
         # object for the subpart.  Extract that object, stringify it, and
         # write it out.
-        payload = msg._payload
-        if isinstance(payload, list):
-            s = StringIO()
-            g = self.clone(s)
-            g.flatten(payload[0], unixfrom=False)
-            self._fp.write(s.getvalue())
-        else:
-            self._fp.write(payload)
+        g.flatten(msg.get_payload(0), unixfrom=False)
+        self._fp.write(s.getvalue())
 
 
 

Diff finished.  Wed Jan  6 15:24:53 2010

--RXcn4LjWyw
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
--RXcn4LjWyw
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
tmda-workers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmda-workers

--RXcn4LjWyw--