popper 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/popper/action/base.rb +8 -10
- data/lib/popper/cli.rb +27 -17
- data/lib/popper/config.rb +0 -16
- data/lib/popper/mail_account.rb +10 -5
- data/lib/popper/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8aa57a97616a3885fc9216806fde0f78ce86bafa
|
4
|
+
data.tar.gz: 1611c6a9cfaa3d53569b589da0eed2c62ed7dd67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdf39038cf7116daebea81aa8d1fa5826e32f8610d7609bc5ef2590c18a3b5d96d6492141c1aacc82e4107ffd31441e478965c46e4482897a460d870db93d30c
|
7
|
+
data.tar.gz: 25f8a470266ef54f88706672cb50af61757e86a8ed000171b9e1f20cd70f8a2377e39f7ce98bc281060c2757ec7d424185efd1186ed98b9475f57e883b7910bf
|
data/lib/popper/action/base.rb
CHANGED
@@ -6,16 +6,14 @@ module Popper::Action
|
|
6
6
|
|
7
7
|
def self.run(config, mail, params={})
|
8
8
|
@action_config = config.send(self.action) if config.respond_to?(self.action)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
9
|
+
begin
|
10
|
+
Popper.log.info "run action #{self.action}"
|
11
|
+
params = task(mail, params)
|
12
|
+
Popper.log.info "exit action #{self.action}"
|
13
|
+
rescue => e
|
14
|
+
Popper.log.warn e
|
15
|
+
Popper.log.warn e.backtrace
|
16
|
+
end if action?
|
19
17
|
next_run(config, mail, params)
|
20
18
|
end
|
21
19
|
|
data/lib/popper/cli.rb
CHANGED
@@ -21,9 +21,15 @@ module Popper
|
|
21
21
|
Popper.load_config(options)
|
22
22
|
|
23
23
|
accounts = Popper.configure.accounts.map {|account| MailAccount.new(account)}
|
24
|
+
interval = case
|
25
|
+
when Popper.configure.global.respond_to?(:interval)
|
26
|
+
Popper.configure.global.interval
|
27
|
+
else
|
28
|
+
60
|
29
|
+
end
|
24
30
|
while true
|
25
31
|
accounts.each(&:run)
|
26
|
-
sleep(
|
32
|
+
sleep(interval)
|
27
33
|
end
|
28
34
|
|
29
35
|
rescue => e
|
@@ -33,7 +39,7 @@ module Popper
|
|
33
39
|
|
34
40
|
class_option :config, type: :string, aliases: '-c'
|
35
41
|
desc "print", "print configure"
|
36
|
-
def print
|
42
|
+
def print
|
37
43
|
Popper.load_config(options)
|
38
44
|
Popper.configure.accounts.each do |account|
|
39
45
|
print_config(account)
|
@@ -56,26 +62,30 @@ module Popper
|
|
56
62
|
|
57
63
|
no_commands do
|
58
64
|
def print_config(config)
|
59
|
-
puts config.name
|
60
65
|
last_rule = nil
|
61
|
-
|
62
|
-
|
63
|
-
config.rule_with_conditions_each do |rule,mail_header,condition|
|
64
|
-
puts " "*1 + "rule[#{rule}]" if rule != last_rule
|
65
|
-
puts " "*2 + "actions" if rule != last_rule
|
66
|
+
puts config.name
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
puts " "*
|
68
|
+
config.rules.to_h.keys.each do |rule|
|
69
|
+
config.condition_by_rule(rule).to_h.each do |mail_header,conditions|
|
70
|
+
if rule != last_rule
|
71
|
+
puts " "*1 + "rule[#{rule}]"
|
72
|
+
puts " "*2 + "actions"
|
73
|
+
print_action(config, rule)
|
71
74
|
end
|
72
|
-
end if rule != last_rule
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
+
puts " "*2 + "header[#{mail_header}]"
|
77
|
+
puts " "*3 + "#{conditions}"
|
78
|
+
last_rule = rule
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
76
82
|
|
77
|
-
|
78
|
-
|
83
|
+
def print_action(config, rule)
|
84
|
+
config.action_by_rule(rule).each_pair do |action,params|
|
85
|
+
puts " "*3 + "#{action}"
|
86
|
+
params.each_pair do |k,v|
|
87
|
+
puts " "*4 + "#{k} #{v}"
|
88
|
+
end
|
79
89
|
end
|
80
90
|
end
|
81
91
|
end
|
data/lib/popper/config.rb
CHANGED
@@ -66,22 +66,6 @@ module Popper
|
|
66
66
|
AccountAttributes.new(hash)
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
70
|
-
def rule_with_conditions_all?(&block)
|
71
|
-
rules.to_h.keys.find do |rule|
|
72
|
-
condition_by_rule(rule).to_h.all? do |mail_header,conditions|
|
73
|
-
block.call(rule, mail_header, conditions)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def rule_with_conditions_each(&block)
|
79
|
-
rules.to_h.keys.each do |rule|
|
80
|
-
condition_by_rule(rule).to_h.each do |mail_header,conditions|
|
81
|
-
block.call(rule, mail_header, conditions)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
69
|
end
|
86
70
|
|
87
71
|
def self.load_config(options)
|
data/lib/popper/mail_account.rb
CHANGED
@@ -51,8 +51,11 @@ module Popper
|
|
51
51
|
|
52
52
|
def session_start(&block)
|
53
53
|
pop = Net::POP3.new(@config.login.server, @config.login.port || 110)
|
54
|
-
|
55
|
-
|
54
|
+
%w(
|
55
|
+
open_timeout
|
56
|
+
read_timeout
|
57
|
+
).each {|m| pop.instance_variable_set("@#{m}", ENV['POP_TIMEOUT'] || 120) }
|
58
|
+
|
56
59
|
pop.start(
|
57
60
|
@config.login.user,
|
58
61
|
@config.login.password
|
@@ -69,9 +72,11 @@ module Popper
|
|
69
72
|
end
|
70
73
|
|
71
74
|
def match_rule?(mail)
|
72
|
-
@config.
|
73
|
-
|
74
|
-
|
75
|
+
@config.rules.to_h.keys.find do |rule|
|
76
|
+
@config.condition_by_rule(rule).to_h.all? do |mail_header,conditions|
|
77
|
+
conditions.all? do |condition|
|
78
|
+
mail.respond_to?(mail_header) && mail.send(mail_header).to_s.match(/#{condition}/)
|
79
|
+
end
|
75
80
|
end
|
76
81
|
end
|
77
82
|
end
|
data/lib/popper/version.rb
CHANGED