Permalink
Browse files

caching subject

  • Loading branch information...
1 parent d035d62 commit e3f565ec6d94f1fc8737068824a1dade1c059c28 Chris Duesing committed Feb 21, 2012
Showing with 23 additions and 2 deletions.
  1. +8 −2 lib/gmail/mailbox.rb
  2. +15 −0 lib/gmail/message.rb
View
@@ -23,10 +23,16 @@ def to_s
name
end
+ def uid_search(key_or_opts = :all, opts={})
+ @gmail.imap.uid_search(search(key_or_opts, opts)).collect { |uid| messages[uid] ||= Message.new(@gmail, self, uid) }
+ end
+
+ alias :emails :uid_search
+
# Method: emails
# Args: [ :all | :unread | :read ]
# Opts: {:since => Date.new}
- def emails(key_or_opts = :all, opts={})
+ def search(key_or_opts = :all, opts={})
if key_or_opts.is_a?(Hash) && opts.empty?
search = ['ALL']
opts = key_or_opts
@@ -55,7 +61,7 @@ def emails(key_or_opts = :all, opts={})
# puts "Gathering #{(aliases[key] || key).inspect} messages for mailbox '#{name}'..."
@gmail.in_mailbox(self) do
puts "search: #{search} ****************************************************************************************************"
- @gmail.imap.uid_search(search).collect { |uid| messages[uid] ||= Message.new(@gmail, self, uid) }
+ return search
end
end
View
@@ -82,6 +82,21 @@ def archive!
move_to('[Gmail]/All Mail')
end
+ def subject
+ require 'mail'
+ if !@message
+ request= '(body[header.fields (subject)])'
+ _body = @gmail.in_mailbox(@mailbox) { @gmail.imap.fetch(@uid, request)[0].attr[request] }
+ @message = Mail.new(_body)
+ elsif !@message.subject
+ request= '(body[header.fields (subject)])'
+ _body = @gmail.in_mailbox(@mailbox) { @gmail.imap.fetch(@uid, request)[0].attr[request] }
+ tmp = Mail.new(_body)
+ @message.subject = tmp.subject
+ end
+ @message.subject
+ end
+
private
# Parsed MIME message object

0 comments on commit e3f565e

Please sign in to comment.