net-imap 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of net-imap might be problematic. Click here for more details.

data/lib/net/imap.rb CHANGED
@@ -152,75 +152,187 @@ module Net
152
152
  #
153
153
  #
154
154
  # == References
155
+ #--
156
+ # TODO: Consider moving references list to REFERENCES.md or REFERENCES.rdoc.
157
+ #++
155
158
  #
156
- # [[IMAP[https://tools.ietf.org/html/rfc3501]]]
157
- # Crispin, M. "INTERNET MESSAGE ACCESS PROTOCOL - \VERSION 4rev1",
158
- # RFC-3501[https://tools.ietf.org/html/rfc3501], March 2003. (Note:
159
- # obsoletes RFC-2060[https://tools.ietf.org/html/rfc2060], December 1996.)
159
+ # [{IMAP4rev1}[https://www.rfc-editor.org/rfc/rfc3501.html]]::
160
+ # Crispin, M., "INTERNET MESSAGE ACCESS PROTOCOL - \VERSION 4rev1",
161
+ # RFC 3501, DOI 10.17487/RFC3501, March 2003,
162
+ # <https://www.rfc-editor.org/info/rfc3501>.
160
163
  #
161
- # [[LANGUAGE-TAGS[https://tools.ietf.org/html/rfc1766]]]
162
- # Phillips, A. and Davis, M. "Tags for Identifying Languages",
163
- # RFC-5646[https://tools.ietf.org/html/rfc5646], September 2009.
164
- # (Note: obsoletes
165
- # RFC-3066[https://tools.ietf.org/html/rfc3066], January 2001,
166
- # RFC-4646[https://tools.ietf.org/html/rfc4646], September 2006, and
167
- # RFC-1766[https://tools.ietf.org/html/rfc1766], March 1995.)
164
+ # [IMAP-ABNF-EXT[https://www.rfc-editor.org/rfc/rfc4466.html]]::
165
+ # Melnikov, A. and C. Daboo, "Collected Extensions to IMAP4 ABNF",
166
+ # RFC 4466, DOI 10.17487/RFC4466, April 2006,
167
+ # <https://www.rfc-editor.org/info/rfc4466>.
168
168
  #
169
- # [[MD5[https://tools.ietf.org/html/rfc1864]]]
170
- # Myers, J. and M. Rose, "The Content-MD5 Header Field",
171
- # RFC-1864[https://tools.ietf.org/html/rfc1864], October 1995.
169
+ # <em>Note: Net::IMAP cannot parse the entire RFC4466 grammar yet.</em>
170
+ #
171
+ # [{IMAP4rev2}[https://www.rfc-editor.org/rfc/rfc9051.html]]::
172
+ # Melnikov, A., Ed., and B. Leiba, Ed., "Internet Message Access Protocol
173
+ # (\IMAP) - Version 4rev2", RFC 9051, DOI 10.17487/RFC9051, August 2021,
174
+ # <https://www.rfc-editor.org/info/rfc9051>.
175
+ #
176
+ # <em>Note: Net::IMAP is not fully compatible with IMAP4rev2 yet.</em>
177
+ #
178
+ # [IMAP-IMPLEMENTATION[https://www.rfc-editor.org/info/rfc2683]]::
179
+ # Leiba, B., "IMAP4 Implementation Recommendations",
180
+ # RFC 2683, DOI 10.17487/RFC2683, September 1999,
181
+ # <https://www.rfc-editor.org/info/rfc2683>.
182
+ #
183
+ # [IMAP-MULTIACCESS[https://www.rfc-editor.org/info/rfc2180]]::
184
+ # Gahrns, M., "IMAP4 Multi-Accessed Mailbox Practice", RFC 2180, DOI
185
+ # 10.17487/RFC2180, July 1997, <https://www.rfc-editor.org/info/rfc2180>.
186
+ #
187
+ # [UTF7[https://tools.ietf.org/html/rfc2152]]::
188
+ # Goldsmith, D. and M. Davis, "UTF-7 A Mail-Safe Transformation Format of
189
+ # Unicode", RFC 2152, DOI 10.17487/RFC2152, May 1997,
190
+ # <https://www.rfc-editor.org/info/rfc2152>.
172
191
  #
173
- # [[MIME-IMB[https://tools.ietf.org/html/rfc2045]]]
174
- # Freed, N. and N. Borenstein, "MIME (Multipurpose Internet
175
- # Mail Extensions) Part One: Format of Internet Message Bodies",
176
- # RFC-2045[https://tools.ietf.org/html/rfc2045], November 1996.
192
+ # === Message envelope and body structure
177
193
  #
178
- # [[RFC-5322[https://tools.ietf.org/html/rfc5322]]]
179
- # Resnick, P., "Internet Message Format",
180
- # RFC-5322[https://tools.ietf.org/html/rfc5322], October 2008.
181
- # (Note: obsoletes
182
- # RFC-2822[https://tools.ietf.org/html/rfc2822], April 2001, and
183
- # RFC-822[https://tools.ietf.org/html/rfc822], August 1982.)
194
+ # [RFC5322[https://tools.ietf.org/html/rfc5322]]::
195
+ # Resnick, P., Ed., "Internet Message Format",
196
+ # RFC 5322, DOI 10.17487/RFC5322, October 2008,
197
+ # <https://www.rfc-editor.org/info/rfc5322>.
184
198
  #
185
- # [[EXT-QUOTA[https://tools.ietf.org/html/rfc2087]]]
186
- # Myers, J., "IMAP4 QUOTA extension",
187
- # RFC-2087[https://tools.ietf.org/html/rfc2087], January 1997.
199
+ # <em>Note: obsoletes</em>
200
+ # RFC-2822[https://tools.ietf.org/html/rfc2822]<em> (April 2001) and</em>
201
+ # RFC-822[https://tools.ietf.org/html/rfc822]<em> (August 1982).</em>
188
202
  #
189
- # [[EXT-NAMESPACE[https://tools.ietf.org/html/rfc2342]]]
190
- # Gahrns, M. and Newman, C., "IMAP4 Namespace",
191
- # RFC-2342[https://tools.ietf.org/html/rfc2342], May 1998.
203
+ # [CHARSET[https://tools.ietf.org/html/rfc2978]]::
204
+ # Freed, N. and J. Postel, "IANA Charset Registration Procedures", BCP 19,
205
+ # RFC 2978, DOI 10.17487/RFC2978, October 2000,
206
+ # <https://www.rfc-editor.org/info/rfc2978>.
192
207
  #
193
- # [[EXT-ID[https://tools.ietf.org/html/rfc2971]]]
194
- # Showalter, T., "IMAP4 ID extension",
195
- # RFC-2971[https://tools.ietf.org/html/rfc2971], October 2000.
208
+ # [DISPOSITION[https://tools.ietf.org/html/rfc2183]]::
209
+ # Troost, R., Dorner, S., and K. Moore, Ed., "Communicating Presentation
210
+ # Information in Internet Messages: The Content-Disposition Header
211
+ # Field", RFC 2183, DOI 10.17487/RFC2183, August 1997,
212
+ # <https://www.rfc-editor.org/info/rfc2183>.
196
213
  #
197
- # [[EXT-ACL[https://tools.ietf.org/html/rfc4314]]]
198
- # Melnikov, A., "IMAP4 ACL extension",
199
- # RFC-4314[https://tools.ietf.org/html/rfc4314], December 2005. (Note:
200
- # obsoletes RFC-2086[https://tools.ietf.org/html/rfc2086], January 1997.)
214
+ # [MIME-IMB[https://tools.ietf.org/html/rfc2045]]::
215
+ # Freed, N. and N. Borenstein, "Multipurpose Internet Mail Extensions
216
+ # (MIME) Part One: Format of Internet Message Bodies",
217
+ # RFC 2045, DOI 10.17487/RFC2045, November 1996,
218
+ # <https://www.rfc-editor.org/info/rfc2045>.
201
219
  #
202
- # [[EXT-SORT-THREAD[https://tools.ietf.org/html/rfc5256]]]
203
- # Crispin, M. and Muchison, K., "INTERNET MESSAGE ACCESS PROTOCOL - SORT
204
- # and THREAD Extensions", RFC-5256[https://tools.ietf.org/html/rfc5256],
205
- # June 2008.
220
+ # [MIME-IMT[https://tools.ietf.org/html/rfc2046]]::
221
+ # Freed, N. and N. Borenstein, "Multipurpose Internet Mail Extensions
222
+ # (MIME) Part Two: Media Types", RFC 2046, DOI 10.17487/RFC2046,
223
+ # November 1996, <https://www.rfc-editor.org/info/rfc2046>.
206
224
  #
207
- # [[EXT-MOVE[https://tools.ietf.org/html/rfc6851]]]
208
- # Gulbrandsen, A. and Freed, N., "Internet Message Access Protocol (\IMAP) -
209
- # MOVE Extension", RFC-6851[https://tools.ietf.org/html/rfc6851], January
210
- # 2013.
225
+ # [MIME-HDRS[https://tools.ietf.org/html/rfc2047]]::
226
+ # Moore, K., "MIME (Multipurpose Internet Mail Extensions) Part Three:
227
+ # Message Header Extensions for Non-ASCII Text",
228
+ # RFC 2047, DOI 10.17487/RFC2047, November 1996,
229
+ # <https://www.rfc-editor.org/info/rfc2047>.
211
230
  #
212
- # [[OSSL]]
213
- # http://www.openssl.org
231
+ # [RFC2231[https://tools.ietf.org/html/rfc2231]]::
232
+ # Freed, N. and K. Moore, "MIME Parameter Value and Encoded Word
233
+ # Extensions: Character Sets, Languages, and Continuations",
234
+ # RFC 2231, DOI 10.17487/RFC2231, November 1997,
235
+ # <https://www.rfc-editor.org/info/rfc2231>.
236
+ #
237
+ # [I18n-HDRS[https://tools.ietf.org/html/rfc6532]]::
238
+ # Yang, A., Steele, S., and N. Freed, "Internationalized Email Headers",
239
+ # RFC 6532, DOI 10.17487/RFC6532, February 2012,
240
+ # <https://www.rfc-editor.org/info/rfc6532>.
241
+ #
242
+ # [LANGUAGE-TAGS[https://www.rfc-editor.org/info/rfc3282]]::
243
+ # Alvestrand, H., "Content Language Headers",
244
+ # RFC 3282, DOI 10.17487/RFC3282, May 2002,
245
+ # <https://www.rfc-editor.org/info/rfc3282>.
246
+ #
247
+ # [LOCATION[https://www.rfc-editor.org/info/rfc2557]]::
248
+ # Palme, J., Hopmann, A., and N. Shelness, "MIME Encapsulation of
249
+ # Aggregate Documents, such as HTML (MHTML)",
250
+ # RFC 2557, DOI 10.17487/RFC2557, March 1999,
251
+ # <https://www.rfc-editor.org/info/rfc2557>.
252
+ #
253
+ # [MD5[https://tools.ietf.org/html/rfc1864]]::
254
+ # Myers, J. and M. Rose, "The Content-MD5 Header Field",
255
+ # RFC 1864, DOI 10.17487/RFC1864, October 1995,
256
+ # <https://www.rfc-editor.org/info/rfc1864>.
214
257
  #
215
- # [[RSSL]]
216
- # http://savannah.gnu.org/projects/rubypki
258
+ #--
259
+ # TODO: Document IMAP keywords.
217
260
  #
218
- # [[UTF7[https://tools.ietf.org/html/rfc2152]]]
219
- # Goldsmith, D. and Davis, M., "UTF-7: A Mail-Safe Transformation Format of
220
- # Unicode", RFC-2152[https://tools.ietf.org/html/rfc2152], May 1997.
261
+ # [RFC3503[https://tools.ietf.org/html/rfc3503]]
262
+ # Melnikov, A., "Message Disposition Notification (MDN)
263
+ # profile for Internet Message Access Protocol (IMAP)",
264
+ # RFC 3503, DOI 10.17487/RFC3503, March 2003,
265
+ # <https://www.rfc-editor.org/info/rfc3503>.
266
+ #++
267
+ #
268
+ # === Supported \IMAP Extensions
269
+ #
270
+ # [QUOTA[https://tools.ietf.org/html/rfc2087]]::
271
+ # Myers, J., "IMAP4 QUOTA extension", RFC 2087, DOI 10.17487/RFC2087,
272
+ # January 1997, <https://www.rfc-editor.org/info/rfc2087>.
273
+ #--
274
+ # TODO: test compatibility with updated QUOTA extension:
275
+ # [QUOTA[https://tools.ietf.org/html/rfc9208]]::
276
+ # Melnikov, A., "IMAP QUOTA Extension", RFC 9208, DOI 10.17487/RFC9208,
277
+ # March 2022, <https://www.rfc-editor.org/info/rfc9208>.
278
+ #++
279
+ # [IDLE[https://tools.ietf.org/html/rfc2177]]::
280
+ # Leiba, B., "IMAP4 IDLE command", RFC 2177, DOI 10.17487/RFC2177,
281
+ # June 1997, <https://www.rfc-editor.org/info/rfc2177>.
282
+ # [NAMESPACE[https://tools.ietf.org/html/rfc2342]]::
283
+ # Gahrns, M. and C. Newman, "IMAP4 Namespace", RFC 2342,
284
+ # DOI 10.17487/RFC2342, May 1998, <https://www.rfc-editor.org/info/rfc2342>.
285
+ # [ID[https://tools.ietf.org/html/rfc2971]]::
286
+ # Showalter, T., "IMAP4 ID extension", RFC 2971, DOI 10.17487/RFC2971,
287
+ # October 2000, <https://www.rfc-editor.org/info/rfc2971>.
288
+ # [ACL[https://tools.ietf.org/html/rfc4314]]::
289
+ # Melnikov, A., "IMAP4 Access Control List (ACL) Extension", RFC 4314,
290
+ # DOI 10.17487/RFC4314, December 2005,
291
+ # <https://www.rfc-editor.org/info/rfc4314>.
292
+ # [UIDPLUS[https://www.rfc-editor.org/rfc/rfc4315.html]]::
293
+ # Crispin, M., "Internet Message Access Protocol (\IMAP) - UIDPLUS
294
+ # extension", RFC 4315, DOI 10.17487/RFC4315, December 2005,
295
+ # <https://www.rfc-editor.org/info/rfc4315>.
296
+ # [SORT[https://tools.ietf.org/html/rfc5256]]::
297
+ # Crispin, M. and K. Murchison, "Internet Message Access Protocol - SORT and
298
+ # THREAD Extensions", RFC 5256, DOI 10.17487/RFC5256, June 2008,
299
+ # <https://www.rfc-editor.org/info/rfc5256>.
300
+ # [THREAD[https://tools.ietf.org/html/rfc5256]]::
301
+ # Crispin, M. and K. Murchison, "Internet Message Access Protocol - SORT and
302
+ # THREAD Extensions", RFC 5256, DOI 10.17487/RFC5256, June 2008,
303
+ # <https://www.rfc-editor.org/info/rfc5256>.
304
+ # [RFC5530[https://www.rfc-editor.org/rfc/rfc5530.html]]::
305
+ # Gulbrandsen, A., "IMAP Response Codes", RFC 5530, DOI 10.17487/RFC5530,
306
+ # May 2009, <https://www.rfc-editor.org/info/rfc5530>.
307
+ # [MOVE[https://tools.ietf.org/html/rfc6851]]::
308
+ # Gulbrandsen, A. and N. Freed, Ed., "Internet Message Access Protocol
309
+ # (\IMAP) - MOVE Extension", RFC 6851, DOI 10.17487/RFC6851, January 2013,
310
+ # <https://www.rfc-editor.org/info/rfc6851>.
311
+ #
312
+ # === IANA registries
313
+ #
314
+ # * {IMAP Capabilities}[http://www.iana.org/assignments/imap4-capabilities]
315
+ # * {IMAP Response Codes}[https://www.iana.org/assignments/imap-response-codes/imap-response-codes.xhtml]
316
+ # * {IMAP Mailbox Name Attributes}[https://www.iana.org/assignments/imap-mailbox-name-attributes/imap-mailbox-name-attributes.xhtml]
317
+ # * {IMAP and JMAP Keywords}[https://www.iana.org/assignments/imap-jmap-keywords/imap-jmap-keywords.xhtml]
318
+ # * {IMAP Threading Algorithms}[https://www.iana.org/assignments/imap-threading-algorithms/imap-threading-algorithms.xhtml]
319
+ #--
320
+ # * {IMAP Quota Resource Types}[http://www.iana.org/assignments/imap4-capabilities#imap-capabilities-2]
321
+ # * [{LIST-EXTENDED options and responses}[https://www.iana.org/assignments/imap-list-extended/imap-list-extended.xhtml]
322
+ # * {IMAP METADATA Server Entry and Mailbox Entry Registries}[https://www.iana.org/assignments/imap-metadata/imap-metadata.xhtml]
323
+ # * {IMAP ANNOTATE Extension Entries and Attributes}[https://www.iana.org/assignments/imap-annotate-extension/imap-annotate-extension.xhtml]
324
+ # * {IMAP URLAUTH Access Identifiers and Prefixes}[https://www.iana.org/assignments/urlauth-access-ids/urlauth-access-ids.xhtml]
325
+ # * {IMAP URLAUTH Authorization Mechanism Registry}[https://www.iana.org/assignments/urlauth-authorization-mechanism-registry/urlauth-authorization-mechanism-registry.xhtml]
326
+ #++
327
+ # * {SASL Mechanisms and SASL SCRAM Family Mechanisms}[https://www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml]
328
+ # * {Service Name and Transport Protocol Port Number Registry}[https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml]:
329
+ # +imap+: tcp/143, +imaps+: tcp/993
330
+ # * {GSSAPI/Kerberos/SASL Service Names}[https://www.iana.org/assignments/gssapi-service-names/gssapi-service-names.xhtml]:
331
+ # +imap+
332
+ # * {Character sets}[https://www.iana.org/assignments/character-sets/character-sets.xhtml]
221
333
  #
222
334
  class IMAP < Protocol
223
- VERSION = "0.3.1"
335
+ VERSION = "0.3.2"
224
336
 
225
337
  include MonitorMixin
226
338
  if defined?(OpenSSL::SSL)
@@ -251,8 +363,7 @@ module Net
251
363
  # Seconds to wait until an IDLE response is received.
252
364
  attr_reader :idle_response_timeout
253
365
 
254
- # The thread to receive exceptions.
255
- attr_accessor :client_thread
366
+ attr_accessor :client_thread # :nodoc:
256
367
 
257
368
  # Returns the debug mode.
258
369
  def self.debug
@@ -341,7 +452,7 @@ module Net
341
452
  # )
342
453
  # end
343
454
  #
344
- # See [EXT-ID[https://tools.ietf.org/html/rfc2971]] for field definitions.
455
+ # See [ID[https://tools.ietf.org/html/rfc2971]] for field definitions.
345
456
  def id(client_id=nil)
346
457
  synchronize do
347
458
  send_command("ID", ClientID.new(client_id))
@@ -434,15 +545,23 @@ module Net
434
545
  # Sends a SELECT command to select a +mailbox+ so that messages
435
546
  # in the +mailbox+ can be accessed.
436
547
  #
437
- # After you have selected a mailbox, you may retrieve the
438
- # number of items in that mailbox from +@responses["EXISTS"][-1]+,
439
- # and the number of recent messages from +@responses["RECENT"][-1]+.
440
- # Note that these values can change if new messages arrive
441
- # during a session; see #add_response_handler for a way of
442
- # detecting this event.
548
+ # After you have selected a mailbox, you may retrieve the number of items in
549
+ # that mailbox from <tt>imap.responses["EXISTS"][-1]</tt>, and the number of
550
+ # recent messages from <tt>imap.responses["RECENT"][-1]</tt>. Note that
551
+ # these values can change if new messages arrive during a session or when
552
+ # existing messages are expunged; see #add_response_handler for a way to
553
+ # detect these events.
443
554
  #
444
555
  # A Net::IMAP::NoResponseError is raised if the mailbox does not
445
556
  # exist or is for some reason non-selectable.
557
+ #
558
+ # ==== Capabilities
559
+ #
560
+ # If [UIDPLUS[https://www.rfc-editor.org/rfc/rfc4315.html]] is supported,
561
+ # the server may return an untagged "NO" response with a "UIDNOTSTICKY"
562
+ # response code indicating that the mailstore does not support persistent
563
+ # UIDs:
564
+ # @responses["NO"].last.code.name == "UIDNOTSTICKY"
446
565
  def select(mailbox)
447
566
  synchronize do
448
567
  @responses.clear
@@ -589,7 +708,7 @@ module Net
589
708
  # end
590
709
  # end
591
710
  #
592
- # The NAMESPACE extension is described in [EXT-NAMESPACE[https://tools.ietf.org/html/rfc2342]]
711
+ # The NAMESPACE extension is described in [NAMESPACE[https://tools.ietf.org/html/rfc2342]]
593
712
  def namespace
594
713
  synchronize do
595
714
  send_command("NAMESPACE")
@@ -634,7 +753,7 @@ module Net
634
753
  # If this mailbox exists, it returns an array containing objects of type
635
754
  # Net::IMAP::MailboxQuotaRoot and Net::IMAP::MailboxQuota.
636
755
  #
637
- # The QUOTA extension is described in [EXT-QUOTA[https://tools.ietf.org/html/rfc2087]]
756
+ # The QUOTA extension is described in [QUOTA[https://tools.ietf.org/html/rfc2087]]
638
757
  def getquotaroot(mailbox)
639
758
  synchronize do
640
759
  send_command("GETQUOTAROOT", mailbox)
@@ -650,7 +769,7 @@ module Net
650
769
  # Net::IMAP::MailboxQuota object is returned. This
651
770
  # command is generally only available to server admin.
652
771
  #
653
- # The QUOTA extension is described in [EXT-QUOTA[https://tools.ietf.org/html/rfc2087]]
772
+ # The QUOTA extension is described in [QUOTA[https://tools.ietf.org/html/rfc2087]]
654
773
  def getquota(mailbox)
655
774
  synchronize do
656
775
  send_command("GETQUOTA", mailbox)
@@ -663,7 +782,7 @@ module Net
663
782
  # mailbox. Typically one needs to be logged in as a server admin
664
783
  # for this to work.
665
784
  #
666
- # The QUOTA extension is described in [EXT-QUOTA[https://tools.ietf.org/html/rfc2087]]
785
+ # The QUOTA extension is described in [QUOTA[https://tools.ietf.org/html/rfc2087]]
667
786
  def setquota(mailbox, quota)
668
787
  if quota.nil?
669
788
  data = '()'
@@ -677,7 +796,7 @@ module Net
677
796
  # +rights+ that user is to have on that mailbox. If +rights+ is nil,
678
797
  # then that user will be stripped of any rights to that mailbox.
679
798
  #
680
- # The ACL extension is described in [EXT-ACL[https://tools.ietf.org/html/rfc4314]]
799
+ # The ACL extension is described in [ACL[https://tools.ietf.org/html/rfc4314]]
681
800
  def setacl(mailbox, user, rights)
682
801
  if rights.nil?
683
802
  send_command("SETACL", mailbox, user, "")
@@ -690,7 +809,7 @@ module Net
690
809
  # If this mailbox exists, an array containing objects of
691
810
  # Net::IMAP::MailboxACLItem will be returned.
692
811
  #
693
- # The ACL extension is described in [EXT-ACL[https://tools.ietf.org/html/rfc4314]]
812
+ # The ACL extension is described in [ACL[https://tools.ietf.org/html/rfc4314]]
694
813
  def getacl(mailbox)
695
814
  synchronize do
696
815
  send_command("GETACL", mailbox)
@@ -752,6 +871,17 @@ module Net
752
871
  # A Net::IMAP::NoResponseError is raised if the mailbox does
753
872
  # not exist (it is not created automatically), or if the flags,
754
873
  # date_time, or message arguments contain errors.
874
+ #
875
+ # ==== Capabilities
876
+ #
877
+ # If +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315.html]] is
878
+ # supported, the server's response should include a +APPENDUID+ response
879
+ # code with the UIDVALIDITY of the destination mailbox and the assigned UID
880
+ # of the appended message.
881
+ #
882
+ #--
883
+ # TODO: add MULTIAPPEND support
884
+ #++
755
885
  def append(mailbox, message, flags = nil, date_time = nil)
756
886
  args = []
757
887
  if flags
@@ -777,6 +907,20 @@ module Net
777
907
  send_command("CLOSE")
778
908
  end
779
909
 
910
+ # Sends an {UNSELECT command [IMAP4rev2
911
+ # §6.4.2]}[https://www.rfc-editor.org/rfc/rfc9051#section-6.4.2] to free the
912
+ # session resources for a mailbox and return to the "_authenticated_" state.
913
+ # This is the same as #close, except that <tt>\\Deleted</tt> messages are
914
+ # not removed from the mailbox.
915
+ #
916
+ # ===== Capabilities
917
+ #
918
+ # The server's capabilities must include +UNSELECT+
919
+ # [RFC3691[https://tools.ietf.org/html/rfc3691]].
920
+ def unselect
921
+ send_command("UNSELECT")
922
+ end
923
+
780
924
  # Sends a EXPUNGE command to permanently remove from the currently
781
925
  # selected mailbox all messages that have the \Deleted flag set.
782
926
  def expunge
@@ -786,6 +930,34 @@ module Net
786
930
  end
787
931
  end
788
932
 
933
+ # Similar to #expunge, but takes a set of unique identifiers as
934
+ # argument. Sends a UID EXPUNGE command to permanently remove all
935
+ # messages that have both the \\Deleted flag set and a UID that is
936
+ # included in +uid_set+.
937
+ #
938
+ # By using UID EXPUNGE instead of EXPUNGE when resynchronizing with
939
+ # the server, the client can ensure that it does not inadvertantly
940
+ # remove any messages that have been marked as \\Deleted by other
941
+ # clients between the time that the client was last connected and
942
+ # the time the client resynchronizes.
943
+ #
944
+ # Note:: Although the command takes a +uid_set+ for its argument, the
945
+ # server still returns regular EXPUNGE responses, which contain
946
+ # a <em>sequence number</em>. These will be deleted from
947
+ # #responses and this method returns them as an array of
948
+ # <em>sequence number</em> integers.
949
+ #
950
+ # ==== Capability requirement
951
+ #
952
+ # +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315.html]] must be
953
+ # supported by the server.
954
+ def uid_expunge(uid_set)
955
+ synchronize do
956
+ send_command("UID EXPUNGE", MessageSet.new(uid_set))
957
+ return @responses.delete("EXPUNGE")
958
+ end
959
+ end
960
+
789
961
  # Sends a SEARCH command to search the mailbox for messages that
790
962
  # match the given searching criteria, and returns message sequence
791
963
  # numbers. +keys+ can either be a string holding the entire
@@ -906,11 +1078,22 @@ module Net
906
1078
  # of the specified destination +mailbox+. The +set+ parameter is
907
1079
  # a number, an array of numbers, or a Range object. The number is
908
1080
  # a message sequence number.
1081
+ #
1082
+ # ==== Capabilities
1083
+ #
1084
+ # If +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315.html]] is
1085
+ # supported, the server's response should include a +COPYUID+ response code
1086
+ # with the UIDVALIDITY of the destination mailbox, the UID set of the source
1087
+ # messages, and the assigned UID set of the moved messages.
909
1088
  def copy(set, mailbox)
910
1089
  copy_internal("COPY", set, mailbox)
911
1090
  end
912
1091
 
913
1092
  # Similar to #copy, but +set+ contains unique identifiers.
1093
+ #
1094
+ # ==== Capabilities
1095
+ #
1096
+ # +UIDPLUS+ affects #uid_copy the same way it affects #copy.
914
1097
  def uid_copy(set, mailbox)
915
1098
  copy_internal("UID COPY", set, mailbox)
916
1099
  end
@@ -920,14 +1103,27 @@ module Net
920
1103
  # a number, an array of numbers, or a Range object. The number is
921
1104
  # a message sequence number.
922
1105
  #
923
- # The MOVE extension is described in [EXT-MOVE[https://tools.ietf.org/html/rfc6851]].
1106
+ # ==== Capabilities requirements
1107
+ #
1108
+ # +MOVE+ [RFC6851[https://tools.ietf.org/html/rfc6851]] must be supported by
1109
+ # the server.
1110
+ #
1111
+ # If +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315.html]] is
1112
+ # also supported, the server's response should include a +COPYUID+ response
1113
+ # code with the UIDVALIDITY of the destination mailbox, the UID set of the
1114
+ # source messages, and the assigned UID set of the moved messages.
1115
+ #
924
1116
  def move(set, mailbox)
925
1117
  copy_internal("MOVE", set, mailbox)
926
1118
  end
927
1119
 
928
1120
  # Similar to #move, but +set+ contains unique identifiers.
929
1121
  #
930
- # The MOVE extension is described in [EXT-MOVE[https://tools.ietf.org/html/rfc6851]].
1122
+ # ==== Capabilities requirements
1123
+ #
1124
+ # Same as #move: +MOVE+ [RFC6851[https://tools.ietf.org/html/rfc6851]] must
1125
+ # be supported by the server. +UIDPLUS+ also affects #uid_move the same way
1126
+ # it affects #move.
931
1127
  def uid_move(set, mailbox)
932
1128
  copy_internal("UID MOVE", set, mailbox)
933
1129
  end
@@ -940,14 +1136,14 @@ module Net
940
1136
  # p imap.sort(["DATE"], ["SUBJECT", "hello"], "US-ASCII")
941
1137
  # #=> [6, 7, 8, 1]
942
1138
  #
943
- # The SORT extension is described in [EXT-SORT-THREAD[https://tools.ietf.org/html/rfc5256]].
1139
+ # The SORT extension is described in [SORT[https://tools.ietf.org/html/rfc5256]].
944
1140
  def sort(sort_keys, search_keys, charset)
945
1141
  return sort_internal("SORT", sort_keys, search_keys, charset)
946
1142
  end
947
1143
 
948
1144
  # Similar to #sort, but returns an array of unique identifiers.
949
1145
  #
950
- # The SORT extension is described in [EXT-SORT-THREAD[https://tools.ietf.org/html/rfc5256]].
1146
+ # The SORT extension is described in [SORT[https://tools.ietf.org/html/rfc5256]].
951
1147
  def uid_sort(sort_keys, search_keys, charset)
952
1148
  return sort_internal("UID SORT", sort_keys, search_keys, charset)
953
1149
  end
@@ -986,7 +1182,7 @@ module Net
986
1182
  # Unlike #search, +charset+ is a required argument. US-ASCII
987
1183
  # and UTF-8 are sample values.
988
1184
  #
989
- # The THREAD extension is described in [EXT-SORT-THREAD[https://tools.ietf.org/html/rfc5256]].
1185
+ # The THREAD extension is described in [THREAD[https://tools.ietf.org/html/rfc5256]].
990
1186
  def thread(algorithm, search_keys, charset)
991
1187
  return thread_internal("THREAD", algorithm, search_keys, charset)
992
1188
  end
@@ -994,7 +1190,7 @@ module Net
994
1190
  # Similar to #thread, but returns unique identifiers instead of
995
1191
  # message sequence numbers.
996
1192
  #
997
- # The THREAD extension is described in [EXT-SORT-THREAD[https://tools.ietf.org/html/rfc5256]].
1193
+ # The THREAD extension is described in [THREAD[https://tools.ietf.org/html/rfc5256]].
998
1194
  def uid_thread(algorithm, search_keys, charset)
999
1195
  return thread_internal("UID THREAD", algorithm, search_keys, charset)
1000
1196
  end
@@ -1072,9 +1268,7 @@ module Net
1072
1268
  #
1073
1269
  # port:: Port number (default value is 143 for imap, or 993 for imaps)
1074
1270
  # ssl:: If +options[:ssl]+ is true, then an attempt will be made
1075
- # to use SSL (now TLS) to connect to the server. For this to work
1076
- # OpenSSL [OSSL] and the Ruby OpenSSL [RSSL] extensions need to
1077
- # be installed.
1271
+ # to use SSL (now TLS) to connect to the server.
1078
1272
  # If +options[:ssl]+ is a hash, it's passed to
1079
1273
  # OpenSSL::SSL::SSLContext#set_params as parameters.
1080
1274
  # open_timeout:: Seconds to wait until a connection is opened
@@ -1474,3 +1668,4 @@ require_relative "imap/flags"
1474
1668
  require_relative "imap/response_data"
1475
1669
  require_relative "imap/response_parser"
1476
1670
  require_relative "imap/authenticators"
1671
+ require_relative "imap/sasl"
data/net-imap.gemspec CHANGED
@@ -32,6 +32,8 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ["lib"]
33
33
 
34
34
  spec.add_dependency "net-protocol"
35
+ spec.add_dependency "date"
36
+
35
37
  spec.add_development_dependency "digest"
36
38
  spec.add_development_dependency "strscan"
37
39
  end
data/rakelib/rdoc.rake ADDED
@@ -0,0 +1,70 @@
1
+ # require "sdoc"
2
+ require "rdoc/task"
3
+ require_relative "../lib/net/imap"
4
+ require 'rdoc/rdoc' unless defined?(RDoc::Markup::ToHtml)
5
+
6
+ module RDoc::Generator
7
+ module NetIMAP
8
+
9
+ module RemoveRedundantParens
10
+ def param_seq
11
+ super.sub(/^\(\)\s*/, "")
12
+ end
13
+ end
14
+
15
+ # See https://github.com/ruby/rdoc/pull/936
16
+ module FixSectionComments
17
+ def markup(text)
18
+ @store ||= @parent&.store
19
+ super
20
+ end
21
+ def description; markup comment end
22
+ def comment; super || @comments&.first end
23
+ def parse(_comment_location = nil) super() end
24
+ end
25
+
26
+ # render "[label] data" lists as tables. adapted from "hanna-nouveau" gem.
27
+ module LabelListTable
28
+ def list_item_start(list_item, list_type)
29
+ case list_type
30
+ when :NOTE
31
+ %(<tr><td class='label'>#{Array(list_item.label).map{|label| to_html(label)}.join("<br />")}</td><td>)
32
+ else
33
+ super
34
+ end
35
+ end
36
+
37
+ def list_end_for(list_type)
38
+ case list_type
39
+ when :NOTE then
40
+ "</td></tr>"
41
+ else
42
+ super
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+ end
49
+
50
+ class RDoc::AnyMethod
51
+ prepend RDoc::Generator::NetIMAP::RemoveRedundantParens
52
+ end
53
+
54
+ class RDoc::Context::Section
55
+ prepend RDoc::Generator::NetIMAP::FixSectionComments
56
+ end
57
+
58
+ class RDoc::Markup::ToHtml
59
+ LIST_TYPE_TO_HTML[:NOTE] = ['<table class="rdoc-list note-list"><tbody>', '</tbody></table>']
60
+ prepend RDoc::Generator::NetIMAP::LabelListTable
61
+ end
62
+
63
+ RDoc::Task.new do |doc|
64
+ doc.main = "README.md"
65
+ doc.title = "net-imap #{Net::IMAP::VERSION}"
66
+ doc.rdoc_dir = "doc"
67
+ doc.rdoc_files = FileList.new %w[lib/**/*.rb *.rdoc *.md]
68
+ doc.options << "--template-stylesheets" << "docs/styles.css"
69
+ # doc.generator = "hanna"
70
+ end