mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: process all incoming email's destinations instead of only the first
This commit is contained in:
parent
a21d52951a
commit
323bd555c0
@ -94,45 +94,19 @@ module Email
|
|||||||
topic: post.topic,
|
topic: post.topic,
|
||||||
skip_validations: user.staged?)
|
skip_validations: user.staged?)
|
||||||
else
|
else
|
||||||
destination = destinations.first
|
first_exception = nil
|
||||||
|
|
||||||
raise BadDestinationAddress if destination.blank?
|
destinations.each do |destination|
|
||||||
|
begin
|
||||||
case destination[:type]
|
process_destination(destination, user, body)
|
||||||
when :group
|
rescue => e
|
||||||
group = destination[:obj]
|
first_exception ||= e
|
||||||
create_topic(user: user,
|
else
|
||||||
raw: body,
|
return
|
||||||
title: subject,
|
|
||||||
archetype: Archetype.private_message,
|
|
||||||
target_group_names: [group.name],
|
|
||||||
is_group_message: true,
|
|
||||||
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: subject,
|
|
||||||
category: category.id,
|
|
||||||
skip_validations: user.staged?)
|
|
||||||
|
|
||||||
when :reply
|
|
||||||
email_log = destination[:obj]
|
|
||||||
|
|
||||||
if email_log.user_id != user.id
|
|
||||||
raise ReplyUserNotMatchingError, "email_log.user_id => #{email_log.user_id.inspect}, user.id => #{user.id.inspect}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
create_reply(user: user,
|
|
||||||
raw: body,
|
|
||||||
post: email_log.post,
|
|
||||||
topic: email_log.post.topic)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
raise first_exception || BadDestinationAddress
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -340,6 +314,44 @@ module Email
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def process_destination(destination, user, body)
|
||||||
|
case destination[:type]
|
||||||
|
when :group
|
||||||
|
group = destination[:obj]
|
||||||
|
create_topic(user: user,
|
||||||
|
raw: body,
|
||||||
|
title: subject,
|
||||||
|
archetype: Archetype.private_message,
|
||||||
|
target_group_names: [group.name],
|
||||||
|
is_group_message: true,
|
||||||
|
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: subject,
|
||||||
|
category: category.id,
|
||||||
|
skip_validations: user.staged?)
|
||||||
|
|
||||||
|
when :reply
|
||||||
|
email_log = destination[:obj]
|
||||||
|
|
||||||
|
if email_log.user_id != user.id
|
||||||
|
raise ReplyUserNotMatchingError, "email_log.user_id => #{email_log.user_id.inspect}, user.id => #{user.id.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
|
create_reply(user: user,
|
||||||
|
raw: body,
|
||||||
|
post: email_log.post,
|
||||||
|
topic: email_log.post.topic)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def reply_by_email_address_regex
|
def reply_by_email_address_regex
|
||||||
@reply_by_email_address_regex ||= begin
|
@reply_by_email_address_regex ||= begin
|
||||||
reply_addresses = [
|
reply_addresses = [
|
||||||
|
Loading…
Reference in New Issue
Block a user