mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 06:33:38 +08:00
64ba5b1d21
Fixes a rare race condition causing the `Imap::Sync` class to create an incoming email and associated post/topic, which then kicks off the PostAlerter to notify others in the PM about a reply in the topic, but for the OP which is not necessary (because the person emailing the IMAP inbox already knows about the OP). Basically, we should never be sending the group SMTP email for the first post in a topic. Also in this PR: * Custom attribute accessors for the to/from/cc addresses on `IncomingEmail`, to parse them from an array to a joined string so the logic for this is only in one place. * Store extra detail against the `IncomingEmail` created in `GroupSmtpMailer` * regex test Mail header Reply-To as string instead of Field, which fixes `warning: deprecated Object#=~ is called on Mail::Field; it always returns nil` * Add DEBUG_IMAP to log all IMAP logs as warnings for easier debugging * Changed the Rails logging to `ImapSyncLog` in the `GroupSmtpMailer`
60 lines
1.6 KiB
Ruby
60 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class ImapSyncLog < ActiveRecord::Base
|
|
RETAIN_LOGS_DAYS ||= 5
|
|
|
|
belongs_to :group
|
|
|
|
def self.levels
|
|
@levels ||= Enum.new(:debug, :info, :warn, :error)
|
|
end
|
|
|
|
def self.log(message, level, group_id = nil)
|
|
now = Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")
|
|
new_log = create(message: message, level: ImapSyncLog.levels[level], group_id: group_id)
|
|
if ENV["DEBUG_IMAP"]
|
|
Rails.logger.send(:warn, "#{level[0].upcase}, [#{now}] [IMAP] (group_id #{group_id}) #{message}")
|
|
else
|
|
Rails.logger.send(level, "#{level[0].upcase}, [#{now}] [IMAP] (group_id #{group_id}) #{message}")
|
|
end
|
|
new_log
|
|
end
|
|
|
|
def self.debug(message, group_or_id)
|
|
group_id = group_or_id.is_a?(Integer) ? group_or_id : group_or_id.id
|
|
log(message, :debug, group_id)
|
|
end
|
|
|
|
def self.info(message, group_or_id)
|
|
group_id = group_or_id.is_a?(Integer) ? group_or_id : group_or_id.id
|
|
log(message, :info, group_id)
|
|
end
|
|
|
|
def self.warn(message, group_or_id)
|
|
group_id = group_or_id.is_a?(Integer) ? group_or_id : group_or_id.id
|
|
log(message, :warn, group_id)
|
|
end
|
|
|
|
def self.error(message, group_or_id)
|
|
group_id = group_or_id.is_a?(Integer) ? group_or_id : group_or_id.id
|
|
log(message, :error, group_id)
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: imap_sync_logs
|
|
#
|
|
# id :bigint not null, primary key
|
|
# level :integer not null
|
|
# message :string not null
|
|
# group_id :bigint
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_imap_sync_logs_on_group_id (group_id)
|
|
# index_imap_sync_logs_on_level (level)
|
|
#
|