Class: RMail::Address

Class RMail::Address |
In: | 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= format local local= name new parse

Classes and Modules

Class RMail::Address::Parser

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.

See mail/deliver.rb

parse(string)

Given a string, this function attempts to extract mailing addresses from it and returns an array of those addresses.

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

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

Public Instance methods

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.

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

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=

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

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.

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

format()

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