Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ruby grep - searching an array for parts of a string
- class ExamineMail
- def initialize(user, domain, pass, box)
- @username = user
- @domain = domain
- @pass = pass
- @mailbox = box
- end
- def login()
- @imap = Net::IMAP.new("mail." + @domain)
- @imap.authenticate('LOGIN', @username + "@" + @domain, @pass)
- mailbox_array = @imap.list('','*').collect{ |mailbox| mailbox.name }
- #mailbox_array.any? { |w| @mailbox =~ /#{w}/ }
- mailbox_array.grep(/^@mailbox/)
- end
- end
- #Get the list of inboxes
- mailbox_array = imap.list('','*').collect{ |mailbox| mailbox.name }
- => ["INBOX", "INBOX.Trash", "INBOX.Sent", "INBOX.Sent Messages", "INBOX.Junk", "INBOX.Drafts", "INBOX.Deleted Messages", "INBOX.Apple Mail To Do"]
- #Search for mailboxes including "Sent"
- >> mailbox_array.grep(/^Sent/)
- => []
- #Search for "INBOX"
- >> mailbox_array.grep(/^INBOX/)
- => ["INBOX", "INBOX.Trash", "INBOX.Sent", "INBOX.Sent Messages", "INBOX.Junk", "INBOX.Drafts", "INBOX.Deleted Messages", "INBOX.Apple Mail To Do"]
- mailbox_array.grep(/Sent/)
Add Comment
Please, Sign In to add comment