32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/smailer/models/finished_mail.rb', line 32
def self.add(queued_mail, status = Statuses::SENT, update_sent_mails_count = true)
finished = self.new
fields_to_copy = [:mail_campaign_id, :key, :from, :to, :subject, :retries, :last_retry_at, :last_error]
fields_to_copy += [:body_html, :body_text] if Smailer::Models::Property.get_boolean('finished_mails.preserve_body')
fields_to_copy.each do |field|
finished.send("#{field}=", queued_mail.send(field))
end
finished.status = status
finished.sent_at = Time.now if status == Statuses::SENT
finished.save!
queued_mail.destroy
queued_mail.delete
if update_sent_mails_count && finished.mail_campaign
finished.mail_campaign.sent_mails_count += 1
Compatibility.save_without_validation finished.mail_campaign
end
finished
end
|