class TMail::Mail

Class Methods

new(port = TMail::StringPort.new, config = DEFAULT_CONFIG) -> TMail::Mail

port: TMail::Port
config: TMail::Config

creates a new TMail::Mail object from PORT.

load(filename) -> TMail::Mail

filename: String

creates a new TMail::Mail object. FILENAME is the name of file which contains just one mail (e.g. MH mail file).

parse(str) -> TMail::Mail

str: String

parses STR and creates a new TMail::Mail object.

Instance Methods

port -> TMail::Port

the source port of this mail.

body_port -> TMail::Port

the port to save body of this mail.

each {|line| .... }

line: String

iterates for each lines of mail body.

body -> String
preamble -> String

the mail body. If the mail is a MIME multipart mail, this attribute represents "preamble".

parts -> [TMail::Mail]

parts of this mail. (valid only if this mail is a MIME multipart mail)

epilogue -> String

If the mail was MIME multipart mail, this represent "epilogue" string. Else, empty string.

multipart?

true if the message is a multi-part mail.

encoded(eol = "\n", encoding = 'j') -> String

eol: String
encoding: String

converts the mail object to a MIME encoded string.

decoded(eol = "\n", encoding = 'e') -> String
to_s(eol = "\n", encoding = 'e') -> String

eol: String
encoding: String

converts the mail object to a decoded string.

inspect -> String

returns simple string representation like "#<TMail::Mail port=<StringPort:str=...>>"

write_back(eol = "\n", encoding = 'e')

eol: String
encoding: String

converts this mail into string and write back to body_port, setting line terminator to EOL.

Property Access Method

date(default = nil) -> Time
date=(datetime)

datetime: Time
default: Object

a Time object of Date: header field.

strftime(format, default = nil) -> String

format: String
default: Object

is equals to date.strftime(format). If date is not exist, this method does nothing and returns default.

to(default = nil) -> [String]
to=(specs)

specs: String | [String]
default: Object

address specs for To: header field.

to_addrs(default = nil) -> [TMail::Address | TMail::AddressGroup]
to_addrs=(addrs)

addrs: TMail::Address | [TMail::Address]
default: Object

adresses which is represented in To: header field.

cc(default = nil) -> [String]
cc=(specs)

specs: String | [String]
default: Object

address specs for Cc: header field.

cc_addrs(default = nil) -> [TMail::Address]
cc_addrs=(addrs)

addrs: TMail::Address | [TMail::Address]
default: Object

addresses which is represented in Cc: header field.

bcc(default = nil) -> [String]
bcc=(specs)

specs: String | [String]
default: Object

address specs for Bcc: header field.

bcc_addrs(default = nil) -> [TMail::Address]
bcc_addrs=(addrs)

addrs: TMail::Address | [TMail::Address]
default: Object

adresses which is represented in Bcc: header field.

from(default = nil) -> [String]
from=(specs)

specs: String | [String]
default: Object

address specs for From: header field.

from_addrs(default = nil) -> [TMail::Address]
from_addrs=(addrs)

addrs: TMail::Address | [TMail::Address]
default: Object

adresses which is represented in From: header field.

friendly_from(default = nil) -> String

default: Object

a "phrase" part or address spec of the first From: address.

reply_to(default = nil) -> [String]
reply_to=(specs)

specs: String | [String]
default: Object

address specs of Reply-To: header field.

reply_to_addrs(default = nil) -> [TMail::Address]
reply_to_addrs=(addrs)

addrs: TMail::Address | [TMail::Address]
default: Object

adresses which is represented in Reply-To: header field.

sender(default = nil) -> String
sender=(spec)

spec: String

address spec for Sender: header field.

sender_addr(default = nil) -> TMail::Address
sender_addr=(addr)

addr: TMail::Address

an address which is represented in Sender: header field.

subject(default = nil) -> String
subject=(sbj)

sbj: String

the subject of the message.

message_id(default = nil) -> String
message_id=(id)

id: String

message ID string.

in_reply_to(default = nil) -> [String]
in_reply_to=(ids)

ids: String | [String]

message IDs of replying mails.

references(default = nil) -> [String]
references=(ids)

ids: String | [String]

message IDs of all referencing (replying) mails.

mime_version(default = nil) -> String
mime_version=(ver)

ver: String

MIME version. If it does not exist, returns the DEFAULT.

set_mime_version(major, minor)

major: Integer
minor: Integer

set MIME version from integers.

content_type(default = nil) -> String

the content type of the mail message (e.g. "text/plain"). If it does not exist, returns the DEFAULT.

main_type(default = nil) -> String

the main content type of the mail message. (e.g. "text") If it does not exist, returns the DEFAULT.

sub_type(default = nil) -> String

the sub content type of the mail message. (e.g. "plain") If it does not exist, returns the DEFAULT.

content_type=(ctype)

ctype: String

set content type to STR.

set_content_type(main, sub, params = nil)

main: String
sub: String
params: {String => String}

set Content-type: header as "main/sub; param=val; param=val; ...".

type_param(name, default = nil) -> String

name: String

returns the value corresponding to the case-insensitive NAME of Content-Type parameter. If it does not exist, returns the default.

# example
mail['Content-Type'] = 'text/plain; charset=iso-2022-jp'
p mail.type_param('charset')   # "iso-2022-jp"
multipart? -> true | false

judge if this mail is MIME multi part mail, by inspecting Content-Type: header field.

transfer_encoding(default = nil) -> String
transfer_encoding=(encoding)

encoding: String

Content-Transfer-Encoding. (e.g. "7bit" "Base64")

disposition(default = nil) -> String
disposition=(pos)

pos: String

Content-Disposition main value (e.g. "attachment"). If it does not exist, returns the DEFAULT.

# example
mail['Content-Disposition'] = 'attachement; filename="test.rb"'
p mail.disposition   # "attachment"
set_content_disposition(pos, params = nil)

pos: String
params: {String => String}

set content disposition.

disposition_param(key, default = nil) -> String

key: String

returns a value corresponding to the Content-Disposition parameter NAME (e.g. filename). If it does not exist, returns the default.

# example
mail.disposition_param('filename')
destinations(default = nil) -> [String]

all address specs which are contained in To:, Cc: and Bcc: header fields.

reply_addresses(default = nil) -> [TMail::Address]

addresses to we reply to.

error_reply_addresses(default = nil) -> [TMail::Address]

addresses to use when returning error message.

Direct Header Handling Methods

clear

clears all header.

keys -> [TMail::HeaderField]

returns an array of contained header names.

[](name) -> TMail::HeaderField

name: String

returns a header field object corresponding to the case-insensitive key NAME. e.g. mail["To"]

[]=(name, field)

name: String
field: TMail::HeaderField

set NAME header field to field.

delete(name)

name: String

deletes header corresponding to case-insensitive key NAME.

delete_if {|name, field| .... }

name: String
field: TMail::HeaderField

evaluates block with a name of header and header field object, and delete the header if block returns true.

each_header {|name, field| .... }
each_pair {|name, field| .... }

name: String
field: TMail::HeaderField

iterates for each header name and its field object.

each_header_name {|name| .... }
each_key {|name| .... }

name: String

iterates for each contained header names.

each_field {|field| .... }
each_value {|field| .... }

field: TMail::HeaderField

iterates for each header field objects.

orderd_each {|name, field| .... }

name: String
field: TMail::HeaderField

iterates for each header field objects, in canonical order.

key?(name)

name: String

returns true if the mail has NAME header.

value?(field)

field: TMail::HeaderField

returns true if the mail has FIELD header field object.

values_at(*names) -> [TMail::HeaderField]
indexes(*names) -> [TMail::HeaderField]
indices(*names) -> [TMail::HeaderField]

names: [String]

equals to names.collect {|k| mail[k] }.

values -> [TMail::HeaderField]

returns an array of all header field object.