From: Mark Alexander Date: Sun, 22 Mar 2009 16:42:55 +0000 (-0400) Subject: correctly parse headers starting with empty lines X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=5e86da2f099e9e6013f1717bfbaf7c100fe1de03;p=sup correctly parse headers starting with empty lines Handle message headers that are split across multiple lines and start with a blank line. Patch modified slightly by William Morgan. --- diff --git a/lib/sup/mbox.rb b/lib/sup/mbox.rb index 89b00ed..be83afc 100644 --- a/lib/sup/mbox.rb +++ b/lib/sup/mbox.rb @@ -11,7 +11,7 @@ module Redwood ## TODO: move functionality to somewhere better, like message.rb module MBox BREAK_RE = /^From \S+/ - HEADER_RE = /\s*(.*?\S)\s*/ + HEADER_RE = /\s*(.*?)\s*/ def read_header f header = {} diff --git a/test/test_message.rb b/test/test_message.rb index c887773..96562aa 100644 --- a/test/test_message.rb +++ b/test/test_message.rb @@ -428,6 +428,100 @@ EOS end + def test_blank_header_lines + + message = < +X-Original-To: nobody@localhost +Delivered-To: nobody@localhost.eng.widget.com +Received: from localhost (localhost.localdomain [127.0.0.1]) + by soquel.eng.widget.com (Postfix) with ESMTP id 609BC13C0DB1 + for ; Thu, 19 Mar 2009 13:43:21 -0700 (PDT) +MIME-Version: 1.0 +Received: from pa-excas-vip.widget.com [10.16.67.200] + by localhost with IMAP (fetchmail-6.2.5) + for nobody@localhost (single-drop); Thu, 19 Mar 2009 13:43:21 -0700 (PDT) +Received: from pa-exht01.widget.com (10.113.81.167) by pa-excaht11.widget.com + (10.113.81.197) with Microsoft SMTP Server (TLS) id 8.1.311.2; Thu, 19 Mar + 2009 13:42:30 -0700 +Received: from mailman2.widget.com (10.16.64.159) by pa-exht01.widget.com + (10.113.81.167) with Microsoft SMTP Server id 8.1.336.0; Thu, 19 Mar 2009 + 13:42:30 -0700 +Received: by mailman2.widget.com (Postfix) id 47095AE30856; Thu, 19 Mar 2009 + 13:42:29 -0700 (PDT) +Received: from countchocula.widget.com (localhost.localdomain [127.0.0.1]) by + mailman2.widget.com (Postfix) with ESMTP id 5F782ABC5948; Thu, 19 Mar 2009 + 13:42:28 -0700 (PDT) +Received: from mailhost4.widget.com (mailhost4.widget.com [10.16.67.124]) by + mailman2.widget.com (Postfix) with ESMTP id 6CDCCABC5948 for + ; Thu, 19 Mar 2009 13:42:26 -0700 (PDT) +Received: by mailhost4.widget.com (Postfix) id 2364AC9AC4; Thu, 19 Mar 2009 + 13:42:26 -0700 (PDT) +Received: from pa-exht01.widget.com (pa-exht01.widget.com [10.113.81.167]) by + mailhost4.widget.com (Postfix) with ESMTP id 17A68C9AC3 for + ; Thu, 19 Mar 2009 13:42:26 -0700 (PDT) +Received: from PA-EXMBX04.widget.com ([10.113.81.142]) by pa-exht01.widget.com + ([10.113.81.167]) with mapi; Thu, 19 Mar 2009 13:42:26 -0700 +From: Some User +To: "monitor-list@widget.com" +Sender: "monitor-list-bounces@widget.com" +Date: Thu, 19 Mar 2009 13:42:25 -0700 +Subject: Looking for a mac +Thread-Topic: Looking for a mac +Thread-Index: AQHJqNM1xIqqjNRWuUCUBaxzPFK5eQ== +Message-ID: + +List-Help: +List-Subscribe: , + +List-Unsubscribe: + , + +Accept-Language: en-US +Content-Language: en-US +X-MS-Exchange-Organization-AuthAs: Anonymous +X-MS-Exchange-Organization-AuthSource: pa-exht01.widget.com +X-MS-Has-Attach: +X-Auto-Response-Suppress: All +X-MS-TNEF-Correlator: +acceptlanguage: en-US +delivered-to: monitor-list@widget.com +errors-to: monitor-list-bounces@widget.com +list-id: engineering monitor related +x-mailman-version: 2.1.8 +x-beenthere: monitor-list@widget.com +x-original-to: monitor-list@mailman2.widget.com +list-post: +list-archive: +Content-Type: text/plain; charset="us-ascii" +Content-Transfer-Encoding: quoted-printable + +Hi all, + + Just wondering if anybody can lend me a mac to reproduce PR 384931 ? + Thanks. + +Michael= +EOS + + source = DummySource.new("sup-test://test_blank_header_lines") + source.messages = [ message ] + source_info = 0 + + sup_message = Message.new( {:source => source, :source_info => source_info } ) + + # See how well parsing the message ID went. + id = sup_message.id + assert_equal("D3C12B2AD838B44DA9D6B2CA334246D011E72A73A4@PA-EXMBX04.widget.com", id) + + # Look at another header field whose first line was blank. + list_unsubscribe = sup_message.list_unsubscribe + assert_equal(" , " + + "", + list_unsubscribe) + + end + # TODO: test different error cases, malformed messages etc. # TODO: test different quoting styles, see that they are all divided