mail_daemon 0.0.15 → 1.0.0
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 +5 -5
- data/.rspec +3 -0
- data/.ruby-version +1 -1
- data/lib/mail_daemon/email_body_parser.rb +2 -2
- data/lib/mail_daemon/helpers.rb +2 -1
- data/lib/mail_daemon/imap/connection.rb +4 -2
- data/lib/mail_daemon/imap/watcher.rb +1 -0
- data/lib/mail_daemon/imap_watcher.rb +12 -9
- data/lib/mail_daemon/version.rb +1 -1
- data/lib/mail_daemon.rb +4 -2
- data/mail_daemon.gemspec +9 -2
- data/spec/examples.txt +147 -0
- data/spec/mail_daemon/email_body_parser_spec.rb +114 -0
- data/spec/mail_daemon/email_handler_spec.rb +309 -0
- data/spec/mail_daemon/encryption_spec.rb +161 -0
- data/spec/mail_daemon/handler_spec.rb +233 -0
- data/spec/mail_daemon/helpers_spec.rb +144 -0
- data/spec/mail_daemon/imap/connection_spec.rb +306 -0
- data/spec/mail_daemon/imap/statuses_spec.rb +47 -0
- data/spec/mail_daemon/imap/watcher_spec.rb +128 -0
- data/spec/mail_daemon/imap_watcher_spec.rb +205 -0
- data/spec/mail_daemon/version_spec.rb +15 -0
- data/spec/spec_helper.rb +36 -0
- metadata +142 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5dc49957f5e88b2e212563de19073c524e516a99e7e5717c2aaeaf23b77c6485
|
|
4
|
+
data.tar.gz: 59ebc8efd0fa48cf99502c237d78f48f2105ef5e747bd978909cf3318a65618b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 68e487850c8a5d3eac0922110a16fdd6a24b7671272198e11810bb95708fa7bda62c7316f729d62000a862fce2e4c07489021eb17e5e2061e153a93531c33a97
|
|
7
|
+
data.tar.gz: bf1c436e16959004738bb9ede0fedb2cb553ec32c5282dc4a09771788017076819b774080e27afc877bd5715885a5578a2316ef3cfb1a1ca25ed8f54f09149bf
|
data/.rspec
ADDED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
3.3.6
|
|
@@ -19,8 +19,8 @@ module MailDaemon
|
|
|
19
19
|
if exit_code == 0
|
|
20
20
|
result
|
|
21
21
|
else
|
|
22
|
-
|
|
23
|
-
raise error
|
|
22
|
+
# @options is not available in class method context, so skip debug output
|
|
23
|
+
raise error || "Process exited with code #{exit_code}"
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
data/lib/mail_daemon/helpers.rb
CHANGED
|
@@ -4,7 +4,8 @@ module MailDaemon
|
|
|
4
4
|
@options = options.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
|
5
5
|
end
|
|
6
6
|
def reload_options(options)
|
|
7
|
-
|
|
7
|
+
normalized = options.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
|
8
|
+
@options.merge!(normalized)
|
|
8
9
|
end
|
|
9
10
|
def default_option(name, value)
|
|
10
11
|
@options[name.to_s.to_sym] = value unless @options.has_key?(name.to_s.to_sym)
|
|
@@ -11,6 +11,7 @@ module MailDaemon
|
|
|
11
11
|
def initialize(options, &block)
|
|
12
12
|
setup_options(options)
|
|
13
13
|
|
|
14
|
+
|
|
14
15
|
required_option [:host, :username, :password]
|
|
15
16
|
|
|
16
17
|
default_option :port, 143
|
|
@@ -18,10 +19,11 @@ module MailDaemon
|
|
|
18
19
|
default_option :ssl, false
|
|
19
20
|
default_option :start_tls, false
|
|
20
21
|
default_option :ssl_options, false
|
|
21
|
-
default_option :sleep_time,
|
|
22
|
+
default_option :sleep_time, 30
|
|
22
23
|
default_option :imap_timeout, 60
|
|
23
24
|
default_option :idle_recycle_time, 29 * SECONDS_IN_MINUTES
|
|
24
25
|
|
|
26
|
+
|
|
25
27
|
@notify_status_block = block
|
|
26
28
|
|
|
27
29
|
puts "initializing new imap connection for #{@options[:username]}:#{@options[:password]}@#{@options[:host]}:#{@options[:port]} " if @options[:debug]
|
|
@@ -152,7 +154,7 @@ module MailDaemon
|
|
|
152
154
|
end
|
|
153
155
|
|
|
154
156
|
def running?
|
|
155
|
-
|
|
157
|
+
!@imap.nil? && !@imap.disconnected?
|
|
156
158
|
end
|
|
157
159
|
|
|
158
160
|
private
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
require 'redis'
|
|
2
|
+
require 'mysql2'
|
|
3
|
+
require_relative 'encryption'
|
|
1
4
|
|
|
2
5
|
module MailDaemon
|
|
3
6
|
class ImapWatcher
|
|
@@ -10,9 +13,9 @@ module MailDaemon
|
|
|
10
13
|
raise "MYSQL_HOST environment variable is required" unless ENV["MYSQL_HOST"]
|
|
11
14
|
raise "MYSQL_DATABASE environment variable is required" unless ENV["MYSQL_DATABASE"]
|
|
12
15
|
raise "MYSQL_USERNAME environment variable is required" unless ENV["MYSQL_USERNAME"]
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
# MYSQL_PASSWORD can be empty string, but not nil
|
|
17
|
+
raise "MYSQL_PASSWORD environment variable is required" if ENV["MYSQL_PASSWORD"].nil?
|
|
18
|
+
|
|
16
19
|
ENV["MYSQL_PORT"] = "3306"
|
|
17
20
|
|
|
18
21
|
redis_url = URI.parse(ENV["REDIS_URL"])
|
|
@@ -34,7 +37,7 @@ module MailDaemon
|
|
|
34
37
|
def setup_watchers
|
|
35
38
|
# load uptodate config
|
|
36
39
|
|
|
37
|
-
watchers = []
|
|
40
|
+
@watchers = []
|
|
38
41
|
mysql_client do |mysql|
|
|
39
42
|
statement = mysql.prepare("select ea.*, a.nickname from case_blocks_email_accounts ea join case_blocks_accounts a on a.id = ea.account_id where ea.imap_enabled=1")
|
|
40
43
|
result = statement.execute()
|
|
@@ -42,8 +45,8 @@ module MailDaemon
|
|
|
42
45
|
ssl = row["imap_ssl"]==1 ? {:verify_mode => "none"} : false
|
|
43
46
|
decrypted_password = Encryption.new.decrypt(row["imap_encrypted_password"])
|
|
44
47
|
begin
|
|
45
|
-
watcher = Imap::Connection.new({:email => row["imap_username"], :host => row["imap_host"], :port => row["imap_port"], :password => decrypted_password, :ssl => ssl, :start_tls => row["imap_start_tls"]==1, :name => row["imap_folder_name"], :search_command => row["imap_search_command"], :message_count => row["imap_messages_processed"], :last_delivered_at => row["imap_last_delivered_at"], :delivery_method=>"sidekiq", :delivery_options=>{:redis_url => ENV["REDIS_URL"], :queue => "email_handler", :worker=>"EmailHandlerWorker"}})
|
|
46
|
-
watchers << watcher
|
|
48
|
+
watcher = Imap::Connection.new(@options.merge({:email => row["imap_username"], :host => row["imap_host"], :port => row["imap_port"], :password => decrypted_password, :ssl => ssl, :start_tls => row["imap_start_tls"]==1, :name => row["imap_folder_name"], :search_command => row["imap_search_command"], :message_count => row["imap_messages_processed"], :last_delivered_at => row["imap_last_delivered_at"], :delivery_method=>"sidekiq", :delivery_options=>{:redis_url => ENV["REDIS_URL"], :queue => "email_handler", :worker=>"EmailHandlerWorker"}}))
|
|
49
|
+
@watchers << watcher
|
|
47
50
|
rescue => e
|
|
48
51
|
puts "Unable to create IMAP4 connection for #{row['nickname']}/#{row['name']}. #{e.message}"
|
|
49
52
|
end
|
|
@@ -53,15 +56,15 @@ module MailDaemon
|
|
|
53
56
|
end
|
|
54
57
|
|
|
55
58
|
def start
|
|
56
|
-
watchers.each do |watcher|
|
|
57
|
-
watcher.
|
|
59
|
+
@watchers.each do |watcher|
|
|
60
|
+
watcher.wait_for_messages do |message|
|
|
58
61
|
ap message
|
|
59
62
|
end
|
|
60
63
|
end
|
|
61
64
|
end
|
|
62
65
|
|
|
63
66
|
def stop
|
|
64
|
-
watchers.map{|watcher| watcher.
|
|
67
|
+
@watchers.map{|watcher| watcher.disconnect }
|
|
65
68
|
end
|
|
66
69
|
|
|
67
70
|
def restart
|
data/lib/mail_daemon/version.rb
CHANGED
data/lib/mail_daemon.rb
CHANGED
|
@@ -6,6 +6,7 @@ require_relative 'mail_daemon/imap/statuses'
|
|
|
6
6
|
require_relative 'mail_daemon/imap/connection'
|
|
7
7
|
require_relative 'mail_daemon/imap/watcher'
|
|
8
8
|
require_relative 'mail_daemon/encryption'
|
|
9
|
+
require_relative 'mail_daemon/imap_watcher'
|
|
9
10
|
require 'sinatra/base'
|
|
10
11
|
require 'json'
|
|
11
12
|
require 'open3'
|
|
@@ -40,7 +41,8 @@ module MailDaemon
|
|
|
40
41
|
end
|
|
41
42
|
|
|
42
43
|
def running?
|
|
43
|
-
|
|
44
|
+
return false unless @watchers
|
|
45
|
+
@watchers.any?{|watcher| watcher.running?}
|
|
44
46
|
end
|
|
45
47
|
|
|
46
48
|
# Signal catching
|
|
@@ -63,7 +65,7 @@ module MailDaemon
|
|
|
63
65
|
mailbox[:ssl_options] = {:verify_mode => OpenSSL::SSL::VERIFY_NONE} if mailbox[:ssl]
|
|
64
66
|
|
|
65
67
|
puts "Setting up watcher for #{mailbox[:username]}" if @options[:debug]
|
|
66
|
-
@watchers << MailDaemon::Imap::Watcher.new(
|
|
68
|
+
@watchers << MailDaemon::Imap::Watcher.new(@options.merge(mailbox))
|
|
67
69
|
end
|
|
68
70
|
@threads = []
|
|
69
71
|
@watchers.each do |watcher|
|
data/mail_daemon.gemspec
CHANGED
|
@@ -18,11 +18,18 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
19
|
spec.require_paths = ["lib"]
|
|
20
20
|
|
|
21
|
-
spec.add_development_dependency "bundler", "~>
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
|
22
22
|
spec.add_development_dependency "rake"
|
|
23
23
|
spec.add_development_dependency "awesome_print"
|
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.12"
|
|
25
|
+
spec.add_development_dependency "rspec-mocks", "~> 3.12"
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
spec.add_dependency 'mail'
|
|
28
|
+
spec.add_dependency 'sinatra'
|
|
29
|
+
spec.add_dependency 'nokogiri'
|
|
30
|
+
spec.add_dependency 'sanitize'
|
|
31
|
+
spec.add_dependency 'redis'
|
|
32
|
+
spec.add_dependency 'mysql2'
|
|
26
33
|
|
|
27
34
|
|
|
28
35
|
end
|
data/spec/examples.txt
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
example_id | status | run_time |
|
|
2
|
+
----------------------------------------------------- | ------ | --------------- |
|
|
3
|
+
./spec/mail_daemon/email_body_parser_spec.rb[1:1:1:1] | passed | 0.00157 seconds |
|
|
4
|
+
./spec/mail_daemon/email_body_parser_spec.rb[1:1:1:2] | passed | 0.00544 seconds |
|
|
5
|
+
./spec/mail_daemon/email_body_parser_spec.rb[1:1:2:1] | passed | 0.01017 seconds |
|
|
6
|
+
./spec/mail_daemon/email_body_parser_spec.rb[1:1:3:1] | passed | 0.00037 seconds |
|
|
7
|
+
./spec/mail_daemon/email_body_parser_spec.rb[1:1:3:2] | passed | 0.00037 seconds |
|
|
8
|
+
./spec/mail_daemon/email_body_parser_spec.rb[1:1:3:3] | passed | 0.00074 seconds |
|
|
9
|
+
./spec/mail_daemon/email_handler_spec.rb[1:1:1] | passed | 0.00086 seconds |
|
|
10
|
+
./spec/mail_daemon/email_handler_spec.rb[1:1:2] | passed | 0.00085 seconds |
|
|
11
|
+
./spec/mail_daemon/email_handler_spec.rb[1:1:3] | passed | 0.18024 seconds |
|
|
12
|
+
./spec/mail_daemon/email_handler_spec.rb[1:1:4] | passed | 0.00276 seconds |
|
|
13
|
+
./spec/mail_daemon/email_handler_spec.rb[1:1:5] | passed | 0.00359 seconds |
|
|
14
|
+
./spec/mail_daemon/email_handler_spec.rb[1:2:1] | passed | 0.00182 seconds |
|
|
15
|
+
./spec/mail_daemon/email_handler_spec.rb[1:2:2] | passed | 0.00142 seconds |
|
|
16
|
+
./spec/mail_daemon/email_handler_spec.rb[1:3:1] | passed | 0.0048 seconds |
|
|
17
|
+
./spec/mail_daemon/email_handler_spec.rb[1:3:2] | passed | 0.00195 seconds |
|
|
18
|
+
./spec/mail_daemon/email_handler_spec.rb[1:3:3] | passed | 0.00257 seconds |
|
|
19
|
+
./spec/mail_daemon/email_handler_spec.rb[1:3:4] | passed | 0.00129 seconds |
|
|
20
|
+
./spec/mail_daemon/email_handler_spec.rb[1:3:5] | passed | 0.00175 seconds |
|
|
21
|
+
./spec/mail_daemon/email_handler_spec.rb[1:4:1] | passed | 0.00293 seconds |
|
|
22
|
+
./spec/mail_daemon/email_handler_spec.rb[1:4:2] | passed | 0.00132 seconds |
|
|
23
|
+
./spec/mail_daemon/email_handler_spec.rb[1:5:1] | passed | 0.01028 seconds |
|
|
24
|
+
./spec/mail_daemon/email_handler_spec.rb[1:5:2] | passed | 0.03103 seconds |
|
|
25
|
+
./spec/mail_daemon/email_handler_spec.rb[1:5:3] | passed | 0.00524 seconds |
|
|
26
|
+
./spec/mail_daemon/email_handler_spec.rb[1:6:1] | passed | 0.00067 seconds |
|
|
27
|
+
./spec/mail_daemon/email_handler_spec.rb[1:6:2] | passed | 0.00186 seconds |
|
|
28
|
+
./spec/mail_daemon/email_handler_spec.rb[1:7:1] | passed | 0.00566 seconds |
|
|
29
|
+
./spec/mail_daemon/email_handler_spec.rb[1:8:1] | passed | 0.00277 seconds |
|
|
30
|
+
./spec/mail_daemon/email_handler_spec.rb[1:9:1] | passed | 0.00195 seconds |
|
|
31
|
+
./spec/mail_daemon/encryption_spec.rb[1:1:1] | passed | 0.00034 seconds |
|
|
32
|
+
./spec/mail_daemon/encryption_spec.rb[1:1:2] | passed | 0.00036 seconds |
|
|
33
|
+
./spec/mail_daemon/encryption_spec.rb[1:1:3] | passed | 0.00053 seconds |
|
|
34
|
+
./spec/mail_daemon/encryption_spec.rb[1:1:4] | passed | 0.00027 seconds |
|
|
35
|
+
./spec/mail_daemon/encryption_spec.rb[1:2:1] | passed | 0.00052 seconds |
|
|
36
|
+
./spec/mail_daemon/encryption_spec.rb[1:2:2] | passed | 0.00151 seconds |
|
|
37
|
+
./spec/mail_daemon/encryption_spec.rb[1:2:3] | passed | 0.00067 seconds |
|
|
38
|
+
./spec/mail_daemon/encryption_spec.rb[1:2:4] | passed | 0.00037 seconds |
|
|
39
|
+
./spec/mail_daemon/encryption_spec.rb[1:2:5] | passed | 0.00147 seconds |
|
|
40
|
+
./spec/mail_daemon/encryption_spec.rb[1:3:1] | passed | 0.00156 seconds |
|
|
41
|
+
./spec/mail_daemon/encryption_spec.rb[1:3:2] | passed | 0.00183 seconds |
|
|
42
|
+
./spec/mail_daemon/encryption_spec.rb[1:3:3] | passed | 0.00047 seconds |
|
|
43
|
+
./spec/mail_daemon/encryption_spec.rb[1:3:4] | passed | 0.0004 seconds |
|
|
44
|
+
./spec/mail_daemon/encryption_spec.rb[1:3:5] | passed | 0.00064 seconds |
|
|
45
|
+
./spec/mail_daemon/encryption_spec.rb[1:4:1] | passed | 0.00035 seconds |
|
|
46
|
+
./spec/mail_daemon/encryption_spec.rb[1:4:2] | passed | 0.00047 seconds |
|
|
47
|
+
./spec/mail_daemon/handler_spec.rb[1:1:1] | passed | 0.00269 seconds |
|
|
48
|
+
./spec/mail_daemon/handler_spec.rb[1:1:2] | passed | 0.0005 seconds |
|
|
49
|
+
./spec/mail_daemon/handler_spec.rb[1:1:3] | passed | 0.00066 seconds |
|
|
50
|
+
./spec/mail_daemon/handler_spec.rb[1:1:4] | passed | 0.00011 seconds |
|
|
51
|
+
./spec/mail_daemon/handler_spec.rb[1:1:5] | passed | 0.00009 seconds |
|
|
52
|
+
./spec/mail_daemon/handler_spec.rb[1:2:1:1] | passed | 0.00019 seconds |
|
|
53
|
+
./spec/mail_daemon/handler_spec.rb[1:2:2:1] | passed | 0.00029 seconds |
|
|
54
|
+
./spec/mail_daemon/handler_spec.rb[1:2:3:1] | passed | 0.00012 seconds |
|
|
55
|
+
./spec/mail_daemon/handler_spec.rb[1:3:1] | passed | 0.00058 seconds |
|
|
56
|
+
./spec/mail_daemon/handler_spec.rb[1:4:1] | passed | 0.00076 seconds |
|
|
57
|
+
./spec/mail_daemon/handler_spec.rb[1:4:2] | passed | 0.00153 seconds |
|
|
58
|
+
./spec/mail_daemon/handler_spec.rb[1:5:1] | passed | 0.00045 seconds |
|
|
59
|
+
./spec/mail_daemon/handler_spec.rb[1:6:1] | passed | 0.10414 seconds |
|
|
60
|
+
./spec/mail_daemon/handler_spec.rb[1:6:2] | passed | 0.10433 seconds |
|
|
61
|
+
./spec/mail_daemon/handler_spec.rb[1:6:3] | passed | 0.10226 seconds |
|
|
62
|
+
./spec/mail_daemon/handler_spec.rb[1:6:4] | passed | 0.10348 seconds |
|
|
63
|
+
./spec/mail_daemon/helpers_spec.rb[1:1:1] | passed | 0.00014 seconds |
|
|
64
|
+
./spec/mail_daemon/helpers_spec.rb[1:1:2] | passed | 0.00016 seconds |
|
|
65
|
+
./spec/mail_daemon/helpers_spec.rb[1:1:3] | passed | 0.00015 seconds |
|
|
66
|
+
./spec/mail_daemon/helpers_spec.rb[1:1:4] | passed | 0.00008 seconds |
|
|
67
|
+
./spec/mail_daemon/helpers_spec.rb[1:2:1] | passed | 0.0001 seconds |
|
|
68
|
+
./spec/mail_daemon/helpers_spec.rb[1:2:2] | passed | 0.00007 seconds |
|
|
69
|
+
./spec/mail_daemon/helpers_spec.rb[1:2:3] | passed | 0.00008 seconds |
|
|
70
|
+
./spec/mail_daemon/helpers_spec.rb[1:3:1] | passed | 0.00007 seconds |
|
|
71
|
+
./spec/mail_daemon/helpers_spec.rb[1:3:2] | passed | 0.00009 seconds |
|
|
72
|
+
./spec/mail_daemon/helpers_spec.rb[1:3:3] | passed | 0.00007 seconds |
|
|
73
|
+
./spec/mail_daemon/helpers_spec.rb[1:3:4] | passed | 0.00008 seconds |
|
|
74
|
+
./spec/mail_daemon/helpers_spec.rb[1:4:1] | passed | 0.00008 seconds |
|
|
75
|
+
./spec/mail_daemon/helpers_spec.rb[1:4:2] | passed | 0.00009 seconds |
|
|
76
|
+
./spec/mail_daemon/helpers_spec.rb[1:4:3] | passed | 0.00009 seconds |
|
|
77
|
+
./spec/mail_daemon/helpers_spec.rb[1:4:4] | passed | 0.00008 seconds |
|
|
78
|
+
./spec/mail_daemon/helpers_spec.rb[1:4:5] | passed | 0.0003 seconds |
|
|
79
|
+
./spec/mail_daemon/helpers_spec.rb[1:4:6] | passed | 0.00007 seconds |
|
|
80
|
+
./spec/mail_daemon/helpers_spec.rb[1:4:7] | passed | 0.00007 seconds |
|
|
81
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:1:1] | passed | 0.0001 seconds |
|
|
82
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:1:2] | passed | 0.00012 seconds |
|
|
83
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:1:3] | passed | 0.00012 seconds |
|
|
84
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:1:4] | passed | 0.00012 seconds |
|
|
85
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:1:5] | passed | 0.00008 seconds |
|
|
86
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:1:6] | passed | 0.00008 seconds |
|
|
87
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:1:7] | passed | 0.00006 seconds |
|
|
88
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:1:8] | passed | 0.00007 seconds |
|
|
89
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:1:9] | passed | 0.0001 seconds |
|
|
90
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:2:1] | passed | 0.00042 seconds |
|
|
91
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:2:2] | passed | 0.001 seconds |
|
|
92
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:2:3] | passed | 0.00082 seconds |
|
|
93
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:2:4] | passed | 0.00047 seconds |
|
|
94
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:2:5] | passed | 0.00071 seconds |
|
|
95
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:2:6] | passed | 0.00044 seconds |
|
|
96
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:2:7] | passed | 0.00059 seconds |
|
|
97
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:2:8] | passed | 0.00057 seconds |
|
|
98
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:3:1] | passed | 0.00335 seconds |
|
|
99
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:3:2] | passed | 0.00044 seconds |
|
|
100
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:3:3] | passed | 0.00098 seconds |
|
|
101
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:4:1] | passed | 0.00065 seconds |
|
|
102
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:4:2] | passed | 0.00056 seconds |
|
|
103
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:4:3] | passed | 0.00104 seconds |
|
|
104
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:5:1] | passed | 0.00117 seconds |
|
|
105
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:5:2] | passed | 0.0014 seconds |
|
|
106
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:5:3] | passed | 0.00083 seconds |
|
|
107
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:6:1] | passed | 0.0001 seconds |
|
|
108
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:6:2] | passed | 0.00104 seconds |
|
|
109
|
+
./spec/mail_daemon/imap/connection_spec.rb[1:7:1] | passed | 0.00226 seconds |
|
|
110
|
+
./spec/mail_daemon/imap/statuses_spec.rb[1:1] | passed | 0.00002 seconds |
|
|
111
|
+
./spec/mail_daemon/imap/statuses_spec.rb[1:2] | passed | 0.00006 seconds |
|
|
112
|
+
./spec/mail_daemon/imap/statuses_spec.rb[1:3] | passed | 0.00002 seconds |
|
|
113
|
+
./spec/mail_daemon/imap/statuses_spec.rb[1:4] | passed | 0.00005 seconds |
|
|
114
|
+
./spec/mail_daemon/imap/statuses_spec.rb[1:5] | passed | 0.00002 seconds |
|
|
115
|
+
./spec/mail_daemon/imap/statuses_spec.rb[1:6] | passed | 0.00002 seconds |
|
|
116
|
+
./spec/mail_daemon/imap/statuses_spec.rb[1:7] | passed | 0.00002 seconds |
|
|
117
|
+
./spec/mail_daemon/imap/statuses_spec.rb[1:8] | passed | 0.00003 seconds |
|
|
118
|
+
./spec/mail_daemon/imap/statuses_spec.rb[1:9] | passed | 0.00002 seconds |
|
|
119
|
+
./spec/mail_daemon/imap/statuses_spec.rb[1:10] | passed | 0.00003 seconds |
|
|
120
|
+
./spec/mail_daemon/imap/statuses_spec.rb[1:11] | passed | 0.00002 seconds |
|
|
121
|
+
./spec/mail_daemon/imap/watcher_spec.rb[1:1:1] | passed | 0.0001 seconds |
|
|
122
|
+
./spec/mail_daemon/imap/watcher_spec.rb[1:2:1] | passed | 0.1052 seconds |
|
|
123
|
+
./spec/mail_daemon/imap/watcher_spec.rb[1:2:2] | passed | 0.10147 seconds |
|
|
124
|
+
./spec/mail_daemon/imap/watcher_spec.rb[1:3:1] | passed | 0.00031 seconds |
|
|
125
|
+
./spec/mail_daemon/imap/watcher_spec.rb[1:4:1] | passed | 0.00079 seconds |
|
|
126
|
+
./spec/mail_daemon/imap/watcher_spec.rb[1:5:1] | passed | 0.00006 seconds |
|
|
127
|
+
./spec/mail_daemon/imap/watcher_spec.rb[1:5:2] | passed | 0.00006 seconds |
|
|
128
|
+
./spec/mail_daemon/imap/watcher_spec.rb[1:6:1] | passed | 0.00005 seconds |
|
|
129
|
+
./spec/mail_daemon/imap/watcher_spec.rb[1:7:1] | passed | 0.00021 seconds |
|
|
130
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:1:1] | passed | 0.00047 seconds |
|
|
131
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:1:2] | passed | 0.00031 seconds |
|
|
132
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:1:3] | passed | 0.0003 seconds |
|
|
133
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:1:4] | passed | 0.00058 seconds |
|
|
134
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:1:5] | passed | 0.00037 seconds |
|
|
135
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:1:6] | passed | 0.00148 seconds |
|
|
136
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:1:7] | passed | 0.00074 seconds |
|
|
137
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:1:8] | passed | 0.00112 seconds |
|
|
138
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:1:9] | passed | 0.00106 seconds |
|
|
139
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:1:10] | passed | 0.00141 seconds |
|
|
140
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:2:1] | passed | 0.00106 seconds |
|
|
141
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:2:2] | passed | 0.00111 seconds |
|
|
142
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:3:1] | passed | 0.00066 seconds |
|
|
143
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:4:1] | passed | 0.00078 seconds |
|
|
144
|
+
./spec/mail_daemon/imap_watcher_spec.rb[1:4:2] | passed | 0.00312 seconds |
|
|
145
|
+
./spec/mail_daemon/version_spec.rb[1:1] | passed | 0.00008 seconds |
|
|
146
|
+
./spec/mail_daemon/version_spec.rb[1:2] | passed | 0.00041 seconds |
|
|
147
|
+
./spec/mail_daemon/version_spec.rb[1:3] | passed | 0.002 seconds |
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe MailDaemon::EmailBodyParser do
|
|
4
|
+
describe '.parse' do
|
|
5
|
+
let(:text) { 'Sample email body text' }
|
|
6
|
+
let(:type) { 'text/plain' }
|
|
7
|
+
|
|
8
|
+
context 'when python script succeeds' do
|
|
9
|
+
it 'returns the parsed result' do
|
|
10
|
+
expected_result = 'Parsed body'
|
|
11
|
+
stdin = StringIO.new
|
|
12
|
+
stdout = StringIO.new(expected_result)
|
|
13
|
+
stderr = StringIO.new
|
|
14
|
+
# Process::Status can be compared to 0 (compares exitstatus)
|
|
15
|
+
process_status = double('Process::Status')
|
|
16
|
+
allow(process_status).to receive(:==).with(0).and_return(true)
|
|
17
|
+
wait_thr = instance_double(Thread, value: process_status)
|
|
18
|
+
|
|
19
|
+
# Open3.popen3 returns an array when called without a block
|
|
20
|
+
allow(Open3).to receive(:popen3).with('python', '/Users/stewartmckee/code/talon/test.py') do
|
|
21
|
+
[stdin, stdout, stderr, wait_thr]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
result = described_class.parse(text, type)
|
|
25
|
+
expect(result).to eq(expected_result)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'writes JSON to stdin' do
|
|
29
|
+
json_input = { body: text, type: type }.to_json
|
|
30
|
+
stdin = StringIO.new
|
|
31
|
+
stdout = StringIO.new('result')
|
|
32
|
+
stderr = StringIO.new
|
|
33
|
+
process_status = double('Process::Status')
|
|
34
|
+
allow(process_status).to receive(:==).with(0).and_return(true)
|
|
35
|
+
wait_thr = instance_double(Thread, value: process_status)
|
|
36
|
+
|
|
37
|
+
allow(Open3).to receive(:popen3) do
|
|
38
|
+
[stdin, stdout, stderr, wait_thr]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
described_class.parse(text, type)
|
|
42
|
+
expect(stdin.string).to eq(json_input)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context 'when python script fails' do
|
|
47
|
+
it 'raises an error with stderr message' do
|
|
48
|
+
error_message = 'Python script error'
|
|
49
|
+
stdin = StringIO.new
|
|
50
|
+
stdout = StringIO.new('')
|
|
51
|
+
stderr = StringIO.new(error_message)
|
|
52
|
+
process_status = double('Process::Status')
|
|
53
|
+
allow(process_status).to receive(:==).with(0).and_return(false)
|
|
54
|
+
wait_thr = instance_double(Thread, value: process_status)
|
|
55
|
+
|
|
56
|
+
allow(Open3).to receive(:popen3) do
|
|
57
|
+
[stdin, stdout, stderr, wait_thr]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
expect { described_class.parse(text, type) }.to raise_error(RuntimeError, error_message)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context 'with different content types' do
|
|
65
|
+
it 'passes text/plain type' do
|
|
66
|
+
stdin = StringIO.new
|
|
67
|
+
stdout = StringIO.new('result')
|
|
68
|
+
stderr = StringIO.new
|
|
69
|
+
process_status = double('Process::Status')
|
|
70
|
+
allow(process_status).to receive(:==).with(0).and_return(true)
|
|
71
|
+
wait_thr = instance_double(Thread, value: process_status)
|
|
72
|
+
|
|
73
|
+
allow(Open3).to receive(:popen3) do
|
|
74
|
+
[stdin, stdout, stderr, wait_thr]
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
described_class.parse(text, 'text/plain')
|
|
78
|
+
expect(JSON.parse(stdin.string)['type']).to eq('text/plain')
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'passes text/html type' do
|
|
82
|
+
stdin = StringIO.new
|
|
83
|
+
stdout = StringIO.new('result')
|
|
84
|
+
stderr = StringIO.new
|
|
85
|
+
process_status = double('Process::Status')
|
|
86
|
+
allow(process_status).to receive(:==).with(0).and_return(true)
|
|
87
|
+
wait_thr = instance_double(Thread, value: process_status)
|
|
88
|
+
|
|
89
|
+
allow(Open3).to receive(:popen3) do
|
|
90
|
+
[stdin, stdout, stderr, wait_thr]
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
described_class.parse(text, 'text/html')
|
|
94
|
+
expect(JSON.parse(stdin.string)['type']).to eq('text/html')
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'defaults to text/plain when type not specified' do
|
|
98
|
+
stdin = StringIO.new
|
|
99
|
+
stdout = StringIO.new('result')
|
|
100
|
+
stderr = StringIO.new
|
|
101
|
+
process_status = double('Process::Status')
|
|
102
|
+
allow(process_status).to receive(:==).with(0).and_return(true)
|
|
103
|
+
wait_thr = instance_double(Thread, value: process_status)
|
|
104
|
+
|
|
105
|
+
allow(Open3).to receive(:popen3) do
|
|
106
|
+
[stdin, stdout, stderr, wait_thr]
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
described_class.parse(text)
|
|
110
|
+
expect(JSON.parse(stdin.string)['type']).to eq('text/plain')
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|