lib/imap/backup/account/backup.rb in imap-backup-11.0.0 vs lib/imap/backup/account/backup.rb in imap-backup-11.0.1
- old
+ new
@@ -25,69 +25,68 @@
# start the connection so we get logging messages in the right order
account.client
Account::FolderEnsurer.new(account: account).run
Account::LocalOnlyFolderDeleter.new(account: account).run if account.mirror_mode
- each_folder do |folder, serializer|
- begin
- next if !folder.exist?
- rescue Encoding::UndefinedConversionError
- message = "Skipping backup for '#{folder.name}' " \
- "as it is not UTF-7 encoded correctly"
- Logger.logger.info message
- next
- end
+ backup_folders = Account::BackupFolders.new(
+ client: account.client, account: account
+ )
+ if backup_folders.none?
+ Logger.logger.warn "Account #{account.username}: No folders found to backup"
+ return
+ end
+ backup_folders.each do |folder|
+ backup_folder folder
+ end
+ end
- Logger.logger.debug "[#{folder.name}] running backup"
+ private
- serializer.apply_uid_validity(folder.uid_validity)
+ def backup_folder(folder)
+ serializer = Serializer.new(account.local_path, folder.name)
+ begin
+ return if !folder.exist?
+ rescue Encoding::UndefinedConversionError
+ message = "Skipping backup for '#{folder.name}' " \
+ "as it is not UTF-7 encoded correctly"
+ Logger.logger.info message
+ return
+ end
- download_serializer =
- case account.download_strategy
- when "direct"
- serializer
- when "delay_metadata"
- Serializer::DelayedMetadataSerializer.new(serializer: serializer)
- else
- raise "Unknown download strategy '#{account.download_strategy}'"
- end
+ Logger.logger.debug "[#{folder.name}] running backup"
- downloader = Downloader.new(
- folder,
- download_serializer,
- multi_fetch_size: account.multi_fetch_size,
- reset_seen_flags_after_fetch: account.reset_seen_flags_after_fetch
- )
- # rubocop:disable Lint/RescueException
- download_serializer.transaction do
- downloader.run
- rescue Exception => e
- message = <<~ERROR
- #{self.class} error #{e}
- #{e.backtrace.join("\n")}
- ERROR
- Logger.logger.error message
- download_serializer.rollback
- raise e
+ serializer.apply_uid_validity(folder.uid_validity)
+
+ download_serializer =
+ case account.download_strategy
+ when "direct"
+ serializer
+ when "delay_metadata"
+ Serializer::DelayedMetadataSerializer.new(serializer: serializer)
+ else
+ raise "Unknown download strategy '#{account.download_strategy}'"
end
- # rubocop:enable Lint/RescueException
- if account.mirror_mode
- Logger.logger.info "Mirror mode - Deleting messages only present locally"
- LocalOnlyMessageDeleter.new(folder, serializer).run
- end
- FlagRefresher.new(folder, serializer).run if account.mirror_mode || refresh
- end
- end
- private
-
- def each_folder
- backup_folders = Account::BackupFolders.new(
- client: account.client, account: account
+ downloader = Downloader.new(
+ folder,
+ download_serializer,
+ multi_fetch_size: account.multi_fetch_size,
+ reset_seen_flags_after_fetch: account.reset_seen_flags_after_fetch
)
- backup_folders.each do |folder|
- serializer = Serializer.new(account.local_path, folder.name)
- yield folder, serializer
+ download_serializer.transaction do
+ downloader.run
+ rescue StandardError => e
+ message = <<~ERROR
+ #{self.class} error #{e}
+ #{e.backtrace.join("\n")}
+ ERROR
+ Logger.logger.error message
+ raise e
end
+ if account.mirror_mode
+ Logger.logger.info "Mirror mode - Deleting messages only present locally"
+ LocalOnlyMessageDeleter.new(folder, serializer).run
+ end
+ FlagRefresher.new(folder, serializer).run if account.mirror_mode || refresh
end
end
end