Subject: [sup-devel] [PATCH] Fix problem with time parsing

From: Hamish <[email-masked]>
Date: Mon, 02 May 2011 23:02:43 +0100

If a message has a date with month first and day second, then if the
day is greater than 12, heliotrope crashes. This patch catches the
error, and tries again after swapping the day and month.
---
 lib/heliotrope/maildir-walker.rb |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/lib/heliotrope/maildir-walker.rb b/lib/heliotrope/maildir-walker.rb
index db9b9d4..47cb08b 100644
--- a/lib/heliotrope/maildir-walker.rb
+++ b/lib/heliotrope/maildir-walker.rb
@@ -43,7 +43,19 @@ private
       while(l = f.gets)
         if l =~ /^Date:\s+(.+\S)\s*$/
           date = $1
-          pdate = Time.parse($1)
+          begin
+            pdate = Time.parse($1)
+          rescue ArgumentError
+            # flip the day and month around and try again
+            if date =~ %r|(\d\d?)([-./])(\d\d?)([-./])(\d{2,4})|
+              date = $3 + $2 + $1 + $4 + $5
+              pdate = Time.parse(date)
+            else
+              puts "Error while parsing time in file #{fn}"
+              puts "Matched date text was #{date}"
+              pdate = Time.at 0
+            end
+          end
           return pdate
         end
       end
-- 
1.7.4.1
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: William Morgan <[email-masked]>
Date: Wed, 11 May 2011 00:34:05 +0000

Reformatted excerpts from Hamish's message of 2011-05-10:
> Sadly it was not spam, but an email from staples (UK) about some stuff
> I bought from then online. So sup should not barf on it, but forging a
> date header would be fine by me. Though "now" might be better than
> date zero, which I think is what sup normally does otherwise ...

I agree. If you have a chance, please add a ticket for this on the
heliotrope github project.
-- 
William <[email-masked]>
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: William Morgan <[email-masked]>
Date: Tue, 10 May 2011 17:45:23 +0000

> error, and tries again after swapping the day and month.

Is this a legitimate email message? Producing rfc2822-compliant date
headers is one of the few things that everyone seems capable of doing
besides spambots. I'm tempted to take the Sup approach of forging a date
header, or giving up on the email, if it's unparseable.
-- 
William <[email-masked]>
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Hamish <[email-masked]>
Date: Tue, 10 May 2011 19:47:10 +0100

> header, or giving up on the email, if it's unparseable.

Sadly it was not spam, but an email from staples (UK) about some stuff I
bought from then online. So sup should not barf on it, but forging a
date header would be fine by me. Though "now" might be better than date
zero, which I think is what sup normally does otherwise ...

Hamish

---

From: Hamish <[email-masked]>
Date: Sun, 22 May 2011 23:03:41 +0100

> heliotrope github project.

Done: https://github.com/wmorgan/heliotrope/issues/2

Hamish Downer