Skip to content

Commit cbd153a

Browse files
committed
📚 Document relevant capabilities for each command
also update existing docs to be consistent with the new format.
1 parent 26cd3b0 commit cbd153a

File tree

1 file changed

+118
-23
lines changed

1 file changed

+118
-23
lines changed

lib/net/imap.rb

Lines changed: 118 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -428,16 +428,33 @@ def disconnected?
428428
# Sends a CAPABILITY command, and returns an array of
429429
# capabilities that the server supports. Each capability
430430
# is a string.
431-
# See the {IANA IMAP capabilities registry}[https://www.iana.org/assignments/imap-capabilities/imap-capabilities.xhtml]
432-
# for a list of possible capabilities and their RFCs.
431+
#
432+
# See the {IANA IMAP4 capabilities
433+
# registry}[http://www.iana.org/assignments/imap4-capabilities] for a list
434+
# of all standard capabilities, and their reference RFCs.
433435
#
434436
# >>>
435-
# <em>*Note* that the Net::IMAP class does not modify its
437+
# <em>*Note* that Net::IMAP does not currently modify its
436438
# behaviour according to the capabilities of the server;
437439
# it is up to the user of the class to ensure that
438440
# a certain capability is supported by a server before
439441
# using it.</em>
440442
#
443+
# Capability requirements—other than +IMAP4rev1+—are listed in the
444+
# documentation for each command method.
445+
#
446+
# ===== Caching +CAPABILITY+ responses
447+
#
448+
# Servers may send their capability list, unsolicited, using the
449+
# +CAPABILITY+ response code or an untagged +CAPABILITY+ response. These
450+
# responses can be retrieved and cached using #responses or
451+
# #add_response_handler.
452+
#
453+
# But cached capabilities must be discarded after #starttls, #login, or
454+
# #authenticate. The OK TaggedResponse to #login and #authenticate may
455+
# include +CAPABILITY+ response code data, but the TaggedResponse for
456+
# #starttls is sent clear-text and cannot be trusted.
457+
#
441458
def capability
442459
synchronize do
443460
send_command("CAPABILITY")
@@ -462,6 +479,11 @@ def capability
462479
# end
463480
#
464481
# See [ID[https://tools.ietf.org/html/rfc2971]] for field definitions.
482+
#
483+
# ===== Capabilities
484+
#
485+
# The server's capabilities must include +ID+
486+
# [RFC2971[https://tools.ietf.org/html/rfc2971]]
465487
def id(client_id=nil)
466488
synchronize do
467489
send_command("ID", ClientID.new(client_id))
@@ -481,6 +503,14 @@ def logout
481503
end
482504

483505
# Sends a STARTTLS command to start TLS session.
506+
# Sends a STARTTLS command to start a TLS session.
507+
#
508+
# ===== Capability
509+
#
510+
# The server's capabilities must include +STARTTLS+.
511+
#
512+
# Server capabilities change after #starttls, #login, and #authenticate. so
513+
# Cached capabilities must be invalidated after this method completes.
484514
def starttls(options = {}, verify = true)
485515
send_command("STARTTLS") do |resp|
486516
if resp.kind_of?(TaggedResponse) && resp.name == "OK"
@@ -529,6 +559,18 @@ def starttls(options = {}, verify = true)
529559
#
530560
# See Net::IMAP::Authenticators for more information on plugging in your
531561
# own authenticator.
562+
#
563+
# ==== Capabilities
564+
#
565+
# Clients MUST NOT attempt to #authenticate or #login when +LOGINDISABLED+
566+
# is listed with the capabilities.
567+
#
568+
# Clients MUST NOT attempt to authenticate with a mechanism unless
569+
# <tt>"AUTH=#{mechanism}"</tt> for that mechanism is a server capability.
570+
#
571+
# Server capabilities may change after #starttls, #login, and #authenticate.
572+
# Any cached capabilities must be invalidated when this method completes.
573+
#
532574
def authenticate(auth_type, *args)
533575
authenticator = self.class.authenticator(auth_type, *args)
534576
send_command("AUTHENTICATE", auth_type) do |resp|
@@ -547,6 +589,14 @@ def authenticate(auth_type, *args)
547589
# of "LOGIN", #login does *not* use the login authenticator.
548590
#
549591
# A Net::IMAP::NoResponseError is raised if authentication fails.
592+
#
593+
# ==== Capabilities
594+
# Clients MUST NOT attempt to #authenticate or #login when +LOGINDISABLED+
595+
# is listed with the capabilities.
596+
#
597+
# Server capabilities may change after #starttls, #login, and #authenticate.
598+
# Cached capabilities must be invalidated when this method completes.
599+
#
550600
def login(user, password)
551601
send_command("LOGIN", user, password)
552602
end
@@ -717,7 +767,10 @@ def list(refname, mailbox)
717767
# end
718768
# end
719769
#
720-
# The NAMESPACE extension is described in [NAMESPACE[https://tools.ietf.org/html/rfc2342]]
770+
# ===== Capabilities
771+
#
772+
# The server's capabilities must include +NAMESPACE+
773+
# [RFC2342[https://tools.ietf.org/html/rfc2342]]
721774
def namespace
722775
synchronize do
723776
send_command("NAMESPACE")
@@ -750,6 +803,16 @@ def namespace
750803
# #=> [#<Net::IMAP::MailboxList attr=[:Noselect], delim="/", name="foo/">, \\
751804
# #<Net::IMAP::MailboxList attr=[:Noinferiors, :Marked], delim="/", name="foo/bar">, \\
752805
# #<Net::IMAP::MailboxList attr=[:Noinferiors], delim="/", name="foo/baz">]
806+
#
807+
# ===== Capabilities
808+
#
809+
# The server's capabilities must include +XLIST+,
810+
# a deprecated Gmail extension (replaced by +SPECIAL-USE+).
811+
#--
812+
# TODO: Net::IMAP doesn't yet have full SPECIAL-USE support. Supporting
813+
# servers MAY return SPECIAL-USE attributes, but are not *required* to
814+
# unless the SPECIAL-USE return option is supplied.
815+
#++
753816
def xlist(refname, mailbox)
754817
synchronize do
755818
send_command("XLIST", refname, mailbox)
@@ -762,7 +825,10 @@ def xlist(refname, mailbox)
762825
# If this mailbox exists, it returns an array containing objects of type
763826
# MailboxQuotaRoot and MailboxQuota.
764827
#
765-
# The QUOTA extension is described in [QUOTA[https://tools.ietf.org/html/rfc2087]]
828+
# ===== Capabilities
829+
#
830+
# The server's capabilities must include +QUOTA+
831+
# [RFC2087[https://tools.ietf.org/html/rfc2087]].
766832
def getquotaroot(mailbox)
767833
synchronize do
768834
send_command("GETQUOTAROOT", mailbox)
@@ -778,7 +844,10 @@ def getquotaroot(mailbox)
778844
# MailboxQuota object is returned. This
779845
# command is generally only available to server admin.
780846
#
781-
# The QUOTA extension is described in [QUOTA[https://tools.ietf.org/html/rfc2087]]
847+
# ===== Capabilities
848+
#
849+
# The server's capabilities must include +QUOTA+
850+
# [RFC2087[https://tools.ietf.org/html/rfc2087]].
782851
def getquota(mailbox)
783852
synchronize do
784853
send_command("GETQUOTA", mailbox)
@@ -791,7 +860,10 @@ def getquota(mailbox)
791860
# mailbox. Typically one needs to be logged in as a server admin
792861
# for this to work.
793862
#
794-
# The QUOTA extension is described in [QUOTA[https://tools.ietf.org/html/rfc2087]]
863+
# ===== Capabilities
864+
#
865+
# The server's capabilities must include +QUOTA+
866+
# [RFC2087[https://tools.ietf.org/html/rfc2087]].
795867
def setquota(mailbox, quota)
796868
if quota.nil?
797869
data = '()'
@@ -805,7 +877,10 @@ def setquota(mailbox, quota)
805877
# +rights+ that user is to have on that mailbox. If +rights+ is nil,
806878
# then that user will be stripped of any rights to that mailbox.
807879
#
808-
# The ACL extension is described in [ACL[https://tools.ietf.org/html/rfc4314]]
880+
# ===== Capabilities
881+
#
882+
# The server's capabilities must include +ACL+
883+
# [RFC4314[https://tools.ietf.org/html/rfc4314]].
809884
def setacl(mailbox, user, rights)
810885
if rights.nil?
811886
send_command("SETACL", mailbox, user, "")
@@ -818,7 +893,10 @@ def setacl(mailbox, user, rights)
818893
# If this mailbox exists, an array containing objects of
819894
# MailboxACLItem will be returned.
820895
#
821-
# The ACL extension is described in [ACL[https://tools.ietf.org/html/rfc4314]]
896+
# ===== Capabilities
897+
#
898+
# The server's capabilities must include +ACL+
899+
# [RFC4314[https://tools.ietf.org/html/rfc4314]].
822900
def getacl(mailbox)
823901
synchronize do
824902
send_command("GETACL", mailbox)
@@ -945,10 +1023,10 @@ def expunge
9451023
# #responses and this method returns them as an array of
9461024
# <em>sequence number</em> integers.
9471025
#
948-
# ===== Capability requirement
1026+
# ===== Capabilities
9491027
#
950-
# +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315.html]] must be
951-
# supported by the server.
1028+
# The server's capabilities must include +UIDPLUS+
1029+
# [RFC4315[https://www.rfc-editor.org/rfc/rfc4315.html]].
9521030
def uid_expunge(uid_set)
9531031
synchronize do
9541032
send_command("UID EXPUNGE", MessageSet.new(uid_set))
@@ -1107,10 +1185,10 @@ def uid_copy(set, mailbox)
11071185
# a number, an array of numbers, or a Range object. The number is
11081186
# a message sequence number.
11091187
#
1110-
# ===== Capabilities requirements
1188+
# ===== Capabilities
11111189
#
1112-
# +MOVE+ [RFC6851[https://tools.ietf.org/html/rfc6851]] must be supported by
1113-
# the server.
1190+
# The server's capabilities must include +MOVE+
1191+
# [RFC6851[https://tools.ietf.org/html/rfc6851]].
11141192
#
11151193
# If +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315.html]] is
11161194
# also supported, the server's response should include a +COPYUID+ response
@@ -1123,11 +1201,11 @@ def move(set, mailbox)
11231201

11241202
# Similar to #move, but +set+ contains unique identifiers.
11251203
#
1126-
# ===== Capabilities requirements
1204+
# ===== Capabilities
11271205
#
1128-
# Same as #move: +MOVE+ [RFC6851[https://tools.ietf.org/html/rfc6851]] must
1129-
# be supported by the server. +UIDPLUS+ also affects #uid_move the same way
1130-
# it affects #move.
1206+
# Same as #move: The server's capabilities must include +MOVE+
1207+
# [RFC6851[https://tools.ietf.org/html/rfc6851]]. +UIDPLUS+ also affects
1208+
# #uid_move the same way it affects #move.
11311209
def uid_move(set, mailbox)
11321210
copy_internal("UID MOVE", set, mailbox)
11331211
end
@@ -1140,14 +1218,20 @@ def uid_move(set, mailbox)
11401218
# p imap.sort(["DATE"], ["SUBJECT", "hello"], "US-ASCII")
11411219
# #=> [6, 7, 8, 1]
11421220
#
1143-
# The SORT extension is described in [SORT[https://tools.ietf.org/html/rfc5256]].
1221+
# ===== Capabilities
1222+
#
1223+
# The server's capabilities must include +SORT+
1224+
# [RFC5256[https://tools.ietf.org/html/rfc5256]].
11441225
def sort(sort_keys, search_keys, charset)
11451226
return sort_internal("SORT", sort_keys, search_keys, charset)
11461227
end
11471228

11481229
# Similar to #sort, but returns an array of unique identifiers.
11491230
#
1150-
# The SORT extension is described in [SORT[https://tools.ietf.org/html/rfc5256]].
1231+
# ===== Capabilities
1232+
#
1233+
# The server's capabilities must include +SORT+
1234+
# [RFC5256[https://tools.ietf.org/html/rfc5256]].
11511235
def uid_sort(sort_keys, search_keys, charset)
11521236
return sort_internal("UID SORT", sort_keys, search_keys, charset)
11531237
end
@@ -1185,15 +1269,21 @@ def remove_response_handler(handler)
11851269
# Unlike #search, +charset+ is a required argument. US-ASCII
11861270
# and UTF-8 are sample values.
11871271
#
1188-
# The THREAD extension is described in [THREAD[https://tools.ietf.org/html/rfc5256]].
1272+
# ===== Capabilities
1273+
#
1274+
# The server's capabilities must include +THREAD+
1275+
# [RFC5256[https://tools.ietf.org/html/rfc5256]].
11891276
def thread(algorithm, search_keys, charset)
11901277
return thread_internal("THREAD", algorithm, search_keys, charset)
11911278
end
11921279

11931280
# Similar to #thread, but returns unique identifiers instead of
11941281
# message sequence numbers.
11951282
#
1196-
# The THREAD extension is described in [THREAD[https://tools.ietf.org/html/rfc5256]].
1283+
# ===== Capabilities
1284+
#
1285+
# The server's capabilities must include +THREAD+
1286+
# [RFC5256[https://tools.ietf.org/html/rfc5256]].
11971287
def uid_thread(algorithm, search_keys, charset)
11981288
return thread_internal("UID THREAD", algorithm, search_keys, charset)
11991289
end
@@ -1212,6 +1302,11 @@ def uid_thread(algorithm, search_keys, charset)
12121302
# ...
12131303
# end
12141304
# end
1305+
#
1306+
# ===== Capabilities
1307+
#
1308+
# The server's capabilities must include +IDLE+
1309+
# [RFC2177[https://tools.ietf.org/html/rfc2177]].
12151310
def idle(timeout = nil, &response_handler)
12161311
raise LocalJumpError, "no block given" unless response_handler
12171312

0 commit comments

Comments
 (0)