@@ -489,12 +489,9 @@ module Net
489
489
# - #move, #uid_move: Moves the specified messages to the end of the
490
490
# specified destination mailbox, expunging them from the current mailbox.
491
491
#
492
- #--
493
- # ==== RFC6855: UTF8=ACCEPT
494
- # TODO...
495
- # ==== RFC6855: UTF8=ONLY
496
- # TODO...
497
- #++
492
+ # ==== RFC6855: <tt>UTF8=ACCEPT</tt>, <tt>UTF8=ONLY</tt>
493
+ #
494
+ # - See #enable for information about support foi UTF-8 string encoding.
498
495
#
499
496
#--
500
497
# ==== RFC7888: <tt>LITERAL+</tt>, +LITERAL-+
@@ -679,6 +676,11 @@ module Net
679
676
# Gulbrandsen, A. and N. Freed, Ed., "Internet Message Access Protocol
680
677
# (\IMAP) - MOVE Extension", RFC 6851, DOI 10.17487/RFC6851, January 2013,
681
678
# <https://www.rfc-editor.org/info/rfc6851>.
679
+ # [UTF8=ACCEPT[https://tools.ietf.org/html/rfc6855]]::
680
+ # [UTF8=ONLY[https://tools.ietf.org/html/rfc6855]]::
681
+ # Resnick, P., Ed., Newman, C., Ed., and S. Shen, Ed.,
682
+ # "IMAP Support for UTF-8", RFC 6855, DOI 10.17487/RFC6855, March 2013,
683
+ # <https://www.rfc-editor.org/info/rfc6855>.
682
684
#
683
685
# === IANA registries
684
686
#
@@ -705,6 +707,12 @@ module Net
705
707
class IMAP < Protocol
706
708
VERSION = "0.3.4"
707
709
710
+ # Aliases for supported capabilities, to be used with the #enable command.
711
+ ENABLE_ALIASES = {
712
+ utf8 : "UTF8=ACCEPT" ,
713
+ "UTF8=ONLY" => "UTF8=ACCEPT" ,
714
+ } . freeze
715
+
708
716
autoload :SASL , File . expand_path ( "imap/sasl" , __dir__ )
709
717
autoload :StringPrep , File . expand_path ( "imap/stringprep" , __dir__ )
710
718
@@ -812,12 +820,14 @@ def disconnected?
812
820
# Capability requirements—other than +IMAP4rev1+—are listed in the
813
821
# documentation for each command method.
814
822
#
823
+ # Related: #enable
824
+ #
815
825
# ===== Basic IMAP4rev1 capabilities
816
826
#
817
827
# All IMAP4rev1 servers must include +IMAP4rev1+ in their capabilities list.
818
828
# All IMAP4rev1 servers must _implement_ the +STARTTLS+,
819
829
# <tt>AUTH=PLAIN</tt>, and +LOGINDISABLED+ capabilities, and clients must
820
- # respect their presence or absence. See the capabilites requirements on
830
+ # respect their presence or absence. See the capabilities requirements on
821
831
# #starttls, #login, and #authenticate.
822
832
#
823
833
# ===== Using IMAP4rev1 extensions
@@ -1886,26 +1896,84 @@ def uid_thread(algorithm, search_keys, charset)
1886
1896
1887
1897
# Sends an {ENABLE command [RFC5161 §3.2]}[https://www.rfc-editor.org/rfc/rfc5161#section-3.1]
1888
1898
# {[IMAP4rev2 §6.3.1]}[https://www.rfc-editor.org/rfc/rfc9051#section-6.3.1]
1889
- # to enable the specified extenstions, which may be either an
1890
- # array or a string. Returns a list of the extensions that were enabled.
1891
- #
1892
- # Some of the extensions that use ENABLE permit the server to send
1893
- # syntax that this class cannot parse. Caution is advised.
1899
+ # to enable the specified server +capabilities+. Each capability may be an
1900
+ # array, string, or symbol. Returns a list of the capabilities that were
1901
+ # enabled.
1894
1902
#
1895
1903
# The +ENABLE+ command is only valid in the _authenticated_ state, before
1896
1904
# any mailbox is selected.
1897
1905
#
1906
+ # Related: #capability
1907
+ #
1898
1908
# ===== Capabilities
1899
1909
#
1900
- # The server's capabilities must include +ENABLE+
1901
- # [RFC5161[https://tools.ietf.org/html/rfc5161]] or IMAP4REV2
1902
- # [RFC9051[https://tools.ietf.org/html/rfc9051]].
1910
+ # The server's capabilities must include
1911
+ # +ENABLE+ [RFC5161[https://tools.ietf.org/html/rfc5161]]
1912
+ # or +IMAP4REV2+ [RFC9051[https://tools.ietf.org/html/rfc9051]].
1903
1913
#
1904
1914
# Additionally, the server capabilities must include a capability matching
1905
1915
# each enabled extension (usually the same name as the enabled extension).
1906
- def enable ( extensions )
1916
+ # The following capabilities may be enabled:
1917
+ #
1918
+ # [+:utf8+ --- an alias for <tt>"UTF8=ACCEPT"</tt>]
1919
+ #
1920
+ # In a future release, <tt>enable(:utf8)</tt> will enable either
1921
+ # <tt>"UTF8=ACCEPT"</tt> or <tt>"IMAP4rev2"</tt>, depending on server
1922
+ # capabilities.
1923
+ #
1924
+ # [<tt>"UTF8=ACCEPT"</tt> [RFC6855[https://tools.ietf.org/html/rfc6855]]]
1925
+ #
1926
+ # The server's capabilities must include <tt>UTF8=ACCEPT</tt> _or_
1927
+ # <tt>UTF8=ONLY</tt>.
1928
+ #
1929
+ # This allows the server to send strings encoded as UTF-8 which might
1930
+ # otherwise need to use a 7-bit encoding, such as {modified
1931
+ # UTF-7}[::decode_utf7] for mailbox names, or RFC2047 encoded-words for
1932
+ # message headers.
1933
+ #
1934
+ # *Note:* For now, strings with 8-bit characters are still _sent_ using
1935
+ # "literal" syntax. A future update will change how commands send UTF-8
1936
+ # strings when <tt>UTF8=ACCEPT</tt> is enabled. This update should be
1937
+ # backward-compatible.
1938
+ #
1939
+ # *Note:* <em>A future update may set string encodings slightly
1940
+ # differently</em>, e.g: "US-ASCII" when UTF-8 is not enabled, and "UTF-8"
1941
+ # when it is. Currently, the encoding of strings sent as "quoted" or
1942
+ # "text" will _always_ be "UTF-8", even when a 7-bit encoding is used
1943
+ # (e.g. UTF-7, encoded-words, quoted-printable, base64). And currently,
1944
+ # string "literals" sent by the server will always have an "ASCII-8BIT"
1945
+ # (binary) encoding, even if they must contain UTF-8 data---although a
1946
+ # server _should_ use "quoted" strings once <tt>UTF8=ACCEPT</tt> is
1947
+ # enabled.
1948
+ #
1949
+ # [<tt>"UTF8=ONLY"</tt> [RFC6855[https://tools.ietf.org/html/rfc6855]]]
1950
+ #
1951
+ # A server that reports the <tt>UTF8=ONLY</tt> #capability _requires_ that
1952
+ # the client <tt>enable("UTF8=ACCEPT")</tt> before any mailboxes may be
1953
+ # selected. For convenience, <tt>enable("UTF8=ONLY")</tt> is aliased to
1954
+ # <tt>enable("UTF8=ACCEPT")</tt>.
1955
+ #
1956
+ # ===== Unsupported capabilities
1957
+ #
1958
+ # *Note:* Some extensions that use ENABLE permit the server to send syntax
1959
+ # that Net::IMAP cannot parse, which may raise an exception and disconnect.
1960
+ # Some extensions may work, but the support may be incomplete, untested, or
1961
+ # experimental.
1962
+ #
1963
+ # Until a capability is documented here as supported, enabling it may result
1964
+ # in undocumented behavior and a future release may update with incompatible
1965
+ # behavior <em>without warning or deprecation</em>.
1966
+ #
1967
+ # <em>Caution is advised.</em>
1968
+ #
1969
+ def enable ( *capabilities )
1970
+ capabilities = capabilities
1971
+ . flatten
1972
+ . map { |e | ENABLE_ALIASES [ e ] || e }
1973
+ . uniq
1974
+ . join ( ' ' )
1907
1975
synchronize do
1908
- send_command ( "ENABLE #{ [ extensions ] . flatten . join ( ' ' ) } " )
1976
+ send_command ( "ENABLE #{ capabilities } " )
1909
1977
return @responses . delete ( "ENABLED" ) [ -1 ]
1910
1978
end
1911
1979
end
0 commit comments