Skip to content

Commit 35f617f

Browse files
committed
Use memoization to avoid costly operations. From: dcparker#82
1 parent f8c2651 commit 35f617f

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

lib/gmail/message.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,19 @@ def archive!
8989

9090
# Parsed MIME message object
9191
def message
92-
require 'mail'
93-
request,part = 'RFC822','RFC822'
94-
request,part = 'BODY.PEEK[]','BODY[]' if @gmail.peek
95-
_body = @gmail.in_mailbox(@mailbox) { @gmail.imap.uid_fetch(uid, request)[0].attr[part] }
96-
@message ||= Mail.new(_body)
92+
if @message
93+
@message
94+
else
95+
require 'mail'
96+
request,part = 'RFC822','RFC822'
97+
request,part = 'BODY.PEEK[]','BODY[]' if @gmail.peek
98+
_body = @gmail.in_mailbox(@mailbox) { @gmail.imap.uid_fetch(uid, request)[0].attr[part] }
99+
@message = Mail.new(_body)
100+
end
97101
end
98102

99103
private
100-
104+
101105
# Delegate all other methods to the Mail message
102106
def method_missing(*args, &block)
103107
if block_given?

0 commit comments

Comments
 (0)