class Gmail::Message
Attributes
uid[R]
Public Class Methods
new(mailbox, uid)
click to toggle source
# File lib/gmail/message.rb, line 10 def initialize(mailbox, uid) @uid = uid @mailbox = mailbox @gmail = mailbox.instance_variable_get("@gmail") if mailbox end
Public Instance Methods
archive!()
click to toggle source
Archive this message.
# File lib/gmail/message.rb, line 78 def archive! move_to('[Gmail]/All Mail') end
delete!()
click to toggle source
Move to trash / bin.
# File lib/gmail/message.rb, line 68 def delete! @mailbox.messages.delete(uid) flag(:deleted) # For some, it's called "Trash", for others, it's called "Bin". Support both. trash = @gmail.labels.exist?('[Gmail]/Bin') ? '[Gmail]/Bin' : '[Gmail]/Trash' move_to(trash) unless %w[[Gmail]/Spam [Gmail]/Bin [Gmail]/Trash].include?(@mailbox.name) end
envelope()
click to toggle source
# File lib/gmail/message.rb, line 150 def envelope @envelope ||= @gmail.mailbox(@mailbox.name) { @gmail.conn.uid_fetch(uid, "ENVELOPE")[0].attr["ENVELOPE"] } end
flag(name)
click to toggle source
Mark message with given flag.
# File lib/gmail/message.rb, line 21 def flag(name) !!@gmail.mailbox(@mailbox.name) { @gmail.conn.uid_store(uid, "+FLAGS", [name]) } end
inspect()
click to toggle source
# File lib/gmail/message.rb, line 125 def inspect "#<Gmail::Message#{'0x%04x' % (object_id << 1)} mailbox=#{@mailbox.external_name}#{' uid='+@uid.to_s if @uid}#{' message_id='+@message_id.to_s if @message_id}>" end
label(name, from=nil)
click to toggle source
Mark this message with given label. When given label doesn't exist then it will raise NoLabelError
.
See also Gmail::Message#label!
.
# File lib/gmail/message.rb, line 100 def label(name, from=nil) @gmail.mailbox(Net::IMAP.encode_utf7(from || @mailbox.external_name)) { @gmail.conn.uid_copy(uid, Net::IMAP.encode_utf7(name)) } rescue Net::IMAP::NoResponseError raise NoLabelError, "Label '#{name}' doesn't exist!" end
label!(name, from=nil)
click to toggle source
Mark this message with given label. When given label doesn't exist then it will be automaticaly created.
See also Gmail::Message#label
.
# File lib/gmail/message.rb, line 110 def label!(name, from=nil) label(name, from) rescue NoLabelError @gmail.labels.add(Net::IMAP.encode_utf7(name)) label(name, from) end
Also aliased as: add_label, add_label!
mark(flag)
click to toggle source
Do commonly used operations on message.
# File lib/gmail/message.rb, line 31 def mark(flag) case flag when :read then read! when :unread then unread! when :deleted then delete! when :spam then spam! else flag(flag) end end
message()
click to toggle source
# File lib/gmail/message.rb, line 156 def message @message ||= Mail.new(@gmail.mailbox(@mailbox.name) { @gmail.conn.uid_fetch(uid, "RFC822")[0].attr["RFC822"] # RFC822 }) end
Also aliased as: raw_message
method_missing(meth, *args, &block)
click to toggle source
Calls superclass method
# File lib/gmail/message.rb, line 129 def method_missing(meth, *args, &block) # Delegate rest directly to the message. if envelope.respond_to?(meth) envelope.send(meth, *args, &block) elsif message.respond_to?(meth) message.send(meth, *args, &block) else super(meth, *args, &block) end end
move_to(name, from=nil)
click to toggle source
Move to given box and delete from others.
# File lib/gmail/message.rb, line 83 def move_to(name, from=nil) label(name, from) delete! if !%w[[Gmail]/Bin [Gmail]/Trash].include?(name) end
Also aliased as: move
move_to!(name, from=nil)
click to toggle source
Move message to given and delete from others. When given mailbox doesn't exist then it will be automaticaly created.
# File lib/gmail/message.rb, line 91 def move_to!(name, from=nil) label!(name, from) && delete! end
Also aliased as: move!
read!()
click to toggle source
Mark as read.
# File lib/gmail/message.rb, line 48 def read! flag(:Seen) end
remove_label!(name)
click to toggle source
Remove given label from this message.
# File lib/gmail/message.rb, line 120 def remove_label!(name) move_to('[Gmail]/All Mail', name) end
Also aliased as: delete_label!
respond_to?(meth, *args, &block)
click to toggle source
Calls superclass method
# File lib/gmail/message.rb, line 140 def respond_to?(meth, *args, &block) if envelope.respond_to?(meth) return true elsif message.respond_to?(meth) return true else super(meth, *args, &block) end end
spam!()
click to toggle source
Mark this message as a spam.
# File lib/gmail/message.rb, line 43 def spam! move_to('[Gmail]/Spam') end
star!()
click to toggle source
Mark message with star.
# File lib/gmail/message.rb, line 58 def star! flag('[Gmail]/Starred') end
unflag(name)
click to toggle source
Unmark message.
# File lib/gmail/message.rb, line 26 def unflag(name) !!@gmail.mailbox(@mailbox.name) { @gmail.conn.uid_store(uid, "-FLAGS", [name]) } end
unread!()
click to toggle source
Mark as unread.
# File lib/gmail/message.rb, line 53 def unread! unflag(:Seen) end
unstar!()
click to toggle source
Remove message from list of starred.
# File lib/gmail/message.rb, line 63 def unstar! unflag('[Gmail]/Starred') end