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.



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 Attribute Details

#folderObject (readonly)

Returns the value of attribute folder.



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

def folder
  @folder
end

#serializerObject (readonly)

Returns the value of attribute serializer.



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

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.



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

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