Class: MList::EmailServer::Imap
- Inherits:
-
Base
- Object
- Base
- MList::EmailServer::Imap
show all
- Defined in:
- lib/mlist/email_server/imap.rb
Instance Attribute Summary
Attributes inherited from Base
#settings
Instance Method Summary
collapse
Methods inherited from Base
#generate_message_id, #receive, #receiver
Constructor Details
#initialize(settings) ⇒ Imap
Returns a new instance of Imap.
7
8
9
|
# File 'lib/mlist/email_server/imap.rb', line 7
def initialize(settings)
super(settings)
end
|
Instance Method Details
#archive_message_id(id) ⇒ Object
24
25
26
27
|
# File 'lib/mlist/email_server/imap.rb', line 24
def archive_message_id(id)
@imap.copy(id, settings[:archive_folder])
@imap.store(id, '+FLAGS', [:Deleted])
end
|
#connect ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/mlist/email_server/imap.rb', line 29
def connect
@imap = Net::IMAP.new(
settings[:server],
settings[:port],
settings[:ssl]
)
@imap.login(settings[:username], settings[:password])
end
|
#deliver(tmail) ⇒ Object
11
12
13
|
# File 'lib/mlist/email_server/imap.rb', line 11
def deliver(tmail)
raise "Mail delivery is not presently supported by the Imap server. Please use the '#{MList::EmailServer::Default.name}' type."
end
|
#disconnect ⇒ Object
38
39
40
|
# File 'lib/mlist/email_server/imap.rb', line 38
def disconnect
@imap.disconnect if @imap && !@imap.disconnected?
end
|
#execute ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/mlist/email_server/imap.rb', line 15
def execute
begin
connect
process_folders
ensure
disconnect
end
end
|
#process_folder(folder) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/mlist/email_server/imap.rb', line 48
def process_folder(folder)
@imap.select(folder)
@imap.search(['NOT','DELETED']).each do |message_id|
process_message_id(message_id)
archive_message_id(message_id)
end
@imap.close
end
|
#process_folders ⇒ Object
42
43
44
45
46
|
# File 'lib/mlist/email_server/imap.rb', line 42
def process_folders
Array(settings[:source_folders]).each do |folder|
process_folder(folder)
end
end
|
#process_message(content) ⇒ Object
71
72
73
|
# File 'lib/mlist/email_server/imap.rb', line 71
def process_message(content)
receive(TMail::Mail.parse(content))
end
|
#process_message_id(id) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/mlist/email_server/imap.rb', line 57
def process_message_id(id)
if rfc822 = @imap.fetch(id, 'RFC822')
content = rfc822[0].attr['RFC822']
process_message(content)
elsif settings[:failure_folder]
begin
@imap.move(id, settings[:failure_folder])
rescue Net::IMAP::NoResponseError
@imap.create(settings[:failure_folder])
retry
end
end
end
|