Class: Imap::Backup::LocalOnlyMessageDeleter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder, serializer) ⇒ LocalOnlyMessageDeleter

Returns a new instance of LocalOnlyMessageDeleter.


6
7
8
9
# File 'lib/imap/backup/local_only_message_deleter.rb', line 6

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

Instance Attribute Details

#folderObject (readonly)

Returns the value of attribute folder.


3
4
5
# File 'lib/imap/backup/local_only_message_deleter.rb', line 3

def folder
  @folder
end

#serializerObject (readonly)

Returns the value of attribute serializer.


4
5
6
# File 'lib/imap/backup/local_only_message_deleter.rb', line 4

def serializer
  @serializer
end

Instance Method Details

#runObject

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.


14
15
16
17
18
19
20
21
# File 'lib/imap/backup/local_only_message_deleter.rb', line 14

def run
  local_only_uids = serializer.uids - folder.uids
  return if local_only_uids.empty?

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