Skip to content

Commit

Permalink
Do not fetch mail message for every call to it
Browse files Browse the repository at this point in the history
  • Loading branch information
jraines committed Mar 12, 2014
1 parent 2ae0827 commit d9e218b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/gmail/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,19 @@ def archive!

# Parsed MIME message object
def message
require 'mail'
request,part = 'RFC822','RFC822'
request,part = 'BODY.PEEK[]','BODY[]' if @gmail.peek
_body = @gmail.in_mailbox(@mailbox) { @gmail.imap.uid_fetch(uid, request)[0].attr[part] }
@message ||= Mail.new(_body)
if @message
return @message
else
require 'mail'
request,part = 'RFC822','RFC822'
request,part = 'BODY.PEEK[]','BODY[]' if @gmail.peek
_body = @gmail.in_mailbox(@mailbox) { @gmail.imap.uid_fetch(uid, request)[0].attr[part] }
@message = Mail.new(_body)
end
end

private

# Delegate all other methods to the Mail message
def method_missing(*args, &block)
if block_given?
Expand Down

0 comments on commit d9e218b

Please sign in to comment.