Skip to content

Commit fa59142

Browse files
committed
Handle legacy configuration format better
1 parent 6b0d6fd commit fa59142

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## 14.4.0 - 2023-11-15
9+
10+
### Changed
11+
12+
* Always check whether the configuration file has folders
13+
listed as an Array of Hashes, and convert to the newer,
14+
simpler, structure. See #184
15+
816
## 14.3.0 - 2023-11-03
917

1018
### Added

lib/imap/backup/configuration.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,30 @@ def data
122122
else
123123
DEFAULT_STRATEGY
124124
end
125-
if data[:version] == VERSION_2_1
126-
dehashify_folders(data)
127-
else
128-
data
129-
end
125+
dehashify_folders(data)
130126
else
131127
{accounts: [], download_strategy: DEFAULT_STRATEGY}
132128
end
133129
end
134130

135131
def dehashify_folders(data)
136-
data[:version] = VERSION
137-
138132
data[:accounts].each do |account|
139133
next if !account.key?(:folders)
140134

141135
folders = account[:folders]
142-
names = folders.map { |f| f[:name] }
136+
names = folders.map do |f|
137+
case f
138+
when Hash
139+
f[:name]
140+
else
141+
f
142+
end
143+
end
143144
account[:folders] = names
144145
end
145146

147+
data[:version] = VERSION
148+
146149
data
147150
end
148151

lib/imap/backup/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Imap; end
22

33
module Imap::Backup
44
MAJOR = 14
5-
MINOR = 3
5+
MINOR = 4
66
REVISION = 0
77
PRE = nil
88
VERSION = [MAJOR, MINOR, REVISION, PRE].compact.map(&:to_s).join(".")

spec/unit/configuration_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ module Imap::Backup
188188
end
189189
end
190190

191-
context "when a version 2.1 file is present" do
191+
context "when a folders are stored as Hashes" do
192192
let(:file) { instance_double(File, write: nil) }
193193
let(:configuration) do
194-
{version: "2.1", accounts: [{username: "account", folders: [{name: "foo"}]}]}.to_json
194+
{accounts: [{username: "account", folders: [{name: "foo"}]}]}.to_json
195195
end
196196

197197
before do

0 commit comments

Comments
 (0)