Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] [PATCH] Fix problem with time parsing
@ 2011-05-02 22:02 Hamish
  2011-05-10 17:45 ` William Morgan
  0 siblings, 1 reply; 5+ messages in thread
From: Hamish @ 2011-05-02 22:02 UTC (permalink / raw)
  To: sup-devel

[-- Attachment #1: Type: text/plain, Size: 1191 bytes --]

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

[-- Attachment #2: 0001-Fix-problem-with-time-parsing.patch --]
[-- Type: application/octet-stream, Size: 1387 bytes --]

From 073fead606d4270445c74e9572a91e67c24b4a7a Mon Sep 17 00:00:00 2001
From: Hamish Downer <dmishd@gmail.com>
Date: Mon, 2 May 2011 22:56:17 +0100
Subject: [PATCH] Fix problem with time parsing

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


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] [PATCH] Fix problem with time parsing
  2011-05-02 22:02 [sup-devel] [PATCH] Fix problem with time parsing Hamish
@ 2011-05-10 17:45 ` William Morgan
  2011-05-10 18:47   ` Hamish
  0 siblings, 1 reply; 5+ messages in thread
From: William Morgan @ 2011-05-10 17:45 UTC (permalink / raw)
  To: sup-devel

Reformatted excerpts from Hamish's message of 2011-05-02:
> 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.

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 <wmorgan-sup@masanjin.net>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] [PATCH] Fix problem with time parsing
  2011-05-10 17:45 ` William Morgan
@ 2011-05-10 18:47   ` Hamish
  2011-05-11  0:34     ` William Morgan
  0 siblings, 1 reply; 5+ messages in thread
From: Hamish @ 2011-05-10 18:47 UTC (permalink / raw)
  To: sup-devel

Excerpts from William Morgan's message of Tue May 10 18:45:23 +0100 2011:
> Reformatted excerpts from Hamish's message of 2011-05-02:
> > 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.
> 
> 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.

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
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] [PATCH] Fix problem with time parsing
  2011-05-10 18:47   ` Hamish
@ 2011-05-11  0:34     ` William Morgan
  2011-05-22 22:03       ` Hamish
  0 siblings, 1 reply; 5+ messages in thread
From: William Morgan @ 2011-05-11  0:34 UTC (permalink / raw)
  To: sup-devel

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 <wmorgan-sup@masanjin.net>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] [PATCH] Fix problem with time parsing
  2011-05-11  0:34     ` William Morgan
@ 2011-05-22 22:03       ` Hamish
  0 siblings, 0 replies; 5+ messages in thread
From: Hamish @ 2011-05-22 22:03 UTC (permalink / raw)
  To: sup-devel

Excerpts from William Morgan's message of Wed May 11 01:34:05 +0100 2011:
> 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.

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

Hamish Downer
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-05-22 22:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-02 22:02 [sup-devel] [PATCH] Fix problem with time parsing Hamish
2011-05-10 17:45 ` William Morgan
2011-05-10 18:47   ` Hamish
2011-05-11  0:34     ` William Morgan
2011-05-22 22:03       ` Hamish

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox