Class: Mail::IMAP

Inherits:
Object
  • Object
show all
Defined in:
lib/kns_email_endpoint/core_extensions/imap.rb

Instance Method Summary collapse

Instance Method Details

#delete_messages(mailbox, messages) ⇒ Object

add a delete message so that we can delete without calling find again



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kns_email_endpoint/core_extensions/imap.rb', line 11

def delete_messages(mailbox, messages)
  mailbox = Net::IMAP.encode_utf7(mailbox)
  messages.each do |message_hash|
    imap = message_hash[:connection]
    message_id = message_hash[:message_id]
    message = message_hash[:message]
    imap.uid_store(message_id, "+FLAGS", [Net::IMAP::DELETED]) if message.is_marked_for_delete?
  end
  start do |imap|
    begin
      imap.select(mailbox)
      imap.expunge
    rescue => e
      puts e.message
      puts e.backtrace.join("\n")
      raise e
    end
  end
  
end