Aggiunge IMAP bounce e flag email non valide nel CRM.
Permette di leggere i bounce dalla stessa MailIdentity SMTP, aggiornare le email in anagrafica e saltare gli indirizzi invalidi nei mailing. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
require "test_helper"
|
||||
|
||||
class Mailings::ImapBounceReaderTest < ActiveSupport::TestCase
|
||||
test "parses aruba-style delivery failure from raw rfc822" do
|
||||
identity = create_mail_identity(
|
||||
from_email: "info@matchlivetv.it",
|
||||
smtp_username: "info@matchlivetv.it",
|
||||
smtp_host: "smtps.aruba.it",
|
||||
smtp_port: 465,
|
||||
encryption: "tls"
|
||||
)
|
||||
|
||||
raw = <<~EML
|
||||
From: mail-daemon@example.com
|
||||
To: info@matchlivetv.it
|
||||
Subject: Recapito fallito
|
||||
Date: Mon, 07 Sep 2026 08:14:05 +0200
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
|
||||
Delivery to the following recipients failed permanently:
|
||||
|
||||
* broken@club.it
|
||||
|
||||
Reason: 550 5.1.1 User unknown
|
||||
|
||||
Final-Recipient: rfc822; broken@club.it
|
||||
Diagnostic-Code: smtp; 550 5.1.1 User unknown
|
||||
|
||||
Subject: Più visibilità per ASD Test Club
|
||||
EML
|
||||
|
||||
reader = Mailings::ImapBounceReader.new(identity)
|
||||
parsed = reader.send(:parse_message, raw, uid: 42)
|
||||
assert_not_nil parsed
|
||||
assert_includes parsed[:failed_emails], "broken@club.it"
|
||||
assert_equal "ASD Test Club", parsed[:club_hint]
|
||||
assert_match(/550|User unknown/i, parsed[:reason].to_s)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user