imap-backup 3.3.1 → 3.4.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: c3446b53604f5895cb09b109cbe663bc4ac131daeb63989b09ae8985c480464b
4
- data.tar.gz: 8c3b6a7176dbda814f208505c49ed63f27d650f683dad7941734e8dbd4018601
3
+ metadata.gz: 44a7f8e8754461ed51afdbd5711ba809ad6b0ed68c0f40ff95a42688d85881b9
4
+ data.tar.gz: a70019109a179506f520b969bb03de78fa67fca66001b182af99427b7a02ecdd
5
5
  SHA512:
6
- metadata.gz: 6926f54cb421029116f0e63533e1a3c3151937c9572b2c5b2143cab08e3c1aef81cba6ae3dcc2c799f77e37f3b983c4adee73f6fa90f585cddf030cff8fffd9d
7
- data.tar.gz: 1ed5e647c1ef08049f928293295cb564d7e87b592dd499dc903bab74717892fffc2aa19d4f214824757dcb80f46356c12864a7cf8332b3f25512c1af637f1aff
6
+ metadata.gz: 5055eea6a69b674f02f2b50c0423df197a4c312171aa04a19b183ce784047699815ac603d8550d28f78ada6f2aa4a904d74d5b7bef8f6ea10633de68752f7a65
7
+ data.tar.gz: 7849285c5b94136b7d5f620eac770630ea4e7cf988b42cc7079021dac95163c271f5fd68d5b620ac9d36326be142557c617459ba890755920c181110cf99531a
data/.rubocop_todo.yml CHANGED
@@ -1,42 +1,129 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2021-01-09 09:21:34 UTC using RuboCop version 0.89.1.
3
+ # on 2021-09-21 15:30:34 UTC using RuboCop version 1.21.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 11
10
- # Configuration parameters: IgnoredMethods.
11
- Metrics/AbcSize:
12
- Max: 33
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ Layout/ElseAlignment:
12
+ Exclude:
13
+ - 'lib/imap/backup/configuration/gmail_oauth2.rb'
13
14
 
14
15
  # Offense count: 2
15
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
16
- # ExcludedMethods: refine
17
- Metrics/BlockLength:
18
- Max: 138
16
+ # Cop supports --auto-correct.
17
+ # Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, AllowAdjacentOneLineDefs, NumberOfEmptyLines.
18
+ Layout/EmptyLineBetweenDefs:
19
+ Exclude:
20
+ - 'lib/google/auth/stores/in_memory_token_store.rb'
21
+
22
+ # Offense count: 1
23
+ # Cop supports --auto-correct.
24
+ # Configuration parameters: EnforcedStyleAlignWith, Severity.
25
+ # SupportedStylesAlignWith: keyword, variable, start_of_line
26
+ Layout/EndAlignment:
27
+ Exclude:
28
+ - 'lib/imap/backup/configuration/gmail_oauth2.rb'
29
+
30
+ # Offense count: 1
31
+ # Cop supports --auto-correct.
32
+ # Configuration parameters: Width, IgnoredPatterns.
33
+ Layout/IndentationWidth:
34
+ Exclude:
35
+ - 'lib/imap/backup/configuration/gmail_oauth2.rb'
36
+
37
+ # Offense count: 34
38
+ # Configuration parameters: AllowedMethods.
39
+ # AllowedMethods: enums
40
+ Lint/ConstantDefinitionInBlock:
41
+ Exclude:
42
+ - 'lib/imap/backup/configuration/asker.rb'
43
+ - 'spec/unit/gmail/authenticator_spec.rb'
44
+ - 'spec/unit/google/auth/stores/in_memory_token_store_spec.rb'
45
+ - 'spec/unit/imap/backup/account/connection_spec.rb'
46
+ - 'spec/unit/imap/backup/account/folder_spec.rb'
47
+ - 'spec/unit/imap/backup/configuration/account_spec.rb'
48
+ - 'spec/unit/imap/backup/configuration/gmail_oauth2_spec.rb'
19
49
 
20
50
  # Offense count: 2
51
+ # Cop supports --auto-correct.
52
+ # Configuration parameters: AllowComments.
53
+ Lint/UselessMethodDefinition:
54
+ Exclude:
55
+ - 'lib/imap/backup/configuration/account.rb'
56
+ - 'lib/imap/backup/configuration/asker.rb'
57
+
58
+ # Offense count: 11
59
+ # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
60
+ Metrics/AbcSize:
61
+ Max: 33
62
+
63
+ # Offense count: 3
21
64
  # Configuration parameters: CountComments, CountAsOne.
22
65
  Metrics/ClassLength:
23
- Max: 167
66
+ Max: 171
24
67
 
25
- # Offense count: 17
26
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
68
+ # Offense count: 19
69
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
27
70
  Metrics/MethodLength:
28
- Max: 25
71
+ Max: 26
29
72
 
30
73
  # Offense count: 2
31
74
  # Configuration parameters: CountComments, CountAsOne.
32
75
  Metrics/ModuleLength:
33
- Max: 141
76
+ Max: 145
77
+
78
+ # Offense count: 2
79
+ # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers.
80
+ # SupportedStyles: snake_case, normalcase, non_integer
81
+ # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
82
+ Naming/VariableNumber:
83
+ Exclude:
84
+ - 'lib/email/provider.rb'
85
+ - 'spec/unit/email/provider_spec.rb'
34
86
 
35
- # Offense count: 200
87
+ # Offense count: 209
36
88
  # Configuration parameters: AllowSubject.
37
89
  RSpec/MultipleMemoizedHelpers:
38
90
  Max: 16
39
91
 
40
- # Offense count: 1
92
+ # Offense count: 49
41
93
  RSpec/NestedGroups:
42
94
  Max: 6
95
+
96
+ # Offense count: 8
97
+ # Cop supports --auto-correct.
98
+ # Configuration parameters: EnforcedStyle.
99
+ # SupportedStyles: nested, compact
100
+ Style/ClassAndModuleChildren:
101
+ Exclude:
102
+ - 'lib/email/mboxrd/message.rb'
103
+ - 'lib/imap/backup/downloader.rb'
104
+ - 'lib/imap/backup/serializer.rb'
105
+ - 'lib/imap/backup/serializer/mbox.rb'
106
+ - 'lib/imap/backup/serializer/mbox_enumerator.rb'
107
+ - 'lib/imap/backup/serializer/mbox_store.rb'
108
+ - 'lib/imap/backup/uploader.rb'
109
+ - 'lib/imap/backup/utils.rb'
110
+
111
+ # Offense count: 1
112
+ # Cop supports --auto-correct.
113
+ Style/RedundantBegin:
114
+ Exclude:
115
+ - 'lib/imap/backup/account/connection.rb'
116
+
117
+ # Offense count: 1
118
+ # Cop supports --auto-correct.
119
+ # Configuration parameters: MinSize, WordRegex.
120
+ # SupportedStyles: percent, brackets
121
+ Style/WordArray:
122
+ EnforcedStyle: percent
123
+
124
+ # Offense count: 1
125
+ # Cop supports --auto-correct.
126
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
127
+ # URISchemes: http, https
128
+ Layout/LineLength:
129
+ Max: 133
data/README.md CHANGED
@@ -16,11 +16,19 @@
16
16
  [Rubygem]: http://rubygems.org/gems/imap-backup "Ruby gem at rubygems.org"
17
17
  [Continuous Integration]: https://circleci.com/gh/joeyates/imap-backup "Build status by CirceCI"
18
18
 
19
- ## GMail
19
+ # GMail
20
20
 
21
- GMail OAuth2 authentication is supported.
21
+ To use imap-backup with GMail, you will need to enable 'App passwords' on your account.
22
22
 
23
- To set it up, [follow the HOWTO](docs/setting-up-gmail.md).
23
+ ## GMail OAuth2
24
+
25
+ GMail OAuth2 authentication is supported, but as GMail's policy requires
26
+ users to set up an application specific to their account, the feature
27
+ is disabled by default.
28
+
29
+ You will need to set the environment variable IMAP_BACKUP_ENABLE_GMAIL_OAUTH2.
30
+
31
+ To set it up, [follow the HOWTO](docs/setting-up-gmail-with-oauth2.md).
24
32
 
25
33
  # Installation
26
34
 
@@ -96,7 +96,7 @@ module Imap::Backup
96
96
  "Creating IMAP instance: #{server}, options: #{options.inspect}"
97
97
  )
98
98
  imap = Net::IMAP.new(server, options)
99
- if gmail? && Gmail::Authenticator.refresh_token?(password)
99
+ if use_gmail_oauth2? && Gmail::Authenticator.refresh_token?(password)
100
100
  authenticator = Gmail::Authenticator.new(email: username, token: password)
101
101
  credentials = authenticator.credentials
102
102
  raise InvalidGmailOauth2RefreshToken if !credentials
@@ -168,8 +168,10 @@ module Imap::Backup
168
168
  password.gsub(/./, "x")
169
169
  end
170
170
 
171
- def gmail?
172
- server == Email::Provider::GMAIL_IMAP_SERVER
171
+ def use_gmail_oauth2?
172
+ # TODO: test use of ENV
173
+ server == Email::Provider::GMAIL_IMAP_SERVER &&
174
+ ENV["IMAP_BACKUP_ENABLE_GMAIL_OAUTH2"]
173
175
  end
174
176
 
175
177
  def local_folders
@@ -69,7 +69,7 @@ module Imap::Backup
69
69
  def modify_password(menu)
70
70
  menu.choice("modify password") do
71
71
  password =
72
- if account[:server] == Email::Provider::GMAIL_IMAP_SERVER
72
+ if use_gmail_oauth2?(account)
73
73
  Configuration::GmailOauth2.new(account).run
74
74
  else
75
75
  Configuration::Asker.password
@@ -82,6 +82,11 @@ module Imap::Backup
82
82
  end
83
83
  end
84
84
 
85
+ def use_gmail_oauth2?(account)
86
+ account[:server] == Email::Provider::GMAIL_IMAP_SERVER &&
87
+ ENV["IMAP_BACKUP_ENABLE_GMAIL_OAUTH2"]
88
+ end
89
+
85
90
  def modify_server(menu)
86
91
  menu.choice("modify server") do
87
92
  server = highline.ask("server: ")
@@ -8,7 +8,7 @@ module Imap::Backup
8
8
  You need to authorize imap_backup to get access to your email.
9
9
  To do so, please follow the instructions here:
10
10
 
11
- https://github.com/joeyates/imap-backup/blob/main/docs/setting-up-gmail.md
11
+ https://github.com/joeyates/imap-backup/blob/main/docs/setting-up-gmail-with-oauth2.md
12
12
 
13
13
  BANNER
14
14
 
@@ -2,8 +2,8 @@ module Imap; end
2
2
 
3
3
  module Imap::Backup
4
4
  MAJOR = 3
5
- MINOR = 3
6
- REVISION = 1
5
+ MINOR = 4
6
+ REVISION = 0
7
7
  PRE = nil
8
8
  VERSION = [MAJOR, MINOR, REVISION, PRE].compact.map(&:to_s).join(".")
9
9
  end
@@ -2,6 +2,6 @@
2
2
  :username: 'address@example.org'
3
3
  :password: 'pass'
4
4
  :connection_options:
5
- :port: <%= ENV.fetch("DOCKER_IMAP_SERVER", 993) %>
5
+ :port: <%= ENV.fetch("DOCKER_IMAP_SERVER", 8993) %>
6
6
  :ssl:
7
7
  :verify_mode: 0
@@ -111,7 +111,15 @@ describe Imap::Backup::Account::Connection do
111
111
  with(email: USERNAME, token: PASSWORD) { authenticator }
112
112
  end
113
113
 
114
- context "when the password is our copy of a GMail refresh token" do
114
+ context "when the password is our copy of a GMail refresh token and the environment IMAP_BACKUP_ENABLE_GMAIL_OAUTH2 is set" do
115
+ before do
116
+ ENV["IMAP_BACKUP_ENABLE_GMAIL_OAUTH2"] = "1"
117
+ end
118
+
119
+ after do
120
+ ENV.delete("IMAP_BACKUP_ENABLE_GMAIL_OAUTH2")
121
+ end
122
+
115
123
  it "uses the OAuth2 access_token to authenticate" do
116
124
  subject.imap
117
125
 
@@ -214,16 +214,10 @@ describe Imap::Backup::Configuration::Account do
214
214
 
215
215
  describe "choosing 'modify password'" do
216
216
  let(:new_password) { "new_password" }
217
- let(:gmail_oauth2) do
218
- instance_double(Imap::Backup::Configuration::GmailOauth2, run: nil)
219
- end
220
217
 
221
218
  before do
222
219
  allow(Imap::Backup::Configuration::Asker).
223
220
  to receive(:password) { new_password }
224
- allow(Imap::Backup::Configuration::GmailOauth2).
225
- to receive(:new).
226
- with(account) { gmail_oauth2 }
227
221
  subject.run
228
222
  menu.choices["modify password"].call
229
223
  end
@@ -245,14 +239,49 @@ describe Imap::Backup::Configuration::Account do
245
239
 
246
240
  include_examples "it doesn't flag the account as modified"
247
241
  end
242
+ end
248
243
 
249
- context "when the server is for GMail" do
250
- let(:current_server) { GMAIL_IMAP_SERVER }
244
+ describe "choosing 'modify password' when the server is for GMail" do
245
+ let(:new_password) { "new_password" }
246
+ let(:current_server) { GMAIL_IMAP_SERVER }
247
+ let(:gmail_oauth2) do
248
+ instance_double(Imap::Backup::Configuration::GmailOauth2, run: nil)
249
+ end
250
+
251
+ before do
252
+ allow(Imap::Backup::Configuration::Asker).
253
+ to receive(:password) { new_password }
254
+ allow(Imap::Backup::Configuration::GmailOauth2).
255
+ to receive(:new).
256
+ with(account) { gmail_oauth2 }
257
+ end
258
+
259
+ context "when the environment IMAP_BACKUP_ENABLE_GMAIL_OAUTH2 is set" do
260
+ before do
261
+ ENV["IMAP_BACKUP_ENABLE_GMAIL_OAUTH2"] = "1"
262
+ subject.run
263
+ menu.choices["modify password"].call
264
+ end
265
+
266
+ after do
267
+ ENV.delete("IMAP_BACKUP_ENABLE_GMAIL_OAUTH2")
268
+ end
251
269
 
252
270
  it "sets up GMail OAuth2" do
253
271
  expect(gmail_oauth2).to have_received(:run)
254
272
  end
255
273
  end
274
+
275
+ context "when the environment IMAP_BACKUP_ENABLE_GMAIL_OAUTH2 is not set" do
276
+ before do
277
+ subject.run
278
+ menu.choices["modify password"].call
279
+ end
280
+
281
+ it "sets up GMail OAuth2" do
282
+ expect(gmail_oauth2).to_not have_received(:run)
283
+ end
284
+ end
256
285
  end
257
286
 
258
287
  describe "choosing 'modify server'" do
@@ -43,7 +43,7 @@ describe Imap::Backup::Configuration::Setup do
43
43
  describe "main menu" do
44
44
  before { subject.run }
45
45
 
46
- %w(add\ account save\ and\ exit exit\ without\ saving).each do |choice|
46
+ ["add account", "save and exit", "exit without saving"].each do |choice|
47
47
  it "includes #{choice}" do
48
48
  expect(output.string).to include(choice)
49
49
  end
@@ -12,7 +12,6 @@ describe Imap::Backup::Utils do
12
12
  describe ".check_permissions" do
13
13
  let(:requested) { 0o345 }
14
14
 
15
- # rubocop:disable RSpec/EmptyExampleGroup
16
15
  context "with existing files" do
17
16
  [
18
17
  [0o100, "less than the limit", true],
@@ -37,7 +36,6 @@ describe Imap::Backup::Utils do
37
36
  end
38
37
  end
39
38
  end
40
- # rubocop:enable RSpec/EmptyExampleGroup
41
39
 
42
40
  context "with non-existent files" do
43
41
  let(:exists) { false }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imap-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-21 00:00:00.000000000 Z
11
+ date: 2021-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gmail_xoauth
@@ -210,7 +210,7 @@ files:
210
210
  - docs/26-type-code-into-imap-backup.png
211
211
  - docs/27-success.png
212
212
  - docs/docker-imap.md
213
- - docs/setting-up-gmail.md
213
+ - docs/setting-up-gmail-with-oauth2.md
214
214
  - imap-backup.gemspec
215
215
  - lib/email/mboxrd/message.rb
216
216
  - lib/email/provider.rb
@@ -290,7 +290,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
290
290
  - !ruby/object:Gem::Version
291
291
  version: '0'
292
292
  requirements: []
293
- rubygems_version: 3.0.3
293
+ rubygems_version: 3.1.4
294
294
  signing_key:
295
295
  specification_version: 4
296
296
  summary: Backup GMail (or other IMAP) accounts to disk