class Mail::Address

Overview

Mail::Address handles all email addresses in Mail. It takes an email address string and parses it, breaking it down into its component parts and allowing you to get the address, comments, display name, name, local part, domain part and fully formatted address.

Mail::Address requires a correctly formatted email address per RFC2822 or RFC822. It handles all obsolete versions including obsolete domain routing on the local part.

a = Address.new('Mikel Lindsaar (My email address) [email protected]') a.format #=> 'Mikel Lindsaar [email protected] (My email address)' a.address #=> '[email protected]' a.display_name #=> 'Mikel Lindsaar' a.local #=> 'mikel' a.domain #=> 'test.lindsaar.net' a.comments #=> ['My email address'] a.to_s #=> 'Mikel Lindsaar [email protected] (My email address)'

Defined in:

mail/elements/address.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(value = nil) #

[View source]

Instance Method Detail

def address(output_type = :decode) #

Returns the address that is in the address itself. That is, the local@domain string, without any angle brackets or the like.

a = Address.new('Mikel Lindsaar (My email address) [email protected]') a.address #=> '[email protected]'


[View source]
def address=(value) #

Provides a way to assign an address to an already made Mail::Address object.

a = Address.new a.address = 'Mikel Lindsaar (My email address) [email protected]' a.address #=> '[email protected]'


[View source]
def comments #

[View source]
def decoded #

[View source]
def display_name(output_type = :decode) #

Returns the display name of the email address passed in.

a = Address.new('Mikel Lindsaar (My email address) [email protected]') a.display_name #=> 'Mikel Lindsaar'


[View source]
def display_name=(str) #

Provides a way to assign a display name to an already made Mail::Address object.

a = Address.new a.address = '[email protected]' a.display_name = 'Mikel Lindsaar' a.format #=> 'Mikel Lindsaar [email protected]'


[View source]
def domain(output_type = :decode) #

Returns the domain part (the right hand side of the @ sign in the email address) of the address

a = Address.new('Mikel Lindsaar (My email address) [email protected]') a.domain #=> 'test.lindsaar.net'


[View source]
def encoded #

[View source]
def format(output_type = :decode) #

Returns a correctly formatted address for the email going out. If given an incorrectly formatted address as input, Mail::Address will do its best to format it correctly. This includes quoting display names as needed and putting the address in angle brackets etc.

a = Address.new('Mikel Lindsaar (My email address) [email protected]') a.format #=> 'Mikel Lindsaar [email protected] (My email address)'


[View source]
def group #

[View source]
def inspect #

Shows the Address object basic details, including the Address a = Address.new('Mikel (My email) [email protected]') a.inspect #=> "#<Mail::Address:14184910 Address: |Mikel [email protected] (My email)| >"


[View source]
def local(output_type = :decode) #

Returns the local part (the left hand side of the @ sign in the email address) of the address

a = Address.new('Mikel Lindsaar (My email address) [email protected]') a.local #=> 'mikel'


[View source]
def name #

Sometimes an address will not have a display name, but might have the name as a comment field after the address. This returns that name if it exists.

a = Address.new('[email protected] (Mikel Lindsaar)') a.name #=> 'Mikel Lindsaar'


[View source]
def raw #

Returns the raw input of the passed in string, this is before it is passed by the parser.


[View source]
def to_s #

Returns the format of the address, or returns nothing

a = Address.new('Mikel Lindsaar (My email address) [email protected]') a.format #=> 'Mikel Lindsaar [email protected] (My email address)'


[View source]