commit ae3f024bcbd29f93c58f95b649e4b90b433fd118
parent aaa384af6ec7054f5e16086b1e54b8f3740723a6
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date: Sun, 28 Feb 2010 11:28:16 -0800
replace RE_UTF8 with backport of String#ascii_only?
Diffstat:
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
@@ -3,10 +3,6 @@ require 'socket' # just for gethostname!
require 'pathname'
require 'rmail'
-# from jcode.rb, not included in ruby 1.9
-PATTERN_UTF8 = '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]'
-RE_UTF8 = Regexp.new(PATTERN_UTF8, 0, 'n')
-
module Redwood
class SendmailCommandFailed < StandardError; end
@@ -208,7 +204,7 @@ protected
end
def mime_encode_subject string
- return string unless string.match(RE_UTF8)
+ return string if string.ascii_only?
mime_encode string
end
@@ -217,7 +213,7 @@ protected
# Encode "bælammet mitt <user@example.com>" into
# "=?utf-8?q?b=C3=A6lammet_mitt?= <user@example.com>
def mime_encode_address string
- return string unless string.match(RE_UTF8)
+ return string if string.ascii_only?
string.sub(RE_ADDRESS) { |match| mime_encode($1) + $2 }
end
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
@@ -329,6 +329,13 @@ class String
def transcode src_encoding=$encoding
Iconv.easy_decode $encoding, src_encoding, self
end
+
+ unless method_defined? :ascii_only?
+ def ascii_only?
+ size.times { |i| return false if self[i] & 128 != 0 }
+ return true
+ end
+ end
end
class Numeric