imap_guard 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99df3a5c8af846514e4270323a001ad4033f602f197965f6eec76dbf9cb999a0
4
- data.tar.gz: 2be62429ce40e9b3e5edd27c8ff166fd5e62193c37cad995019958cf0997b7da
3
+ metadata.gz: 25df25da92ea0dae5ec4d6aaf9484049aa9713cc358ad43e6fce41628e2007a3
4
+ data.tar.gz: '0028b947283d027fa80184fbcbc211e922539644a452e4ed859c4ea3822ec832'
5
5
  SHA512:
6
- metadata.gz: 7d777c406347aff9d485111676a39ce14ea3348e8c17daa5ce343db7a91b1c6a6a4dd57504fecde6a4fa719501f4d1cd848119e6820bc085c3a7fd33382b9c5c
7
- data.tar.gz: eda7c841a6b0b6e86d4c4d3ab62f5f7992bff53d0510cd303afd46b29d5780e00f8b3769f0386e0baf70908a53a048799104d46c11629d46eaa88c9b4f2f41cf
6
+ metadata.gz: 87d43bcba3020e0d2ec1b4a7e5d589abff5fa842ce83ab3405c2216818cfd43c877003613a4d65cb42abe190ab75d72435ab577efdd1dc914ebc77b87f46d74a
7
+ data.tar.gz: 4279c2dd1877d4f83508094d0725298d8e08ea1940c0c925c89a4842ffd196465b0cb3186555f73dbf15e50cafbda2b884d8982df0b3162dd1740a608316765a
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,16 @@
1
+ # Official language image. Look for the different tagged releases at:
2
+ # https://hub.docker.com/r/library/ruby/tags/
3
+ image: ruby:latest
4
+
5
+ before_script:
6
+ - ruby -v
7
+ - bundle install -j $(nproc)
8
+
9
+ rspec:
10
+ script: rspec spec
11
+
12
+ rubocop:
13
+ script: rubocop
14
+
15
+ yard:
16
+ script: yard stats --list-undoc
data/.rubocop.yml CHANGED
@@ -1,5 +1,10 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
1
5
  AllCops:
2
- TargetRubyVersion: 2.4
6
+ TargetRubyVersion: 3.0
7
+ NewCops: enable
3
8
 
4
9
  Metrics:
5
10
  Enabled: false
@@ -7,14 +12,8 @@ Metrics:
7
12
  Layout/AccessModifierIndentation:
8
13
  EnforcedStyle: outdent
9
14
 
10
- Style/FormatStringToken:
11
- Enabled: false
12
-
13
- Style/SafeNavigation:
14
- Enabled: false
15
-
16
- Style/SpecialGlobalVars:
17
- Enabled: false
15
+ Layout/LineLength:
16
+ Enabled: 100
18
17
 
19
18
  Style/StringLiterals:
20
19
  EnforcedStyle: double_quotes
@@ -24,3 +23,24 @@ Style/TrailingCommaInArguments:
24
23
 
25
24
  Style/TrailingCommaInHashLiteral:
26
25
  EnforcedStyleForMultiline: comma
26
+
27
+ RSpec/ExampleLength:
28
+ Enabled: false
29
+
30
+ RSpec/ExpectInHook:
31
+ Enabled: false
32
+
33
+ RSpec/ExpectOutput:
34
+ Enabled: false
35
+
36
+ RSpec/MessageSpies:
37
+ Enabled: false # TODO: enable
38
+
39
+ RSpec/MultipleExpectations:
40
+ Enabled: false
41
+
42
+ RSpec/NamedSubject:
43
+ Enabled: false
44
+
45
+ RSpec/NestedGroups:
46
+ Enabled: false
data/Gemfile CHANGED
@@ -2,5 +2,15 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- # Specify your gem's dependencies in imap_guard.gemspec
5
+ # Specify your gem's runtime dependencies in imap_guard.gemspec
6
6
  gemspec
7
+
8
+ # Specify your gem's development dependencies below:
9
+ gem "bundler", ">= 1.3"
10
+ gem "rake"
11
+ gem "rspec"
12
+ gem "rubocop"
13
+ gem "rubocop-rake"
14
+ gem "rubocop-rspec"
15
+ gem "simplecov"
16
+ gem "yard"
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2019 Cédric Félizard
1
+ Copyright (c) 2013-2022 Cédric Félizard
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # ImapGuard
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/imap_guard.svg)](https://badge.fury.io/rb/imap_guard)
4
- [![Build Status](https://secure.travis-ci.org/infertux/imap_guard.png?branch=master)](https://travis-ci.org/infertux/imap_guard)
4
+ [![Build Status](https://gitlab.com/infertux/imap_guard/badges/master/pipeline.svg)](https://gitlab.com/infertux/imap_guard/-/pipelines)
5
5
  [![Code Climate](https://codeclimate.com/github/infertux/imap_guard.png)](https://codeclimate.com/github/infertux/imap_guard)
6
6
  [![Inline docs](http://inch-ci.org/github/infertux/imap_guard.svg)](http://inch-ci.org/github/infertux/imap_guard)
7
7
 
data/imap_guard.gemspec CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "imap_guard"
8
- spec.version = "1.2.0"
8
+ spec.version = "2.0.0"
9
9
  spec.authors = ["Cédric Félizard"]
10
10
  spec.email = ["cedric@felizard.fr"]
11
11
  spec.description = "A guard for your IMAP server"
@@ -13,20 +13,15 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/infertux/imap_guard"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files`.split($/)
16
+ spec.files = `git ls-files`.split($/) # rubocop:disable Style/SpecialGlobalVars
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ["lib"]
20
19
 
21
- spec.add_dependency "mail", ">= 2.5.3"
22
- spec.add_dependency "term-ansicolor", ">= 1.2.2"
20
+ spec.required_ruby_version = ">= 3.0.5"
21
+
22
+ spec.metadata["rubygems_mfa_required"] = "true"
23
23
 
24
- spec.add_development_dependency "bundler", ">= 1.3"
25
- spec.add_development_dependency "cane"
26
- spec.add_development_dependency "rake"
27
- spec.add_development_dependency "redcarpet" # for yardoc
28
- spec.add_development_dependency "rspec"
29
- spec.add_development_dependency "rubocop"
30
- spec.add_development_dependency "simplecov"
31
- spec.add_development_dependency "yard"
24
+ spec.add_dependency "mail", ">= 2.7.1"
25
+ spec.add_dependency "net-imap"
26
+ spec.add_dependency "term-ansicolor", ">= 1.2.2"
32
27
  end
@@ -5,8 +5,8 @@ require "ostruct"
5
5
  require "mail"
6
6
  require "term/ansicolor"
7
7
 
8
- String.send(:include, Term::ANSIColor)
9
- Term::ANSIColor.coloring = STDOUT.isatty
8
+ String.include Term::ANSIColor
9
+ Term::ANSIColor.coloring = $stdout.isatty
10
10
 
11
11
  module ImapGuard
12
12
  # Guard allows you to process your mailboxes.
@@ -17,11 +17,13 @@ module ImapGuard
17
17
  # List of optional settings
18
18
  OPTIONAL_SETTINGS = %i[read_only verbose].freeze
19
19
 
20
+ Settings = Struct.new("Settings", *(REQUIRED_SETTINGS + OPTIONAL_SETTINGS))
21
+
20
22
  # @return [Proc, nil] Matched emails are passed to this debug lambda if present
21
23
  attr_accessor :debug
22
24
 
23
25
  # @note The settings are frozen
24
- # @return [OpenStruct] ImapGuard settings
26
+ # @return [Struct::Settings] ImapGuard settings
25
27
  attr_reader :settings
26
28
 
27
29
  # @return [String, nil] Currently selected mailbox
@@ -86,7 +88,7 @@ module ImapGuard
86
88
  # @param opration Lambda to call on each message
87
89
  # @return [void]
88
90
  def each(query)
89
- operation = ->(message_id) { yield message_id }
91
+ operation = ->(message_id) { yield message_id } # rubocop:disable Style/ExplicitBlockArgument
90
92
  process query, operation
91
93
  end
92
94
 
@@ -137,7 +139,7 @@ module ImapGuard
137
139
  if block_given? || debug
138
140
  mail = fetch_mail message_id
139
141
 
140
- debug.call(mail) if debug
142
+ debug.call(mail) if debug # rubocop:disable Style/SafeNavigation
141
143
 
142
144
  if block_given?
143
145
  result = yield(mail)
@@ -152,7 +154,9 @@ module ImapGuard
152
154
  end
153
155
 
154
156
  def search(query)
155
- raise TypeError, "Query must be either a string holding the entire search string, or a single-dimension array of search keywords and arguments." unless [Array, String].any? { |type| query.is_a? type }
157
+ unless [Array, String].any? { |type| query.is_a? type }
158
+ raise TypeError, "Query must be either a string holding the entire search string, or a single-dimension array of search keywords and arguments."
159
+ end
156
160
 
157
161
  messages = @imap.search query
158
162
  puts "Query on #{mailbox}: #{query.inspect}: #{messages.count} results".cyan
@@ -178,7 +182,8 @@ module ImapGuard
178
182
  unknown = settings.keys - REQUIRED_SETTINGS - OPTIONAL_SETTINGS
179
183
  raise ArgumentError, "Unknown settings: #{unknown}" unless unknown.empty?
180
184
 
181
- @settings = OpenStruct.new(settings).freeze
185
+ struct = Settings.members.map { |member| settings.fetch(member, false) }
186
+ @settings = Settings.new(*struct).freeze
182
187
  puts "DRY-RUN MODE ENABLED".yellow.bold.negative if @settings.read_only
183
188
  end
184
189
  end
@@ -20,7 +20,7 @@ module ImapGuard
20
20
  end
21
21
 
22
22
  let(:imap) do
23
- double("Net::IMAP", search: [7, 28], expunge: nil, select: nil, list: [])
23
+ instance_double(Net::IMAP, search: [7, 28], expunge: nil, select: nil, list: [])
24
24
  end
25
25
 
26
26
  def guard_instance(custom_settings = {})
@@ -80,13 +80,13 @@ module ImapGuard
80
80
  it "accepts arrays" do
81
81
  expect do
82
82
  guard_instance.send(:search, ["ALL"])
83
- end.to_not raise_error
83
+ end.not_to raise_error
84
84
  end
85
85
 
86
86
  it "accepts strings" do
87
87
  expect do
88
88
  guard_instance.send(:search, "ALL")
89
- end.to_not raise_error
89
+ end.not_to raise_error
90
90
  end
91
91
 
92
92
  it "returns results" do
@@ -128,10 +128,10 @@ module ImapGuard
128
128
  it "executes the filter block" do
129
129
  expect(guard).to receive(:fetch_mail).twice
130
130
 
131
- guard.send(:process, "ALL", opeartion) {}
131
+ guard.send(:process, "ALL", opeartion) { nil }
132
132
  end
133
133
 
134
- context "returning false" do
134
+ context "when returning false" do
135
135
  it "does not perform the operation" do
136
136
  expect(opeartion).not_to receive(:call)
137
137
 
@@ -139,7 +139,7 @@ module ImapGuard
139
139
  end
140
140
  end
141
141
 
142
- context "returning true" do
142
+ context "when returning true" do
143
143
  it "does perform the operation" do
144
144
  expect(opeartion).to receive(:call).twice
145
145
 
@@ -173,9 +173,11 @@ module ImapGuard
173
173
 
174
174
  describe "#each" do
175
175
  it "iterates over messages without errors" do
176
- guard_instance.each "ALL" do |message_id|
177
- # noop
178
- end
176
+ expect do
177
+ guard_instance.each "ALL" do |message_id|
178
+ # noop
179
+ end
180
+ end.not_to raise_error
179
181
  end
180
182
  end
181
183
 
@@ -222,7 +224,7 @@ module ImapGuard
222
224
 
223
225
  describe "#settings=" do
224
226
  it "freezes the settings" do
225
- guard = Guard.new(settings)
227
+ guard = described_class.new(settings)
226
228
 
227
229
  exception = (RUBY_VERSION >= "2.1.0" ? RuntimeError : TypeError)
228
230
 
@@ -233,13 +235,13 @@ module ImapGuard
233
235
 
234
236
  it "raises ArgumentError if any required key is missing" do
235
237
  expect do
236
- Guard.new({})
238
+ described_class.new({})
237
239
  end.to raise_error ArgumentError, /missing/i
238
240
  end
239
241
 
240
242
  it "raises ArgumentError if any key is unknown" do
241
243
  expect do
242
- Guard.new(settings.merge(coffee: true))
244
+ described_class.new(settings.merge(coffee: true))
243
245
  end.to raise_error ArgumentError, /unknown/i
244
246
  end
245
247
  end
@@ -3,7 +3,7 @@
3
3
  module ImapGuard
4
4
  describe Query do
5
5
  describe "#initialize" do
6
- it { should be_empty }
6
+ it { is_expected.to be_empty }
7
7
  end
8
8
 
9
9
  describe "#seen" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imap_guard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cédric Félizard
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-20 00:00:00.000000000 Z
11
+ date: 2023-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -16,120 +16,22 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.5.3
19
+ version: 2.7.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.5.3
26
+ version: 2.7.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: term-ansicolor
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.2.2
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 1.2.2
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '1.3'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '1.3'
55
- - !ruby/object:Gem::Dependency
56
- name: cane
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: redcarpet
28
+ name: net-imap
85
29
  requirement: !ruby/object:Gem::Requirement
86
30
  requirements:
87
31
  - - ">="
88
32
  - !ruby/object:Gem::Version
89
33
  version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rspec
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: rubocop
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: simplecov
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
34
+ type: :runtime
133
35
  prerelease: false
134
36
  version_requirements: !ruby/object:Gem::Requirement
135
37
  requirements:
@@ -137,19 +39,19 @@ dependencies:
137
39
  - !ruby/object:Gem::Version
138
40
  version: '0'
139
41
  - !ruby/object:Gem::Dependency
140
- name: yard
42
+ name: term-ansicolor
141
43
  requirement: !ruby/object:Gem::Requirement
142
44
  requirements:
143
45
  - - ">="
144
46
  - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
47
+ version: 1.2.2
48
+ type: :runtime
147
49
  prerelease: false
148
50
  version_requirements: !ruby/object:Gem::Requirement
149
51
  requirements:
150
52
  - - ">="
151
53
  - !ruby/object:Gem::Version
152
- version: '0'
54
+ version: 1.2.2
153
55
  description: A guard for your IMAP server
154
56
  email:
155
57
  - cedric@felizard.fr
@@ -158,9 +60,9 @@ extensions: []
158
60
  extra_rdoc_files: []
159
61
  files:
160
62
  - ".gitignore"
63
+ - ".gitlab-ci.yml"
161
64
  - ".rspec"
162
65
  - ".rubocop.yml"
163
- - ".travis.yml"
164
66
  - Gemfile
165
67
  - Guardfile
166
68
  - LICENSE.txt
@@ -177,8 +79,9 @@ files:
177
79
  homepage: https://github.com/infertux/imap_guard
178
80
  licenses:
179
81
  - MIT
180
- metadata: {}
181
- post_install_message:
82
+ metadata:
83
+ rubygems_mfa_required: 'true'
84
+ post_install_message:
182
85
  rdoc_options: []
183
86
  require_paths:
184
87
  - lib
@@ -186,18 +89,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
89
  requirements:
187
90
  - - ">="
188
91
  - !ruby/object:Gem::Version
189
- version: '0'
92
+ version: 3.0.5
190
93
  required_rubygems_version: !ruby/object:Gem::Requirement
191
94
  requirements:
192
95
  - - ">="
193
96
  - !ruby/object:Gem::Version
194
97
  version: '0'
195
98
  requirements: []
196
- rubygems_version: 3.0.1
197
- signing_key:
99
+ rubygems_version: 3.4.6
100
+ signing_key:
198
101
  specification_version: 4
199
102
  summary: A guard for your IMAP server
200
- test_files:
201
- - spec/imap_guard/guard_spec.rb
202
- - spec/imap_guard/query_spec.rb
203
- - spec/spec_helper.rb
103
+ test_files: []
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- language: ruby
2
- after_script:
3
- - cane
4
- - yard stats --list-undoc
5
- rvm:
6
- - 2.6.0
7
- - 2.5.3
8
- - 2.4.5