aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2014-07-10 13:40:22 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2014-07-10 13:40:22 +0100
commit4833e4a06086a81841b31a2eb62e0cdddaea50af (patch)
tree8aeb04c381f699edaf61cfacc24e73f5c15d5df6 /lib
parentceb8199f922c8e56713ed6c73e051ebb0d649d1d (diff)
Tidied up iconv for ruby1.9
Diffstat (limited to 'lib')
-rw-r--r--lib/mauve/sender.rb23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/mauve/sender.rb b/lib/mauve/sender.rb
index fc12a99..c54cb0b 100644
--- a/lib/mauve/sender.rb
+++ b/lib/mauve/sender.rb
@@ -8,7 +8,7 @@ rescue LoadError
end
begin
- require 'iconv'
+ require 'iconv' unless String.new.respond_to?(:encode)
rescue LoadError
# Do nothing -- these are bonus libraries :)
end
@@ -165,7 +165,16 @@ module Mauve
#
# Make sure all string fields are UTF8 -- to ensure the maximal amount of information is sent.
#
- update.__send__("#{field.name}=", Iconv.conv("UTF-8//IGNORE", from_charset, value)) if value.is_a?(String) and defined?(Iconv)
+ if value.is_a?(String)
+ if value.respond_to?(:encode)
+ value = value.encode("UTF-8", :undef => :replace, :invalid => :replace)
+ elsif defined? Iconv
+ value = Iconv.conv("UTF-8//IGNORE", from_charset, value)
+ end
+
+ update.__send__("#{field.name}=", value)
+ end
+
end
update.alert.each do |alert|
@@ -178,7 +187,15 @@ module Mauve
#
# Make sure all string fields are UTF8 -- to ensure the maximal amount of information is sent.
#
- alert.__send__("#{field.name}=", Iconv.conv("UTF-8//IGNORE", from_charset, value)) if value.is_a?(String) and defined?(Iconv)
+ if value.is_a?(String)
+ if value.respond_to?(:encode)
+ value = value.encode("UTF-8", :undef => :replace, :invalid => :replace)
+ elsif defined? Iconv
+ value = Iconv.conv("UTF-8//IGNORE", from_charset, value)
+ end
+
+ alert.__send__("#{field.name}=", value)
+ end
end
end