commit 1e1256182f8c9d3be51903b3db956bc19d1a04ed
parent 582e97faf70e41caa65109ac8bdc1c7ecdecd718
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date: Sun, 7 Mar 2010 13:18:43 -0800
Merge branch 'fix-utf8'
Diffstat:
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/lib/sup/account.rb b/lib/sup/account.rb
@@ -50,6 +50,8 @@ class AccountManager
end
hash[:alternates] ||= []
+ [:name, :signature].each { |x| hash[x].force_encoding Encoding::UTF_8 if hash[x].respond_to? :encoding }
+
a = Account.new hash
@accounts[a] = true
diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
@@ -612,7 +612,7 @@ EOS
tf.deactivate
draw_screen :sync => false, :status => status, :title => title
end
- tf.value
+ tf.value.tap { |x| x.force_encoding Encoding::UTF_8 if x && x.respond_to?(:encoding) }
end
def ask_getch question, accept=nil
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
@@ -218,7 +214,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
@@ -227,7 +223,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
@@ -333,6 +333,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