Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quirky received header breaks date parsing #81

Open
djmaze opened this issue Apr 1, 2024 · 1 comment
Open

Quirky received header breaks date parsing #81

djmaze opened this issue Apr 1, 2024 · 1 comment

Comments

@djmaze
Copy link

djmaze commented Apr 1, 2024

I got sent a mail which makes the parser output None for the received date. Here is a test case to reproduce the problem:

diff --git a/resources/received.json b/resources/received.json
index 4c9161a..652ab61 100644
--- a/resources/received.json
+++ b/resources/received.json
@@ -4200,5 +4200,31 @@
         "tz_minute": 0
       }
     }
+  },
+  {
+    "header": " from [127.0.0.1] (host.example.com [35.173.1.1])\r\n by bf7aa1d4e8a6 with SMTP id 660a079b99f27ed5a03038a8; Mon, 01 Apr 2024\r\n 01:02:19 GMT\r\n",
+    "expected": {
+      "from": {
+        "IpAddr": "127.0.0.1"
+      },
+      "from_ip": "35.173.1.1",
+      "from_iprev": "host.example.com",
+      "by": {
+        "Name": "bf7aa1d4e8a6"
+      },
+      "with": "SMTP",
+      "id": "660a079b99f27ed5a03038a8",
+      "date": {
+        "year": 2024,
+        "month": 4,
+        "day": 1,
+        "hour": 1,
+        "minute": 2,
+        "second": 19,
+        "tz_before_gmt": true,
+        "tz_hour": 0,
+        "tz_minute": 0
+      }
+    }
   }

The problem is the line break (\r\n) inside the date part.

I am not an expert, but looking at RFC 5322, this case looks to me like the obsolete date and time syntax. Is this crate meant to support that? Or are we supposed to work around this? (E.g. by reading the Date header field in these cases.)

By the way, thanks for your work on this. Really useful for my upcoming mail client :)

@mdecimus
Copy link
Member

mdecimus commented Apr 4, 2024

The date seems correct, it's the CRLF that is breaking the parser. Although the ABNF does not allow CRLFs within a date, any whitespace can be replaced with a CRLF in order to fold the lines.
I'll look into this as soon as I have some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants