mikel / mail

A Really Ruby Mail Library
MIT License
3.62k stars 936 forks source link

References splitting over multiple lines not parsed #1240

Open Flauschbaellchen opened 6 years ago

Flauschbaellchen commented 6 years ago

I got old e-mails which reference other emails within the thread in the following form. References are split over multiple lines and some of them missing , at the end of the line.

References: <trinity-1aaa12d0-b7cd-4bdc-951e-4c252be36810-1385751703953@3capp-webde-bs47>,
 <31d38016f7028fc8f0fcefe9f883f66c@example.com>
 <trinity-6e3e4369-0a45-4088-becf-fe7d287ea387-1386180136909@3capp-webde-bs19>,
 <df9bd0540780d5883a0d56133c570312@example.com>

The references could not be parsed and results in the following object:

mail.header[:references]:

 => #<Mail::Field 0x55bd4c569230 @name="References" @unparsed_value="<trinity-1aaa12d0-b7cd-4bdc-951e-4c252be36810-1385751703953@3capp-webde-bs47>,=0D=0A=0D=0A\r\n <31d38016f7028fc8f0fcefe9f883f66c@example.com>=0D=0A=0D=0A\r\n <trinity-6e3e4369-0a45-4088-becf-fe7d287ea387-1386180136909@3capp-webde-bs19>,=0D=0A=0D=0A\r\n <df9bd0540780d5883a0d56133c570312@example.com>" @charset="UTF-8" @field_order_id=18>

mail.references:

"<trinity-1aaa12d0-b7cd-4bdc-951e-4c252be36810-1385751703953@3capp-webde-bs47>,=0D=0A=0D=0A\r\n <31d38016f7028fc8f0fcefe9f883f66c@example.com>=0D=0A=0D=0A\r\n <trinity-6e3e4369-0a45-4088-becf-fe7d287ea387-1386180136909@3capp-webde-bs19>,=0D=0A=0D=0A\r\n <df9bd0540780d5883a0d56133c570312@example.com>"

The original email has been sent through web.de dating back to 2013.

Mail gem tested against 2.7.0 and 2.7.1-rc1.

Flauschbaellchen commented 6 years ago

Github throws an error when I want to upload the email as .txt or .eml... so I'll paste it inline:

Return-Path: <t@example.com>
Delivered-To: b@example.com
Received: from mx1.goneo.de (mx1.goneo.de [85.220.129.24])
    by mailbox3.goneo.de (Postfix) with ESMTP id E418E9593F;
    Thu,  5 Dec 2013 11:52:48 +0100 (CET)
X-Virus-Scanned: by goneo
X-Spam-Flag: NO
X-Spam-Score: -0.799
X-Spam-Level:
X-Spam-Status: No, score=-0.799 tagged_above=-9999 required=5
    tests=[BAYES_00=-1.9, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001,
    HTML_MIME_NO_HTML_TAG=0.377, MIME_HTML_ONLY=0.723,
    RCVD_IN_DNSWL_NONE=-0.0001, RP_MATCHES_RCVD=-0.001] autolearn=no
Received: from mx1.goneo.de ([127.0.0.1])
    by localhost (mx1.goneo.de [127.0.0.1]) (amavisd-new, port 10024)
    with ESMTP id 1ttNYSGHjHai; Thu,  5 Dec 2013 11:52:47 +0100 (CET)
X-policyd-weight: using cached result; rate: -7
Received: from mout.web.de (mout.web.de [212.227.15.14])
    by mx1.goneo.de (Postfix) with ESMTPS id A823423F036
    for <b@example.com>; Thu,  5 Dec 2013 11:52:47 +0100 (CET)
Received: from 3capp-webde-bs25.server.lan ([172.19.170.25]) by
 mriweb.server.lan (mriweb001) with ESMTP (Nemesis) id
 0M7oBK-1VbNLL2AiG-00vSPN for <b@example.com>; Thu, 05 Dec 2013
 11:52:47 +0100
Received: from [194.76.232.190] by 3capp-webde-bs25.server.lan with HTTP;
 Thu Dec 05 11:52:47 CET 2013
MIME-Version: 1.0
Message-ID: <trinity-42bbd277-d1b3-481a-a35a-25d4d6e9886f-1386240767421@3capp-webde-bs25>
From: "Name X" <t@example.com>
To: b@example.com
Subject: Subject
Content-Type: text/html; charset=UTF-8
Date: Thu, 5 Dec 2013 11:52:47 +0100 (CET)
Importance: normal
Sensitivity: Normal
In-Reply-To: <df9bd0540780d5883a0d56133c570312@example.com>
References: <trinity-1aaa12d0-b7cd-4bdc-951e-4c252be36810-1385751703953@3capp-webde-bs47>,
 <31d38016f7028fc8f0fcefe9f883f66c@example.com>
 <trinity-6e3e4369-0a45-4088-becf-fe7d287ea387-1386180136909@3capp-webde-bs19>,
 <df9bd0540780d5883a0d56133c570312@example.com>
X-UI-Message-Type: mail
X-Priority: 3
X-Provags-ID: V03:K0:ETy9mNwvRDvryGH3te/9ABng8U7ZRnksS+F/hqteXyF
 z6sttQSOMsai4AZJAAhBfiGr0PsmuYF7qISDO8KFLrTk1KdfAP
 t2uv9+ZzJ51Ee5YhezCHLyZKJTflnTixFoPtLQBC2TrX6fBhhF
 zQTgqfEHXrmJTmT5gdBPRT0GwJkiejTsiEEiKQM0oK5YesLd5q
 lWuEvfowGLo/HIJARj2fKtHlqrQm+0DPlcIaHFsRgSJBP4WWkh
 7XwRVlBsUlsvZq0/sI7nrWHOO+yNU0QrYJwrVudrTgZyWE8JMa
 5zAhlDE7zutXa6LwIP6rSQPu2Eu

Hey Name
Flauschbaellchen commented 6 years ago

I could not find that , is allowed (nor denied) in message-ids. Within my tests the issue above could be fixed by ignoring/removing the , beforehand. Afterwards the references are parsed correctly.

Maybe this is a quick fix?