lib/imap/backup/serializer/appender.rb in imap-backup-11.0.0.rc1 vs lib/imap/backup/serializer/appender.rb in imap-backup-11.0.0
- old
+ new
@@ -12,11 +12,11 @@
@folder = folder
@imap = imap
@mbox = mbox
end
- def single(uid:, message:, flags:)
+ def append(uid:, message:, flags:)
raise "Can't add messages without uid_validity" if !imap.uid_validity
uid = uid.to_i
existing = imap.get(uid)
if existing
@@ -25,44 +25,41 @@
)
return
end
rollback_on_error do
- do_append uid, message, flags
+ serialized = to_serialized(message)
+ mbox.append serialized
+ imap.append uid, serialized.length, flags: flags
rescue StandardError => e
raise <<-ERROR.gsub(/^\s*/m, "")
- [#{folder}] failed to append message #{uid}:
- #{message}. #{e}:
+ [#{folder}] failed to append message #{uid}: #{message}.
+ #{e}:
#{e.backtrace.join("\n")}"
ERROR
end
end
- def multi(appends)
- rollback_on_error do
- appends.each do |a|
- do_append a[:uid], a[:message], a[:flags]
- end
- end
- end
-
private
- def do_append(uid, message, flags)
+ def to_serialized(message)
mboxrd_message = Email::Mboxrd::Message.new(message)
- serialized = mboxrd_message.to_serialized
- mbox.append serialized
- imap.append uid, serialized.length, flags: flags
+ mboxrd_message.to_serialized
end
def rollback_on_error(&block)
imap.transaction do
mbox.transaction do
block.call
rescue StandardError => e
Logger.logger.error e
imap.rollback
mbox.rollback
+ rescue SignalException => e
+ Logger.logger.error e
+ imap.rollback
+ mbox.rollback
+ raise
end
end
end
end
end