commit 6ef251d9e9ca538f68bf1899b12c9d96453f2429
parent c54156ce142289514bd45c3776cd2ce8ef4a8a00
Author: Gaute Hope <eg@gaute.vetsj.com>
Date: Sun, 26 May 2013 15:26:22 +0200
patch RMail field parser to use UTF-8 regexps and fix_encoding before parsing field
Diffstat:
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'thread'
require 'lockfile'
require 'mime/types'
@@ -113,6 +115,25 @@ module RMail
end
class Header
+
+ # Convert to ASCII before trying to match with regexp
+ class Field
+
+ EXTRACT_FIELD_NAME_RE = /\A([^\x00-\x1f\x7f-\xff :]+):\s*/no
+
+ class << self
+ def parse(field)
+ field = field.dup.to_s
+ field = field.fix_encoding.ascii
+ if field =~ EXTRACT_FIELD_NAME_RE
+ [ $1, $'.chomp ]
+ else
+ [ "", Field.value_strip(field) ]
+ end
+ end
+ end
+ end
+
## Be more cautious about invalid content-type headers
## the original RMail code calls
## value.strip.split(/\s*;\s*/)[0].downcase