imap-backup 1.0.15 → 1.0.16
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 +4 -4
- data/README.md +20 -2
- data/lib/imap/backup/account/connection.rb +2 -1
- data/lib/imap/backup/account/folder.rb +12 -7
- data/lib/imap/backup/downloader.rb +6 -2
- data/lib/imap/backup/serializer/base.rb +3 -0
- data/lib/imap/backup/serializer/mbox.rb +5 -2
- data/lib/imap/backup/version.rb +1 -1
- data/spec/unit/downloader_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87979e52b9e7629fc1b5a90e2567e795a36cc89c
|
4
|
+
data.tar.gz: 286d05d106efb19a22bda37446154531a396fe41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19e5fecd98e2bedb65b4da2fca103a65baedf04627e5ed83aacabf3b2408b4c4f2b1e0bc2a267705e2acad0d6ecc303c5db15d555759162a2b7356cf24086bcc
|
7
|
+
data.tar.gz: 9f4a7e727c2a544271846cd541adf9e4cd57d190eb31d09c198bf95f242b3d20fcfaac6376f92809ff9887c88432ba7340ad0a8f830e323106d99d1fa657a4be
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ It creates ~/.imap-backup directory and configuration file. E.g.:
|
|
53
53
|
It connects to GMail by default, but you can also specify a server:
|
54
54
|
|
55
55
|
```json
|
56
|
-
{
|
56
|
+
{
|
57
57
|
"accounts":
|
58
58
|
[
|
59
59
|
{
|
@@ -68,7 +68,7 @@ It connects to GMail by default, but you can also specify a server:
|
|
68
68
|
]
|
69
69
|
}
|
70
70
|
]
|
71
|
-
}
|
71
|
+
}
|
72
72
|
```
|
73
73
|
|
74
74
|
## Google Apps
|
@@ -101,6 +101,23 @@ Each folder is saved to an mbox file.
|
|
101
101
|
Alongside each mbox is a file with extension '.imap', which lists the source IMAP
|
102
102
|
UIDs to allow a full restore.
|
103
103
|
|
104
|
+
# Troubleshooting
|
105
|
+
|
106
|
+
If you have problems:
|
107
|
+
|
108
|
+
1. ensure that you have the latest release,
|
109
|
+
2. turn on debugging output:
|
110
|
+
|
111
|
+
```json
|
112
|
+
{
|
113
|
+
"accounts":
|
114
|
+
[
|
115
|
+
...
|
116
|
+
],
|
117
|
+
"debug": true
|
118
|
+
}
|
119
|
+
```
|
120
|
+
|
104
121
|
# Other Usage
|
105
122
|
|
106
123
|
List IMAP folders:
|
@@ -126,6 +143,7 @@ $ imap-backup status
|
|
126
143
|
* https://github.com/thefloweringash/gmail-imap-backup
|
127
144
|
* https://github.com/mleonhard/imapbackup
|
128
145
|
* https://github.com/rgrove/larch - copies between IMAP servers
|
146
|
+
* https://github.com/OfflineIMAP/offlineimap
|
129
147
|
|
130
148
|
## Contributing
|
131
149
|
|
@@ -38,7 +38,7 @@ module Imap::Backup
|
|
38
38
|
# start the connection so we get logging messages in the right order
|
39
39
|
imap
|
40
40
|
backup_folders.each do |folder|
|
41
|
-
Imap::Backup.logger.debug "
|
41
|
+
Imap::Backup.logger.debug "[#{folder[:name]}] running backup"
|
42
42
|
f = Account::Folder.new(self, folder[:name])
|
43
43
|
s = Serializer::Mbox.new(local_path, folder[:name])
|
44
44
|
d = Downloader.new(f, s)
|
@@ -61,6 +61,7 @@ module Imap::Backup
|
|
61
61
|
@imap = Net::IMAP.new(server, options)
|
62
62
|
Imap::Backup.logger.debug "Logging in: #{username}/#{masked_password}"
|
63
63
|
@imap.login(username, password)
|
64
|
+
Imap::Backup.logger.debug "Login complete"
|
64
65
|
@imap
|
65
66
|
end
|
66
67
|
|
@@ -10,29 +10,34 @@ module Imap::Backup
|
|
10
10
|
REQUESTED_ATTRIBUTES = ['RFC822', 'FLAGS', 'INTERNALDATE']
|
11
11
|
|
12
12
|
attr_reader :connection
|
13
|
-
attr_reader :
|
13
|
+
attr_reader :name
|
14
14
|
|
15
15
|
delegate imap: :connection
|
16
16
|
|
17
|
-
def initialize(connection,
|
18
|
-
@connection
|
17
|
+
def initialize(connection, name)
|
18
|
+
@connection = connection
|
19
|
+
@name = name
|
20
|
+
end
|
21
|
+
|
22
|
+
def folder
|
23
|
+
name
|
19
24
|
end
|
20
25
|
|
21
26
|
def uids
|
22
|
-
imap.examine(
|
27
|
+
imap.examine(name)
|
23
28
|
imap.uid_search(['ALL']).sort
|
24
29
|
rescue Net::IMAP::NoResponseError => e
|
25
|
-
Imap::Backup.logger.warn "Folder '#{
|
30
|
+
Imap::Backup.logger.warn "Folder '#{name}' does not exist"
|
26
31
|
[]
|
27
32
|
end
|
28
33
|
|
29
34
|
def fetch(uid)
|
30
|
-
imap.examine(
|
35
|
+
imap.examine(name)
|
31
36
|
message = imap.uid_fetch([uid.to_i], REQUESTED_ATTRIBUTES)[0][1]
|
32
37
|
message['RFC822'].force_encoding('utf-8') if RUBY_VERSION > '1.9'
|
33
38
|
message
|
34
39
|
rescue Net::IMAP::NoResponseError => e
|
35
|
-
Imap::Backup.logger.warn "Folder '#{
|
40
|
+
Imap::Backup.logger.warn "Folder '#{name}' does not exist"
|
36
41
|
nil
|
37
42
|
end
|
38
43
|
end
|
@@ -13,10 +13,14 @@ module Imap::Backup
|
|
13
13
|
|
14
14
|
def run
|
15
15
|
uids = folder.uids - serializer.uids
|
16
|
-
Imap::Backup.logger.debug "
|
16
|
+
Imap::Backup.logger.debug "[#{folder.name}] #{uids.count} new messages"
|
17
17
|
uids.each do |uid|
|
18
18
|
message = folder.fetch(uid)
|
19
|
-
|
19
|
+
if message.nil?
|
20
|
+
Imap::Backup.logger.debug "[#{folder.name}] #{uid} - not available - skipped"
|
21
|
+
next
|
22
|
+
end
|
23
|
+
Imap::Backup.logger.debug "[#{folder.name}] #{uid} - #{message["RFC822"].size} bytes"
|
20
24
|
serializer.save(uid, message)
|
21
25
|
end
|
22
26
|
end
|
@@ -29,7 +29,10 @@ module Imap::Backup
|
|
29
29
|
|
30
30
|
def save(uid, message)
|
31
31
|
uid = uid.to_s
|
32
|
-
|
32
|
+
if uids.include?(uid)
|
33
|
+
Imap::Backup.logger.debug "[#{folder}] message #{uid} already downloaded - skipping"
|
34
|
+
return
|
35
|
+
end
|
33
36
|
body = message['RFC822']
|
34
37
|
mboxrd_message = Email::Mboxrd::Message.new(body)
|
35
38
|
mbox = imap = nil
|
@@ -39,7 +42,7 @@ module Imap::Backup
|
|
39
42
|
mbox.write mboxrd_message.to_s
|
40
43
|
imap.write uid + "\n"
|
41
44
|
rescue => e
|
42
|
-
Imap::Backup.logger.warn "
|
45
|
+
Imap::Backup.logger.warn "[#{folder}] failed to save message #{uid}:\n#{body}. #{e}"
|
43
46
|
ensure
|
44
47
|
mbox.close if mbox
|
45
48
|
imap.close if imap
|
data/lib/imap/backup/version.rb
CHANGED
@@ -3,8 +3,8 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Imap::Backup::Downloader do
|
5
5
|
describe '#run' do
|
6
|
-
let(:message) { '
|
7
|
-
let(:folder) { double('Imap::Backup::Account::Folder', :fetch => message) }
|
6
|
+
let(:message) { {'RFC822' => 'blah'} }
|
7
|
+
let(:folder) { double('Imap::Backup::Account::Folder', :fetch => message, :name => 'folder') }
|
8
8
|
let(:folder_uids) { ['111', '222', '333'] }
|
9
9
|
let(:serializer) { double('Imap::Backup::Serializer', :save => nil) }
|
10
10
|
let(:serializer_uids) { ['222'] }
|
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: 1.0.
|
4
|
+
version: 1.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Yates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|