Ruby 1.9.2 リファレンスマニュアル > ライブラリ一覧 > net/imapライブラリ > Net::IMAPクラス

class Net::IMAP

クラスの継承リスト: Net::IMAP < Object < Kernel < BasicObject

Abstract

IMAP access class.

特異メソッド

add_authenticator(auth_type, authenticator)

Adds an authenticator for Net::IMAP#authenticate.

debug

Returns the debug mode.

debug=(val)

Sets the debug mode.

decode_utf7
encode_utf7
new(host, port = 143, usessl = false, certs = nil, verify = false)

Creates a new Net::IMAP object and connects it to the specified port on the named host. If usessl is true, then an attempt will be made to use SSL (now TLS) to connect to the server. For this to work OpenSSL[OSSL] and the Ruby OpenSSL (openssl) extension need to be installed. The certs parameter indicates the path or file containing the CA cert of the server, and the verify parameter is for the OpenSSL verification callback.

インスタンスメソッド

add_response_handler(handler = Proc.new)

Adds a response handler.

ex).

imap.add_response_handler do |resp|
  p resp
end
append(mailbox, message, flags = nil, date_time = nil)

Sends a APPEND command to append the message to the end of the mailbox.

ex).

imap.append("inbox", <<EOF.gsub(/\n/, "\r\n"), [:Seen], Time.now)
Subject: hello
From: shugo@ruby-lang.org
To: shugo@ruby-lang.org

hello world
EOF
authenticate(auth_type, arg...)

Sends an AUTEHNTICATE command to authenticate the client. The auth_type parameter is a string that represents the authentication mechanism to be used. Currently Net::IMAP supports "LOGIN" and "CRAM-MD5" for the auth_type.

ex).

imap.authenticate('LOGIN', user, password)
capability

Sends a CAPABILITY command, and returns a listing of capabilities that the server supports.

check

Sends a CHECK command to request a checkpoint of the currently selected mailbox.

client_thread
client_thread=(th)

The thread to receive exceptions.

close

Sends a CLOSE command to close the currently selected mailbox. The CLOSE command permanently removes from the mailbox all messages that have the \Deleted flag set.

copy(set, mailbox)
uid_copy(set, mailbox)

Sends a COPY command to copy the specified message(s) to the end of the specified destination mailbox. the set parameter is a number or an array of numbers or a Range object. the number is a message sequence number (copy) or a unique identifier (uid_copy).

create(mailbox)

Sends a CREATE command to create a new mailbox.

delete(mailbox)

Sends a DELETE command to remove the mailbox.

disconnect

Disconnects from the server.

disconnected?

Returns true if disconnected from the server.

examine(mailbox)

Sends a EXAMINE command to select a mailbox so that messages in the mailbox can be accessed. However, the selected mailbox is identified as read-only.

expunge

Sends a EXPUNGE command to permanently remove from the currently selected mailbox all messages that have the \Deleted flag set.

fetch(set, attr)
uid_fetch(set, attr)

Sends a FETCH command to retrieve data associated with a message in the mailbox. the set parameter is a number or an array of numbers or a Range object. the number is a message sequence number (fetch) or a unique identifier (uid_fetch). The return value is an array of Net::IMAP::FetchData.

ex).

p imap.fetch(6..8, "UID")
#=> [#<Net::IMAP::FetchData seqno=6, attr={"UID"=>98}>, #<Net::IMAP::FetchData seqno=7, attr={"UID"=>99}>, #<Net::IMAP::FetchData seqno=8, attr={"UID"=>100}>]
p imap.fetch(6, "BODY[HEADER.FIELDS (SUBJECT)]")
#=> [#<Net::IMAP::FetchData seqno=6, attr={"BODY[HEADER.FIELDS (SUBJECT)]"=>"Subject: test\r\n\r\n"}>]
data = imap.uid_fetch(98, ["RFC822.SIZE", "INTERNALDATE"])[0]
p data.seqno
#=> 6
p data.attr["RFC822.SIZE"]
#=> 611
p data.attr["INTERNALDATE"]
#=> "12-Oct-2000 22:40:59 +0900"
p data.attr["UID"]
#=> 98
getacl(mailbox)

Send the GETACL command along with specified mailbox. If this mailbox exists, an array containing objects of Net::IMAP::MailboxACLItem will be returned.

getquota(mailbox)

Sends the GETQUOTA command along with specified mailbox. If this mailbox exists, then an array containing a Net::IMAP::MailboxQuota object is returned. This command generally is only available to server admin.

getquotaroot(mailbox)

Sends the GETQUOTAROOT command along with specified mailbox. This command is generally available to both admin and user. If mailbox exists, returns an array containing objects of Net::IMAP::MailboxQuotaRoot and Net::IMAP::MailboxQuota.

greeting

Returns an initial greeting response from the server.

list(refname, mailbox)

Sends a LIST command, and returns a subset of names from the complete set of all names available to the client. The return value is an array of Net::IMAP::MailboxList.

ex).

imap.create("foo/bar")
imap.create("foo/baz")
p imap.list("", "foo/%")
#=> [#<Net::IMAP::MailboxList attr=[:Noselect], delim="/", name="foo/">, #<Net::IMAP::MailboxList attr=[:Noinferiors, :Marked], delim="/", name="foo/bar">, #<Net::IMAP::MailboxList attr=[:Noinferiors], delim="/", name="foo/baz">]
login(user, password)

Sends a LOGIN command to identify the client and carries the plaintext password authenticating this user.

logout

Sends a LOGOUT command to inform the server that the client is done with the connection.

lsub(refname, mailbox)

Sends a LSUB command, and returns a subset of names from the set of names that the user has declared as being "active" or "subscribed". The return value is an array of Net::IMAP::MailboxList.

noop

Sends a NOOP command to the server. It does nothing.

remove_response_handler(handler)

Removes the response handler.

rename(mailbox, newname)

Sends a RENAME command to change the name of the mailbox to the newname.

response_handlers

Returns all response handlers.

responses

Returns recorded untagged responses.

ex).

imap.select("inbox")
p imap.responses["EXISTS"][-1]
#=> 2
p imap.responses["UIDVALIDITY"][-1]
#=> 968263756
search(keys, charset = nil)
uid_search(keys, charset = nil)

Sends a SEARCH command to search the mailbox for messages that match the given searching criteria, and returns message sequence numbers (search) or unique identifiers (uid_search).

ex).

p imap.search(["SUBJECT", "hello"])
#=> [1, 6, 7, 8]
p imap.search('SUBJECT "hello"')
#=> [1, 6, 7, 8]
select(mailbox)

Sends a SELECT command to select a mailbox so that messages in the mailbox can be accessed.

setacl(mailbox, user, rights)

Sends the SETACL command along with mailbox, user and the rights that user is to have on that mailbox. If rights is nil, then that user will be stripped of any rights to that mailbox. The IMAP ACL commands are described in [RFC2086].

setquota(mailbox, quota)

Sends a SETQUOTA command along with the specified mailbox and quota. If quota is nil, then quota will be unset for that mailbox. Typically one needs to be logged in as server admin for this to work. The IMAP quota commands are described in [RFC2087].

sort(sort_keys, search_keys, charset)
uid_sort(sort_keys, search_keys, charset)

Sends a SORT command to sort messages in the mailbox.

ex).

p imap.sort(["FROM"], ["ALL"], "US-ASCII")
#=> [1, 2, 3, 5, 6, 7, 8, 4, 9]
p imap.sort(["DATE"], ["SUBJECT", "hello"], "US-ASCII")
#=> [6, 7, 8, 1]
starttls(cxt = nil)

Sends a STARTTLS command to start TLS session.

status(mailbox, attr)

Sends a STATUS command, and returns the status of the indicated mailbox. return value is a hash of attributes.

ex).

p imap.status("inbox", ["MESSAGES", "RECENT"])
#=> {"RECENT"=>0, "MESSAGES"=>44}
store(set, attr, flags)
uid_store(set, attr, flags)

Sends a STORE command to alter data associated with a message in the mailbox. the set parameter is a number or an array of numbers or a Range object. the number is a message sequence number (store) or a unique identifier (uid_store). The return value is an array of Net::IMAP::FetchData.

ex).

p imap.store(6..8, "+FLAGS", [:Deleted])
#=> [#<Net::IMAP::FetchData seqno=6, attr={"FLAGS"=>[:Seen, :Deleted]}>, #<Net::IMAP::FetchData seqno=7, attr={"FLAGS"=>[:Seen, :Deleted]}>, #<Net::IMAP::FetchData seqno=8, attr={"FLAGS"=>[:Seen, :Deleted]}>]
subscribe(mailbox)

Sends a SUBSCRIBE command to add the specified mailbox name to the server's set of "active" or "subscribed" mailboxes.

thread(algorithm, search_keys, charset)

As for #search(), but returns message sequence numbers in threaded format, as a Net::IMAP::ThreadMember tree. The supported algorithms are:

ORDEREDSUBJECT:: split into single-level threads according to subject,

ordered by date.

REFERENCES:: split into threads by parent/child relationships determined

by which message is a reply to which.

Unlike #search(), +charset+ is a required argument. US-ASCII and UTF-8 are sample values.

See [SORT-THREAD-EXT] for more details.

uid_thread(algorithm, search_keys, charset)

As for #thread(), but returns unique identifiers instead of message sequence numbers.

unsubscribe(mailbox)

Sends a UNSUBSCRIBE command to remove the specified mailbox name from the server's set of "active" or "subscribed" mailboxes.

Methods

Classes