Skip to content

Commit 61079c6

Browse files
committed
Merge branch 'feature/extend-logging-in-thunderbird-export'
2 parents 209f289 + 8cd28eb commit 61079c6

27 files changed

+109
-42
lines changed

.rubocop.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ RSpec/NoExpectationExample:
261261
Enabled: true
262262
RSpec/NotToNot:
263263
Enabled: false
264+
RSpec/Output:
265+
Enabled: true
266+
Exclude:
267+
- spec/performance/**/*
264268
RSpec/PendingWithoutReason:
265269
Enabled: true
266270
RSpec/PredicateMatcher:
@@ -342,6 +346,8 @@ Style/DoubleNegation:
342346
Enabled: false
343347
Style/EmptyCaseCondition:
344348
Enabled: false
349+
Style/EmptyClassDefinition:
350+
Enabled: true
345351
Style/EmptyHeredoc:
346352
Enabled: true
347353
Style/EmptyMethod:
@@ -424,6 +430,8 @@ Style/NegatedIf:
424430
Enabled: false
425431
Style/NegatedIfElseCondition:
426432
Enabled: true
433+
Style/NegativeArrayIndex:
434+
Enabled: true
427435
Style/NestedFileDirname:
428436
Enabled: true
429437
Style/NilLambda: # TODO
@@ -490,6 +498,8 @@ Style/RedundantStringEscape:
490498
Enabled: true
491499
Style/ReturnNilInPredicateMethodDefinition:
492500
Enabled: true
501+
Style/ReverseFind:
502+
Enabled: true
493503
Style/SafeNavigationChainLength:
494504
Enabled: true
495505
Style/SelectByRegexp:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ 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+
## 16.4.2 - 2026-02-08
9+
10+
### Changed
11+
12+
* Added more logging to the Thunderbird export utility.
13+
814
## 16.4.1 - 2026-01-06
915

1016
### Changed

imap-backup.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Gem::Specification.new do |gem|
3030
gem.add_dependency "rake"
3131
gem.add_dependency "sys-proctable"
3232
gem.add_dependency "thor", "~> 1.1"
33-
gem.add_dependency "thunderbird", "0.3.0"
33+
gem.add_dependency "thunderbird", "~> 0.6.0"
3434

3535
gem.metadata = {
3636
"rubygems_mfa_required" => "true"

lib/imap/backup/cli/utils.rb

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,41 @@ def ignore_folder_history(folder, serializer)
130130
end
131131

132132
def thunderbird_profile(name = nil)
133+
Logger.logger.info("[CLI::Utils] Fetching Thunderbird profile")
133134
profiles = ::Thunderbird::Profiles.new
135+
Logger.logger.debug("[CLI::Utils] Found #{profiles.installs.count} Thunderbird install(s)")
134136
if name
137+
Logger.logger.debug("[CLI::Utils] Using profile name '#{name}'")
135138
profiles.profile(name)
136139
else
137-
if profiles.installs.count > 1
138-
raise <<~MESSAGE
139-
Thunderbird has multiple installs, so no default profile exists.
140-
Please supply a profile name
141-
MESSAGE
142-
end
143-
144-
profiles.installs[0].default
140+
choose_default_profile(profiles)
141+
end
142+
end
143+
144+
def choose_default_profile(profiles)
145+
Logger.logger.debug("[CLI::Utils] No profile name supplied, so looking for default profile")
146+
case profiles.installs.count
147+
when 0
148+
raise "No Thunderbird installs found, so no default profile exists"
149+
when 1
150+
install = profiles.installs.first
151+
Logger.logger.debug(
152+
"[CLI::Utils] Only one Thunderbird install found '#{install.title}', " \
153+
"so using its default profile"
154+
)
155+
156+
profile = install.default_profile
157+
raise "Thunderbird install '#{install.title}' does not have a default profile" if !profile
158+
159+
Logger.logger.debug(
160+
"[CLI::Utils] Default profile '#{profile.title}' has path '#{profile.root}'"
161+
)
162+
profile
163+
else
164+
raise <<~MESSAGE
165+
Thunderbird has multiple installs, so no default profile exists.
166+
Please supply a profile name
167+
MESSAGE
145168
end
146169
end
147170
end

lib/imap/backup/thunderbird/mailbox_exporter.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def initialize(email, serializer, profile, force: false)
2323
# in the format expected by Thunderbird
2424
# @return [void]
2525
def run
26+
debug "Starting export of '#{email}' to Thunderbird profile '#{profile.title}'"
2627
if !profile_set_up
2728
error "The Thunderbird profile '#{profile.title}' " \
2829
"has not been set up. " \
@@ -59,6 +60,7 @@ def run
5960
attr_reader :force
6061

6162
def profile_set_up
63+
debug "Checking for local folders path '#{profile.local_folders_path}'"
6264
File.exist?(profile.local_folders_path)
6365
end
6466

@@ -109,6 +111,10 @@ def local_folder
109111
end
110112
end
111113

114+
def debug(message)
115+
Logger.logger.debug("[Thunderbird::MailboxExporter] #{message}")
116+
end
117+
112118
def error(message)
113119
Logger.logger.error("[Thunderbird::MailboxExporter] #{message}")
114120
end

lib/imap/backup/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Imap::Backup
66
# @private
77
MINOR = 4
88
# @private
9-
REVISION = 1
9+
REVISION = 2
1010
# @private
1111
PRE = nil
1212
# The application version

spec/features/backup_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
let(:config_options) { {accounts: [account_config]} }
2323
let(:write_config) { create_config(**config_options) }
2424

25+
let!(:logger) { stub_logger }
2526
let!(:pre) { test_server.warn_about_non_default_folders }
2627
let!(:setup) do
2728
test_server.create_folder folder

spec/features/support/20_test_email_server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def warn_about_non_default_folders
156156
actual = folders.map(&:name).sort
157157
extra = actual - expected
158158
extra.each do |name|
159-
puts "Unexpected folder '#{name}' found - deleting"
159+
warn "Unexpected folder '#{name}' found - deleting"
160160
delete_folder name
161161
end
162162
end

spec/spec_helper.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@
77

88
support_glob = File.join(__dir__, "support", "**", "*.rb")
99
Dir[support_glob].each { |f| require f }
10-
11-
silence_logging

spec/support/silence_logging.rb

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,29 @@
33

44
require "imap/backup/logger"
55

6-
def silence_logging
7-
RSpec.configure do |config|
8-
config.before do
9-
Imap::Backup::Logger.logger.level = Logger::Severity::UNKNOWN
10-
Net::IMAP.debug = false
11-
end
6+
# This function can be used in specs/examples do logging and alter the logger configuration
7+
def stub_logger
8+
logger = instance_double(
9+
Logger,
10+
debug: nil,
11+
error: nil,
12+
info: nil,
13+
"level=": nil
14+
)
15+
allow(Imap::Backup::Logger).to receive(:logger) { logger }
16+
logger
17+
end
18+
19+
# Pass the `:silence_logging` option to `RSpec.describe`
20+
# for specs that do logging, but do not alter logging setup
21+
RSpec.configure do |config|
22+
config.around(:each, :silence_logging) do |example|
23+
previous_logger_level = Imap::Backup::Logger.logger.level
24+
previous_net_imap_debug = Net::IMAP.debug
25+
Imap::Backup::Logger.logger.level = Logger::Severity::UNKNOWN
26+
Net::IMAP.debug = false
27+
example.run
28+
Imap::Backup::Logger.logger.level = previous_logger_level
29+
Net::IMAP.debug = previous_net_imap_debug
1230
end
1331
end

0 commit comments

Comments
 (0)