mail_new_activity: properly implement QP for email subjects
This commit is contained in:
parent
ffa1b879da
commit
28a6faab9d
|
@ -8,32 +8,14 @@ require APP_PATH
|
||||||
Rails.application.require_environment!
|
Rails.application.require_environment!
|
||||||
|
|
||||||
class String
|
class String
|
||||||
def force_to_ascii
|
|
||||||
# fixup some "smart" quotes and things instead of forcing them to "?" chars
|
|
||||||
gsub("\u201C", '"').
|
|
||||||
gsub("\u201D", '"').
|
|
||||||
gsub("\u2018", "'").
|
|
||||||
gsub("\u2019", "'").
|
|
||||||
gsub("\u2013", "-").
|
|
||||||
gsub("\u2014", "--").
|
|
||||||
gsub("\u2026", "...").
|
|
||||||
encode("us-ascii", :invalid => :replace, :undef => :replace,
|
|
||||||
:replace => "?")
|
|
||||||
end
|
|
||||||
|
|
||||||
def quoted_printable(encoded_word = false)
|
def quoted_printable(encoded_word = false)
|
||||||
s = ""
|
s = [ self ].pack("M")
|
||||||
if encoded_word
|
|
||||||
s << "=?UTF-8?Q?"
|
|
||||||
end
|
|
||||||
|
|
||||||
s << [ self ].pack("M")
|
|
||||||
|
|
||||||
if encoded_word
|
if encoded_word
|
||||||
s << "?="
|
s.split(/\r?\n/).map{|l| "=?UTF-8?Q?#{l.gsub(/=*$/, "")}?=" }.join("\n\t")
|
||||||
|
else
|
||||||
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
s
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# like ActionView::Helpers::TextHelper but preserve > and indentation when
|
# like ActionView::Helpers::TextHelper but preserve > and indentation when
|
||||||
|
@ -55,6 +37,16 @@ class String
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def story_subject(story, prefix = "")
|
||||||
|
ss = "#{prefix}#{story.title}"
|
||||||
|
|
||||||
|
story.tags.sort_by{|t| t.tag }.each do |t|
|
||||||
|
ss << " [#{t.tag}]"
|
||||||
|
end
|
||||||
|
|
||||||
|
ss.quoted_printable(true)
|
||||||
|
end
|
||||||
|
|
||||||
EMAIL_WIDTH = 72
|
EMAIL_WIDTH = 72
|
||||||
LAST_STORY_KEY = "mailing:last_story_id"
|
LAST_STORY_KEY = "mailing:last_story_id"
|
||||||
LAST_COMMENT_KEY = "mailing:last_comment_id"
|
LAST_COMMENT_KEY = "mailing:last_comment_id"
|
||||||
|
@ -103,9 +95,7 @@ Story.where("id > ? AND is_expired = ?", last_story_id, false).order(:id).each d
|
||||||
mail.puts "Content-Transfer-Encoding: quoted-printable"
|
mail.puts "Content-Transfer-Encoding: quoted-printable"
|
||||||
mail.puts "Message-ID: <#{s.mailing_list_message_id}>"
|
mail.puts "Message-ID: <#{s.mailing_list_message_id}>"
|
||||||
mail.puts "Date: " << s.created_at.strftime("%a, %d %b %Y %H:%M:%S %z")
|
mail.puts "Date: " << s.created_at.strftime("%a, %d %b %Y %H:%M:%S %z")
|
||||||
mail.puts "Subject: " << s.title.force_to_ascii <<
|
mail.puts "Subject: " << story_subject(s)
|
||||||
s.tags.sort_by{|t| t.tag }.map{|t| " [#{t.tag}]" }.join
|
|
||||||
|
|
||||||
mail.puts ""
|
mail.puts ""
|
||||||
|
|
||||||
body = []
|
body = []
|
||||||
|
@ -221,9 +211,7 @@ last_comment_id, false, false).order(:id).each do |c|
|
||||||
end
|
end
|
||||||
|
|
||||||
mail.puts "Date: " << c.created_at.strftime("%a, %d %b %Y %H:%M:%S %z")
|
mail.puts "Date: " << c.created_at.strftime("%a, %d %b %Y %H:%M:%S %z")
|
||||||
mail.puts "Subject: Re: " << c.story.title.force_to_ascii <<
|
mail.puts "Subject: " << story_subject(c.story, "Re: ")
|
||||||
c.story.tags.sort_by{|t| t.tag }.map{|t| " [#{t.tag}]" }.join
|
|
||||||
|
|
||||||
mail.puts ""
|
mail.puts ""
|
||||||
|
|
||||||
body = []
|
body = []
|
||||||
|
|
Loading…
Reference in a new issue