imap_guard 1.0.0 → 1.2.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
- SHA1:
3
- metadata.gz: b9bad59e96b10c29a2a065cd6b5d866f10e8d7c8
4
- data.tar.gz: d110224b73afef6abc0cc7805aefc906ee222b35
2
+ SHA256:
3
+ metadata.gz: 99df3a5c8af846514e4270323a001ad4033f602f197965f6eec76dbf9cb999a0
4
+ data.tar.gz: 2be62429ce40e9b3e5edd27c8ff166fd5e62193c37cad995019958cf0997b7da
5
5
  SHA512:
6
- metadata.gz: ef2d1979d3459bf83732861e5d6972af03cf698dd3178b8d9b7326eed9b0c44c4b17b3dab7c038a14425c5eb980c7f3255f6d412729af4c89810e66d597a42f9
7
- data.tar.gz: f23003553803bf31aaf648d840f221a627387c147e326e399f8ecf02a320059325ef6a412161a00c35a96efea91fc65f1e2e2097309c18097045f8b932b02a0d
6
+ metadata.gz: 7d777c406347aff9d485111676a39ce14ea3348e8c17daa5ce343db7a91b1c6a6a4dd57504fecde6a4fa719501f4d1cd848119e6820bc085c3a7fd33382b9c5c
7
+ data.tar.gz: eda7c841a6b0b6e86d4c4d3ab62f5f7992bff53d0510cd303afd46b29d5780e00f8b3769f0386e0baf70908a53a048799104d46c11629d46eaa88c9b4f2f41cf
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
1
  --color
2
2
  --format d
3
- --order random
3
+ --require spec_helper
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Metrics:
5
+ Enabled: false
6
+
7
+ Layout/AccessModifierIndentation:
8
+ EnforcedStyle: outdent
9
+
10
+ Style/FormatStringToken:
11
+ Enabled: false
12
+
13
+ Style/SafeNavigation:
14
+ Enabled: false
15
+
16
+ Style/SpecialGlobalVars:
17
+ Enabled: false
18
+
19
+ Style/StringLiterals:
20
+ EnforcedStyle: double_quotes
21
+
22
+ Style/TrailingCommaInArguments:
23
+ EnforcedStyleForMultiline: comma
24
+
25
+ Style/TrailingCommaInHashLiteral:
26
+ EnforcedStyleForMultiline: comma
@@ -3,13 +3,6 @@ after_script:
3
3
  - cane
4
4
  - yard stats --list-undoc
5
5
  rvm:
6
- - 1.9.3
7
- - 2.0.0
8
- - 2.1
9
- - 2.2
10
- - ruby-head
11
- - rbx
12
- matrix:
13
- allow_failures:
14
- - rvm: ruby-head
15
- - rvm: rbx
6
+ - 2.6.0
7
+ - 2.5.3
8
+ - 2.4.5
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in imap_guard.gemspec
4
6
  gemspec
data/Guardfile CHANGED
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # More info at https://github.com/guard/guard#readme
2
4
 
3
- guard 'rspec' do
5
+ guard "rspec" do
4
6
  watch(%r{^spec/.+_spec\.rb$})
5
7
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
6
8
  watch(%r{^lib/(.+)/(.+)\.rb$}) { |m| "spec/#{m[1]}/#{m[2]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
9
+ watch("spec/spec_helper.rb") { "spec" }
8
10
  watch(%r{^spec/support/.+\.rb$}) { "spec" }
9
11
  end
10
-
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2015 Cédric Félizard
1
+ Copyright (c) 2013-2019 Cédric Félizard
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,13 +1,11 @@
1
- # ImapGuard [![Build Status](https://secure.travis-ci.org/infertux/imap_guard.png?branch=master)](https://travis-ci.org/infertux/imap_guard) [![Dependency Status](https://gemnasium.com/infertux/imap_guard.png)](https://gemnasium.com/infertux/imap_guard) [![Code Climate](https://codeclimate.com/github/infertux/imap_guard.png)](https://codeclimate.com/github/infertux/imap_guard)
1
+ # ImapGuard
2
2
 
3
- **A guard for your IMAP mailboxes.**
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)
5
+ [![Code Climate](https://codeclimate.com/github/infertux/imap_guard.png)](https://codeclimate.com/github/infertux/imap_guard)
6
+ [![Inline docs](http://inch-ci.org/github/infertux/imap_guard.svg)](http://inch-ci.org/github/infertux/imap_guard)
4
7
 
5
- * [Source Code](https://github.com/infertux/imap_guard "Source Code on Github")
6
- * [Bug Tracker](https://github.com/infertux/imap_guard/issues "Bug Tracker on Github")
7
- * [API documentation](http://rubydoc.info/gems/imap_guard/frames "API Documentation on Rubydoc")
8
- * [Rubygem](https://rubygems.org/gems/imap_guard "ImapGuard on Rubygems")
9
- * [Continuous Integration](https://travis-ci.org/infertux/imap_guard "ImapGuard on Travis-CI")
10
- * [Dependencies](https://gemnasium.com/infertux/imap_guard "ImapGuard dependencies on Gemnasium")
8
+ **A guard for your IMAP mailboxes.**
11
9
 
12
10
  ImapGuard connects to your IMAP server and processes your emails.
13
11
  You can finely pick them thanks to advanced search queries and Ruby blocks.
@@ -70,7 +68,7 @@ guard.delete base_query.dup.before(7).subject("Logwatch for ") do |mail|
70
68
  end
71
69
  ```
72
70
 
73
- Finally, you can always forge your own raw IMAP search queries (the [RFC](http://tools.ietf.org/html/rfc3501#section-6.4.4) can help in that case):
71
+ You can always forge your own raw IMAP search queries (the [RFC](http://tools.ietf.org/html/rfc3501#section-6.4.4) can help in that case):
74
72
 
75
73
  ```ruby
76
74
  query = 'SEEN SUBJECT "ALERT" FROM "root"'
@@ -79,19 +77,19 @@ guard.delete query do |mail|
79
77
  end
80
78
  ```
81
79
 
82
- Be aware that emails won't be touched until you `expunge` or `close` the mailbox:
80
+ There is a `move` method as well:
83
81
 
84
82
  ```ruby
85
- guard.expunge # effectively delete emails marked as deleted
86
- guard.close # expunge then close the connection
83
+ guard.move query, 'destination_folder' do |mail|
84
+ # and it can take a filter block like `delete`
85
+ end
87
86
  ```
88
87
 
89
- Oh, and there is a `move` method as well:
88
+ Finally, this should be handled automatically but you can explicitly expunge pending emails and close the connection:
90
89
 
91
90
  ```ruby
92
- guard.move query, 'destination_folder' do |mail|
93
- # and it can take a filter block like `delete`
94
- end
91
+ guard.expunge # effectively delete emails marked as deleted
92
+ guard.close # expunge then close the connection
95
93
  ```
96
94
 
97
95
  ### Advanced features
@@ -134,4 +132,3 @@ MIT
134
132
 
135
133
 
136
134
  [Mail]: https://github.com/mikel/mail
137
-
data/Rakefile CHANGED
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
3
6
 
4
7
  RSpec::Core::RakeTask.new(:spec) do |t|
5
- t.ruby_opts = '-w'
8
+ t.ruby_opts = "-w"
6
9
  end
7
10
 
8
- task default: :spec
11
+ RuboCop::RakeTask.new(:rubocop)
9
12
 
13
+ task default: %i[spec rubocop]
@@ -1,43 +1,45 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'imap_guard'
3
+ # frozen_string_literal: true
4
+ # rubocop:disable all
5
+
6
+ require "imap_guard"
4
7
 
5
8
  SETTINGS = {
6
- host: 'imap.googlemail.com',
9
+ host: "imap.googlemail.com",
7
10
  port: 993,
8
- username: 'you@gmail.com',
9
- password: 'your_pass',
10
- }
11
+ username: "you@gmail.com",
12
+ password: "your_pass",
13
+ }.freeze
11
14
 
12
- settings = SETTINGS.merge({ read_only: false })
15
+ settings = SETTINGS.merge(read_only: false)
13
16
  base_query = ImapGuard::Query.new.unflagged.unanswered.freeze
14
17
  guard = ImapGuard::Guard.new settings
15
18
  # guard.debug = ->(mail) { print "#{mail.subject}: " }
16
19
  guard.login
17
20
 
18
- guard.select 'INBOX'
21
+ guard.select "INBOX"
19
22
 
20
23
  # Github
21
24
  %w(github.com notifications@travis-ci.org app@gemnasium.com).map do |from|
22
25
  base_query.dup.from(from)
23
26
  end.each do |query|
24
- guard.move query, 'INBOX.Github'
27
+ guard.move query, "INBOX.Github"
25
28
  end
26
29
 
27
30
  # To Do
28
- guard.move base_query.dup.from("me").to("me"), 'INBOX.TODO'
31
+ guard.move base_query.dup.from("me").to("me"), "INBOX.TODO"
29
32
 
30
33
  # Ops
31
- guard.select 'INBOX.Ops'
34
+ guard.select "INBOX.Ops"
32
35
  query = base_query.dup.seen
33
36
  guard.delete query.dup.subject("monit alert -- ").before(7)
34
37
  guard.delete query.dup.subject("CRON-APT completed on ").before(3)
35
38
  guard.delete query.dup.subject("Logwatch for ").before(7)
36
- guard.select 'INBOX'
39
+ guard.select "INBOX"
37
40
 
38
41
  # Uni
39
- guard.move base_query.dup.or.from("uni.tld").to("uni.tld"), 'INBOX.Uni'
42
+ guard.move base_query.dup.or.from("uni.tld").to("uni.tld"), "INBOX.Uni"
40
43
 
41
44
  # Bye!
42
45
  guard.disconnect
43
-
@@ -1,13 +1,14 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
5
6
  Gem::Specification.new do |spec|
6
7
  spec.name = "imap_guard"
7
- spec.version = "1.0.0"
8
+ spec.version = "1.2.0"
8
9
  spec.authors = ["Cédric Félizard"]
9
10
  spec.email = ["cedric@felizard.fr"]
10
- spec.description = %q{A guard for your IMAP server}
11
+ spec.description = "A guard for your IMAP server"
11
12
  spec.summary = spec.description
12
13
  spec.homepage = "https://github.com/infertux/imap_guard"
13
14
  spec.license = "MIT"
@@ -17,16 +18,15 @@ Gem::Specification.new do |spec|
17
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
19
  spec.require_paths = ["lib"]
19
20
 
20
- spec.add_dependency 'mail', '>= 2.5.3'
21
- spec.add_dependency 'term-ansicolor', '>= 1.2.2'
21
+ spec.add_dependency "mail", ">= 2.5.3"
22
+ spec.add_dependency "term-ansicolor", ">= 1.2.2"
22
23
 
23
- spec.add_development_dependency 'bundler', '>= 1.3'
24
- spec.add_development_dependency 'rake'
25
- spec.add_development_dependency 'simplecov'
26
- spec.add_development_dependency 'rspec'
27
- spec.add_development_dependency 'guard-rspec'
28
- spec.add_development_dependency 'rb-inotify'
29
- spec.add_development_dependency 'cane'
30
- spec.add_development_dependency 'yard'
31
- spec.add_development_dependency 'redcarpet' # for yardoc
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"
32
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "imap_guard/guard"
2
4
  require "imap_guard/query"
3
5
 
@@ -1,18 +1,21 @@
1
- require 'net/imap'
2
- require 'ostruct'
3
- require 'mail'
4
- require 'term/ansicolor'
1
+ # frozen_string_literal: true
2
+
3
+ require "net/imap"
4
+ require "ostruct"
5
+ require "mail"
6
+ require "term/ansicolor"
7
+
5
8
  String.send(:include, Term::ANSIColor)
6
- Term::ANSIColor::coloring = STDOUT.isatty
9
+ Term::ANSIColor.coloring = STDOUT.isatty
7
10
 
8
11
  module ImapGuard
9
12
  # Guard allows you to process your mailboxes.
10
13
  class Guard
11
14
  # List of required settings
12
- REQUIRED_SETTINGS = [:host, :port, :username, :password]
15
+ REQUIRED_SETTINGS = %i[host port username password].freeze
13
16
 
14
17
  # List of optional settings
15
- OPTIONAL_SETTINGS = [:read_only, :verbose]
18
+ OPTIONAL_SETTINGS = %i[read_only verbose].freeze
16
19
 
17
20
  # @return [Proc, nil] Matched emails are passed to this debug lambda if present
18
21
  attr_accessor :debug
@@ -24,7 +27,7 @@ module ImapGuard
24
27
  # @return [String, nil] Currently selected mailbox
25
28
  attr_reader :mailbox
26
29
 
27
- def initialize settings
30
+ def initialize(settings)
28
31
  self.settings = settings
29
32
  end
30
33
 
@@ -39,7 +42,7 @@ module ImapGuard
39
42
 
40
43
  # Selects a mailbox (folder)
41
44
  # @return [void]
42
- def select mailbox
45
+ def select(mailbox)
43
46
  if @settings.read_only
44
47
  @imap.examine(mailbox) # open in read-only
45
48
  else
@@ -53,15 +56,15 @@ module ImapGuard
53
56
  # @param mailbox Destination mailbox
54
57
  # @param filter Optional filter block
55
58
  # @return [void]
56
- def move query, mailbox, &filter
57
- operation = lambda { |message_id|
59
+ def move(query, mailbox, &filter)
60
+ operation = lambda do |message_id|
58
61
  unless @settings.read_only
59
62
  @imap.copy(message_id, mailbox)
60
63
  @imap.store(message_id, "+FLAGS", [Net::IMAP::DELETED])
61
64
  end
62
65
 
63
66
  "moved to #{mailbox}".yellow
64
- }
67
+ end
65
68
  process query, operation, &filter
66
69
  end
67
70
 
@@ -69,14 +72,12 @@ module ImapGuard
69
72
  # @param query IMAP query
70
73
  # @param filter Optional filter block
71
74
  # @return [void]
72
- def delete query, &filter
73
- operation = lambda { |message_id|
74
- unless @settings.read_only
75
- @imap.store(message_id, "+FLAGS", [Net::IMAP::DELETED])
76
- end
75
+ def delete(query, &filter)
76
+ operation = lambda do |message_id|
77
+ @imap.store(message_id, "+FLAGS", [Net::IMAP::DELETED]) unless @settings.read_only
77
78
 
78
- 'deleted'.red
79
- }
79
+ "deleted".red
80
+ end
80
81
  process query, operation, &filter
81
82
  end
82
83
 
@@ -84,16 +85,16 @@ module ImapGuard
84
85
  # @param query IMAP query
85
86
  # @param opration Lambda to call on each message
86
87
  # @return [void]
87
- def each query
88
- operation = lambda { |message_id| yield message_id }
88
+ def each(query)
89
+ operation = ->(message_id) { yield message_id }
89
90
  process query, operation
90
91
  end
91
92
 
92
93
  # Fetches a message from its UID
93
94
  # @return [Mail]
94
95
  # @note We use "BODY.PEEK[]" to avoid setting the \Seen flag.
95
- def fetch_mail message_id
96
- msg = @imap.fetch(message_id, 'BODY.PEEK[]').first.attr['BODY[]']
96
+ def fetch_mail(message_id)
97
+ msg = @imap.fetch(message_id, "BODY.PEEK[]").first.attr["BODY[]"]
97
98
  Mail.read_from_string msg
98
99
  end
99
100
 
@@ -125,7 +126,7 @@ module ImapGuard
125
126
 
126
127
  private
127
128
 
128
- def process query, operation
129
+ def process(query, operation)
129
130
  message_ids = search query
130
131
  count = message_ids.size
131
132
 
@@ -133,7 +134,7 @@ module ImapGuard
133
134
  print "Processing UID #{message_id} (#{index.succ}/#{count}): "
134
135
 
135
136
  result = true
136
- if block_given? or debug
137
+ if block_given? || debug
137
138
  mail = fetch_mail message_id
138
139
 
139
140
  debug.call(mail) if debug
@@ -146,15 +147,12 @@ module ImapGuard
146
147
 
147
148
  puts result ? operation.call(message_id) : "ignored".green
148
149
  end
149
-
150
150
  ensure
151
151
  expunge
152
152
  end
153
153
 
154
- def search query
155
- unless [Array, String].any? { |type| query.is_a? type }
156
- raise TypeError, "Query must be either a string holding the entire search string, or a single-dimension array of search keywords and arguments."
157
- end
154
+ 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 }
158
156
 
159
157
  messages = @imap.search query
160
158
  puts "Query on #{mailbox}: #{query.inspect}: #{messages.count} results".cyan
@@ -164,18 +162,16 @@ module ImapGuard
164
162
 
165
163
  def verbose
166
164
  @verbose ||= if @settings.verbose
167
- $stdout
168
- else
169
- # anonymous null object
170
- Class.new do
171
- def method_missing(*)
172
- nil
173
- end
174
- end.new
175
- end
165
+ $stdout
166
+ else
167
+ # anonymous null object
168
+ # rubocop:disable all
169
+ Class.new do def method_missing(*); nil end end.new
170
+ # rubocop:enable all
171
+ end
176
172
  end
177
173
 
178
- def settings= settings
174
+ def settings=(settings)
179
175
  missing = REQUIRED_SETTINGS - settings.keys
180
176
  raise ArgumentError, "Missing settings: #{missing}" unless missing.empty?
181
177
 
@@ -187,4 +183,3 @@ module ImapGuard
187
183
  end
188
184
  end
189
185
  end
190
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ImapGuard
2
4
  # Query is a neat DSL to help you generate IMAP search queries.
3
5
  # @note All methods return self so they can be chained.
@@ -5,31 +7,31 @@ module ImapGuard
5
7
  # Messages that have the +\Seen+ flag set.
6
8
  # @return [self]
7
9
  def seen
8
- self << 'SEEN'
10
+ self << "SEEN"
9
11
  end
10
12
 
11
13
  # Messages that do not have the +\Seen+ flag set.
12
14
  # @return [self]
13
15
  def unseen
14
- self << 'UNSEEN'
16
+ self << "UNSEEN"
15
17
  end
16
18
 
17
19
  # Messages that do not have the +\Answered+ flag set.
18
20
  # @return [self]
19
21
  def unanswered
20
- self << 'UNANSWERED'
22
+ self << "UNANSWERED"
21
23
  end
22
24
 
23
25
  # Messages that do not have the +\Flagged+ flag set.
24
26
  # @return [self]
25
27
  def unflagged
26
- self << 'UNFLAGGED'
28
+ self << "UNFLAGGED"
27
29
  end
28
30
 
29
31
  # Messages with the +\Deleted+ flag set.
30
32
  # @return [self]
31
33
  def deleted
32
- self << 'DELETED'
34
+ self << "DELETED"
33
35
  end
34
36
 
35
37
  # Messages that match either search key.
@@ -41,13 +43,13 @@ module ImapGuard
41
43
  # or.unanswered.unflagged #=> ["OR", "UNANSWERED", "UNFLAGGED"]
42
44
  # or(:unanswered, :unflagged) #=> ["OR", "UNANSWERED", "UNFLAGGED"]
43
45
  # @return [self]
44
- def or search_key1 = nil, search_key2 = nil
45
- self << 'OR'
46
+ def or(search_key1 = nil, search_key2 = nil)
47
+ self << "OR"
46
48
 
47
- if search_key1 and search_key2
49
+ if search_key1 && search_key2
48
50
  send(search_key1)
49
51
  send(search_key2)
50
- elsif search_key1 or search_key2
52
+ elsif search_key1 || search_key2
51
53
  raise ArgumentError, "You must give either zero or two arguments."
52
54
  end
53
55
 
@@ -60,8 +62,8 @@ module ImapGuard
60
62
  # not.deleted #=> ["NOT", "DELETED"]
61
63
  # not(:deleted) #=> ["NOT", "DELETED"]
62
64
  # @return [self]
63
- def not search_key = nil
64
- self << 'NOT'
65
+ def not(search_key = nil)
66
+ self << "NOT"
65
67
  send(search_key) if search_key
66
68
  self
67
69
  end
@@ -69,29 +71,29 @@ module ImapGuard
69
71
  # Messages that contain the specified string in the envelope
70
72
  # structure's SUBJECT field.
71
73
  # @return [self]
72
- def subject string
73
- self << 'SUBJECT' << string
74
+ def subject(string)
75
+ self << "SUBJECT" << string
74
76
  end
75
77
 
76
78
  # Messages that contain the specified string in the envelope
77
79
  # structure's FROM field.
78
80
  # @return [self]
79
- def from string
80
- self << 'FROM' << string
81
+ def from(string)
82
+ self << "FROM" << string
81
83
  end
82
84
 
83
85
  # Messages that contain the specified string in the envelope
84
86
  # structure's TO field.
85
87
  # @return [self]
86
- def to string
87
- self << 'TO' << string
88
+ def to(string)
89
+ self << "TO" << string
88
90
  end
89
91
 
90
92
  # Messages that contain the specified string in the envelope
91
93
  # structure's CC field.
92
94
  # @return [self]
93
- def cc string
94
- self << 'CC' << string
95
+ def cc(string)
96
+ self << "CC" << string
95
97
  end
96
98
 
97
99
  # Messages whose internal date (disregarding time and timezone)
@@ -101,20 +103,19 @@ module ImapGuard
101
103
  # - [Fixnum]: _n_ days before today
102
104
  # - [Date]: uses this date
103
105
  # @return [self]
104
- def before date
105
- case date
106
- when String
107
- # noop, uses it as is
108
- when Fixnum
109
- date = (Date.today - date).strftime '%e-%b-%Y'
110
- when Date
111
- date = date.strftime '%e-%b-%Y'
112
- else
113
- raise ArgumentError, "#{date.inspect} is invalid."
114
- end
106
+ def before(date)
107
+ date = case date
108
+ when String
109
+ date
110
+ when Integer
111
+ (Date.today - date).strftime "%e-%b-%Y"
112
+ when Date
113
+ date.strftime "%e-%b-%Y"
114
+ else
115
+ raise ArgumentError, "#{date.inspect} is invalid."
116
+ end
115
117
 
116
- self << 'BEFORE' << date
118
+ self << "BEFORE" << date
117
119
  end
118
120
  end
119
121
  end
120
-
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module ImapGuard
4
4
  describe Guard do
@@ -12,21 +12,21 @@ module ImapGuard
12
12
 
13
13
  let(:settings) do
14
14
  {
15
- host: 'localhost',
15
+ host: "localhost",
16
16
  port: 993,
17
- username: 'bob',
18
- password: 'PASS',
17
+ username: "bob",
18
+ password: "PASS",
19
19
  }
20
20
  end
21
21
 
22
22
  let(:imap) do
23
- double('Net::IMAP', search: [7, 28], expunge: nil, select: nil, list: [])
23
+ double("Net::IMAP", search: [7, 28], expunge: nil, select: nil, list: [])
24
24
  end
25
25
 
26
- def guard_instance custom_settings = {}
26
+ def guard_instance(custom_settings = {})
27
27
  guard = Guard.new(settings.merge(custom_settings))
28
28
  guard.instance_variable_set(:@imap, imap)
29
- guard.stub(:fetch_mail)
29
+ allow(guard).to receive(:fetch_mail)
30
30
  guard
31
31
  end
32
32
 
@@ -35,7 +35,7 @@ module ImapGuard
35
35
  let(:guard) { guard_instance(read_only: true) }
36
36
 
37
37
  it "opens the mailbox in read-only" do
38
- imap.should_receive(:examine)
38
+ expect(imap).to receive(:examine)
39
39
  guard.select nil
40
40
  end
41
41
  end
@@ -44,7 +44,7 @@ module ImapGuard
44
44
  let(:guard) { guard_instance(read_only: false) }
45
45
 
46
46
  it "opens the mailbox in read-write" do
47
- imap.should_receive(:select)
47
+ expect(imap).to receive(:select)
48
48
  guard.select nil
49
49
  end
50
50
  end
@@ -52,46 +52,46 @@ module ImapGuard
52
52
 
53
53
  describe "#mailbox" do
54
54
  it "returns nil when no mailbox has been selected" do
55
- guard_instance.mailbox.should be_nil
55
+ expect(guard_instance.mailbox).to be_nil
56
56
  end
57
57
 
58
58
  it "returns the currently selected mailbox" do
59
59
  guard = guard_instance
60
60
 
61
- guard.select 'Sent'
62
- guard.mailbox.should eq 'Sent'
61
+ guard.select "Sent"
62
+ expect(guard.mailbox).to eq "Sent"
63
63
  end
64
64
  end
65
65
 
66
66
  describe "#list" do
67
67
  it "returns the list of mailboxes" do
68
- imap.should_receive(:list)
69
- guard_instance.list.should eq []
68
+ expect(imap).to receive(:list)
69
+ expect(guard_instance.list).to eq []
70
70
  end
71
71
  end
72
72
 
73
73
  describe "#search" do
74
74
  before do
75
- imap.should_receive(:search) do |arg|
76
- [13, 37] if [['ALL'], 'ALL'].include? arg
75
+ expect(imap).to receive(:search) do |arg|
76
+ [13, 37] if [["ALL"], "ALL"].include? arg
77
77
  end
78
78
  end
79
79
 
80
80
  it "accepts arrays" do
81
- expect {
82
- guard_instance.send(:search, ['ALL'])
83
- }.to_not raise_error
81
+ expect do
82
+ guard_instance.send(:search, ["ALL"])
83
+ end.to_not raise_error
84
84
  end
85
85
 
86
86
  it "accepts strings" do
87
- expect {
88
- guard_instance.send(:search, 'ALL')
89
- }.to_not raise_error
87
+ expect do
88
+ guard_instance.send(:search, "ALL")
89
+ end.to_not raise_error
90
90
  end
91
91
 
92
92
  it "returns results" do
93
- messages = guard_instance.send(:search, 'ALL')
94
- messages.should eq [13, 37]
93
+ messages = guard_instance.send(:search, "ALL")
94
+ expect(messages).to eq [13, 37]
95
95
  end
96
96
  end
97
97
 
@@ -101,49 +101,49 @@ module ImapGuard
101
101
 
102
102
  context "without a filter block" do
103
103
  it "does perform the operation" do
104
- opeartion.should_receive(:call).with(7)
105
- opeartion.should_receive(:call).with(28)
104
+ expect(opeartion).to receive(:call).with(7)
105
+ expect(opeartion).to receive(:call).with(28)
106
106
 
107
- guard.send(:process, 'ALL', opeartion)
107
+ guard.send(:process, "ALL", opeartion)
108
108
  end
109
109
 
110
110
  it "does not execute the filter block" do
111
- guard.should_not_receive(:fetch_mail)
111
+ expect(guard).not_to receive(:fetch_mail)
112
112
 
113
- guard.send(:process, 'ALL', opeartion)
113
+ guard.send(:process, "ALL", opeartion)
114
114
  end
115
115
 
116
116
  context "with a debug proc" do
117
117
  it "calls the proc" do
118
118
  block = ->(mail) {}
119
119
  guard.debug = block
120
- block.should_receive(:call).twice
120
+ expect(block).to receive(:call).twice
121
121
 
122
- guard.send(:process, 'ALL', opeartion)
122
+ guard.send(:process, "ALL", opeartion)
123
123
  end
124
124
  end
125
125
  end
126
126
 
127
127
  context "with a filter block" do
128
128
  it "executes the filter block" do
129
- guard.should_receive(:fetch_mail).twice
129
+ expect(guard).to receive(:fetch_mail).twice
130
130
 
131
- guard.send(:process, 'ALL', opeartion) { }
131
+ guard.send(:process, "ALL", opeartion) {}
132
132
  end
133
133
 
134
134
  context "returning false" do
135
135
  it "does not perform the operation" do
136
- opeartion.should_not_receive(:call)
136
+ expect(opeartion).not_to receive(:call)
137
137
 
138
- guard.send(:process, 'ALL', opeartion) { false }
138
+ guard.send(:process, "ALL", opeartion) { false }
139
139
  end
140
140
  end
141
141
 
142
142
  context "returning true" do
143
143
  it "does perform the operation" do
144
- opeartion.should_receive(:call).twice
144
+ expect(opeartion).to receive(:call).twice
145
145
 
146
- guard.send(:process, 'ALL', opeartion) { true }
146
+ guard.send(:process, "ALL", opeartion) { true }
147
147
  end
148
148
  end
149
149
  end
@@ -151,29 +151,29 @@ module ImapGuard
151
151
 
152
152
  describe "#move" do
153
153
  it "copies emails before adding the :Deleted flag" do
154
- imap.should_receive(:search)
155
- imap.should_receive(:copy).with(7, 'destination').ordered
156
- imap.should_receive(:store).with(7, '+FLAGS', [:Deleted]).ordered
157
- imap.should_receive(:copy).with(28, 'destination').ordered
158
- imap.should_receive(:store).with(28, '+FLAGS', [:Deleted]).ordered
154
+ expect(imap).to receive(:search)
155
+ expect(imap).to receive(:copy).with(7, "destination").ordered
156
+ expect(imap).to receive(:store).with(7, "+FLAGS", [:Deleted]).ordered
157
+ expect(imap).to receive(:copy).with(28, "destination").ordered
158
+ expect(imap).to receive(:store).with(28, "+FLAGS", [:Deleted]).ordered
159
159
 
160
- guard_instance.move 'ALL', 'destination'
160
+ guard_instance.move "ALL", "destination"
161
161
  end
162
162
  end
163
163
 
164
164
  describe "#delete" do
165
165
  it "adds the :Deleted flag" do
166
- imap.should_receive(:search)
167
- imap.should_receive(:store).with(7, '+FLAGS', [:Deleted])
168
- imap.should_receive(:store).with(28, '+FLAGS', [:Deleted])
166
+ expect(imap).to receive(:search)
167
+ expect(imap).to receive(:store).with(7, "+FLAGS", [:Deleted])
168
+ expect(imap).to receive(:store).with(28, "+FLAGS", [:Deleted])
169
169
 
170
- guard_instance.delete 'ALL'
170
+ guard_instance.delete "ALL"
171
171
  end
172
172
  end
173
173
 
174
174
  describe "#each" do
175
175
  it "iterates over messages without errors" do
176
- guard_instance.each 'ALL' do |message_id|
176
+ guard_instance.each "ALL" do |message_id|
177
177
  # noop
178
178
  end
179
179
  end
@@ -181,21 +181,21 @@ module ImapGuard
181
181
 
182
182
  describe "#expunge" do
183
183
  it "expunges the folder" do
184
- imap.should_receive(:expunge)
184
+ expect(imap).to receive(:expunge)
185
185
  guard_instance.expunge
186
186
  end
187
187
  end
188
188
 
189
189
  describe "#close" do
190
190
  it "closes the IMAP connection" do
191
- imap.should_receive(:close)
191
+ expect(imap).to receive(:close)
192
192
  guard_instance.close
193
193
  end
194
194
  end
195
195
 
196
196
  describe "#disconnect" do
197
197
  it "disconnects from the server" do
198
- imap.should_receive(:disconnect)
198
+ expect(imap).to receive(:disconnect)
199
199
  guard_instance.disconnect
200
200
  end
201
201
  end
@@ -205,7 +205,7 @@ module ImapGuard
205
205
  let(:guard) { guard_instance(verbose: true) }
206
206
 
207
207
  it "does output to $stdout" do
208
- $stdout.should_receive(:write).with("ham")
208
+ expect($stdout).to receive(:write).with("ham")
209
209
  guard.send(:verbose).print "ham"
210
210
  end
211
211
  end
@@ -214,7 +214,7 @@ module ImapGuard
214
214
  let(:guard) { guard_instance(verbose: false) }
215
215
 
216
216
  it "does not output to $stdout" do
217
- $stdout.should_not_receive(:write)
217
+ expect($stdout).not_to receive(:write)
218
218
  guard.send(:verbose).print "ham"
219
219
  end
220
220
  end
@@ -226,23 +226,22 @@ module ImapGuard
226
226
 
227
227
  exception = (RUBY_VERSION >= "2.1.0" ? RuntimeError : TypeError)
228
228
 
229
- expect {
230
- guard.settings.host = 'example.net'
231
- }.to raise_error(exception, /frozen/)
229
+ expect do
230
+ guard.settings.host = "example.net"
231
+ end.to raise_error(exception, /frozen/)
232
232
  end
233
233
 
234
234
  it "raises ArgumentError if any required key is missing" do
235
- expect {
235
+ expect do
236
236
  Guard.new({})
237
- }.to raise_error ArgumentError, /missing/i
237
+ end.to raise_error ArgumentError, /missing/i
238
238
  end
239
239
 
240
240
  it "raises ArgumentError if any key is unknown" do
241
- expect {
241
+ expect do
242
242
  Guard.new(settings.merge(coffee: true))
243
- }.to raise_error ArgumentError, /unknown/i
243
+ end.to raise_error ArgumentError, /unknown/i
244
244
  end
245
245
  end
246
246
  end
247
247
  end
248
-
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module ImapGuard
4
4
  describe Query do
@@ -9,35 +9,35 @@ module ImapGuard
9
9
  describe "#seen" do
10
10
  it "adds 'SEEN'" do
11
11
  subject.seen
12
- subject.last.should eq 'SEEN'
12
+ expect(subject.last).to eq "SEEN"
13
13
  end
14
14
  end
15
15
 
16
16
  describe "#unseen" do
17
17
  it "adds 'UNSEEN'" do
18
18
  subject.unseen
19
- subject.last.should eq 'UNSEEN'
19
+ expect(subject.last).to eq "UNSEEN"
20
20
  end
21
21
  end
22
22
 
23
23
  describe "#unanswered" do
24
24
  it "adds 'UNANSWERED'" do
25
25
  subject.unanswered
26
- subject.last.should eq 'UNANSWERED'
26
+ expect(subject.last).to eq "UNANSWERED"
27
27
  end
28
28
  end
29
29
 
30
30
  describe "#unflagged" do
31
31
  it "adds 'UNFLAGGED'" do
32
32
  subject.unflagged
33
- subject.last.should eq 'UNFLAGGED'
33
+ expect(subject.last).to eq "UNFLAGGED"
34
34
  end
35
35
  end
36
36
 
37
37
  describe "#deleted" do
38
38
  it "adds 'DELETED'" do
39
39
  subject.deleted
40
- subject.last.should eq 'DELETED'
40
+ expect(subject.last).to eq "DELETED"
41
41
  end
42
42
  end
43
43
 
@@ -45,26 +45,26 @@ module ImapGuard
45
45
  context "without a search key" do
46
46
  it "adds 'OR'" do
47
47
  subject.or
48
- subject.last.should eq 'OR'
48
+ expect(subject.last).to eq "OR"
49
49
  end
50
50
  end
51
51
 
52
52
  context "with search keys" do
53
53
  it "adds 'OR UNANSWERED UNFLAGGED '" do
54
54
  subject.or(:unanswered, :unflagged)
55
- subject.last(3).should eq ["OR", "UNANSWERED", "UNFLAGGED"]
55
+ expect(subject.last(3)).to eq %w[OR UNANSWERED UNFLAGGED]
56
56
  end
57
57
  end
58
58
 
59
59
  context "with only one non-nil search key" do
60
60
  it "raises ArgumentError" do
61
- expect {
61
+ expect do
62
62
  subject.or(:whatever)
63
- }.to raise_error(ArgumentError)
63
+ end.to raise_error(ArgumentError)
64
64
 
65
- expect {
65
+ expect do
66
66
  subject.or(nil, :whatever)
67
- }.to raise_error(ArgumentError)
67
+ end.to raise_error(ArgumentError)
68
68
  end
69
69
  end
70
70
  end
@@ -72,28 +72,28 @@ module ImapGuard
72
72
  describe "#subject" do
73
73
  it "adds the search value" do
74
74
  subject.subject("Hey you")
75
- subject.last.should eq "Hey you"
75
+ expect(subject.last).to eq "Hey you"
76
76
  end
77
77
  end
78
78
 
79
79
  describe "#from" do
80
80
  it "adds the search value" do
81
81
  subject.from("root@example.net")
82
- subject.last.should eq "root@example.net"
82
+ expect(subject.last).to eq "root@example.net"
83
83
  end
84
84
  end
85
85
 
86
86
  describe "#to" do
87
87
  it "adds the search value" do
88
88
  subject.to("root@example.net")
89
- subject.last.should eq "root@example.net"
89
+ expect(subject.last).to eq "root@example.net"
90
90
  end
91
91
  end
92
92
 
93
93
  describe "#cc" do
94
94
  it "adds the search value" do
95
95
  subject.cc("root@example.net")
96
- subject.last.should eq "root@example.net"
96
+ expect(subject.last).to eq "root@example.net"
97
97
  end
98
98
  end
99
99
 
@@ -101,14 +101,14 @@ module ImapGuard
101
101
  context "without a search key" do
102
102
  it "adds 'NOT'" do
103
103
  subject.not.deleted
104
- subject.last(2).should eq ["NOT", "DELETED"]
104
+ expect(subject.last(2)).to eq %w[NOT DELETED]
105
105
  end
106
106
  end
107
107
 
108
108
  context "with a search key" do
109
109
  it "adds 'NOT DELETED'" do
110
110
  subject.not(:deleted)
111
- subject.last(2).should eq ["NOT", "DELETED"]
111
+ expect(subject.last(2)).to eq %w[NOT DELETED]
112
112
  end
113
113
  end
114
114
  end
@@ -116,40 +116,39 @@ module ImapGuard
116
116
  describe "#before" do
117
117
  context "when I pass 'nil' as an argument" do
118
118
  it "raises" do
119
- expect {
119
+ expect do
120
120
  subject.before(nil)
121
- }.to raise_error ArgumentError
121
+ end.to raise_error ArgumentError
122
122
  end
123
123
  end
124
124
 
125
125
  context "when I pass '1' as an argument" do
126
126
  it "returns yesterday" do
127
127
  subject.before(1)
128
- Date.parse(subject.last).should eq Date.today.prev_day
128
+ expect(Date.parse(subject.last)).to eq Date.today.prev_day
129
129
  end
130
130
  end
131
131
 
132
132
  context "when I pass an integer" do
133
133
  it "uses it as a negative offset in days" do
134
134
  subject.before(3)
135
- (Date.today - Date.parse(subject.last)).should eq 3
135
+ expect((Date.today - Date.parse(subject.last))).to eq 3
136
136
  end
137
137
  end
138
138
 
139
139
  context "when I pass '18-Mar-2013' as an argument" do
140
140
  it "uses it as is" do
141
- subject.before('18-Mar-2013')
142
- subject.last.should eq '18-Mar-2013'
141
+ subject.before("18-Mar-2013")
142
+ expect(subject.last).to eq "18-Mar-2013"
143
143
  end
144
144
  end
145
145
 
146
146
  context "when I pass an instance of Date as an argument" do
147
147
  it "extracts the date" do
148
148
  subject.before(Date.today)
149
- Date.parse(subject.last).should eq Date.today
149
+ expect(Date.parse(subject.last)).to eq Date.today
150
150
  end
151
151
  end
152
152
  end
153
153
  end
154
154
  end
155
-
@@ -1,11 +1,12 @@
1
- require 'simplecov'
1
+ # frozen_string_literal: true
2
+
3
+ require "simplecov"
2
4
  SimpleCov.start do
3
- minimum_coverage 90
5
+ minimum_coverage 95
4
6
  add_group "Sources", "lib"
5
7
  add_group "Tests", "spec"
6
8
  end
7
9
 
8
- require 'imap_guard'
10
+ require "imap_guard"
9
11
 
10
12
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |file| require file }
11
-
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.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cédric Félizard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-15 00:00:00.000000000 Z
11
+ date: 2019-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: cane
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: simplecov
70
+ name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rspec
84
+ name: redcarpet
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: guard-rspec
98
+ name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: rb-inotify
112
+ name: rubocop
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: cane
126
+ name: simplecov
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -150,20 +150,6 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: redcarpet
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
153
  description: A guard for your IMAP server
168
154
  email:
169
155
  - cedric@felizard.fr
@@ -173,7 +159,7 @@ extra_rdoc_files: []
173
159
  files:
174
160
  - ".gitignore"
175
161
  - ".rspec"
176
- - ".ruby-version"
162
+ - ".rubocop.yml"
177
163
  - ".travis.yml"
178
164
  - Gemfile
179
165
  - Guardfile
@@ -207,8 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
193
  - !ruby/object:Gem::Version
208
194
  version: '0'
209
195
  requirements: []
210
- rubyforge_project:
211
- rubygems_version: 2.4.6
196
+ rubygems_version: 3.0.1
212
197
  signing_key:
213
198
  specification_version: 4
214
199
  summary: A guard for your IMAP server
@@ -216,4 +201,3 @@ test_files:
216
201
  - spec/imap_guard/guard_spec.rb
217
202
  - spec/imap_guard/query_spec.rb
218
203
  - spec/spec_helper.rb
219
- has_rdoc:
@@ -1 +0,0 @@
1
- 2.2