diff --git a/Changelog.md b/Changelog.md index 42ed5ff94..aabc68a3b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -59,6 +59,7 @@ We use yarn to install the frontend dependencies now, so you need to have that i * Escape mentions before markdown parsing in mobile UI [#8398](https://github.com/diaspora/diaspora/pull/8398) * Cleanup duplicate pods in database [#8403](https://github.com/diaspora/diaspora/pull/8403) * Fix scrolling issue after closing photo viewer on photos page [#8404](https://github.com/diaspora/diaspora/pull/8404) +* Filter unicode emojis from email headers [#8421](https://github.com/diaspora/diaspora/pull/8421) ## Features * Add client-side cropping of profile image uploads [#7581](https://github.com/diaspora/diaspora/pull/7581) diff --git a/app/mailers/notification_mailers/base.rb b/app/mailers/notification_mailers/base.rb index 7b2a6135c..c19c6bd71 100644 --- a/app/mailers/notification_mailers/base.rb +++ b/app/mailers/notification_mailers/base.rb @@ -36,15 +36,23 @@ module NotificationMailers def default_headers from_name = AppConfig.settings.pod_name - from_name += " (#{@sender.profile.full_name.empty? ? @sender.username : @sender.name})" if @sender.present? + from_name += " (#{person_name(@sender)})" if @sender.present? { from: name_and_address(from_name, AppConfig.mail.sender_address), - to: name_and_address(@recipient.name, @recipient.email), + to: name_and_address(person_name(@recipient), @recipient.email), template_name: self.class.name.demodulize.underscore } end + def person_name(person) + if person.profile.full_name.empty? + person.username + else + person.name.gsub(/\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Presentation}/, "").strip + end + end + def with_recipient_locale(&block) I18n.with_locale(@recipient.language, &block) end diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index a4e79e631..ead4a115a 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -262,6 +262,11 @@ describe Notifier, type: :mailer do expect(@mail["From"].to_s).to eq("\"#{pod_name} (#{@cnv.author.name})\" <#{AppConfig.mail.sender_address}>") end + it "FROM: removes emojis from sender's name" do + bob.person.profile.update!(first_name: "1️⃣2️3️⃣ Numbers 123", last_name: "👍✅👍🏻Emojis😀😇❄️") + expect(@mail["From"].to_s).to eq("\"#{pod_name} (Numbers 123 Emojis)\" <#{AppConfig.mail.sender_address}>") + end + it "should use a generic subject" do expect(@mail.subject).to eq(I18n.translate("notifier.private_message.subject")) end @@ -302,6 +307,12 @@ describe Notifier, type: :mailer do expect(comment_mail["From"].to_s).to eq("\"#{pod_name} (#{eve.name})\" <#{AppConfig.mail.sender_address}>") end + it "FROM: removes emojis from sender's name" do + eve.person.profile.update!(first_name: "1️⃣2️3️⃣ Numbers 123", last_name: "👍✅👍🏻Emojis😀😇❄️") + expect(comment_mail["From"].to_s) + .to eq("\"#{pod_name} (Numbers 123 Emojis)\" <#{AppConfig.mail.sender_address}>") + end + it "SUBJECT: has a snippet of the post contents, without markdown and without newlines" do expect(comment_mail.subject).to eq("Re: Headline") end @@ -390,6 +401,11 @@ describe Notifier, type: :mailer do expect(mail["From"].to_s).to eq("\"#{pod_name} (#{bob.name})\" <#{AppConfig.mail.sender_address}>") end + it "FROM: removes emojis from sender's name" do + bob.person.profile.update!(first_name: "1️⃣2️3️⃣ Numbers 123", last_name: "👍✅👍🏻Emojis😀😇❄️") + expect(mail["From"].to_s).to eq("\"#{pod_name} (Numbers 123 Emojis)\" <#{AppConfig.mail.sender_address}>") + end + it "SUBJECT: does not show the limited post" do expect(mail.subject).not_to include("Limited headline") end @@ -415,6 +431,11 @@ describe Notifier, type: :mailer do expect(mail["From"].to_s).to eq("\"#{pod_name} (#{bob.name})\" <#{AppConfig.mail.sender_address}>") end + it "FROM: removes emojis from sender's name" do + bob.person.profile.update!(first_name: "1️⃣2️3️⃣ Numbers 123", last_name: "👍✅👍🏻Emojis😀😇❄️") + expect(mail["From"].to_s).to eq("\"#{pod_name} (Numbers 123 Emojis)\" <#{AppConfig.mail.sender_address}>") + end + it "SUBJECT: does not show the limited post" do expect(mail.subject).not_to include("Limited headline") end @@ -446,6 +467,11 @@ describe Notifier, type: :mailer do expect(mail["From"].to_s).to eq("\"#{pod_name} (#{bob.name})\" <#{AppConfig.mail.sender_address}>") end + it "FROM: removes emojis from sender's name" do + bob.person.profile.update!(first_name: "1️⃣2️3️⃣ Numbers 123", last_name: "👍✅👍🏻Emojis😀😇❄️") + expect(mail["From"].to_s).to eq("\"#{pod_name} (Numbers 123 Emojis)\" <#{AppConfig.mail.sender_address}>") + end + it "SUBJECT: does not show the limited post" do expect(mail.subject).not_to include("Limited headline") end