imap.rb 0.4.9 → 0.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b062efdc696b59573e564f135485c3e987a8a8078b36e87783537cbcd040712a
4
- data.tar.gz: 150f927c8023ed6cbbb1b58fa5b863620ba2043ec71058c52f36a75c817e9e0a
3
+ metadata.gz: 8be67e0de4db977ee6ba474e7355fadae929bd267132fd867d64f96caa3c7a19
4
+ data.tar.gz: e930fe80e9f8cffac1837670688e22f8826ce50391a36b5f5cc8474f0c89e9fb
5
5
  SHA512:
6
- metadata.gz: c979d4b09d86154e500454440396443d9db9ee8134603ea5d432ed093e46bc3a54fa33aaa24667302dc540566e8863c6d50c22c112c87ee91a1b224c7a4d567c
7
- data.tar.gz: 4e91af7317d63811a9ec9dff17ff14130926bf101d4631e6fbfa5069501c12e90b1af0fa28efa315a6a1dc52b823b012e89f14e6d7dbdec3b8b7fe1fa44e3bff
6
+ metadata.gz: 3b8f36bc1285a4f379624038e387cd70e825c07b617f07a60ebd5ba11ee62a775126eb1a0263107739bea073b44b2d2cc86c4c3f05a5533eb8ea848f5f11b0f0
7
+ data.tar.gz: 36f1969380582aef53570369140fdffddd920fabc04a157faca0accd49f38286f8563934b3db3c049e0769074d355339cc234ccfe65fa63f53d8a61eebc096fa
data/CHANGELOG CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## 20260917
4
4
 
5
+ 0.5.0: + OR and NOT to the criteria, and HEADER given its field
6
+
7
+ 1. + Imap::Search#any_of: or: [{from: 'a@x'}, {to: 'b@y'}]. OR takes two keys and no more, so three or more nest, OR OR a b c, as the server reads them. Each side is a criteria hash of its own and may nest further.
8
+ 2. + Imap::Search#none_of: not: {subject: 'Payday'}. NOT takes one key, so several are negated apiece, NOT a NOT b.
9
+ 3. ~ Imap::Search#to_imap_search_keys: OR and NOT read before the operator tests, being neither general nor boolean.
10
+ 4. HEADER wanted no change: an array value already flattens to ['HEADER', field, value], which nothing said and nothing tested. It is tested now.
11
+ 5. + tests for each, and for OR mixed with the plain keys.
12
+ 6. ~ Imap::VERSION: /0.4.9/0.5.0/
13
+
14
+
5
15
  0.4.9: + imap.rb.gemspec, so that the gem resolves under both names.
6
16
 
7
17
  1. + imap.rb.gemspec: the same code published as imap.rb, which is how gems are named here: 21 carry the suffix and imap is one of the few which do not. rubygems has no notion of an alias, so the two are separate gems which must be kept at the same version by hand.
data/lib/Imap/Search.rb CHANGED
@@ -123,6 +123,10 @@ class Imap
123
123
  criteria.inject([]) do |m, kv|
124
124
  key, value = kv.first.to_s.upcase, kv.last
125
125
  case
126
+ when key == 'OR'
127
+ m << any_of(value)
128
+ when key == 'NOT'
129
+ m << none_of(value)
126
130
  when general_operator?(key)
127
131
  m << general_to_imap_search_key(key, value)
128
132
  when boolean_operator?(key)
@@ -133,6 +137,17 @@ class Imap
133
137
  end.flatten
134
138
  end
135
139
 
140
+ # OR takes two keys and no more, so three criteria nest: OR OR a b c. Each
141
+ # is a criteria hash of its own, so either side may nest further.
142
+ def any_of(criteria_hashes)
143
+ criteria_hashes.collect{|criteria_hash| Search.new(nil, criteria_hash).to_imap_search_keys}.inject{|m, keys| ['OR'] + m + keys}
144
+ end
145
+
146
+ # NOT takes one key, so each criterion is negated on its own: NOT a NOT b.
147
+ def none_of(criteria_hash)
148
+ criteria_hash.inject([]){|m, kv| m + ['NOT'] + Search.new(nil, Hash[*kv]).to_imap_search_keys}
149
+ end
150
+
136
151
  def general_to_imap_search_key(key, value)
137
152
  value.is_a?(Negated) ? ['NOT', key, value.value] : [key, value]
138
153
  end
data/lib/Imap/VERSION.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Imap
2
- VERSION = '0.4.9'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -44,6 +44,34 @@ describe Imap::Search do
44
44
  end
45
45
  end
46
46
 
47
+ describe 'OR, NOT and HEADER' do
48
+ def keys(criteria) = Imap::Search.new(client, criteria).to_imap_search_keys
49
+
50
+ it 'takes two criteria hashes for OR' do
51
+ _(keys(or: [{from: 'a@x'}, {to: 'b@y'}])).must_equal ['OR', 'FROM', 'a@x', 'TO', 'b@y']
52
+ end
53
+
54
+ it 'nests OR where there are more than two, it taking only two' do
55
+ _(keys(or: [{from: 'a@x'}, {to: 'b@y'}, {cc: 'c@z'}])).must_equal ['OR', 'OR', 'FROM', 'a@x', 'TO', 'b@y', 'CC', 'c@z']
56
+ end
57
+
58
+ it 'negates a criterion for NOT' do
59
+ _(keys(not: {subject: 'Payday'})).must_equal ['NOT', 'SUBJECT', 'Payday']
60
+ end
61
+
62
+ it 'negates each on its own where NOT carries more than one, it taking only one' do
63
+ _(keys(not: {subject: 'Payday', seen: true})).must_equal ['NOT', 'SUBJECT', 'Payday', 'NOT', 'SEEN']
64
+ end
65
+
66
+ it 'takes a field and a value for HEADER' do
67
+ _(keys(header: ['List-Id', 'announce'])).must_equal ['HEADER', 'List-Id', 'announce']
68
+ end
69
+
70
+ it 'mixes with the plain keys' do
71
+ _(keys(since: '1-Sep-2026', or: [{from: 'a@x'}, {to: 'b@y'}])).must_equal ['SINCE', '1-Sep-2026', 'OR', 'FROM', 'a@x', 'TO', 'b@y']
72
+ end
73
+ end
74
+
47
75
  describe 'the chaining interface' do
48
76
  it 'names the keys in lower case' do
49
77
  _(Imap::Search.new(client).from('x@y.com').criteria).must_equal({FROM: 'x@y.com'})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imap.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran