@@ -101,7 +101,7 @@ module Net
101
101
# end
102
102
# imap.expunge
103
103
#
104
- # == Server capabilities and protocol extensions
104
+ # == Capabilities
105
105
#
106
106
# Net::IMAP does not _currently_ modify its behaviour according to the
107
107
# server's advertised #capabilities. Users of this class must check that the
@@ -144,12 +144,12 @@ module Net
144
144
#
145
145
# === Caching +CAPABILITY+ responses
146
146
#
147
- # Net::IMAP stores and discards capability
148
- # data according to the requirements and recommendations in IMAP4rev2
149
- # {§6.1.1}[https://www.rfc-editor.org/rfc/rfc9051#section-6.1.1],
147
+ # Net::IMAP automatically stores and discards capability data according to the
148
+ # the requirements and recommendations in
149
+ # {IMAP4rev2 §6.1.1}[https://www.rfc-editor.org/rfc/rfc9051#section-6.1.1],
150
150
# {§6.2}[https://www.rfc-editor.org/rfc/rfc9051#section-6.2], and
151
151
# {§7.1}[https://www.rfc-editor.org/rfc/rfc9051#section-7.1].
152
- # Use #capable?, #auth_capable?, or #capabilities to this caching and avoid
152
+ # Use #capable?, #auth_capable?, or #capabilities to use this cache and avoid
153
153
# sending the #capability command unnecessarily.
154
154
#
155
155
# The server may advertise its initial capabilities using the +CAPABILITY+
@@ -166,6 +166,10 @@ module Net
166
166
#
167
167
# === Using IMAP4rev1 extensions
168
168
#
169
+ # See the {IANA IMAP4 capabilities
170
+ # registry}[http://www.iana.org/assignments/imap4-capabilities] for a list of
171
+ # all standard capabilities, and their reference RFCs.
172
+ #
169
173
# IMAP4rev1 servers must not activate behavior that is incompatible with the
170
174
# base specification until an explicit client action invokes a capability,
171
175
# e.g. sending a command or command argument specific to that capability.
@@ -179,7 +183,7 @@ module Net
179
183
# BadResponseError, or cause other unexpected behavior.
180
184
#
181
185
# Some capabilities must be explicitly activated using the #enable command.
182
- # See #enable for more details.
186
+ # See #enable for details.
183
187
#
184
188
# == Thread Safety
185
189
#
@@ -751,66 +755,61 @@ def disconnected?
751
755
return @sock . closed?
752
756
end
753
757
754
- # Returns the server capabilities. When available, cached capabilities are
755
- # used without sending a new #capability command to the server.
756
- #
757
- # To ensure case-insensitive capability comparison, use #capable? instead.
758
- #
759
- # Related: #capable?, #auth_capable?, #capability
760
- def capabilities
761
- @capabilities || capability
762
- end
763
-
764
758
# Returns whether the server supports a given +capability+. When available,
765
759
# cached #capabilities are used without sending a new #capability command to
766
760
# the server.
767
761
#
768
- # See the {IANA IMAP4 capabilities
769
- # registry}[http://www.iana.org/assignments/imap4-capabilities] for a list
770
- # of all standard capabilities, and their reference RFCs.
771
- #
772
- # >>>
773
- # <em>*NOTE:* Net::IMAP does not _currently_ modify its behaviour
774
- # according to the server's advertised capabilities. Users of this class
775
- # must check that the server is #capable? of extension commands or command
776
- # arguments before sending them.</em>
762
+ # <em>*NOTE:* Net::IMAP does not</em> currently <em>modify its behaviour
763
+ # according to the server's advertised capabilities.</em>
777
764
#
778
- # <em>Capability requirements—other than +IMAP4rev1+—are listed in the
779
- # documentation for each command method.</em>
765
+ # See Net::IMAP@Capabilities for more about \IMAP capabilities.
780
766
#
781
767
# Related: #auth_capable?, #capabilities, #capability, #enable
782
768
#
783
- # ===== Caching +CAPABILITY+ responses
784
- #
785
- # Servers may send their capability list unsolicited, using the +CAPABILITY+
786
- # response code or an untagged +CAPABILITY+ response. Cached capabilities
787
- # are discarded after #starttls, #login, or #authenticate. Caching and
788
- # cache invalidation are handled internally by Net::IMAP.
789
- #
790
769
def capable? ( capability ) capabilities . include? capability . to_s . upcase end
791
770
alias capability? capable?
792
771
772
+ # Returns the server capabilities. When available, cached capabilities are
773
+ # used without sending a new #capability command to the server.
774
+ #
775
+ # To ensure a case-insensitive comparison, #capable? can be used instead.
776
+ #
777
+ # <em>*NOTE:* Net::IMAP does not</em> currently <em>modify its behaviour
778
+ # according to the server's advertised capabilities.</em>
779
+ #
780
+ # See Net::IMAP@Capabilities for more about \IMAP capabilities.
781
+ #
782
+ # Related: #capable?, #auth_capable?, #capability
783
+ def capabilities
784
+ @capabilities || capability
785
+ end
786
+
793
787
# Returns the #authenticate mechanisms that the server claims to support.
794
788
# These are derived from the #capabilities with an <tt>AUTH=</tt> prefix.
795
789
#
796
790
# This may be different when the connection is cleartext or using TLS. Most
797
791
# servers will drop all <tt>AUTH=</tt> mechanisms from #capabilities after
798
792
# the connection has authenticated.
799
793
#
800
- # Related: #auth_capable?, #capabilities
801
- #
802
- # ===== Example
803
- #
804
794
# imap = Net::IMAP.new(hostname, ssl: false)
805
795
# imap.capabilities # => ["IMAP4REV1", "LOGINDISABLED"]
806
796
# imap.auth_mechanisms # => []
797
+ #
807
798
# imap.starttls
808
799
# imap.capabilities # => ["IMAP4REV1", "AUTH=PLAIN", "AUTH=XOAUTH2",
809
- # "AUTH=OAUTHBEARER", "AUTH=SCRAM-SHA-256"]
810
- # imap.auth_mechanisms # => ["PLAIN", "XOAUTH2", "SCRAM-SHA-256"]
811
- # imap.authenticate("OAUTHBEARER", username, oauth2_access_token)
800
+ # # "AUTH=OAUTHBEARER"]
801
+ # imap.auth_mechanisms # => ["PLAIN", "XOAUTH2", "OAUTHBEARER"]
802
+ #
803
+ # imap.authenticate("XOAUTH2", username, oauth2_access_token)
812
804
# imap.auth_mechanisms # => []
813
805
#
806
+ # <em>*NOTE:* Net::IMAP does not</em> currently <em>modify its behaviour
807
+ # according to the server's advertised capabilities.</em>
808
+ #
809
+ # See Net::IMAP@Capabilities for more about \IMAP capabilities.
810
+ #
811
+ # Related: #auth_capable?, #capabilities
812
+ #
814
813
def auth_mechanisms
815
814
capabilities
816
815
. grep ( /\A AUTH=/i )
@@ -823,12 +822,15 @@ def auth_mechanisms
823
822
# available, cached capabilities are used without sending a new #capability
824
823
# command to the server.
825
824
#
826
- # Per {[IMAP4rev1 §6.2.2]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.2.2],
827
- #
828
825
# imap.capable? "AUTH=PLAIN" # => true
829
826
# imap.auth_capable? "PLAIN" # => true
830
827
# imap.auth_capable? "blurdybloop" # => false
831
828
#
829
+ # <em>*NOTE:* Net::IMAP does not</em> currently <em>modify its behaviour
830
+ # according to the server's advertised capabilities.</em>
831
+ #
832
+ # See Net::IMAP@Capabilities for more about \IMAP capabilities.
833
+ #
832
834
# Related: #authenticate, #capable?, #capabilities
833
835
def auth_capable? ( mechanism )
834
836
capable? "AUTH=#{ mechanism } "
@@ -837,16 +839,22 @@ def auth_capable?(mechanism)
837
839
# Returns whether capabilities have been cached. When true, #capable? and
838
840
# #capabilities don't require sending a #capability command to the server.
839
841
#
840
-
841
- # Returns whether capabilities have been cached. When true, #capable? and
842
- # #capabilities don't require sending a #capability command to the server.
842
+ # See Net::IMAP@Capabilities for more about \IMAP capabilities.
843
+ #
844
+ # Related: #capable?, #capability, #clear_cached_capabilities
843
845
def capabilities_cached?
844
846
!!@capabilities
845
847
end
846
848
847
- # Clears capabilities that are currently cached by the Net::IMAP client.
848
- # This forces a #capability command to be sent the next time that #capable?
849
- # or #capabilities? are called.
849
+ # Clears capabilities that have been remembered by the Net::IMAP client.
850
+ # This forces a #capability command to be sent the next time a #capabilities
851
+ # query method is called.
852
+ #
853
+ # Net::IMAP automatically discards its cached capabilities when they can
854
+ # change. Explicitly calling this _should_ be unnecessary for well-behaved
855
+ # servers.
856
+ #
857
+ # Related: #capable?, #capability, #capabilities_cached?
850
858
def clear_cached_capabilities
851
859
synchronize do
852
860
clear_responses ( "CAPABILITY" )
@@ -856,23 +864,22 @@ def clear_cached_capabilities
856
864
857
865
# Sends a {CAPABILITY command [IMAP4rev1 §6.1.1]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.1.1]
858
866
# and returns an array of capabilities that are supported by the server.
859
- # The result will be stored for use by #capable? and #capabilities.
867
+ # The result is stored for use by #capable? and #capabilities.
860
868
#
861
- # In general, #capable? or #capabilities should be used instead. They cache
862
- # the capability result to avoid sending unnecessary commands. They also
863
- # ensure cache invalidation is handled correctly.
869
+ # <em>*NOTE:* Net::IMAP does not</em> currently <em>modify its behaviour
870
+ # according to the server's advertised capabilities.</em>
864
871
#
865
- # >>>
866
- # <em>*NOTE:* Net::IMAP does not _currently_ modify its behaviour
867
- # according to the server's advertised capabilities. Users of this class
868
- # must check that the server is #capable? of extension commands or command
869
- # arguments before sending them.</em>
872
+ # Net::IMAP automatically stores and discards capability data according to
873
+ # the requirements and recommendations in
874
+ # {IMAP4rev2 §6.1.1}[https://www.rfc-editor.org/rfc/rfc9051#section-6.1.1],
875
+ # {§6.2}[https://www.rfc-editor.org/rfc/rfc9051#section-6.2], and
876
+ # {§7.1}[https://www.rfc-editor.org/rfc/rfc9051#section-7.1].
877
+ # Use #capable?, #auth_capable?, or #capabilities to this cache and avoid
878
+ # sending the #capability command unnecessarily.
870
879
#
871
- # <em>Capability requirements—other than +IMAP4rev1+—are listed in the
872
- # documentation for each command method.</em>
880
+ # See Net::IMAP@Capabilities for more about \IMAP capabilities.
873
881
#
874
882
# Related: #capable?, #auth_capable?, #capability, #enable
875
- #
876
883
def capability
877
884
synchronize do
878
885
send_command ( "CAPABILITY" )
@@ -994,7 +1001,7 @@ def starttls(options = {}, verify = true)
994
1001
#
995
1002
# An exception Net::IMAP::NoResponseError is raised if authentication fails.
996
1003
#
997
- # Related: #login, #starttls
1004
+ # Related: #login, #starttls, #auth_capable?, #auth_mechanisms
998
1005
#
999
1006
# ==== Supported SASL Mechanisms
1000
1007
#
@@ -1024,40 +1031,28 @@ def starttls(options = {}, verify = true)
1024
1031
# for information on these and other SASL mechanisms.
1025
1032
#
1026
1033
# ===== Capabilities
1027
- # Clients should not call #authenticate with mechanisms that are included in the server #capabilities as <tt>"AUTH=#{mechanism}"</tt>.
1034
+ #
1035
+ # The server should list <tt>"AUTH=#{mechanism}"</tt> capabilities for
1036
+ # supported mechanisms. Check #auth_capable? or #auth_mechanisms before
1037
+ # using a particular mechanism.
1038
+ #
1039
+ # if imap.auth_capable? "XOAUTH2"
1040
+ # imap.authenticate "XOAUTH2", username, oauth2_access_token
1041
+ # elsif imap.auth_capable? "PLAIN"
1042
+ # imap.authenticate "PLAIN", username, password
1043
+ # elsif imap.auth_capable? "DIGEST-MD5"
1044
+ # imap.authenticate "DIGEST-MD5", username, password
1045
+ # elsif !imap.capability? "LOGINDISABLED"
1046
+ # imap.login username, password
1047
+ # else
1048
+ # raise "No acceptable authentication mechanism is available"
1049
+ # end
1028
1050
#
1029
1051
# Server capabilities may change after #starttls, #login, and #authenticate.
1030
1052
# Cached #capabilities will be cleared when this method completes.
1031
1053
# If the TaggedResponse to #authenticate includes updated capabilities, they
1032
1054
# will be cached.
1033
1055
#
1034
- # ===== Example
1035
- # Use auth_capable? to discover which mechanisms are suuported by the
1036
- # server. For authenticators that ignore unhandled keyword arguments, the
1037
- # same config can be used for multiple mechanisms:
1038
- #
1039
- # password = nil # saved locally, so we don't ask more than once
1040
- # accesstok = nil # saved locally...
1041
- # creds = {
1042
- # authcid: username,
1043
- # password: proc { password ||= ui.prompt_for_password },
1044
- # oauth2_token: proc { accesstok ||= kms.fresh_access_token },
1045
- # }
1046
- # mechanism = %w[
1047
- # OAUTHBEARER XOAUTH2
1048
- # SCRAM-SHA-256 SCRAM-SHA-1
1049
- # PLAIN
1050
- # ].find {|m|
1051
- # imap.auth_capable?(m)
1052
- # }
1053
- # if mechanism
1054
- # imap.authenticate mechanism, **creds
1055
- # elsif capable? "LOGINDISABLED"
1056
- # raise "the server has disabled login"
1057
- # else
1058
- # imap.login username, password
1059
- # end
1060
- #
1061
1056
def authenticate ( mechanism , ...)
1062
1057
authenticator = self . class . authenticator ( mechanism , ...)
1063
1058
send_command ( "AUTHENTICATE" , mechanism ) do |resp |
@@ -1085,10 +1080,17 @@ def authenticate(mechanism, ...)
1085
1080
#
1086
1081
# Related: #authenticate, #starttls
1087
1082
#
1088
- # ==== Capabilities
1089
- # An IMAP client MUST NOT call #login unless the server advertises the
1083
+ # ===== Capabilities
1084
+ #
1085
+ # An IMAP client MUST NOT call #login when the server advertises the
1090
1086
# +LOGINDISABLED+ capability.
1091
1087
#
1088
+ # if imap.capability? "LOGINDISABLED"
1089
+ # raise "Remote server has disabled the login command"
1090
+ # else
1091
+ # imap.login username, password
1092
+ # end
1093
+ #
1092
1094
# Server capabilities may change after #starttls, #login, and #authenticate.
1093
1095
# Cached capabilities _must_ be invalidated after this method completes.
1094
1096
# The TaggedResponse to #login may include updated capabilities in its
0 commit comments