mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FIX: don't process the same incoming email more than once
This commit is contained in:
parent
13e489b4ca
commit
4fb335f1f0
2 changed files with 18 additions and 9 deletions
|
@ -41,8 +41,9 @@ module Email
|
|||
return if is_blacklisted?
|
||||
DistributedMutex.synchronize(@message_id) do
|
||||
begin
|
||||
return if IncomingEmail.exists?(message_id: @message_id)
|
||||
@from_email, @from_display_name = parse_from_field(@mail)
|
||||
@incoming_email = find_or_create_incoming_email
|
||||
@incoming_email = create_incoming_email
|
||||
process_internal
|
||||
rescue => e
|
||||
@incoming_email.update_columns(error: e.to_s) if @incoming_email
|
||||
|
@ -56,14 +57,15 @@ module Email
|
|||
Regexp.new(SiteSetting.ignore_by_title) =~ @mail.subject
|
||||
end
|
||||
|
||||
def find_or_create_incoming_email
|
||||
IncomingEmail.find_or_create_by(message_id: @message_id) do |ie|
|
||||
ie.raw = @raw_email
|
||||
ie.subject = subject
|
||||
ie.from_address = @from_email
|
||||
ie.to_addresses = @mail.to.map(&:downcase).join(";") if @mail.to.present?
|
||||
ie.cc_addresses = @mail.cc.map(&:downcase).join(";") if @mail.cc.present?
|
||||
end
|
||||
def create_incoming_email
|
||||
IncomingEmail.create(
|
||||
message_id: @message_id,
|
||||
raw: @raw_email,
|
||||
subject: subject,
|
||||
from_address: @from_email,
|
||||
to_addresses: @mail.to&.map(&:downcase)&.join(";"),
|
||||
cc_addresses: @mail.cc&.map(&:downcase)&.join(";"),
|
||||
)
|
||||
end
|
||||
|
||||
def process_internal
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue