[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sup-devel] [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: 0001-Fix-problem-with-time-parsing.patch
Description: Binary data

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