summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>2012-11-21 05:37:22 +0000
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>2012-11-21 05:37:22 +0000
commit6740f441c4993259c69aa60a7d44ec8275941870 (patch)
tree116be10431723be5a1c0278d22693945f7020d9d /app/models
parentadcf54a92b13449709c2cdbe7914fed44ef68fc9 (diff)
downloadredmine-6740f441c4993259c69aa60a7d44ec8275941870.tar.gz
redmine-6740f441c4993259c69aa60a7d44ec8275941870.zip
fix non ASCII attachment filename encoding broken (MOJIBAKE) in receiving mail on Ruby 1.8 (#12399)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10852 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r--app/models/mail_handler.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index b6cb2ac47..b87fbeda4 100644
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -249,9 +249,26 @@ class MailHandler < ActionMailer::Base
def add_attachments(obj)
if email.attachments && email.attachments.any?
email.attachments.each do |attachment|
+ filename = attachment.filename
+ unless filename.respond_to?(:encoding)
+ # try to reencode to utf8 manually with ruby1.8
+ h = attachment.header['Content-Disposition']
+ unless h.nil?
+ begin
+ if m = h.value.match(/filename\*[0-9\*]*=([^=']+)'/)
+ filename = Redmine::CodesetUtil.to_utf8(filename, m[1])
+ elsif m = h.value.match(/filename=.*=\?([^\?]+)\?[BbQq]\?/)
+ # http://tools.ietf.org/html/rfc2047#section-4
+ filename = Redmine::CodesetUtil.to_utf8(filename, m[1])
+ end
+ rescue
+ # nop
+ end
+ end
+ end
obj.attachments << Attachment.create(:container => obj,
:file => attachment.decoded,
- :filename => attachment.filename,
+ :filename => filename,
:author => user,
:content_type => attachment.mime_type)
end