mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FIX: support incoming emails with no subject
This commit is contained in:
parent
904e532439
commit
49d1f88f6e
4 changed files with 27 additions and 4 deletions
|
@ -47,6 +47,10 @@ en:
|
||||||
disable_remote_images_download_reason: "Remote images download was disabled because there wasn't enough disk space available."
|
disable_remote_images_download_reason: "Remote images download was disabled because there wasn't enough disk space available."
|
||||||
anonymous: "Anonymous"
|
anonymous: "Anonymous"
|
||||||
|
|
||||||
|
emails:
|
||||||
|
incoming:
|
||||||
|
default_subject: "Incoming email from %{email}"
|
||||||
|
|
||||||
errors: &errors
|
errors: &errors
|
||||||
format: ! '%{attribute} %{message}'
|
format: ! '%{attribute} %{message}'
|
||||||
messages:
|
messages:
|
||||||
|
|
|
@ -40,7 +40,7 @@ module Email
|
||||||
def find_or_create_incoming_email
|
def find_or_create_incoming_email
|
||||||
IncomingEmail.find_or_create_by(message_id: @mail.message_id) do |incoming_email|
|
IncomingEmail.find_or_create_by(message_id: @mail.message_id) do |incoming_email|
|
||||||
incoming_email.raw = @raw_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.from_address = @mail.from.first.downcase
|
||||||
incoming_email.to_addresses = @mail.to.map(&:downcase).join(";") if @mail.to.present?
|
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?
|
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
|
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)
|
message = SubscriptionMailer.send(action, user)
|
||||||
Email::Sender.new(message, :subscription).send
|
Email::Sender.new(message, :subscription).send
|
||||||
elsif post = find_related_post
|
elsif post = find_related_post
|
||||||
|
@ -73,14 +73,14 @@ module Email
|
||||||
case destination[:type]
|
case destination[:type]
|
||||||
when :group
|
when :group
|
||||||
group = destination[:obj]
|
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
|
when :category
|
||||||
category = destination[:obj]
|
category = destination[:obj]
|
||||||
|
|
||||||
raise StrangersNotAllowedError if user.staged? && !category.email_in_allow_strangers
|
raise StrangersNotAllowedError if user.staged? && !category.email_in_allow_strangers
|
||||||
raise InsufficientTrustLevelError if !user.has_trust_level?(SiteSetting.email_in_min_trust)
|
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
|
when :reply
|
||||||
email_log = destination[:obj]
|
email_log = destination[:obj]
|
||||||
|
|
||||||
|
@ -156,6 +156,10 @@ module Email
|
||||||
@from ||= @mail[:from].address_list.addresses.first
|
@from ||= @mail[:from].address_list.addresses.first
|
||||||
end
|
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)
|
def find_or_create_user(address_field)
|
||||||
# decode the address field
|
# decode the address field
|
||||||
address_field.decoded
|
address_field.decoded
|
||||||
|
|
|
@ -219,6 +219,7 @@ describe Email::Receiver do
|
||||||
expect { process(:encoded_display_name) }.to change(Topic, :count)
|
expect { process(:encoded_display_name) }.to change(Topic, :count)
|
||||||
|
|
||||||
topic = Topic.last
|
topic = Topic.last
|
||||||
|
expect(topic.title).to eq("I need help")
|
||||||
expect(topic.private_message?).to eq(true)
|
expect(topic.private_message?).to eq(true)
|
||||||
expect(topic.allowed_groups).to include(group)
|
expect(topic.allowed_groups).to include(group)
|
||||||
|
|
||||||
|
@ -228,6 +229,11 @@ describe Email::Receiver do
|
||||||
expect(user.name).to eq("Случайная Имя")
|
expect(user.name).to eq("Случайная Имя")
|
||||||
end
|
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
|
it "invites everyone in the chain but emails configured as 'incoming' (via reply, group or category)" do
|
||||||
expect { process(:cc) }.to change(Topic, :count)
|
expect { process(:cc) }.to change(Topic, :count)
|
||||||
emails = Topic.last.allowed_users.pluck(:email)
|
emails = Topic.last.allowed_users.pluck(:email)
|
||||||
|
|
9
spec/fixtures/emails/no_subject.eml
vendored
Normal file
9
spec/fixtures/emails/no_subject.eml
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
From: Some One <some@one.com>
|
||||||
|
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...
|
Loading…
Reference in a new issue