Module: SearchMbox
- Defined in:
- lib/search_mbox.rb,
lib/search_mbox/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
Class Method Details
.delete_all ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/search_mbox.rb', line 37 def self.delete_all @imap.select('INBOX') @imap.search(['ALL']).each do |msg_id| @imap.store(msg_id, "+FLAGS", [:Deleted]) end @imap.expunge end |
.login(host, account, passwd) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/search_mbox.rb', line 6 def self.login(host, account, passwd) @subject_attr_name = 'BODY[HEADER.FIELDS (SUBJECT)]' @body_attr_name = 'BODY[TEXT]' @imap_port = 143 @imap_usessl = false begin @imap = Net::IMAP.new(host, @imap_port, @imap_usessl) @imap.login(account, passwd) rescue => e STDERR.puts "[ERROR] #{e}" exit 1 end end |
.logout ⇒ Object
45 46 47 |
# File 'lib/search_mbox.rb', line 45 def self.logout @imap.logout end |
.search ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/search_mbox.rb', line 20 def self.search rule = ['ALL'] if rule.nil? @mails = Array.new @imap.examine('INBOX') @imap.search(rule).each do |msg_id| @mail = Hash.new msg = @imap.fetch(msg_id, [@subject_attr_name, @body_attr_name]).first subject = msg.attr[@subject_attr_name].toutf8.strip body = msg.attr[@body_attr_name].toutf8.strip @mail[:msg_id] = msg_id @mail[:subject] = subject @mail[:body] = body @mails.push(@mail) end return @mails end |