Guest User

Untitled

a guest
Mar 8th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3.  
  4. require 'net/imap'
  5. require 'date'
  6. require 'rubygems'
  7. require 'active_support/core_ext/array/grouping'
  8.  
  9. include ActiveSupport::CoreExtensions::Array::Grouping
  10.  
  11. mailbox = "Inbox/Cron"
  12. host = ''
  13. port = 143
  14.  
  15. username = ''
  16. password = ''
  17.  
  18. conn = Net::IMAP.new(host, port)
  19. conn.login(username, password)
  20. conn.select(mailbox)
  21.  
  22. date = (Date.today - 10).strftime("%e-%b-%Y")
  23. msg_ids = conn.search(["SUBJECT", "Cron", "SINCE", date ])
  24. msg_ids.reverse!
  25.  
  26. puts "Found #{msg_ids.length} messages in #{mailbox} since #{date}"
  27. puts "First subject line: #{conn.fetch(msg_ids.first, "BODY[HEADER.FIELDS (SUBJECT)]")}"
  28.  
  29. flags = [:Seen, :Deleted]
  30.  
  31. msg_ids.in_groups_of(200) do |msg_group|
  32. conn.store(msg_group.compact, "+FLAGS", flags)
  33. conn.expunge
  34. end
  35.  
  36. conn.expunge
  37. conn.logout
Add Comment
Please, Sign In to add comment