module Mail::CheckDeliveryParams
def check(mail)
def check(mail) envelope = Mail::SmtpEnvelope.new(mail) [ envelope.from, envelope.to, envelope.message ] end
def check_addr(addr_name, addr)
def check_addr(addr_name, addr) mail = Mail.new(from: 'deprecated@example.com', to: 'deprecated@example.com') Mail::SmtpEnvelope.new(mail).send(:validate_addr, addr_name, addr) end
def check_from(addr)
def check_from(addr) mail = Mail.new(from: 'deprecated@example.com', to: 'deprecated@example.com') Mail::SmtpEnvelope.new(mail).send(:validate_addr, 'From', addr) end
def check_message(message)
def check_message(message) message = message.encoded if message.respond_to?(:encoded) if Utilities.blank?(message) raise ArgumentError, 'An encoded message is required to send an email' end message end
def check_to(addrs)
def check_to(addrs) mail = Mail.new(from: 'deprecated@example.com', to: 'deprecated@example.com') Array(addrs).map do |addr| Mail::SmtpEnvelope.new(mail).send(:validate_addr, 'To', addr) end end
def validate_smtp_addr(addr)
def validate_smtp_addr(addr) if addr if addr.bytesize > 2048 yield 'may not exceed 2kB' end if /[\r\n]/ =~ addr yield 'may not contain CR or LF line breaks' end end addr end