diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 2418a02b92e..37d4855d1da 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -47,6 +47,10 @@ en: disable_remote_images_download_reason: "Remote images download was disabled because there wasn't enough disk space available." anonymous: "Anonymous" + emails: + incoming: + default_subject: "Incoming email from %{email}" + errors: &errors format: ! '%{attribute} %{message}' messages: diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 454dbdf54b3..50cc7998fb8 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -40,7 +40,7 @@ module Email def find_or_create_incoming_email IncomingEmail.find_or_create_by(message_id: @mail.message_id) do |incoming_email| incoming_email.raw = @raw_email - incoming_email.subject = @mail.subject + incoming_email.subject = subject incoming_email.from_address = @mail.from.first.downcase incoming_email.to_addresses = @mail.to.map(&:downcase).join(";") if @mail.to.present? incoming_email.cc_addresses = @mail.cc.map(&:downcase).join(";") if @mail.cc.present? @@ -60,7 +60,7 @@ module Email raise InactiveUserError if !user.active && !user.staged - if action = subscription_action_for(body, @mail.subject) + if action = subscription_action_for(body, subject) message = SubscriptionMailer.send(action, user) Email::Sender.new(message, :subscription).send elsif post = find_related_post @@ -73,14 +73,14 @@ module Email case destination[:type] when :group group = destination[:obj] - create_topic(user: user, raw: body, title: @mail.subject, archetype: Archetype.private_message, target_group_names: [group.name], skip_validations: true) + create_topic(user: user, raw: body, title: subject, archetype: Archetype.private_message, target_group_names: [group.name], skip_validations: true) when :category category = destination[:obj] raise StrangersNotAllowedError if user.staged? && !category.email_in_allow_strangers raise InsufficientTrustLevelError if !user.has_trust_level?(SiteSetting.email_in_min_trust) - create_topic(user: user, raw: body, title: @mail.subject, category: category.id) + create_topic(user: user, raw: body, title: subject, category: category.id) when :reply email_log = destination[:obj] @@ -156,6 +156,10 @@ module Email @from ||= @mail[:from].address_list.addresses.first end + def subject + @suject ||= @mail.subject.presence || I18n.t("emails.incoming.default_subject", email: @mail.from.first.downcase) + end + def find_or_create_user(address_field) # decode the address field address_field.decoded diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index b07c70dc2e0..36121204c21 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -219,6 +219,7 @@ describe Email::Receiver do expect { process(:encoded_display_name) }.to change(Topic, :count) topic = Topic.last + expect(topic.title).to eq("I need help") expect(topic.private_message?).to eq(true) expect(topic.allowed_groups).to include(group) @@ -228,6 +229,11 @@ describe Email::Receiver do expect(user.name).to eq("Случайная Имя") end + it "handles email with no subject" do + expect { process(:no_subject) }.to change(Topic, :count) + expect(Topic.last.title).to eq("Incoming email from some@one.com") + end + it "invites everyone in the chain but emails configured as 'incoming' (via reply, group or category)" do expect { process(:cc) }.to change(Topic, :count) emails = Topic.last.allowed_users.pluck(:email) diff --git a/spec/fixtures/emails/no_subject.eml b/spec/fixtures/emails/no_subject.eml new file mode 100644 index 00000000000..5804109647f --- /dev/null +++ b/spec/fixtures/emails/no_subject.eml @@ -0,0 +1,9 @@ +From: Some One +To: team@bar.com +Date: Mon, 1 Feb 2016 00:12:43 +0100 +Message-ID: <40@foo.bar.mail> +Mime-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: quoted-printable + +This is an email with no subject...