imap-backup 4.0.0.rc3 → 4.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: 956fde3bc96dc3acd872d51905a88fa9478d9b5cd7022cf55f8e73db769d8ef7
4
- data.tar.gz: 28d653dc4e1cfebaed0a730c0231ec13a3c3c04e1a8514352183b11f152db065
3
+ metadata.gz: 85e081f686a106384d27ffc91cb21965832edd629da671261bda69b668776d5e
4
+ data.tar.gz: 8253587491a279e76ebed2268a66b60d9aab4f517cdafadb8c9494e7c3f3648b
5
5
  SHA512:
6
- metadata.gz: 75643fb06176ab9017d0a7673bb428df4907e1350075cf4e3429702b42f03f8a6ef8a2be1095af3b6f4032ebd682d165e05d94b2e3930397ecb31ad95b2be665
7
- data.tar.gz: e703041a7ed4e38ced9ef1b762fb3f2ebaf178cd7beb88a204624f6dd7fc53c8f9b9635942018c0f02abfa664db90e52c17eccf3278251e23395072153fe99da
6
+ metadata.gz: e2b3806cedfe124c286477f50690781c4593db1f3b12d53281c666d3d5771f9a42aa4cc24851fb88f9205a2f11a8e299c74a331a606de1aab056e56b753e3cf1
7
+ data.tar.gz: fc96edce37dd33793d04da272f2aea087ad7a16aa409726c83d6cf453bd386e3673a75b8d4e0eee90f352fc1e9168d611865dd87f79c05ff0cf132278bf59df3
data/docs/restore.md ADDED
@@ -0,0 +1,13 @@
1
+ # FAQ
2
+
3
+ # How does restore work?
4
+
5
+ # What are all these 'INBOX.12345' files?
6
+
7
+ # Will my email get overwritten?
8
+
9
+ ## How do I restore to a different service?
10
+
11
+ 1. Run setup and add the new server, (but don't run any backups),
12
+ 2. Rename of the existing backup directory to match the new email address,
13
+ 3. Run the restore.
data/docs/setup.md ADDED
@@ -0,0 +1,5 @@
1
+ # HOWTOs
2
+
3
+ ## Set the server for a Google Apps account
4
+
5
+ Use imap.gmail.com
data/imap-backup.gemspec CHANGED
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.expand_path("lib", __dir__))
2
2
  require "imap/backup/version"
3
+ require "rake/file_list"
3
4
 
4
5
  Gem::Specification.new do |gem|
5
6
  gem.name = "imap-backup"
@@ -8,8 +9,17 @@ Gem::Specification.new do |gem|
8
9
  gem.authors = ["Joe Yates"]
9
10
  gem.email = ["joe.g.yates@gmail.com"]
10
11
  gem.homepage = "https://github.com/joeyates/imap-backup"
12
+ gem.licenses = ["MIT"]
13
+
14
+ # Build list of files manually, see also
15
+ # https://github.com/rubygems/rubygems/blob/master/bundler/bundler.gemspec#L37
16
+ gem.files = %w[bin/imap-backup]
17
+ gem.files += Dir.glob("docs/*{.png,.md}")
18
+ gem.files += Dir.glob("lib/**/*.rb")
19
+ gem.files += Dir.glob("spec/**/*{.rb,.yml}")
20
+ gem.files += %w[imap-backup.gemspec]
21
+ gem.files += %w[LICENSE README.md]
11
22
 
12
- gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
13
23
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
14
24
  gem.test_files = gem.files.grep(%r{^spec/})
15
25
  gem.require_paths = ["lib"]
@@ -21,8 +21,8 @@ module Imap::Backup
21
21
  end
22
22
  end
23
23
 
24
- desc "emails EMAIL FOLDER", "List emails in a folder"
25
- def emails(email, folder_name)
24
+ desc "list EMAIL FOLDER", "List emails in a folder"
25
+ def list(email, folder_name)
26
26
  connections = Imap::Backup::Configuration::List.new
27
27
  account = connections.accounts.find { |a| a[:username] == email }
28
28
  raise "#{email} is not a configured account" if !account
@@ -40,7 +40,11 @@ module Imap::Backup
40
40
  uids = folder_serializer.uids
41
41
 
42
42
  folder_serializer.each_message(uids).map do |uid, message|
43
- m = {uid: uid, date: message.parsed.date.to_s, subject: message.parsed.subject}
43
+ m = {
44
+ uid: uid,
45
+ date: message.parsed.date.to_s,
46
+ subject: message.parsed.subject || ""
47
+ }
44
48
  if m[:subject].length > max_subject
45
49
  puts format("% 10<uid>u: %.#{max_subject - 3}<subject>s... - %<date>s", m)
46
50
  else
@@ -49,8 +53,13 @@ module Imap::Backup
49
53
  end
50
54
  end
51
55
 
52
- desc "email EMAIL FOLDER UID", "Show an email"
53
- def email(email, folder_name, uid)
56
+ desc "show EMAIL FOLDER UID[,UID]", "Show one or more emails"
57
+ long_desc <<~DESC
58
+ Prints out the requested emails.
59
+ If more than one UID is given, they are separated by a header indicating
60
+ the UID.
61
+ DESC
62
+ def show(email, folder_name, uids)
54
63
  connections = Imap::Backup::Configuration::List.new
55
64
  account = connections.accounts.find { |a| a[:username] == email }
56
65
  raise "#{email} is not a configured account" if !account
@@ -61,10 +70,17 @@ module Imap::Backup
61
70
  end
62
71
  raise "Folder '#{folder_name}' not found" if !folder_serializer
63
72
 
64
- loaded_message = folder_serializer.load(uid)
65
- raise "Message #{uid} not found in folder '#{folder_name}'" if !loaded_message
66
-
67
- puts loaded_message.supplied_body
73
+ uid_list = uids.split(",")
74
+ folder_serializer.each_message(uid_list).each do |uid, message|
75
+ if uid_list.count > 1
76
+ puts <<~HEADER
77
+ #{"-" * 80}
78
+ #{format("| UID: %-71s |", uid)}
79
+ #{"-" * 80}
80
+ HEADER
81
+ end
82
+ puts message.supplied_body
83
+ end
68
84
  end
69
85
  end
70
86
  end
@@ -1,5 +1,7 @@
1
1
  require "thor"
2
2
 
3
+ module Imap; end
4
+
3
5
  module Imap::Backup
4
6
  class CLI < Thor
5
7
  require "imap/backup/cli/helpers"
@@ -22,7 +22,8 @@ module Imap::Backup
22
22
  Imap::Backup.logger.debug(
23
23
  "#{log_prefix} #{message['RFC822'].size} bytes"
24
24
  )
25
- serializer.save(uid, message)
25
+ body = message["RFC822"]
26
+ serializer.save(uid, body)
26
27
  end
27
28
  end
28
29
  end
@@ -40,7 +40,7 @@ module Imap::Backup
40
40
  @uids || []
41
41
  end
42
42
 
43
- def add(uid, message)
43
+ def add(uid, body)
44
44
  do_load if !loaded
45
45
  raise "Can't add messages without uid_validity" if !uid_validity
46
46
 
@@ -52,7 +52,6 @@ module Imap::Backup
52
52
  return
53
53
  end
54
54
 
55
- body = message["RFC822"]
56
55
  mboxrd_message = Email::Mboxrd::Message.new(body)
57
56
  mbox = nil
58
57
  begin
@@ -84,7 +83,8 @@ module Imap::Backup
84
83
  def each_message(required_uids)
85
84
  return enum_for(:each_message, required_uids) if !block_given?
86
85
 
87
- indexes = required_uids.each.with_object({}) do |uid, acc|
86
+ indexes = required_uids.each.with_object({}) do |uid_maybe_string, acc|
87
+ uid = uid_maybe_string.to_i
88
88
  index = uids.find_index(uid)
89
89
  acc[index] = uid if index
90
90
  end
@@ -4,6 +4,6 @@ module Imap::Backup
4
4
  MAJOR = 4
5
5
  MINOR = 0
6
6
  REVISION = 0
7
- PRE = "rc3"
7
+ PRE = nil
8
8
  VERSION = [MAJOR, MINOR, REVISION, PRE].compact.map(&:to_s).join(".")
9
9
  end
@@ -2,7 +2,8 @@ describe Imap::Backup::Downloader do
2
2
  describe "#run" do
3
3
  subject { described_class.new(folder, serializer) }
4
4
 
5
- let(:message) { {"RFC822" => "blah"} }
5
+ let(:body) { "blah" }
6
+ let(:message) { {"RFC822" => body} }
6
7
  let(:folder) do
7
8
  instance_double(
8
9
  Imap::Backup::Account::Folder,
@@ -18,7 +19,7 @@ describe Imap::Backup::Downloader do
18
19
 
19
20
  context "with fetched messages" do
20
21
  specify "are saved" do
21
- expect(serializer).to receive(:save).with("111", message)
22
+ expect(serializer).to receive(:save).with("111", body)
22
23
 
23
24
  subject.run
24
25
  end
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: 4.0.0.rc3
4
+ version: 4.0.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-11-19 00:00:00.000000000 Z
11
+ date: 2021-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -158,21 +158,12 @@ executables:
158
158
  extensions: []
159
159
  extra_rdoc_files: []
160
160
  files:
161
- - ".circleci/config.yml"
162
- - ".gitignore"
163
- - ".rspec"
164
- - ".rspec-all"
165
- - ".rubocop.yml"
166
- - ".rubocop_todo.yml"
167
- - CHANGELOG.md
168
- - Gemfile
169
161
  - LICENSE
170
162
  - README.md
171
- - Rakefile
172
163
  - bin/imap-backup
173
- - docker-compose.yml
174
164
  - docs/docker-imap.md
175
- - imap-backup
165
+ - docs/restore.md
166
+ - docs/setup.md
176
167
  - imap-backup.gemspec
177
168
  - lib/email/mboxrd/message.rb
178
169
  - lib/email/provider.rb
@@ -235,9 +226,9 @@ files:
235
226
  - spec/unit/imap/backup/uploader_spec.rb
236
227
  - spec/unit/imap/backup/utils_spec.rb
237
228
  - spec/unit/imap/backup_spec.rb
238
- - tmp/.gitkeep
239
229
  homepage: https://github.com/joeyates/imap-backup
240
- licenses: []
230
+ licenses:
231
+ - MIT
241
232
  metadata: {}
242
233
  post_install_message:
243
234
  rdoc_options: []
@@ -250,9 +241,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
250
241
  version: '2.5'
251
242
  required_rubygems_version: !ruby/object:Gem::Requirement
252
243
  requirements:
253
- - - ">"
244
+ - - ">="
254
245
  - !ruby/object:Gem::Version
255
- version: 1.3.1
246
+ version: '0'
256
247
  requirements: []
257
248
  rubygems_version: 3.1.4
258
249
  signing_key:
data/.circleci/config.yml DELETED
@@ -1,51 +0,0 @@
1
- version: 2.1
2
-
3
- orbs:
4
- ruby: circleci/ruby@1.1.2
5
-
6
- references:
7
- restore: &restore
8
- restore_cache:
9
- keys:
10
- - 'imap.backup.<< parameters.ruby_version >>.{{checksum "imap-backup.gemspec"}}'
11
- bundle: &bundle
12
- run:
13
- name: Install Ruby dependencies
14
- command: |
15
- bundle install
16
- bundle clean
17
- save: &save
18
- save_cache:
19
- key: 'imap.backup.<< parameters.ruby_version >>.{{checksum "imap-backup.gemspec"}}'
20
- paths:
21
- - vendor/bundle
22
-
23
- jobs:
24
- test:
25
- parameters:
26
- ruby_version:
27
- type: string
28
- environment:
29
- BUNDLE_PATH: ./vendor/bundle
30
- DOCKER_IMAP_SERVER: 993
31
- docker:
32
- - image: "cimg/ruby:<< parameters.ruby_version >>"
33
- - image: antespi/docker-imap-devel:latest
34
- environment:
35
- MAIL_ADDRESS: address@example.org
36
- MAIL_PASS: pass
37
- MAILNAME: example.org
38
- steps:
39
- - checkout
40
- - <<: *restore
41
- - <<: *bundle
42
- - <<: *save
43
- - ruby/rspec-test
44
-
45
- workflows:
46
- all-tests:
47
- jobs:
48
- - test:
49
- matrix:
50
- parameters:
51
- ruby_version: ["2.5", "2.6", "2.7"]
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- coverage
5
- pkg
6
- .rbenv-version
7
- vendor
8
- /tmp
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
data/.rspec-all DELETED
@@ -1,4 +0,0 @@
1
- --color
2
- --format documentation
3
- --order random
4
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,21 +0,0 @@
1
- inherit_from:
2
- - https://raw.githubusercontent.com/leanpanda-com/rubocop/0.89.1/rubocop-rspec.yml
3
- - .rubocop_todo.yml
4
-
5
- AllCops:
6
- Exclude:
7
- - "bin/stubs/*"
8
- DisplayCopNames:
9
- Enabled: true
10
-
11
- RSpec/ContextWording:
12
- Exclude:
13
- - "spec/features/**/*"
14
- RSpec/LeakyConstantDeclaration:
15
- Enabled: false
16
- RSpec/MessageSpies:
17
- Enabled: false
18
- RSpec/ReturnFromStub:
19
- Enabled: false
20
- Style/EmptyCaseCondition:
21
- Enabled: false
data/.rubocop_todo.yml DELETED
@@ -1,129 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2021-09-21 15:30:34 UTC using RuboCop version 1.21.0.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 1
10
- # Cop supports --auto-correct.
11
- Layout/ElseAlignment:
12
- Exclude:
13
- - 'lib/imap/backup/configuration/gmail_oauth2.rb'
14
-
15
- # Offense count: 2
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'
49
-
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
64
- # Configuration parameters: CountComments, CountAsOne.
65
- Metrics/ClassLength:
66
- Max: 172
67
-
68
- # Offense count: 19
69
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
70
- Metrics/MethodLength:
71
- Max: 26
72
-
73
- # Offense count: 2
74
- # Configuration parameters: CountComments, CountAsOne.
75
- Metrics/ModuleLength:
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'
86
-
87
- # Offense count: 209
88
- # Configuration parameters: AllowSubject.
89
- RSpec/MultipleMemoizedHelpers:
90
- Max: 16
91
-
92
- # Offense count: 49
93
- RSpec/NestedGroups:
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/CHANGELOG.md DELETED
@@ -1,19 +0,0 @@
1
- # Change Log
2
- All notable changes to this project will be documented in this file.
3
-
4
- The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
- and this project adheres to [Semantic Versioning](http://semver.org/).
6
-
7
- ## [4.0.0.rc2] - 2021-11-18
8
-
9
- ### Removed
10
-
11
- * GMail OAuth2 support. Tokens only last a few days, so this authentication
12
- method is not usable for automated backups.
13
-
14
- ## [4.0.0.rc1] - 2021-11-17
15
-
16
- ### Added
17
-
18
- * `local` commands to list accounts, folders and emails and to view single
19
- emails.
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
data/Rakefile DELETED
@@ -1,18 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
- require "rubocop/rake_task"
4
-
5
- RSpec::Core::RakeTask.new do |t|
6
- t.pattern = "spec/**/*_spec.rb"
7
- end
8
-
9
- desc "Run RSpec examples, excluding ones relying on Docker IMAP"
10
- RSpec::Core::RakeTask.new("no-docker") do |t|
11
- t.pattern = "spec/**/*_spec.rb"
12
- t.rspec_opts = "--tag ~docker"
13
- end
14
-
15
- RuboCop::RakeTask.new
16
-
17
- task default: :spec
18
- task default: :rubocop
data/docker-compose.yml DELETED
@@ -1,15 +0,0 @@
1
- # This file adapted from github.com/antespi/docker-imap-devel
2
- version: "3"
3
-
4
- services:
5
- imap:
6
- image: antespi/docker-imap-devel:latest
7
- container_name: imap
8
- ports:
9
- - "8025:25"
10
- - "8143:143"
11
- - "8993:993"
12
- environment:
13
- - MAILNAME=example.org
14
- - MAIL_ADDRESS=address@example.org
15
- - MAIL_PASS=pass
data/imap-backup DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH.unshift(File.expand_path("../lib/", __dir__))
4
- require "imap/backup/cli"
5
-
6
- Imap::Backup::CLI.start(ARGV)
7
-
8
- __END__
9
-
data/tmp/.gitkeep DELETED
File without changes