aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-03-23 12:24:11 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-03-23 12:24:11 +0000
commite7fe15fbac906d17c1e8b93659396adbd150c5cd (patch)
tree8bb5d6a82334cc22568e4cd0e55ed54560c38cab /actionmailer/lib
parent3306813be1efaa6f696142cd3977c25d09317875 (diff)
downloadrails-e7fe15fbac906d17c1e8b93659396adbd150c5cd.tar.gz
rails-e7fe15fbac906d17c1e8b93659396adbd150c5cd.tar.bz2
rails-e7fe15fbac906d17c1e8b93659396adbd150c5cd.zip
Added rescue for missing iconv library and throws warnings if subject/body is called on a TMail object without it instead
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@987 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer/lib')
-rw-r--r--actionmailer/lib/action_mailer/vendor/tmail/quoting.rb143
1 files changed, 80 insertions, 63 deletions
diff --git a/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb b/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb
index c060863db5..f4f2463e34 100644
--- a/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb
+++ b/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb
@@ -1,83 +1,100 @@
-require 'iconv'
-require 'base64'
+begin
+ require 'iconv'
+ require 'base64'
-module TMail
- class Mail
- def subject(to_charset = 'utf-8')
- Unquoter.unquote_and_convert_to(quoted_subject, to_charset)
- end
+ module TMail
+ class Mail
+ def subject(to_charset = 'utf-8')
+ Unquoter.unquote_and_convert_to(quoted_subject, to_charset)
+ end
- def unquoted_body(to_charset = 'utf-8')
- Unquoter.unquote_and_convert_to(quoted_body, to_charset, header["content-type"]["charset"])
- end
+ def unquoted_body(to_charset = 'utf-8')
+ Unquoter.unquote_and_convert_to(quoted_body, to_charset, header["content-type"]["charset"])
+ end
- def body(to_charset = 'utf-8', &block)
- attachment_presenter = block || Proc.new { |file_name| "Attachment: #{file_name}\n" }
+ def body(to_charset = 'utf-8', &block)
+ attachment_presenter = block || Proc.new { |file_name| "Attachment: #{file_name}\n" }
- if multipart?
- parts.collect { |part|
- part.header["content-type"].main_type == "text" ?
- part.unquoted_body(to_charset) :
- attachment_presenter.call(part.header["content-type"].params["name"])
- }.join
- else
- unquoted_body(to_charset)
+ if multipart?
+ parts.collect { |part|
+ part.header["content-type"].main_type == "text" ?
+ part.unquoted_body(to_charset) :
+ attachment_presenter.call(part.header["content-type"].params["name"])
+ }.join
+ else
+ unquoted_body(to_charset)
+ end
end
end
- end
- class Unquoter
- class << self
- def unquote_and_convert_to(text, to_charset, from_charset = "iso-8859-1")
- return "" if text.nil?
- if text =~ /^=\?(.*?)\?(.)\?(.*)\?=$/
- from_charset = $1
- quoting_method = $2
- text = $3
- case quoting_method
- when "Q" then
- unquote_quoted_printable_and_convert_to(text, from_charset, to_charset)
- when "B" then
- unquote_base64_and_convert_to(text, from_charset, to_charset)
- else
- raise "unknown quoting method #{quoting_method.inspect}"
+ class Unquoter
+ class << self
+ def unquote_and_convert_to(text, to_charset, from_charset = "iso-8859-1")
+ return "" if text.nil?
+ if text =~ /^=\?(.*?)\?(.)\?(.*)\?=$/
+ from_charset = $1
+ quoting_method = $2
+ text = $3
+ case quoting_method
+ when "Q" then
+ unquote_quoted_printable_and_convert_to(text, from_charset, to_charset)
+ when "B" then
+ unquote_base64_and_convert_to(text, from_charset, to_charset)
+ else
+ raise "unknown quoting method #{quoting_method.inspect}"
+ end
+ else
+ unquote_quoted_printable_and_convert_to(text, from_charset, to_charset)
end
- else
- unquote_quoted_printable_and_convert_to(text, from_charset, to_charset)
end
- end
- def unquote_quoted_printable_and_convert_to(text, from, to)
- text ? Iconv.iconv(to, from || "ISO-8859-1", text.gsub(/_/," ").unpack("M*").first).first : ""
- end
+ def unquote_quoted_printable_and_convert_to(text, from, to)
+ text ? Iconv.iconv(to, from || "ISO-8859-1", text.gsub(/_/," ").unpack("M*").first).first : ""
+ end
- def unquote_base64_and_convert_to(text, from, to)
- text ? Iconv.iconv(to, from || "ISO-8859-1", Base64.decode64(text)).first : ""
+ def unquote_base64_and_convert_to(text, from, to)
+ text ? Iconv.iconv(to, from || "ISO-8859-1", Base64.decode64(text)).first : ""
+ end
end
end
end
-end
-if __FILE__ == $0
- require 'test/unit'
+ if __FILE__ == $0
+ require 'test/unit'
- class TC_Unquoter < Test::Unit::TestCase
- def test_unquote_quoted_printable
- a ="=?ISO-8859-1?Q?[166417]_Bekr=E6ftelse_fra_Rejsefeber?="
- b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8')
- assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b
- end
+ class TC_Unquoter < Test::Unit::TestCase
+ def test_unquote_quoted_printable
+ a ="=?ISO-8859-1?Q?[166417]_Bekr=E6ftelse_fra_Rejsefeber?="
+ b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8')
+ assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b
+ end
- def test_unquote_base64
- a ="=?ISO-8859-1?B?WzE2NjQxN10gQmVrcuZmdGVsc2UgZnJhIFJlanNlZmViZXI=?="
- b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8')
- assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b
- end
+ def test_unquote_base64
+ a ="=?ISO-8859-1?B?WzE2NjQxN10gQmVrcuZmdGVsc2UgZnJhIFJlanNlZmViZXI=?="
+ b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8')
+ assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b
+ end
- def test_unquote_without_charset
- a ="[166417]_Bekr=E6ftelse_fra_Rejsefeber"
- b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8')
- assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b
+ def test_unquote_without_charset
+ a ="[166417]_Bekr=E6ftelse_fra_Rejsefeber"
+ b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8')
+ assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b
+ end
+ end
+ end
+rescue LoadError => e
+ # Not providing quoting support
+ module TMail
+ class Mail
+ def subject
+ warn "Action Mailer: iconv couldn't be required, so the charset conversion is skipped"
+ quoted_subject
+ end
+
+ def body
+ warn "Action Mailer: iconv couldn't be required, so the charset conversion is skipped"
+ quoted_body
+ end
end
end
-end
+end \ No newline at end of file