imap-backup 6.0.0 → 6.0.1
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/lib/imap/backup/account.rb +3 -1
- data/lib/imap/backup/serializer/imap.rb +27 -3
- data/lib/imap/backup/serializer/mbox.rb +18 -2
- data/lib/imap/backup/serializer/unused_name_finder.rb +5 -7
- data/lib/imap/backup/serializer.rb +45 -11
- data/lib/imap/backup/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6d4b9386097e77af34706992fb42b6ff9edd3a62a3cfb98e0b3363d864ee75dc
|
|
4
|
+
data.tar.gz: d72ec8493ea2436ccb033f2957d44236b71d3c607e25b15b0b755e93f011da10
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ab38ba548fa009c6f718f8da9b9fbb971751297eac03d2839e14f247c06d6858a155350291619090ef8165ffeb865674a19ef51c13dbf1220928106abfc79fa5
|
|
7
|
+
data.tar.gz: ad4e17a2b6b0b5a9ee1cc4737c324981069525a129018278514e51e8664008c71fc610539df58a2da590084bb7e3c46cd635fe1409ba0b53ad56bd241edfb9c8
|
data/lib/imap/backup/account.rb
CHANGED
|
@@ -18,12 +18,13 @@ module Imap::Backup
|
|
|
18
18
|
@server = options[:server]
|
|
19
19
|
@connection_options = options[:connection_options]
|
|
20
20
|
@multi_fetch_size = options[:multi_fetch_size]
|
|
21
|
+
@connection = nil
|
|
21
22
|
@changes = {}
|
|
22
23
|
@marked_for_deletion = false
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
def connection
|
|
26
|
-
Account::Connection.new(self)
|
|
27
|
+
@connection ||= Account::Connection.new(self)
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
def valid?
|
|
@@ -114,6 +115,7 @@ module Imap::Backup
|
|
|
114
115
|
changes[field] = {from: current, to: value} if value != current
|
|
115
116
|
end
|
|
116
117
|
|
|
118
|
+
@connection = nil
|
|
117
119
|
instance_variable_set(key, value)
|
|
118
120
|
end
|
|
119
121
|
end
|
|
@@ -12,6 +12,15 @@ module Imap::Backup
|
|
|
12
12
|
@loaded = false
|
|
13
13
|
@uid_validity = nil
|
|
14
14
|
@uids = nil
|
|
15
|
+
@version = nil
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def valid?
|
|
19
|
+
return false if !exist?
|
|
20
|
+
return false if version != CURRENT_VERSION
|
|
21
|
+
return false if !uid_validity
|
|
22
|
+
|
|
23
|
+
true
|
|
15
24
|
end
|
|
16
25
|
|
|
17
26
|
def append(uid)
|
|
@@ -19,8 +28,10 @@ module Imap::Backup
|
|
|
19
28
|
save
|
|
20
29
|
end
|
|
21
30
|
|
|
22
|
-
def
|
|
23
|
-
|
|
31
|
+
def delete
|
|
32
|
+
return if !exist?
|
|
33
|
+
|
|
34
|
+
File.unlink(pathname)
|
|
24
35
|
end
|
|
25
36
|
|
|
26
37
|
def include?(uid)
|
|
@@ -66,12 +77,21 @@ module Imap::Backup
|
|
|
66
77
|
save
|
|
67
78
|
end
|
|
68
79
|
|
|
80
|
+
def version
|
|
81
|
+
ensure_loaded
|
|
82
|
+
@version
|
|
83
|
+
end
|
|
84
|
+
|
|
69
85
|
private
|
|
70
86
|
|
|
71
87
|
def pathname
|
|
72
88
|
"#{folder_path}.imap"
|
|
73
89
|
end
|
|
74
90
|
|
|
91
|
+
def exist?
|
|
92
|
+
File.exist?(pathname)
|
|
93
|
+
end
|
|
94
|
+
|
|
75
95
|
def ensure_loaded
|
|
76
96
|
return if loaded
|
|
77
97
|
|
|
@@ -79,9 +99,11 @@ module Imap::Backup
|
|
|
79
99
|
if data
|
|
80
100
|
@uids = data[:uids].map(&:to_i)
|
|
81
101
|
@uid_validity = data[:uid_validity]
|
|
102
|
+
@version = data[:version]
|
|
82
103
|
else
|
|
83
104
|
@uids = []
|
|
84
105
|
@uid_validity = nil
|
|
106
|
+
@version = CURRENT_VERSION
|
|
85
107
|
end
|
|
86
108
|
@loaded = true
|
|
87
109
|
end
|
|
@@ -97,6 +119,8 @@ module Imap::Backup
|
|
|
97
119
|
return nil
|
|
98
120
|
end
|
|
99
121
|
|
|
122
|
+
return nil if !data.key?(:version)
|
|
123
|
+
return nil if !data.key?(:uid_validity)
|
|
100
124
|
return nil if !data.key?(:uids)
|
|
101
125
|
return nil if !data[:uids].is_a?(Array)
|
|
102
126
|
|
|
@@ -109,7 +133,7 @@ module Imap::Backup
|
|
|
109
133
|
raise "Cannot save metadata without a uid_validity" if !uid_validity
|
|
110
134
|
|
|
111
135
|
data = {
|
|
112
|
-
version:
|
|
136
|
+
version: @version,
|
|
113
137
|
uid_validity: @uid_validity,
|
|
114
138
|
uids: @uids
|
|
115
139
|
}
|
|
@@ -6,14 +6,20 @@ module Imap::Backup
|
|
|
6
6
|
@folder_path = folder_path
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
def valid?
|
|
10
|
+
exist?
|
|
11
|
+
end
|
|
12
|
+
|
|
9
13
|
def append(message)
|
|
10
14
|
File.open(pathname, "ab") do |file|
|
|
11
15
|
file.write message
|
|
12
16
|
end
|
|
13
17
|
end
|
|
14
18
|
|
|
15
|
-
def
|
|
16
|
-
|
|
19
|
+
def delete
|
|
20
|
+
return if !exist?
|
|
21
|
+
|
|
22
|
+
File.unlink(pathname)
|
|
17
23
|
end
|
|
18
24
|
|
|
19
25
|
def length
|
|
@@ -41,5 +47,15 @@ module Imap::Backup
|
|
|
41
47
|
f.truncate(length)
|
|
42
48
|
end
|
|
43
49
|
end
|
|
50
|
+
|
|
51
|
+
def touch
|
|
52
|
+
File.open(pathname, "a") {}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def exist?
|
|
58
|
+
File.exist?(pathname)
|
|
59
|
+
end
|
|
44
60
|
end
|
|
45
61
|
end
|
|
@@ -8,20 +8,18 @@ module Imap::Backup
|
|
|
8
8
|
|
|
9
9
|
def run
|
|
10
10
|
digit = 0
|
|
11
|
-
|
|
11
|
+
folder = nil
|
|
12
12
|
|
|
13
13
|
loop do
|
|
14
14
|
extra = digit.zero? ? "" : "-#{digit}"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
test_imap = Serializer::Imap.new(new_folder_path)
|
|
19
|
-
break if !test_mbox.exist? && !test_imap.exist?
|
|
15
|
+
folder = "#{serializer.folder}-#{serializer.uid_validity}#{extra}"
|
|
16
|
+
test = Serializer.new(serializer.path, folder)
|
|
17
|
+
break if !test.validate!
|
|
20
18
|
|
|
21
19
|
digit += 1
|
|
22
20
|
end
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
folder
|
|
25
23
|
end
|
|
26
24
|
end
|
|
27
25
|
end
|
|
@@ -28,10 +28,25 @@ module Imap::Backup
|
|
|
28
28
|
@folder = folder
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
# Returns true if there are existing, valid files
|
|
32
|
+
# false otherwise (in which case any existing files are deleted)
|
|
33
|
+
def validate!
|
|
34
|
+
return true if imap.valid? && mbox.valid?
|
|
35
|
+
|
|
36
|
+
imap.delete
|
|
37
|
+
@imap = nil
|
|
38
|
+
mbox.delete
|
|
39
|
+
@mbox = nil
|
|
40
|
+
|
|
41
|
+
false
|
|
42
|
+
end
|
|
43
|
+
|
|
31
44
|
def apply_uid_validity(value)
|
|
45
|
+
validate!
|
|
46
|
+
|
|
32
47
|
case
|
|
33
48
|
when uid_validity.nil?
|
|
34
|
-
|
|
49
|
+
internal_force_uid_validity(value)
|
|
35
50
|
nil
|
|
36
51
|
when uid_validity == value
|
|
37
52
|
# NOOP
|
|
@@ -42,39 +57,45 @@ module Imap::Backup
|
|
|
42
57
|
end
|
|
43
58
|
|
|
44
59
|
def force_uid_validity(value)
|
|
45
|
-
|
|
60
|
+
validate!
|
|
61
|
+
|
|
62
|
+
internal_force_uid_validity(value)
|
|
46
63
|
end
|
|
47
64
|
|
|
48
65
|
def append(uid, message)
|
|
66
|
+
validate!
|
|
67
|
+
|
|
49
68
|
appender = Serializer::Appender.new(folder: folder, imap: imap, mbox: mbox)
|
|
50
69
|
appender.run(uid: uid, message: message)
|
|
51
70
|
end
|
|
52
71
|
|
|
53
72
|
def load(uid_maybe_string)
|
|
73
|
+
validate!
|
|
74
|
+
|
|
54
75
|
uid = uid_maybe_string.to_i
|
|
55
76
|
message_index = imap.index(uid)
|
|
56
77
|
return nil if message_index.nil?
|
|
57
78
|
|
|
58
|
-
|
|
79
|
+
internal_load_nth(message_index)
|
|
59
80
|
end
|
|
60
81
|
|
|
61
82
|
def load_nth(index)
|
|
62
|
-
|
|
63
|
-
enumerator.each.with_index do |raw, i|
|
|
64
|
-
next if i != index
|
|
83
|
+
validate!
|
|
65
84
|
|
|
66
|
-
|
|
67
|
-
end
|
|
68
|
-
nil
|
|
85
|
+
internal_load_nth(index)
|
|
69
86
|
end
|
|
70
87
|
|
|
71
88
|
def each_message(required_uids, &block)
|
|
89
|
+
validate!
|
|
90
|
+
|
|
72
91
|
return enum_for(:each_message, required_uids) if !block
|
|
73
92
|
|
|
74
93
|
enumerator = Serializer::MessageEnumerator.new(imap: imap, mbox: mbox)
|
|
75
94
|
enumerator.run(uids: required_uids, &block)
|
|
76
95
|
end
|
|
77
96
|
|
|
97
|
+
private
|
|
98
|
+
|
|
78
99
|
def rename(new_name)
|
|
79
100
|
destination = self.class.folder_path_for(path: path, folder: new_name)
|
|
80
101
|
ensure_containing_directory(new_name)
|
|
@@ -82,7 +103,20 @@ module Imap::Backup
|
|
|
82
103
|
imap.rename destination
|
|
83
104
|
end
|
|
84
105
|
|
|
85
|
-
|
|
106
|
+
def internal_force_uid_validity(value)
|
|
107
|
+
imap.uid_validity = value
|
|
108
|
+
mbox.touch
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def internal_load_nth(index)
|
|
112
|
+
enumerator = Serializer::MboxEnumerator.new(mbox.pathname)
|
|
113
|
+
enumerator.each.with_index do |raw, i|
|
|
114
|
+
next if i != index
|
|
115
|
+
|
|
116
|
+
return Email::Mboxrd::Message.from_serialized(raw)
|
|
117
|
+
end
|
|
118
|
+
nil
|
|
119
|
+
end
|
|
86
120
|
|
|
87
121
|
def mbox
|
|
88
122
|
@mbox ||=
|
|
@@ -115,7 +149,7 @@ module Imap::Backup
|
|
|
115
149
|
# Clear memoization so we get empty data
|
|
116
150
|
@mbox = nil
|
|
117
151
|
@imap = nil
|
|
118
|
-
|
|
152
|
+
internal_force_uid_validity(value)
|
|
119
153
|
|
|
120
154
|
new_name
|
|
121
155
|
end
|
data/lib/imap/backup/version.rb
CHANGED
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: 6.0.
|
|
4
|
+
version: 6.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joe Yates
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-07-
|
|
11
|
+
date: 2022-07-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: highline
|