net-imap 0.4.4 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/docs/styles.css +0 -12
- data/lib/net/imap/data_encoding.rb +14 -2
- data/lib/net/imap/fetch_data.rb +518 -0
- data/lib/net/imap/response_data.rb +26 -207
- data/lib/net/imap/response_parser/parser_utils.rb +1 -1
- data/lib/net/imap/response_parser.rb +477 -243
- data/lib/net/imap/sequence_set.rb +67 -0
- data/lib/net/imap.rb +82 -17
- data/rakelib/benchmarks.rake +4 -11
- metadata +5 -3
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Net
|
4
|
+
class IMAP
|
5
|
+
|
6
|
+
##
|
7
|
+
# An IMAP {sequence
|
8
|
+
# set}[https://www.rfc-editor.org/rfc/rfc9051.html#section-4.1.1],
|
9
|
+
# is a set of message sequence numbers or unique identifier numbers
|
10
|
+
# ("UIDs"). It contains numbers and ranges of numbers. The numbers are all
|
11
|
+
# non-zero unsigned 32-bit integers and one special value, <tt>*</tt>, that
|
12
|
+
# represents the largest value in the mailbox.
|
13
|
+
#
|
14
|
+
# *NOTE:* This SequenceSet class is currently a placeholder for unhandled
|
15
|
+
# extension data. All it does now is validate. It will be expanded to a
|
16
|
+
# full API in a future release.
|
17
|
+
class SequenceSet
|
18
|
+
|
19
|
+
def self.[](str) new(str).freeze end
|
20
|
+
|
21
|
+
def initialize(input)
|
22
|
+
@atom = -String.try_convert(input)
|
23
|
+
validate
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the IMAP string representation. In the IMAP grammar,
|
27
|
+
# +sequence-set+ is a subset of +atom+ which is a subset of +astring+.
|
28
|
+
attr_accessor :atom
|
29
|
+
|
30
|
+
# Returns #atom. In the IMAP grammar, +atom+ is a subset of +astring+.
|
31
|
+
alias astring atom
|
32
|
+
|
33
|
+
# Returns the value of #atom
|
34
|
+
alias to_s atom
|
35
|
+
|
36
|
+
# Hash equality requires the same encoded #atom representation.
|
37
|
+
#
|
38
|
+
# Net::IMAP::SequenceSet["1:3"] .eql? Net::IMAP::SequenceSet["1:3"] # => true
|
39
|
+
# Net::IMAP::SequenceSet["1,2,3"].eql? Net::IMAP::SequenceSet["1:3"] # => false
|
40
|
+
# Net::IMAP::SequenceSet["1,3"] .eql? Net::IMAP::SequenceSet["3,1"] # => false
|
41
|
+
# Net::IMAP::SequenceSet["9,1:*"].eql? Net::IMAP::SequenceSet["1:*"] # => false
|
42
|
+
#
|
43
|
+
def eql?(other) self.class == other.class && atom == other.atom end
|
44
|
+
alias == eql?
|
45
|
+
|
46
|
+
# See #eql?
|
47
|
+
def hash; [self.class. atom].hash end
|
48
|
+
|
49
|
+
def inspect
|
50
|
+
(frozen? ? "%s[%p]" : "#<%s %p>") % [self.class, to_s]
|
51
|
+
end
|
52
|
+
|
53
|
+
# Unstable API, for internal use only (Net::IMAP#validate_data)
|
54
|
+
def validate # :nodoc:
|
55
|
+
ResponseParser::Patterns::SEQUENCE_SET_STR.match?(@atom) or
|
56
|
+
raise ArgumentError, "invalid sequence-set: %p" % [input]
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
# Unstable API, for internal use only (Net::IMAP#send_data)
|
61
|
+
def send_data(imap, tag) # :nodoc:
|
62
|
+
imap.__send__(:put_string, atom)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/net/imap.rb
CHANGED
@@ -404,18 +404,18 @@ module Net
|
|
404
404
|
#
|
405
405
|
# Although IMAP4rev2[https://tools.ietf.org/html/rfc9051] is not supported
|
406
406
|
# yet, Net::IMAP supports several extensions that have been folded into it:
|
407
|
-
# +ENABLE+, +IDLE+, +MOVE+, +NAMESPACE+, +SASL-IR+, +UIDPLUS+,
|
407
|
+
# +ENABLE+, +IDLE+, +MOVE+, +NAMESPACE+, +SASL-IR+, +UIDPLUS+, +UNSELECT+, and
|
408
|
+
# the fetch side of +BINARY+.
|
408
409
|
# Commands for these extensions are listed with the {Core IMAP
|
409
410
|
# commands}[rdoc-ref:Net::IMAP@Core+IMAP+commands], above.
|
410
411
|
#
|
411
412
|
# >>>
|
412
413
|
# <em>The following are folded into +IMAP4rev2+ but are currently
|
413
414
|
# unsupported or incompletely supported by</em> Net::IMAP<em>: RFC4466
|
414
|
-
# extensions, +ESEARCH+, +SEARCHRES+, +LIST-EXTENDED+,
|
415
|
-
# +
|
416
|
-
#
|
417
|
-
#
|
418
|
-
# <tt>STATUS=DELETED</tt>.</em>
|
415
|
+
# extensions, +ESEARCH+, +SEARCHRES+, +LIST-EXTENDED+, +LIST-STATUS+,
|
416
|
+
# +LITERAL-+, and +SPECIAL-USE+. The following extensions are implicitly
|
417
|
+
# supported, but will be updated with more direct support: RFC5530 response
|
418
|
+
# codes, <tt>STATUS=SIZE</tt>, and <tt>STATUS=DELETED</tt>.</em>
|
419
419
|
#
|
420
420
|
# ==== RFC2087: +QUOTA+
|
421
421
|
# - #getquota: returns the resource usage and limits for a quota root
|
@@ -437,6 +437,15 @@ module Net
|
|
437
437
|
# ==== RFC2971: +ID+
|
438
438
|
# - #id: exchanges client and server implementation information.
|
439
439
|
#
|
440
|
+
# ==== RFC3516: +BINARY+
|
441
|
+
# The fetch side of +BINARY+ has been folded into
|
442
|
+
# IMAP4rev2[https://tools.ietf.org/html/rfc9051].
|
443
|
+
# - Updates #fetch and #uid_fetch with the +BINARY+, +BINARY.PEEK+, and
|
444
|
+
# +BINARY.SIZE+ items. See FetchData#binary and FetchData#binary_size.
|
445
|
+
#
|
446
|
+
# >>>
|
447
|
+
# *NOTE:* The binary extension the #append command is _not_ supported yet.
|
448
|
+
#
|
440
449
|
# ==== RFC3691: +UNSELECT+
|
441
450
|
# Folded into IMAP4rev2[https://tools.ietf.org/html/rfc9051] and also included
|
442
451
|
# above with {Core IMAP commands}[rdoc-ref:Net::IMAP@Core+IMAP+commands].
|
@@ -474,9 +483,17 @@ module Net
|
|
474
483
|
# which arranges the results into ordered groups or threads according to a
|
475
484
|
# chosen algorithm.
|
476
485
|
#
|
477
|
-
# ==== +
|
486
|
+
# ==== +X-GM-EXT-1+
|
487
|
+
# +X-GM-EXT-1+ is a non-standard Gmail extension. See {Google's
|
488
|
+
# documentation}[https://developers.google.com/gmail/imap/imap-extensions].
|
489
|
+
# - Updates #fetch and #uid_fetch with support for +X-GM-MSGID+ (unique
|
490
|
+
# message ID), +X-GM-THRID+ (thread ID), and +X-GM-LABELS+ (Gmail labels).
|
491
|
+
# - Updates #search with the +X-GM-RAW+ search attribute.
|
478
492
|
# - #xlist: replaced by +SPECIAL-USE+ attributes in #list responses.
|
479
493
|
#
|
494
|
+
# *NOTE:* The +OBJECTID+ extension should replace +X-GM-MSGID+ and
|
495
|
+
# +X-GM-THRID+, but Gmail does not support it (as of 2023-11-10).
|
496
|
+
#
|
480
497
|
# ==== RFC6851: +MOVE+
|
481
498
|
# Folded into IMAP4rev2[https://tools.ietf.org/html/rfc9051] and also included
|
482
499
|
# above with {Core IMAP commands}[rdoc-ref:Net::IMAP@Core+IMAP+commands].
|
@@ -487,6 +504,13 @@ module Net
|
|
487
504
|
#
|
488
505
|
# - See #enable for information about support for UTF-8 string encoding.
|
489
506
|
#
|
507
|
+
# ==== RFC8474: +OBJECTID+
|
508
|
+
# - Adds +MAILBOXID+ ResponseCode to #create tagged response.
|
509
|
+
# - Adds +MAILBOXID+ ResponseCode to #select and #examine untagged response.
|
510
|
+
# - Updates #fetch and #uid_fetch with the +EMAILID+ and +THREADID+ items.
|
511
|
+
# See FetchData#emailid and FetchData#emailid.
|
512
|
+
# - Updates #status with support for the +MAILBOXID+ status attribute.
|
513
|
+
#
|
490
514
|
# == References
|
491
515
|
#
|
492
516
|
# [{IMAP4rev1}[https://www.rfc-editor.org/rfc/rfc3501.html]]::
|
@@ -612,6 +636,10 @@ module Net
|
|
612
636
|
# [ID[https://tools.ietf.org/html/rfc2971]]::
|
613
637
|
# Showalter, T., "IMAP4 ID extension", RFC 2971, DOI 10.17487/RFC2971,
|
614
638
|
# October 2000, <https://www.rfc-editor.org/info/rfc2971>.
|
639
|
+
# [BINARY[https://tools.ietf.org/html/rfc3516]]::
|
640
|
+
# Nerenberg, L., "IMAP4 Binary Content Extension", RFC 3516,
|
641
|
+
# DOI 10.17487/RFC3516, April 2003,
|
642
|
+
# <https://www.rfc-editor.org/info/rfc3516>.
|
615
643
|
# [ACL[https://tools.ietf.org/html/rfc4314]]::
|
616
644
|
# Melnikov, A., "IMAP4 Access Control List (ACL) Extension", RFC 4314,
|
617
645
|
# DOI 10.17487/RFC4314, December 2005,
|
@@ -662,7 +690,7 @@ module Net
|
|
662
690
|
# * {IMAP URLAUTH Authorization Mechanism Registry}[https://www.iana.org/assignments/urlauth-authorization-mechanism-registry/urlauth-authorization-mechanism-registry.xhtml]
|
663
691
|
#
|
664
692
|
class IMAP < Protocol
|
665
|
-
VERSION = "0.4.
|
693
|
+
VERSION = "0.4.6"
|
666
694
|
|
667
695
|
# Aliases for supported capabilities, to be used with the #enable command.
|
668
696
|
ENABLE_ALIASES = {
|
@@ -1662,21 +1690,58 @@ module Net
|
|
1662
1690
|
|
1663
1691
|
# Sends a {STATUS commands [IMAP4rev1 §6.3.10]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.3.10]
|
1664
1692
|
# and returns the status of the indicated +mailbox+. +attr+ is a list of one
|
1665
|
-
# or more attributes whose statuses are to be requested.
|
1666
|
-
#
|
1693
|
+
# or more attributes whose statuses are to be requested.
|
1694
|
+
#
|
1695
|
+
# The return value is a hash of attributes. Most status attributes return
|
1696
|
+
# integer values, but some return other value types (documented below).
|
1697
|
+
#
|
1698
|
+
# A Net::IMAP::NoResponseError is raised if status values
|
1699
|
+
# for +mailbox+ cannot be returned; for instance, because it
|
1700
|
+
# does not exist.
|
1701
|
+
#
|
1702
|
+
# ===== Supported attributes
|
1703
|
+
#
|
1704
|
+
# +MESSAGES+:: The number of messages in the mailbox.
|
1705
|
+
#
|
1706
|
+
# +UIDNEXT+:: The next unique identifier value of the mailbox.
|
1707
|
+
#
|
1708
|
+
# +UIDVALIDITY+:: The unique identifier validity value of the mailbox.
|
1667
1709
|
#
|
1668
|
-
#
|
1669
|
-
# RECENT:: the number of recent messages in the mailbox.
|
1670
|
-
# UNSEEN:: the number of unseen messages in the mailbox.
|
1710
|
+
# +UNSEEN+:: The number of messages without the <tt>\Seen</tt> flag.
|
1671
1711
|
#
|
1672
|
-
# The
|
1712
|
+
# +DELETED+:: The number of messages with the <tt>\Deleted</tt> flag.
|
1713
|
+
#
|
1714
|
+
# +SIZE+::
|
1715
|
+
# The approximate size of the mailbox---must be greater than or equal to
|
1716
|
+
# the sum of all messages' +RFC822.SIZE+ fetch item values.
|
1717
|
+
#
|
1718
|
+
# +MAILBOXID+::
|
1719
|
+
# A server-allocated unique _string_ identifier for the mailbox.
|
1720
|
+
# See +OBJECTID+
|
1721
|
+
# {[RFC8474]}[https://www.rfc-editor.org/rfc/rfc8474.html#section-4].
|
1722
|
+
#
|
1723
|
+
# +RECENT+::
|
1724
|
+
# The number of messages with the <tt>\Recent</tt> flag.
|
1725
|
+
# _NOTE:_ +RECENT+ was removed from IMAP4rev2.
|
1726
|
+
#
|
1727
|
+
# Unsupported attributes may be requested. The attribute value will be
|
1728
|
+
# either an Integer or an ExtensionData object.
|
1729
|
+
#
|
1730
|
+
# ===== For example:
|
1673
1731
|
#
|
1674
1732
|
# p imap.status("inbox", ["MESSAGES", "RECENT"])
|
1675
1733
|
# #=> {"RECENT"=>0, "MESSAGES"=>44}
|
1676
1734
|
#
|
1677
|
-
#
|
1678
|
-
#
|
1679
|
-
#
|
1735
|
+
# ===== Capabilities
|
1736
|
+
#
|
1737
|
+
# +SIZE+ requires the server's capabilities to include either +IMAP4rev2+ or
|
1738
|
+
# <tt>STATUS=SIZE</tt>
|
1739
|
+
# {[RFC8483]}[https://www.rfc-editor.org/rfc/rfc8483.html].
|
1740
|
+
#
|
1741
|
+
# +DELETED+ requires the server's capabilities to include +IMAP4rev2+.
|
1742
|
+
#
|
1743
|
+
# +MAILBOXID+ requires the server's capabilities to include +OBJECTID+
|
1744
|
+
# {[RFC8474]}[https://www.rfc-editor.org/rfc/rfc8474.html].
|
1680
1745
|
def status(mailbox, attr)
|
1681
1746
|
synchronize do
|
1682
1747
|
send_command("STATUS", mailbox, attr)
|
data/rakelib/benchmarks.rake
CHANGED
@@ -17,11 +17,6 @@ BENCHMARK_INIT = <<RUBY
|
|
17
17
|
parser = Net::IMAP::ResponseParser.new
|
18
18
|
RUBY
|
19
19
|
|
20
|
-
PER_BENCHMARK_PRELUDE = <<RUBY
|
21
|
-
response = load_response(%p,
|
22
|
-
%p)
|
23
|
-
RUBY
|
24
|
-
|
25
20
|
file "benchmarks/parser.yml" => PARSER_TEST_FIXTURES do |t|
|
26
21
|
require "yaml"
|
27
22
|
require "pathname"
|
@@ -31,7 +26,7 @@ file "benchmarks/parser.yml" => PARSER_TEST_FIXTURES do |t|
|
|
31
26
|
files = path.glob("*.yml")
|
32
27
|
tests = files.flat_map {|file|
|
33
28
|
file.read
|
34
|
-
.gsub(%r{([-:]) !ruby/struct:\S+}) { $1 }
|
29
|
+
.gsub(%r{([-:]) !ruby/(object|struct):\S+}) { $1 }
|
35
30
|
.then {
|
36
31
|
YAML.safe_load(_1, filename: file,
|
37
32
|
permitted_classes: [Symbol, Regexp], aliases: true)
|
@@ -42,14 +37,12 @@ file "benchmarks/parser.yml" => PARSER_TEST_FIXTURES do |t|
|
|
42
37
|
test.key?(:expected) ? :parser_assert_equal : :parser_pending
|
43
38
|
}
|
44
39
|
}
|
45
|
-
.map {|test_name,
|
46
|
-
[file.relative_path_from(__dir__).to_s, test_name.to_s]
|
47
|
-
}
|
40
|
+
.map {|test_name, test| [test_name.to_s, test.fetch(:response)] }
|
48
41
|
}
|
49
42
|
|
50
|
-
benchmarks = tests.map {|
|
43
|
+
benchmarks = tests.map {|fixture_name, response|
|
51
44
|
{"name" => fixture_name.delete_prefix("test_"),
|
52
|
-
"prelude" =>
|
45
|
+
"prelude" => "response = -%s.b" % [response.dump],
|
53
46
|
"script" => "parser.parse(response)"}
|
54
47
|
}
|
55
48
|
.sort_by { _1["name"] }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-imap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shugo Maeda
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-11-
|
12
|
+
date: 2023-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-protocol
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/net/imap/data_encoding.rb
|
91
91
|
- lib/net/imap/deprecated_client_options.rb
|
92
92
|
- lib/net/imap/errors.rb
|
93
|
+
- lib/net/imap/fetch_data.rb
|
93
94
|
- lib/net/imap/flags.rb
|
94
95
|
- lib/net/imap/response_data.rb
|
95
96
|
- lib/net/imap/response_parser.rb
|
@@ -112,6 +113,7 @@ files:
|
|
112
113
|
- lib/net/imap/sasl/stringprep.rb
|
113
114
|
- lib/net/imap/sasl/xoauth2_authenticator.rb
|
114
115
|
- lib/net/imap/sasl_adapter.rb
|
116
|
+
- lib/net/imap/sequence_set.rb
|
115
117
|
- lib/net/imap/stringprep.rb
|
116
118
|
- lib/net/imap/stringprep/nameprep.rb
|
117
119
|
- lib/net/imap/stringprep/saslprep.rb
|
@@ -146,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
148
|
- !ruby/object:Gem::Version
|
147
149
|
version: '0'
|
148
150
|
requirements: []
|
149
|
-
rubygems_version: 3.4.
|
151
|
+
rubygems_version: 3.4.22
|
150
152
|
signing_key:
|
151
153
|
specification_version: 4
|
152
154
|
summary: Ruby client api for Internet Message Access Protocol
|