|
"DTD/xhtml1-strict.dtd">
OverviewThe RMail::Header class supports the creation and manipulation of RFC2822 mail headers. A mail header is a little bit like a Hash. The fields are keyed by a string field name. It is also a little bit like an Array, since the fields are in a specific order. This class provides many of the methods of both the Hash and Array class. It also includes the Enumerable module. Terminology
ConventionsThe header's fields are stored in a particular order. Methods such as #each process the headers in this order. When field names or values are added to the object they are frozen. This helps prevent accidental modification to what is stored in the object.
==
[]
[]=
add
add_message_id
add_raw
address_list_assign
address_list_fetch
bcc
bcc=
cc
cc=
clear
clone
content_type
date
date=
delete
delete_at
delete_if
dup
each
each_key
each_name
each_pair
each_value
empty?
fetch
fetch_all
field?
from
from=
has_key?
include?
key?
keys
length
match
match?
mbox_from
mbox_from=
media_type
member?
message_id
names
new
param
params
recipients
replace
reply_to
reply_to=
select
set
set_boundary
size
subject
subject=
subtype
to
to=
to_a
to_s
to_string
Enumerable
Creates a new empty header object.
Return the value of the first matching field of a field name, or nil if none found. If passed a Fixnum, returns the header indexed by the number.
Creates a copy of this header object. A new RMail::Header is created and the instance data is copied over. However, the new object will still reference the same strings held in the original object. Since these strings are frozen, this usually won't matter.
Creates a complete copy of this header object, including any singleton methods and strings. The returned object will be a complete and unrelated duplicate of the original.
Delete all fields in this object. Returns self.
Replaces the contents of this header with that of another header object. Returns self.
Return the number of fields in this object.
This method is also aliased as
size
Alias for #length
Return the value of the first matching field of a given name. If there is no such field, the value returned by the supplied block is returned. If no block is passed, the value of default_value is returned. If no default_value is specified, an IndexError exception is raised.
Returns the values of every field named name. If there are no such fields, the value returned by the block is returned. If no block is passed, the value of default_value is returned. If no default_value is specified, an IndexError exception is raised.
Returns true if the message has a field named 'name'.
Alias for #field?
Alias for #field?
Alias for #field?
Alias for #field?
Deletes all fields with name. Returns self.
Deletes the field at the specified index and returns its value.
Deletes the field if the passed block returns true. Returns self.
Executes block once for each field in the header, passing the key and value as parameters. Returns self.
This method is also aliased as
each_pair
Alias for #each
Executes block once for each field in the header, passing the field's name as a parameter. Returns self
This method is also aliased as
each_key
Alias for #each_name
Executes block once for each field in the header, passing the field's value as a parameter. Returns self
Returns true if the header contains no fields
Returns an array of pairs [ name, value ] for all fields with one of the names passed.
Returns an array consisting of the names of every field in this header.
This method is also aliased as
keys
Alias for #names
Add a new field with name and value. When index is nil (the default if not specified) the line is appended to the header, otherwise it is inserted at the specified index. E.g. an index of 0 will prepend the header line. You can pass additional parameters for the header as a hash table params. Every key of the hash will be the name of the parameter, and every key's value the parameter value. E.g. header.add('Content-Type', 'multipart/mixed', nil, 'boundary' => 'the boundary') will add this header Content-Type: multipart/mixed; boundary="the boundary" Always returns self.
Add a new field as a raw string together with a parsed name/value. This method is used mainly by the parser and regular programs should stick to #add.
First delete any fields with name, then append a new field with name, value, and params as in #add.
Append a new field with name and value. If you want control of where the field is inserted, see #add. Returns value.
Returns true if the two objects have the same number of fields, in the same order, with the same values.
Returns a new array holding one [ name, value ] array per field in the header.
Converts the header to a string, including any mbox from line. Equivalent to header.to_string(true).
Converts the header to a string. If mbox_from is true, then the mbox from line is also included.
Determine if there is any fields that match the given name and value. If name is a String, all fields of that name are tested. If name is a Regexp the field names are matched against the regexp (the field names are converted to lower case first). Use the regexp // if you want to test all field names. If value is a String, it is converted to a case insensitive Regexp that matches the string. Otherwise, it must be a Regexp. Note that the field value may be folded across many lines, so you should use a multi-line Regexp. Also consider using a case insensitive Regexp. Use the regexp // if you want to match all possible field values. Returns true if there is a match, false otherwise. Example: if h.match?('x-ml-name', /ruby-dev/im) # do something end See also: #match
Find all fields that match the given +name and value. If name is a String, all fields of that name are tested. If name is a Regexp, the field names are matched against the regexp (the field names are converted to lower case first). Use the regexp // if you want to test all field names. If value is a String, it is converted to a case insensitive Regexp that matches the string. Otherwise, it must be a Regexp. Note that the field value may be folded across many lines, so you may need to use a multi-line Regexp. Also consider using a case insensitive Regexp. Use the regexp // if you want to match all possible field values. Returns a new RMail::Header holding all matching headers. Examples: received = header.match('Received', //) destinations = header.match(/^(to|cc|bcc)$/, //) bigfoot_received = header.match('received', /from.*by.*bigfoot\.com.*LiteMail/im) See also: #match?
Sets the "From " line commonly used in the Unix mbox mailbox format. The value supplied should be the entire "From " line.
Gets the "From " line previously set with mbox_from=, or nil.
This returns the full content type of this message converted to lower case. If there is no content type header, returns the passed block is executed and its return value is returned. If no block is passed, the value of the default argument is returned.
This returns the main media type for this message converted to lower case. This is the first portion of the content type. E.g. a content type of text/plain has a media type of text. If there is no content type field, returns the passed block is executed and its return value is returned. If no block is passed, the value of the default argument is returned.
This returns the media subtype for this message, converted to lower case. This is the second portion of the content type. E.g. a content type of text/plain has a media subtype of plain. If there is no content type field, returns the passed block is executed and its return value is returned. If no block is passed, the value of the default argument is returned.
This returns a hash of parameters. Each key in the hash is the name of the parameter in lower case and each value in the hash is the unquoted parameter value. If a parameter has no value, its value in the hash will be true. If the field or parameter does not exist or it is malformed in a way that makes it impossible to parse, then the passed block is executed and its return value is returned. If no block is passed, the value of the default argument is returned.
This returns the parameter value for the given parameter in the given field. The value returned is unquoted. If the field or parameter does not exist or it is malformed in a way that makes it impossible to parse, then the passed block is executed and its return value is returned. If no block is passed, the value of the default argument is returned.
Set the boundary parameter of this message's Content-Type: field.
Return the value of the Date: field, parsed into a Time object. Returns nil if there is no Date: field or the field value could not be parsed.
Deletes any existing Date: fields and appends a new one corresponding to the given Time object.
Returns the value of the From: header as an Array of RMail::Address objects. See #address_list_fetch for details on what is returned. This method does not return a single RMail::Address value because it is legal to have multiple addresses in a From: header. This method always returns at least the empty list. So if you are always only interested in the first from address (most likely the case), you can safely say: header.from.first
Sets the From: field to the supplied address or addresses. See #address_list_assign for information on valid values for addresses. Note that the From: header usually contains only one address, but it is legal to have more than one.
Returns the value of the To: field as an Array of RMail::Address objects. See #address_list_fetch for details on what is returned.
Sets the To: field to the supplied address or addresses. See #address_list_assign for information on valid values for addresses.
Returns the value of the Cc: field as an Array of RMail::Address objects. See #address_list_fetch for details on what is returned.
Sets the Cc: field to the supplied address or addresses. See #address_list_assign for information on valid values for addresses.
Returns the value of the Bcc: field as an Array of RMail::Address objects. See #address_list_fetch for details on what is returned.
Sets the Bcc: field to the supplied address or addresses. See #address_list_assign for information on valid values for addresses.
Returns the value of the Reply-To: header as an Array of RMail::Address objects.
Sets the Reply-To: field to the supplied address or addresses. See #address_list_assign for information on valid values for addresses.
Returns the value of this object's Message-Id: field.
Sets the value of this object's Message-Id: field to a new random value. If you don't supply a fqdn (fully qualified domain name) then one will be randomly generated for you. If a valid address exists in the From: field, its domain will be used as a basis. Part of the randomness in the header is taken from the header itself, so it is best to call this method after adding other fields to the header -- especially those that make it unique (Subject:, To:, Cc:, etc).
Return the subject of this message.
Set the subject of this message
Returns an RMail::Address::List array holding all the recipients of this message. This uses the contents of the To, Cc, and Bcc fields. Duplicate addresses are eliminated.
Retrieve a given field's value as an RMail::Address::List of RMail::Address objects. This method is used to implement many of the convenience methods such as #from, #to, etc.
Set a given field to a list of supplied addresses. The addresses may be a String, RMail::Address, or Array. If a String, it is parsed for valid email addresses and those found are used. If an RMail::Address, the result of RMail::Address#format is used. If an Array, each element of the array must be either a String or RMail::Address and is treated as above. This method is used to implement many of the convenience methods such as #from=, #to=, etc. |