Merge pull request #8421 from SuperTux88/cleanup-from-header-unicode-emojis

Cleanup unicode emojis from email headers
This commit is contained in:
Benjamin Neff 2023-06-10 17:25:54 +02:00
commit 02182e3b59
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
3 changed files with 37 additions and 2 deletions

View file

@ -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)

View file

@ -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

View file

@ -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⃣23⃣ 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⃣23⃣ 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⃣23⃣ 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⃣23⃣ 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⃣23⃣ 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