Skip to content

Commit ca966f4

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

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)
@@ -959,10 +1037,10 @@ def expunge
9591037
# #responses and this method returns them as an array of
9601038
# <em>sequence number</em> integers.
9611039
#
962-
# ===== Capability requirement
1040+
# ===== Capabilities
9631041
#
964-
# +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315.html]] must be
965-
# supported by the server.
1042+
# The server's capabilities must include +UIDPLUS+
1043+
# [RFC4315[https://www.rfc-editor.org/rfc/rfc4315.html]].
9661044
def uid_expunge(uid_set)
9671045
synchronize do
9681046
send_command("UID EXPUNGE", MessageSet.new(uid_set))
@@ -1121,10 +1199,10 @@ def uid_copy(set, mailbox)
11211199
# a number, an array of numbers, or a Range object. The number is
11221200
# a message sequence number.
11231201
#
1124-
# ===== Capabilities requirements
1202+
# ===== Capabilities
11251203
#
1126-
# +MOVE+ [RFC6851[https://tools.ietf.org/html/rfc6851]] must be supported by
1127-
# the server.
1204+
# The server's capabilities must include +MOVE+
1205+
# [RFC6851[https://tools.ietf.org/html/rfc6851]].
11281206
#
11291207
# If +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315.html]] is
11301208
# also supported, the server's response should include a +COPYUID+ response
@@ -1137,11 +1215,11 @@ def move(set, mailbox)
11371215

11381216
# Similar to #move, but +set+ contains unique identifiers.
11391217
#
1140-
# ===== Capabilities requirements
1218+
# ===== Capabilities
11411219
#
1142-
# Same as #move: +MOVE+ [RFC6851[https://tools.ietf.org/html/rfc6851]] must
1143-
# be supported by the server. +UIDPLUS+ also affects #uid_move the same way
1144-
# it affects #move.
1220+
# Same as #move: The server's capabilities must include +MOVE+
1221+
# [RFC6851[https://tools.ietf.org/html/rfc6851]]. +UIDPLUS+ also affects
1222+
# #uid_move the same way it affects #move.
11451223
def uid_move(set, mailbox)
11461224
copy_internal("UID MOVE", set, mailbox)
11471225
end
@@ -1154,14 +1232,20 @@ def uid_move(set, mailbox)
11541232
# p imap.sort(["DATE"], ["SUBJECT", "hello"], "US-ASCII")
11551233
# #=> [6, 7, 8, 1]
11561234
#
1157-
# The SORT extension is described in [SORT[https://tools.ietf.org/html/rfc5256]].
1235+
# ===== Capabilities
1236+
#
1237+
# The server's capabilities must include +SORT+
1238+
# [RFC5256[https://tools.ietf.org/html/rfc5256]].
11581239
def sort(sort_keys, search_keys, charset)
11591240
return sort_internal("SORT", sort_keys, search_keys, charset)
11601241
end
11611242

11621243
# Similar to #sort, but returns an array of unique identifiers.
11631244
#
1164-
# The SORT extension is described in [SORT[https://tools.ietf.org/html/rfc5256]].
1245+
# ===== Capabilities
1246+
#
1247+
# The server's capabilities must include +SORT+
1248+
# [RFC5256[https://tools.ietf.org/html/rfc5256]].
11651249
def uid_sort(sort_keys, search_keys, charset)
11661250
return sort_internal("UID SORT", sort_keys, search_keys, charset)
11671251
end
@@ -1199,15 +1283,21 @@ def remove_response_handler(handler)
11991283
# Unlike #search, +charset+ is a required argument. US-ASCII
12001284
# and UTF-8 are sample values.
12011285
#
1202-
# The THREAD extension is described in [THREAD[https://tools.ietf.org/html/rfc5256]].
1286+
# ===== Capabilities
1287+
#
1288+
# The server's capabilities must include +THREAD+
1289+
# [RFC5256[https://tools.ietf.org/html/rfc5256]].
12031290
def thread(algorithm, search_keys, charset)
12041291
return thread_internal("THREAD", algorithm, search_keys, charset)
12051292
end
12061293

12071294
# Similar to #thread, but returns unique identifiers instead of
12081295
# message sequence numbers.
12091296
#
1210-
# The THREAD extension is described in [THREAD[https://tools.ietf.org/html/rfc5256]].
1297+
# ===== Capabilities
1298+
#
1299+
# The server's capabilities must include +THREAD+
1300+
# [RFC5256[https://tools.ietf.org/html/rfc5256]].
12111301
def uid_thread(algorithm, search_keys, charset)
12121302
return thread_internal("UID THREAD", algorithm, search_keys, charset)
12131303
end
@@ -1226,6 +1316,11 @@ def uid_thread(algorithm, search_keys, charset)
12261316
# ...
12271317
# end
12281318
# end
1319+
#
1320+
# ===== Capabilities
1321+
#
1322+
# The server's capabilities must include +IDLE+
1323+
# [RFC2177[https://tools.ietf.org/html/rfc2177]].
12291324
def idle(timeout = nil, &response_handler)
12301325
raise LocalJumpError, "no block given" unless response_handler
12311326

0 commit comments

Comments
 (0)