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