imap 0.4.6 → 0.4.7

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: 26d3a42b29eb3be8775fc3ec60f3559b0834e8ef106e2e3458cd2b93bdee7364
4
- data.tar.gz: 85aebe82c105a2d7db62c581ca61bd2c0630fcd7054dc777a02a86e84fd620ba
3
+ metadata.gz: 4b8f4ea427e7f3c30d6ce897ad13cdf4d22693b18170941d13c96f0e267bde83
4
+ data.tar.gz: 59a416b6e3687d94b3be00a9c2ce3c43090bd3ae09570b8cb0f9158f07d9a8a0
5
5
  SHA512:
6
- metadata.gz: bb36b35b0cd5f9ddc6895aa0bfe9c0d644cd5386f13f4b26a66324d767560c3af41a8741be6a4fecf4f69fbbf6028dc823e1207e9aba50ab63a382b0a9750c50
7
- data.tar.gz: 79add07e74eb8acc3105b3791be56d020cc50c89e80d47d3e47f8b46cf997b6e9c7fdd44e536292435f5560f380bd1bdac2d966c4bfc53bd548a010e77b93432
6
+ metadata.gz: 16d311031d31ef2f8b50ebf349134429a3bd4a82174062ffbcf867369c23f039c444a099115ced05911f89093f5f30c3a0a4fe1014d45e1499beb6ecbf522fc4
7
+ data.tar.gz: '08dc54d7f1f9e867461b521f9383f9e6a56d3e747ee5ec697a53e7015c0f6df079fd2ec96cd8a677c3607bd824ec4e7cb4daefccde1acac09ad3265365457149'
data/CHANGELOG CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## [0.4.7] - 2026-09-17, ~ Imap::Search: the chaining interface, which the header has documented and which has never run
4
+ - ~ Imap::Search: the generated methods named in lower case, so that from() answers where FROM() did. All 32 were upper case, being defined straight off the key constants, and none was reachable as the header wrote it.
5
+ - ~ Imap::Search: the generated methods return self, having returned the criteria hash, so that they chain.
6
+ - + Imap::Search#not: applies to what follows immediately and to nothing after it. + Negated, which carries a general key's value through the hash; a boolean needs none, false already reading as NOT.
7
+ - ~ Imap::Search#general_to_imap_search_key: ['NOT', key, value] where the value is Negated.
8
+ - ~ Imap::Search: the Usage header takes an imap_client, without which all() has nothing to search.
9
+ - + tests: the lower case names, that they chain, both negations, and that not applies once only.
10
+ - ~ Imap::VERSION: /0.4.6/0.4.7/
11
+
3
12
  ## [0.4.6] - 2026-09-17, ~ Imap::Message#body: BODY.PEEK[TEXT]; ~ Imap::Search#to_imap_search_keys: raise upon a key which is neither
4
13
  - ~ Imap::Message#body: BODY.PEEK[TEXT] for BODY[TEXT]. Reading a body set \Seen, so anything which looked at one marked it read; PEEK is the whole of the difference and the response still answers to BODY[TEXT].
5
14
  - ~ Imap::Search#to_imap_search_keys: + UnknownSearchKey where the case matched neither operator. An unrecognised key was dropped and the search ran wider than it was asked for, saying nothing.
data/lib/Imap/Search.rb CHANGED
@@ -2,8 +2,8 @@
2
2
  # Imap::Search
3
3
 
4
4
  # Usage:
5
- # 1. Imap::Search.new.not.subject('Payday Loans').answered.from('noreply@example.com').all
6
- # 2. Imap::Search.new({from: 'noreply@example.com', answered: true})
5
+ # 1. Imap::Search.new(imap_client).not.subject('Payday Loans').answered.from('noreply@example.com').all
6
+ # 2. Imap::Search.new(imap_client, {from: 'noreply@example.com', answered: true})
7
7
 
8
8
  # Notes:
9
9
  # 1. List of search keys taken from RFC-3501 (INTERNET MESSAGE ACCESS PROTOCOL - VERSION 4rev1), http://tools.ietf.org/html/rfc3501.
@@ -13,6 +13,11 @@ class Imap
13
13
 
14
14
  class UnknownSearchKey < ArgumentError; end
15
15
 
16
+ # A general key carries its value; negating one has to carry both, the hash
17
+ # having nowhere else to put it. A boolean key needs none of this: false
18
+ # already reads as NOT.
19
+ Negated = Struct.new(:value)
20
+
16
21
  ALL_SEARCH_KEYS = %w{
17
22
  ALL
18
23
  ANSWERED
@@ -84,17 +89,25 @@ class Imap
84
89
  }
85
90
 
86
91
  BOOLEAN_SEARCH_KEYS.each do |boolean_search_key|
87
- define_method boolean_search_key do |value = true|
88
- criteria.merge!(boolean_search_key.to_sym => value)
92
+ define_method boolean_search_key.downcase do |value = true|
93
+ criteria.merge!(boolean_search_key.to_sym => negating? ? !value : value)
94
+ self
89
95
  end
90
96
  end
91
97
 
92
98
  GENERAL_SEARCH_KEYS.each do |general_search_key|
93
- define_method general_search_key do |value|
94
- criteria.merge!(general_search_key.to_sym => value)
99
+ define_method general_search_key.downcase do |value|
100
+ criteria.merge!(general_search_key.to_sym => negating? ? Negated.new(value) : value)
101
+ self
95
102
  end
96
103
  end
97
104
 
105
+ # Applies to what follows immediately, and to nothing after that.
106
+ def not
107
+ @negate = true
108
+ self
109
+ end
110
+
98
111
  attr_accessor :criteria
99
112
  attr_accessor :imap_client
100
113
 
@@ -121,7 +134,7 @@ class Imap
121
134
  end
122
135
 
123
136
  def general_to_imap_search_key(key, value)
124
- [key, value]
137
+ value.is_a?(Negated) ? ['NOT', key, value.value] : [key, value]
125
138
  end
126
139
 
127
140
  def boolean_to_imap_search_key(key, value)
@@ -132,6 +145,12 @@ class Imap
132
145
  end
133
146
  end
134
147
 
148
+ def negating?
149
+ negate = @negate
150
+ @negate = false
151
+ negate
152
+ end
153
+
135
154
  def message_ids
136
155
  imap_client.imap.search(to_imap_search_keys)
137
156
  end
data/lib/Imap/VERSION.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Imap
2
- VERSION = '0.4.6'
2
+ VERSION = '0.4.7'
3
3
  end
@@ -44,6 +44,30 @@ describe Imap::Search do
44
44
  end
45
45
  end
46
46
 
47
+ describe 'the chaining interface' do
48
+ it 'names the keys in lower case' do
49
+ _(Imap::Search.new(client).from('x@y.com').criteria).must_equal({FROM: 'x@y.com'})
50
+ end
51
+
52
+ it 'returns itself, so that it chains' do
53
+ search = Imap::Search.new(client)
54
+ _(search.from('x@y.com')).must_be_same_as search
55
+ end
56
+
57
+ it 'negates a general key' do
58
+ _(Imap::Search.new(client).not.subject('Payday Loans').to_imap_search_keys).must_equal ['NOT', 'SUBJECT', 'Payday Loans']
59
+ end
60
+
61
+ it 'negates a boolean key' do
62
+ _(Imap::Search.new(client).not.seen.to_imap_search_keys).must_equal ['NOT', 'SEEN']
63
+ end
64
+
65
+ it 'negates what follows immediately and nothing after it' do
66
+ keys = Imap::Search.new(client).not.subject('Payday Loans').answered.from('noreply@example.com').to_imap_search_keys
67
+ _(keys).must_equal ['NOT', 'SUBJECT', 'Payday Loans', 'ANSWERED', 'FROM', 'noreply@example.com']
68
+ end
69
+ end
70
+
47
71
  describe '#message_ids' do
48
72
  it 'returns an array of message IDs' do
49
73
  ids = search.message_ids
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran