DEV: Update mail and use fork (#10639)

Version 2.8 brings some changes to how address fields are handled and
this commits updates that and should also include a fix which handles
encoded attachment filenames.

The fork contains a bugfix to correctly decode mail attachments.
This commit is contained in:
Bianca Nenciu 2021-02-18 20:15:02 +02:00 committed by GitHub
parent 447ea3f888
commit 3246c3cc92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 28 deletions

View File

@ -40,7 +40,7 @@ gem 'actionview_precompiler', require: false
gem 'seed-fu' gem 'seed-fu'
gem 'mail', require: false gem 'mail', git: 'https://github.com/discourse/mail.git', require: false
gem 'mini_mime' gem 'mini_mime'
gem 'mini_suffix' gem 'mini_suffix'

View File

@ -1,3 +1,10 @@
GIT
remote: https://github.com/discourse/mail.git
revision: 5b700fc95ee66378e0cf2559abc73c8bc3062a4b
specs:
mail (2.8.0.edge)
mini_mime (>= 0.1.1)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
@ -192,8 +199,6 @@ GEM
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
lru_redux (1.1.0) lru_redux (1.1.0)
lz4-ruby (0.3.3) lz4-ruby (0.3.3)
mail (2.7.1)
mini_mime (>= 0.1.1)
maxminddb (0.1.22) maxminddb (0.1.22)
memory_profiler (1.0.0) memory_profiler (1.0.0)
message_bus (3.3.4) message_bus (3.3.4)
@ -517,7 +522,7 @@ DEPENDENCIES
logster logster
lru_redux lru_redux
lz4-ruby lz4-ruby
mail mail!
maxminddb maxminddb
memory_profiler memory_profiler
message_bus message_bus

View File

@ -564,8 +564,7 @@ module Email
return unless mail[:from] return unless mail[:from]
if mail[:from].errors.blank? if mail[:from].errors.blank?
mail[:from].address_list.addresses.each do |address_field| mail[:from].each do |address_field|
address_field.decoded
from_address = address_field.address from_address = address_field.address
from_display_name = address_field.display_name.try(:to_s) from_display_name = address_field.display_name.try(:to_s)
return [from_address&.downcase, from_display_name&.strip] if from_address["@"] return [from_address&.downcase, from_display_name&.strip] if from_address["@"]
@ -1243,29 +1242,29 @@ module Email
def add_other_addresses(post, sender) def add_other_addresses(post, sender)
%i(to cc bcc).each do |d| %i(to cc bcc).each do |d|
if @mail[d] && @mail[d].address_list && @mail[d].address_list.addresses next if @mail[d].blank?
@mail[d].address_list.addresses.each do |address_field|
begin @mail[d].each do |address_field|
address_field.decoded begin
email = address_field.address.downcase address_field.decoded
display_name = address_field.display_name.try(:to_s) email = address_field.address.downcase
next unless email["@"] display_name = address_field.display_name.try(:to_s)
if should_invite?(email) next unless email["@"]
user = find_or_create_user(email, display_name) if should_invite?(email)
if user && can_invite?(post.topic, user) user = find_or_create_user(email, display_name)
post.topic.topic_allowed_users.create!(user_id: user.id) if user && can_invite?(post.topic, user)
TopicUser.auto_notification_for_staging(user.id, post.topic_id, TopicUser.notification_reasons[:auto_watch]) post.topic.topic_allowed_users.create!(user_id: user.id)
post.topic.add_small_action(sender, "invited_user", user.username, import_mode: @opts[:import_mode]) TopicUser.auto_notification_for_staging(user.id, post.topic_id, TopicUser.notification_reasons[:auto_watch])
end post.topic.add_small_action(sender, "invited_user", user.username, import_mode: @opts[:import_mode])
# cap number of staged users created per email end
if @staged_users.count > SiteSetting.maximum_staged_users_per_email # cap number of staged users created per email
post.topic.add_moderator_post(sender, I18n.t("emails.incoming.maximum_staged_user_per_email_reached"), import_mode: @opts[:import_mode]) if @staged_users.count > SiteSetting.maximum_staged_users_per_email
return post.topic.add_moderator_post(sender, I18n.t("emails.incoming.maximum_staged_user_per_email_reached"), import_mode: @opts[:import_mode])
end return
end end
rescue ActiveRecord::RecordInvalid, EmailNotAllowed
# don't care if user already allowed or the user's email address is not allowed
end end
rescue ActiveRecord::RecordInvalid, EmailNotAllowed
# don't care if user already allowed or the user's email address is not allowed
end end
end end
end end

View File

@ -646,6 +646,14 @@ describe Email::Receiver do
MD MD
end end
it "can decode attachments" do
SiteSetting.authorized_extensions = "pdf"
Fabricate(:group, incoming_email: "one@foo.com")
process(:encoded_filename)
expect(Upload.last.original_filename).to eq("This is a test.pdf")
end
context "when attachment is rejected" do context "when attachment is rejected" do
it "sends out the warning email" do it "sends out the warning email" do
expect { process(:attached_txt_file) }.to change { EmailLog.count }.by(1) expect { process(:attached_txt_file) }.to change { EmailLog.count }.by(1)

View File

@ -18,7 +18,7 @@ def EmailFabricator(options)
email += "Cc: #{options[:cc]}\n" if options[:cc] email += "Cc: #{options[:cc]}\n" if options[:cc]
email += "In-Reply-To: #{options[:in_reply_to]}\n" if options[:in_reply_to] email += "In-Reply-To: #{options[:in_reply_to]}\n" if options[:in_reply_to]
email += "References: #{options[:in_reply_to]}\n" if options[:in_reply_to] email += "References: #{options[:in_reply_to]}\n" if options[:in_reply_to]
email += "Message-ID: #{options[:message_id]}\n" if options[:message_id] email += "Message-ID: <#{options[:message_id]}>\n" if options[:message_id]
email += "Subject: #{options[:subject] || "This is a test email subhect"}\n" email += "Subject: #{options[:subject] || "This is a test email subhect"}\n"
email += "Mime-Version: 1.0\n" email += "Mime-Version: 1.0\n"
email += "Content-Type: #{options[:content_type] || "text/plain;\n charset=UTF-8"}\n" email += "Content-Type: #{options[:content_type] || "text/plain;\n charset=UTF-8"}\n"

Binary file not shown.