Class: RMail::Address

Class | RMail::Address
In: | lib/rmail/address.rb
Parent: | Object

This class provides the following functionality:

- Parses RFC2822 address lists into a list of Address objects (see parse).
- Format Address objects as appropriate for insertion into email messages (see format).
- Allows manipulation of the various parts of the address (see local=, domain=, display_name=, comments=).

### Methods

<=> address comments comments= display_name display_name= domain domain= eql? format hash local local= name new parse to_str

### Included Modules

Comparable

### Classes and Modules

Class RMail::Address::List
Class RMail::Address::Parser

### Constants

ATEXT | = | '[\w=!#$%&\'*+-?^\`{|}~]+'

### Public Class methods

new(string = nil)

Create a new address. If the `string` argument is not nil, it is parsed for mail addresses and if one is found, it is used to initialize this object.

parse(string)

Given a string, this function attempts to extract mailing addresses from it and returns an RMail::Address::List of those addresses (RMail::Address::List is a subclass of Array).

This is identical to using a RMail::Address::Parser directly like this:

     RMail::Address::Parser.new(string).parse

### Public Instance methods

<=>(other)

Compare this address with another based on the email address portion only (any display name and comments are ignored). If the other object is not an RMail::Address, it is coerced into a string with its to_str method and then parsed into an RMail::Address object.

address()

Returns the email address portion of the address (i.e. without a display name, angle addresses, or comments).

The string returned is not suitable for insertion into an e-mail. RFC2822 quoting rules are not followed. The raw address is returned instead.

For example, if the local part requires quoting, this function will not perform the quoting (see format for that). So this function can returns strings such as:

     "address with no quoting@example.net"

See also format

comments()

Returns the comments in this address as an array of strings.

comments=(comments)

Set the comments for this address. The `comments` argument can be a string, or an array of strings. In either case, any existing comments are replaced.

See also comments, name

display_name()

Returns the display name of this address. The display name is present only for "angle addr" style addresses such as:

      John Doe <johnd@example.net>

In this case, the display name will be "John Doe". In particular this old style address has no display name:

      bobs@example.net (Bob Smith)

See also display_name=, name

display_name=(str)

Assign a display name to this address. See display_name for a definition of what this is.

See also display_name

domain()

Retrieve to the domain portion of the mail address. This is the portion after the `@` sign.

domain=(domain)

Assign a domain name to this address. This is the portion after the `@` sign. Any existing domain name will be changed.

eql?(other)

Return true if the two objects are equal. Do this based solely on the email address portion (any display name and comments are ignored). Fails if the other object is not an RMail::Address object.

format()

Return this address as a String formated as appropriate for insertion into a mail message.

hash()

Return a hash value for this address. This is based solely on the email address portion (any display name and comments are ignored).

local()

Retrieve the local portion of the mail address. This is the portion that precedes the `@` sign.

local=(l)

Assign the local portion of the mail address. This is the portion that precedes the `@` sign.

name()

Returns a best guess at a display name for this email address. This function first checks if the address has a true display name (see display_name) and returns it if so. Otherwise, if the address has any comments, the last comment will be returned.

In most cases, this will behave reasonably. For example, it will return "Bob Smith" for this address:

      bobs@example.net (Bob Smith)

See also display_name, comments, comments=

to_str()

Alias for format

[Validate]