52 lines
1.6 KiB
Ruby
52 lines
1.6 KiB
Ruby
require "test_helper"
|
|
require "protocols"
|
|
|
|
module Protocols
|
|
class MailTest < Minitest::Test
|
|
def setup
|
|
@headers = <<~MAILEND
|
|
From: SenderH <sender@head.local>\r
|
|
To: DestH <dest@head.local>\r
|
|
Subject: -subject.head-\r
|
|
Date: #{DateTime.parse('2022-02-03T12:30:00Z').strftime(Protocols::Mail::DATE_FORMAT)}\r
|
|
Content-Type: plain/text\r
|
|
User-Agent: minitest\r
|
|
MAILEND
|
|
@imap_mail = OpenStruct.new(
|
|
attr: {
|
|
Protocols::ENVELOPE => OpenStruct.new(
|
|
from: [OpenStruct.new(mailbox: "sender", host: "local", name: "Sender")],
|
|
to: [OpenStruct.new(mailbox: "dest", host: "local", name: "Dest")],
|
|
subject: "-subject-",
|
|
),
|
|
Protocols::HEADERS => @headers,
|
|
Protocols::BODYTEXT => "Content of the mail",
|
|
},
|
|
)
|
|
super
|
|
end
|
|
|
|
def test_parse_rfc822_headers
|
|
h1 = Mail.parse_rfc822_headers("Key: Value\r\n")
|
|
assert_equal 1, h1.size
|
|
h1.each { |tuple| assert_equal 2, tuple.size }
|
|
assert_equal "Key", h1.first.first
|
|
assert_equal "Value", h1.first.last
|
|
|
|
h2 = Mail.parse_rfc822_headers("Key: Value\r\n\tPartTwo\r\n")
|
|
assert_equal 1, h2.size
|
|
h2.each { |tuple| assert_equal 2, tuple.size }
|
|
assert_equal "Value\r\n\tPartTwo", h2.first.last
|
|
end
|
|
|
|
def test_init_with_imap_mail
|
|
mail = Mail.new(imap_mail: @imap_mail)
|
|
assert_equal "Sender", mail.from_name
|
|
assert_equal "sender@local", mail.from
|
|
assert_equal "Dest", mail.to_name
|
|
assert_equal "dest@local", mail.to
|
|
assert_equal "SenderH <sender@head.local>", mail.header("From")
|
|
end
|
|
end
|
|
end
|