-
Notifications
You must be signed in to change notification settings - Fork 0
/
Delete.rb
39 lines (34 loc) · 1.09 KB
/
Delete.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'net/imap'
require 'uri'
require 'cgi'
require 'time'
require_relative 'Utilities.rb'
include Utilities
class Delete
def delete_all_emails(rcpt)
imap = getImap(rcpt)
mailIds = imap.search(['ALL'])
mailIds.each do |message_id|
envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
puts "Deleting: #{envelope.subject}" if @@options.debug
imap.store(message_id, "+FLAGS", [:Deleted]) # must be marked as deleted to be expunged
end
imap.expunge
imap.disconnect()
end
def delete_all_emails_in_array(rcpt, to_be_deleted)
imap = getImap(rcpt)
mailIds = imap.search(['ALL'])
mailIds.each do |message_id|
envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
if to_be_deleted.include?(envelope.subject)
puts "#{envelope.subject} is being deleted and is in array"
imap.store(message_id, "+FLAGS", [:Deleted]) # must be marked as deleted to be expunged
else
puts "#{envelope.subject} is NOT in ARRAY and will NOT be deleted"
end
end
imap.expunge
imap.disconnect()
end
end