Class: Gmail::Message
Instance Method Summary
collapse
Constructor Details
#initialize(gmail, mailbox, uid) ⇒ Message
5
6
7
8
9
|
# File 'lib/gmail/message.rb', line 5
def initialize(gmail, mailbox, uid)
@gmail = gmail
@mailbox = mailbox
@uid = uid
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
Delegate all other methods to the Mail message
104
105
106
107
108
109
110
|
# File 'lib/gmail/message.rb', line 104
def method_missing(*args, &block)
if block_given?
message.send(*args, &block)
else
message.send(*args)
end
end
|
Instance Method Details
88
89
90
|
# File 'lib/gmail/message.rb', line 88
def archive!
move_to_special_folder(:All)
end
|
47
48
49
50
|
# File 'lib/gmail/message.rb', line 47
def delete!
@mailbox.messages.delete(uid)
flag(:Deleted)
end
|
#flag(flg) ⇒ Object
21
22
23
24
25
|
# File 'lib/gmail/message.rb', line 21
def flag(flg)
@gmail.in_mailbox(@mailbox) do
@gmail.imap.uid_store(uid, "+FLAGS", [flg])
end ? true : false
end
|
11
12
13
|
# File 'lib/gmail/message.rb', line 11
def inspect
"<#Message:#{object_id} mailbox=#{@mailbox.name}#{' uid='[email protected]_s if @uid}#{' message_id='+@message_id.to_s if @message_id}>"
end
|
#label(name) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/gmail/message.rb', line 52
def label(name)
@gmail.in_mailbox(@mailbox) do
begin
@gmail.imap.uid_copy(uid, name)
rescue Net::IMAP::NoResponseError
raise Gmail::NoLabel, "No label `#{name}' exists!"
end
end
end
|
#label!(name) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/gmail/message.rb', line 62
def label!(name)
@gmail.in_mailbox(@mailbox) do
begin
@gmail.imap.uid_copy(uid, name)
rescue Net::IMAP::NoResponseError
@gmail.create_label(name)
retry
end
end
end
|
#mark(flag) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/gmail/message.rb', line 34
def mark(flag)
case flag
when :read
flag(:Seen)
when :unread
unflag(:Seen)
when :deleted
flag(:Deleted)
when :spam
move_to_special_folder(:Junk)
end ? true : false
end
|
Parsed MIME message object
93
94
95
96
97
98
99
|
# File 'lib/gmail/message.rb', line 93
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)
end
|
#move_to(name) ⇒ Object
We’re not sure of any ‘labels’ except the ‘mailbox’ we’re in at the moment. Research whether we can find flags that tell which other labels this email is a part of. def remove_label(name) end
79
80
81
|
# File 'lib/gmail/message.rb', line 79
def move_to(name)
label(name) && delete!
end
|
#move_to_special_folder(attribute) ⇒ Object
83
84
85
86
|
# File 'lib/gmail/message.rb', line 83
def move_to_special_folder(attribute)
name = @gmail.find_label_by_attribute(attribute).name
move_to(name)
end
|
16
17
18
|
# File 'lib/gmail/message.rb', line 16
def uid
@uid ||= @gmail.imap.uid_search(['HEADER', 'Message-ID', message_id])[0]
end
|
#unflag(flg) ⇒ Object
27
28
29
30
31
|
# File 'lib/gmail/message.rb', line 27
def unflag(flg)
@gmail.in_mailbox(@mailbox) do
@gmail.imap.uid_store(uid, "-FLAGS", [flg])
end ? true : false
end
|