clacks 1.0.8 → 1.1.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 +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +4 -11
- data/clacks.gemspec +16 -17
- data/lib/clacks/command.rb +6 -7
- data/lib/clacks/configurator.rb +0 -1
- data/lib/clacks/service.rb +0 -1
- data/lib/clacks/version.rb +1 -2
- data/lib/clacks.rb +0 -1
- data/spec/command_spec.rb +5 -0
- data/spec/configurator_spec.rb +58 -0
- data/spec/service_spec.rb +17 -0
- data/spec/spec_helper.rb +11 -0
- metadata +13 -6
- data/lib/clacks/stdlib_extensions/ruby_1_8.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c26bb094d7008dbb5094d22439e3fc55c75a375
|
4
|
+
data.tar.gz: b6f54e2f8b485168c67b41b1fc0f5689c9e1e046
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8c93393c43b4a7d19e0829efc1d83e1feecb478e1c34884d178c7bf02a304fa8bb60b3596b2cb7ca35f3d055eb4056763d874ccaca3d7a02f5e24c14e7c62ac
|
7
|
+
data.tar.gz: 9b102599520b751e9be9093f0ba6c61d2647e6ef3c90a67c95175b9c7c6db6401dfd7c5798ddda0a3894aa2a50f65bf1fe9f5950963668159c09fe2a9a912a16
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Clacks
|
1
|
+
# Clacks
|
2
2
|
|
3
3
|
[](http://travis-ci.org/itrp/clacks?branch=master)
|
4
4
|
[](https://codeclimate.com/github/itrp/clacks)
|
@@ -21,7 +21,6 @@ If you use Rails, add this to your Gemfile:
|
|
21
21
|
Then create a configuration file, using ruby syntax, such as:
|
22
22
|
|
23
23
|
``` ruby
|
24
|
-
# -*- encoding: binary -*-
|
25
24
|
# Configuration of clacks
|
26
25
|
# See Clacks::Configurator for documentation on options
|
27
26
|
#
|
@@ -85,20 +84,14 @@ See the [contrib](https://github.com/itrp/clacks/tree/master/contrib/) directory
|
|
85
84
|
Signals
|
86
85
|
-------
|
87
86
|
|
88
|
-
*
|
87
|
+
* KILL - quick shutdown, kills the process immediately.
|
89
88
|
|
90
|
-
* QUIT - graceful shutdown, waits for the worker process to finish processing an email.
|
89
|
+
* TERM/QUIT/INT - graceful shutdown, waits for the worker process to finish processing an email.
|
91
90
|
|
92
91
|
* USR1 - reopen logs
|
93
92
|
|
94
93
|
|
95
|
-
Author
|
96
|
-
----------
|
97
|
-
|
98
|
-
ITRP, mathijs.sterk@itrp.com, [developer.itrp.com](http://developer.itrp.com)
|
99
|
-
|
100
|
-
|
101
94
|
Copyright
|
102
95
|
-----------
|
103
96
|
|
104
|
-
Copyright (c) 2013 ITRP. See MIT-LICENSE for details.
|
97
|
+
Copyright (c) 2013-2016 ITRP. See MIT-LICENSE for details.
|
data/clacks.gemspec
CHANGED
@@ -1,31 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require "clacks/version"
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'clacks/version'
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
6
5
|
s.name = %q{clacks}
|
7
6
|
s.version = Clacks::VERSION
|
8
7
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = [
|
10
|
-
s.email = %q{
|
8
|
+
s.authors = ['ITRP']
|
9
|
+
s.email = %q{developer@itrp.com}
|
11
10
|
s.license = 'MIT'
|
12
|
-
s.homepage = %q{
|
11
|
+
s.homepage = %q{https://github.com/itrp/clacks}
|
13
12
|
s.summary = %q{Clacks system for receiving emails}
|
14
13
|
s.description = %q{Clacks system for receiving emails to be processed in ruby}
|
15
|
-
s.date = Time.now.utc.strftime(
|
16
|
-
s.files = Dir.glob(
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
s.date = Time.now.utc.strftime('%Y-%m-%d')
|
15
|
+
s.files = Dir.glob('lib/**/*') + [
|
16
|
+
'MIT-LICENSE',
|
17
|
+
'README.md',
|
18
|
+
'Gemfile',
|
19
|
+
'clacks.gemspec'
|
21
20
|
]
|
22
21
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
22
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
-
s.require_paths = [
|
25
|
-
s.rdoc_options = [
|
23
|
+
s.require_paths = ['lib']
|
24
|
+
s.rdoc_options = ['--charset=UTF-8']
|
26
25
|
s.add_dependency('mail')
|
27
|
-
s.add_development_dependency
|
28
|
-
# s.add_development_dependency
|
29
|
-
s.add_development_dependency
|
26
|
+
s.add_development_dependency 'rake'
|
27
|
+
# s.add_development_dependency 'rcov'
|
28
|
+
s.add_development_dependency 'rspec'
|
30
29
|
end
|
31
30
|
|
data/lib/clacks/command.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: binary -*-
|
2
1
|
module Clacks
|
3
2
|
class Command
|
4
3
|
require 'optparse'
|
@@ -7,7 +6,7 @@ module Clacks
|
|
7
6
|
PROC_ARGV = ARGV.map { |a| a.dup }
|
8
7
|
|
9
8
|
def initialize(args)
|
10
|
-
@options = { :
|
9
|
+
@options = { config_file: 'config/clacks.rb' }
|
11
10
|
|
12
11
|
opts = OptionParser.new do |opts|
|
13
12
|
opts.banner = "Usage: #{PROC_NAME} [options]"
|
@@ -73,7 +72,7 @@ module Clacks
|
|
73
72
|
reopen_io($stderr, config[:stderr_path])
|
74
73
|
|
75
74
|
unless config[:pid]
|
76
|
-
config.pid(@options[:pid] ||
|
75
|
+
config.pid(@options[:pid] || 'clacks.pid')
|
77
76
|
end
|
78
77
|
pid = config[:pid]
|
79
78
|
if wpid = running?(pid)
|
@@ -152,11 +151,11 @@ module Clacks
|
|
152
151
|
end
|
153
152
|
|
154
153
|
def setup_signal_handling
|
155
|
-
|
156
|
-
Signal.trap(
|
157
|
-
Thread.new { Clacks.logger.info '
|
154
|
+
graceful_exit_signal = (Signal.list.keys & ['INT', 'QUIT', 'TERM']).sort.last
|
155
|
+
Signal.trap(graceful_exit_signal) do
|
156
|
+
Thread.new { Clacks.logger.info 'Exiting...' }
|
158
157
|
@service.stop if @service
|
159
|
-
end unless
|
158
|
+
end unless graceful_exit_signal.nil?
|
160
159
|
|
161
160
|
Signal.trap('USR1') do
|
162
161
|
Thread.new { Clacks.logger.info 'USR1 signal received. Rotating logs.' }
|
data/lib/clacks/configurator.rb
CHANGED
data/lib/clacks/service.rb
CHANGED
data/lib/clacks/version.rb
CHANGED
data/lib/clacks.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
describe Clacks::Configurator do
|
5
|
+
|
6
|
+
it "has defaults" do
|
7
|
+
config = Clacks::Configurator.new
|
8
|
+
expect(config[:poll_interval]).to eq(60)
|
9
|
+
expect(config[:pid]).to be_nil
|
10
|
+
expect(config[:stdout_path]).to be_nil
|
11
|
+
expect(config[:stderr_path]).to be_nil
|
12
|
+
config[:on_mail].call(Mail.new(from: 'foo@example.com', subject: 'foo'))
|
13
|
+
last_log_line = `tail -n 1 /tmp/clacks.log`
|
14
|
+
expect(last_log_line).to include('Mail from foo@example.com, subject: foo')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has invalid config" do
|
18
|
+
tmp = Tempfile.new('clacks.config')
|
19
|
+
tmp.syswrite(%[foo "hello-world"])
|
20
|
+
expect { Clacks::Configurator.new(tmp.path) }.to raise_error(NoMethodError)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has non-existent config" do
|
24
|
+
tmp = Tempfile.new('clacks.config')
|
25
|
+
path = tmp.path
|
26
|
+
tmp.close!
|
27
|
+
expect { Clacks::Configurator.new(path) }.to raise_error(Errno::ENOENT)
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'on_mail proc' do
|
31
|
+
it "should test for arity of the on_mail proc" do
|
32
|
+
tmp = Tempfile.new('clacks.config')
|
33
|
+
tmp.syswrite(%[on_mail{|x,y|x+y}])
|
34
|
+
expect { Clacks::Configurator.new(tmp.path) }.to raise_error(ArgumentError, /on_mail=.* has invalid arity: 2 \(need 1\)/)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should configure the on_mail hook" do
|
38
|
+
tmp = Tempfile.new('clacks.config')
|
39
|
+
tmp.syswrite(%[on_mail{|mail|mail+1}])
|
40
|
+
expect(Clacks::Configurator.new(tmp.path)[:on_mail].call(5)).to eq(6)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'after_initialize proc' do
|
45
|
+
it "should test for arity of the after_initialize proc" do
|
46
|
+
tmp = Tempfile.new('clacks.config')
|
47
|
+
tmp.syswrite(%[after_initialize{|x,y|x+y}])
|
48
|
+
expect { Clacks::Configurator.new(tmp.path) }.to raise_error(ArgumentError, /after_initialize=.* has invalid arity: 2 \(need 0\)/)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should configure the after_initialize hook" do
|
52
|
+
tmp = Tempfile.new('clacks.config')
|
53
|
+
tmp.syswrite(%[after_initialize { 42 }])
|
54
|
+
expect(Clacks::Configurator.new(tmp.path)[:after_initialize].call).to eq(42)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Clacks::Service do
|
4
|
+
|
5
|
+
it "should ensure utf7 conversion for mailbox names" do
|
6
|
+
Mail::IMAP.new({})
|
7
|
+
allow(Net::IMAP).to receive(:encode_utf7).with('INBOX').and_return('UTF7_INBOX')
|
8
|
+
allow(Net::IMAP).to receive(:encode_utf7).with('ARCHIVE').and_return('ARCHIVE_INBOX')
|
9
|
+
options = Clacks::Service.new.send(:imap_validate_options, {
|
10
|
+
:mailbox => 'INBOX',
|
11
|
+
:archivebox => 'ARCHIVE'
|
12
|
+
})
|
13
|
+
expect(options[:mailbox]).to eq('UTF7_INBOX')
|
14
|
+
expect(options[:archivebox]).to eq('ARCHIVE_INBOX')
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
3
|
+
|
4
|
+
STDERR.puts("Running Specs under Ruby Version #{RUBY_VERSION}")
|
5
|
+
|
6
|
+
require 'rspec'
|
7
|
+
require 'clacks'
|
8
|
+
|
9
|
+
require 'logger'
|
10
|
+
Clacks.config.logger(Logger.new('/tmp/clacks.log'))
|
11
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clacks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ITRP
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: Clacks system for receiving emails to be processed in ruby
|
56
|
-
email:
|
56
|
+
email: developer@itrp.com
|
57
57
|
executables:
|
58
58
|
- clacks
|
59
59
|
extensions: []
|
@@ -68,9 +68,12 @@ files:
|
|
68
68
|
- lib/clacks/command.rb
|
69
69
|
- lib/clacks/configurator.rb
|
70
70
|
- lib/clacks/service.rb
|
71
|
-
- lib/clacks/stdlib_extensions/ruby_1_8.rb
|
72
71
|
- lib/clacks/version.rb
|
73
|
-
|
72
|
+
- spec/command_spec.rb
|
73
|
+
- spec/configurator_spec.rb
|
74
|
+
- spec/service_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
homepage: https://github.com/itrp/clacks
|
74
77
|
licenses:
|
75
78
|
- MIT
|
76
79
|
metadata: {}
|
@@ -95,4 +98,8 @@ rubygems_version: 2.4.8
|
|
95
98
|
signing_key:
|
96
99
|
specification_version: 4
|
97
100
|
summary: Clacks system for receiving emails
|
98
|
-
test_files:
|
101
|
+
test_files:
|
102
|
+
- spec/command_spec.rb
|
103
|
+
- spec/configurator_spec.rb
|
104
|
+
- spec/service_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# -*- encoding: binary -*-
|
2
|
-
# Backport from ruby 1.9.3 source to ruby 1.8.7
|
3
|
-
class Net::IMAP
|
4
|
-
def idle(&response_handler)
|
5
|
-
raise LocalJumpError, "no block given" unless response_handler
|
6
|
-
|
7
|
-
response = nil
|
8
|
-
|
9
|
-
synchronize do
|
10
|
-
tag = Thread.current[:net_imap_tag] = generate_tag
|
11
|
-
put_string("#{tag} IDLE#{CRLF}")
|
12
|
-
|
13
|
-
begin
|
14
|
-
add_response_handler(response_handler)
|
15
|
-
@idle_done_cond = new_cond
|
16
|
-
@idle_done_cond.wait
|
17
|
-
@idle_done_cond = nil
|
18
|
-
if @receiver_thread_terminating
|
19
|
-
raise Net::IMAP::Error, "connection closed"
|
20
|
-
end
|
21
|
-
ensure
|
22
|
-
unless @receiver_thread_terminating
|
23
|
-
remove_response_handler(response_handler)
|
24
|
-
put_string("DONE#{CRLF}")
|
25
|
-
response = get_tagged_response(tag) #, "IDLE")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
return response
|
31
|
-
end
|
32
|
-
|
33
|
-
def idle_done
|
34
|
-
synchronize do
|
35
|
-
if @idle_done_cond.nil?
|
36
|
-
raise Net::IMAP::Error, "not during IDLE"
|
37
|
-
end
|
38
|
-
@idle_done_cond.signal
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|