Class: Imap::Backup::LocalOnlyMessageDeleter

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/local_only_message_deleter.rb

Overview

Deletes locally backed-up emails that are no longer on the server

Instance Method Summary collapse

Constructor Details

#initialize(folder, serializer) ⇒ LocalOnlyMessageDeleter

Returns a new instance of LocalOnlyMessageDeleter.



8
9
10
11
# File 'lib/imap/backup/local_only_message_deleter.rb', line 8

def initialize(folder, serializer)
  @folder = folder
  @serializer = serializer
end

Instance Method Details

#runvoid

This method returns an undefined value.

TODO: this method is very slow as it copies all messages. A quicker method would only remove UIDs from the .imap file, but that would require a garbage collection later.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/imap/backup/local_only_message_deleter.rb', line 17

def run
  local_only_uids = serializer.uids - folder.uids
  if local_only_uids.empty?
    Logger.logger.debug "There are no 'local-only' messages to delete"
    return
  end

  Logger.logger.info "Deleting messages only present locally"
  Logger.logger.debug "Messages to be deleted: #{local_only_uids.inspect}"

  serializer.filter do |message|
    !local_only_uids.include?(message.uid)
  end
end