mail_daemon 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mail_daemon.rb +5 -1
- data/lib/mail_daemon/imap/connection.rb +28 -4
- data/lib/mail_daemon/imap/watcher.rb +1 -0
- data/lib/mail_daemon/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ecde2f676af4e347e1b2bb397cb159f90c3ff32
|
4
|
+
data.tar.gz: 31cfa71d1badd6db7ede971d9dc8d81b9a2ad806
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df0bbced18789453cab87582caf191167b05f512078a2e415456f4d0026eec91fc65de4342a8cef125425e210f55230b9aca4976ce716a8cca6a3d8ab8032ce7
|
7
|
+
data.tar.gz: 72dd6f014d8b61917d575f572f95774db97651d1d9f9943fc33f9ae8275f4bc88b680bc849b2113592c3c902bf0abff127ca5855e8f3aa34fc3c63708ddd95e0
|
data/lib/mail_daemon.rb
CHANGED
@@ -18,7 +18,9 @@ module MailDaemon
|
|
18
18
|
def initialize(options)
|
19
19
|
setup_options(options)
|
20
20
|
default_option :connections, []
|
21
|
+
default_option :debug, false
|
21
22
|
|
23
|
+
puts "Setting up Signal Traps" if @options[:debug]
|
22
24
|
Signal.trap("INT") {
|
23
25
|
Thread.new {self.stop}.join
|
24
26
|
}
|
@@ -29,8 +31,10 @@ module MailDaemon
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def restart
|
34
|
+
puts "Restarting... " if @options[:debug]
|
32
35
|
self.stop if self.running?
|
33
36
|
Thread.new do
|
37
|
+
puts "Starting in new thread " if @options[:debug]
|
34
38
|
self.start(&@client_handler_block)
|
35
39
|
end
|
36
40
|
end
|
@@ -59,7 +63,7 @@ module MailDaemon
|
|
59
63
|
mailbox[:ssl_options] = {:verify_mode => OpenSSL::SSL::VERIFY_NONE} if mailbox[:ssl]
|
60
64
|
|
61
65
|
puts "Setting up watcher for #{mailbox[:username]}"
|
62
|
-
@watchers << MailDaemon::Imap::Watcher.new(mailbox)
|
66
|
+
@watchers << MailDaemon::Imap::Watcher.new(mailbox.merge(:debug => @options[:debug]))
|
63
67
|
end
|
64
68
|
@threads = []
|
65
69
|
@watchers.each do |watcher|
|
@@ -24,33 +24,50 @@ module MailDaemon
|
|
24
24
|
|
25
25
|
@notify_status_block = block
|
26
26
|
|
27
|
+
puts "initializing new imap connection for #{@options[:username]}:#{@options[:password]}@#{@options[:host]}:#{@options[:port]} " if @options[:debug]
|
28
|
+
|
27
29
|
set_status(INITIALIZING)
|
28
30
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def login
|
32
34
|
set_status(CONNECTING)
|
35
|
+
puts "Creating a new imap object" if @options[:debug]
|
36
|
+
puts "SSL Options;" if @options[:debug]
|
37
|
+
puts @options[:ssl_options] if @options[:debug]
|
38
|
+
puts "" if @options[:debug]
|
33
39
|
@imap = Net::IMAP.new(@options[:host], :port => @options[:port], :ssl => @options[:ssl_options])
|
34
40
|
capabilities = @imap.capability
|
41
|
+
puts "Imap server capabilities are as follows:" if @options[:debug]
|
42
|
+
puts capabilities if @options[:debug]
|
43
|
+
puts "" if @options[:debug]
|
35
44
|
@idle_available = capabilities.include?("IDLE")
|
36
45
|
|
46
|
+
if @idle_available
|
47
|
+
puts "Idle is available" if @options[:debug]
|
48
|
+
else
|
49
|
+
puts "Idle is not available" if @options[:debug]
|
50
|
+
end
|
51
|
+
|
37
52
|
set_status(LOGGING_ON)
|
38
|
-
@imap.login(@options[:username], @options[:password])
|
39
53
|
|
40
|
-
|
54
|
+
puts "Logging in..." if @options[:debug]
|
55
|
+
@imap.login(@options[:username], @options[:password])
|
41
56
|
|
42
57
|
@options[:folder] = "INBOX"
|
58
|
+
puts "Selecting folder '#{@options[:folder]}'" if @options[:debug]
|
43
59
|
@imap.select(@options[:folder])
|
44
60
|
|
45
61
|
# puts "starting tls"
|
46
62
|
# @imap.starttls({}, verify=false) if @options[:start_tls]
|
47
63
|
|
48
64
|
@idle_required = true
|
49
|
-
|
65
|
+
puts "Logged on." if @options[:debug]
|
50
66
|
set_status(LOGGED_ON)
|
51
67
|
end
|
52
68
|
|
53
69
|
def wait_for_messages(&block)
|
70
|
+
puts "Fetching awaiting messages" if @options[:debug]
|
54
71
|
fetch_message_ids.each do |message_id|
|
55
72
|
yield fetch_message(message_id)
|
56
73
|
end
|
@@ -59,12 +76,14 @@ module MailDaemon
|
|
59
76
|
|
60
77
|
if @idle_available
|
61
78
|
while(@idle_required)
|
62
|
-
|
79
|
+
puts "Starting Idle thread..." if @options[:debug]
|
80
|
+
puts "Will recycle in #{@options[:idle_recycle_time]} seconds" if @options[:debug]
|
63
81
|
recycle_thread = Thread.new(Time.now + @options[:idle_recycle_time]) do |end_time|
|
64
82
|
begin
|
65
83
|
while Time.now < end_time
|
66
84
|
sleep 1
|
67
85
|
end
|
86
|
+
puts "Recycling idle thread" if @options[:debug]
|
68
87
|
@imap.idle_done
|
69
88
|
rescue => e
|
70
89
|
puts e.message
|
@@ -85,13 +104,16 @@ module MailDaemon
|
|
85
104
|
end
|
86
105
|
recycle_thread.kill
|
87
106
|
@idleing = false
|
107
|
+
puts "Fetching messages" if @options[:debug]
|
88
108
|
fetch_message_ids.each do |message_id|
|
89
109
|
yield fetch_message(message_id)
|
90
110
|
end
|
91
111
|
end
|
92
112
|
else
|
113
|
+
puts "We're in polling mode..." if @options[:debug]
|
93
114
|
set_status(POLLING)
|
94
115
|
while(@idle_required)
|
116
|
+
puts "Checking for messages" if @options[:debug]
|
95
117
|
fetch_message_ids.each do |message_id|
|
96
118
|
yield fetch_message(message_id)
|
97
119
|
end
|
@@ -101,6 +123,7 @@ module MailDaemon
|
|
101
123
|
end
|
102
124
|
|
103
125
|
def logout
|
126
|
+
puts "Logging out" if @options[:debug]
|
104
127
|
@imap.idle_done if @idleing
|
105
128
|
set_status(LOGGING_OFF)
|
106
129
|
@imap.logout
|
@@ -108,6 +131,7 @@ module MailDaemon
|
|
108
131
|
end
|
109
132
|
|
110
133
|
def disconnect
|
134
|
+
puts "disconnecting" if @options[:debug]
|
111
135
|
@idle_required = false
|
112
136
|
logout unless @imap.disconnected?
|
113
137
|
|
data/lib/mail_daemon/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail_daemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- EmergeAdapt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|