popper 0.2.4 → 0.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72ac0486fff5d4f83876ef9886d1c28995406a2b
4
- data.tar.gz: 74fb566a42ced8e653ec1fb4ba28351a703a51aa
3
+ metadata.gz: f00b7008ef966d2df6766ef842a17a560cf26b83
4
+ data.tar.gz: 0ddadcef3b9fa3513866832e99e74686f567e970
5
5
  SHA512:
6
- metadata.gz: 4b38a249533f6104b875bf86abdcbaa9df13c890bc49fb30adc1048e33e28ba381d5c0fb45cdeb2efed7df4ee95831d06a3ba842c4af30a88e5730f5ccd05e2b
7
- data.tar.gz: 18fc4142645cc586c61f9fa364159a03baa93423b96ffc88c9c5b734224607c4af96e73ee1711601131ecaeb625fcfa118b532819b4ec885b31ca8dd1211e7ca
6
+ metadata.gz: cf618186323477f48b7ecf604cb819b7b30f136ab0bd3bef1ddb929a49a1d437c7263e56a1f48f93d2e2f6fc314766cab30d089820ffcef13b0835b09cacf944
7
+ data.tar.gz: 06fac7bd05a05bd63d843e8f4faf5b4d1812aacfc9b445fc0f0cd262618623a92101c14948670e57969bb44ccdad1bb27047f5316b864e4a2abbec6ddfb95d82
data/README.md CHANGED
@@ -50,6 +50,7 @@ server = "example.com"
50
50
  user = "example@example.com"
51
51
  password = "password"
52
52
  port = 110(default)
53
+ ssl = false
53
54
 
54
55
  # [config_name].default.condition
55
56
  [example.default.condition]
data/lib/popper/cli.rb CHANGED
@@ -65,18 +65,16 @@ module Popper
65
65
  last_rule = nil
66
66
  puts config.name
67
67
 
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)
74
- end
75
-
76
- puts " "*2 + "header[#{mail_header}]"
77
- puts " "*3 + "#{conditions}"
78
- last_rule = rule
68
+ config.rule_with_conditions_each do |rule,mail_header,conditions|
69
+ if rule != last_rule
70
+ puts " "*1 + "rule[#{rule}]"
71
+ puts " "*2 + "actions"
72
+ print_action(config, rule)
79
73
  end
74
+
75
+ puts " "*2 + "header[#{mail_header}]"
76
+ puts " "*3 + "#{conditions}"
77
+ last_rule = rule
80
78
  end
81
79
  end
82
80
 
data/lib/popper/config.rb CHANGED
@@ -39,6 +39,19 @@ module Popper
39
39
  @hash_table
40
40
  end
41
41
 
42
+ [
43
+ %w(find all?),
44
+ %w(each each),
45
+ ].each do |arr|
46
+ define_method("rule_with_conditions_#{arr[0]}") do |&blk|
47
+ self.rules.to_h.keys.send(arr[0]) do |rule|
48
+ self.condition_by_rule(rule).to_h.send(arr[1]) do |mail_header,conditions|
49
+ blk.call(rule, mail_header, conditions)
50
+ end
51
+ end
52
+ end
53
+ end
54
+
42
55
  %w(
43
56
  condition
44
57
  action
@@ -59,10 +72,13 @@ module Popper
59
72
  end
60
73
  }
61
74
 
75
+ # merge global default and account default
62
76
  define_method("#{name}_by_rule") do |rule|
63
77
  hash = self.send("global_default_#{name}")
64
78
  hash = hash.deep_merge(self.send("account_default_#{name}").to_h) if self.send("account_default_#{name}")
65
79
  hash = hash.deep_merge(self.rules.send(rule).send(name).to_h) if rules.send(rule).respond_to?(name.to_sym)
80
+
81
+ # replace body to utf_body
66
82
  AccountAttributes.new(Hash[hash.map {|k,v| [k.to_s.gsub(/^body$/, "utf_body").to_sym, v]}])
67
83
  end
68
84
  end
@@ -4,14 +4,16 @@ require 'kconv'
4
4
 
5
5
  module Popper
6
6
  class MailAccount
7
+ attr_accessor :config, :current_list, :complete_list
8
+
7
9
  def initialize(config)
8
- @config = config
10
+ self.config = config
9
11
  end
10
12
 
11
13
  def run
12
14
  session_start do |conn|
13
- @current_uidl_list = conn.mails.map(&:uidl)
14
- @complete_uidl_list = @current_uidl_list unless @complete_uidl_list
15
+ self.current_list = conn.mails.map(&:uidl)
16
+ self.complete_list = current_list unless complete_list
15
17
  pop(conn)
16
18
  end
17
19
  rescue => e
@@ -22,7 +24,7 @@ module Popper
22
24
  done_uidls = []
23
25
  error_uidls = []
24
26
 
25
- Popper.log.info "start popper #{@config.name}"
27
+ Popper.log.info "start popper #{config.name}"
26
28
 
27
29
  process_uidl_list(conn).each do |m|
28
30
  begin
@@ -31,12 +33,12 @@ module Popper
31
33
 
32
34
  if rule = match_rule?(mail)
33
35
  Popper.log.info "do action:#{mail.subject}"
34
- Popper::Action::Git.run(@config.action_by_rule(rule), mail) if @config.action_by_rule(rule)
36
+ Popper::Action::Git.run(config.action_by_rule(rule), mail) if config.action_by_rule(rule)
35
37
  end
36
38
  done_uidls << m.uidl
37
39
 
38
40
  rescue Net::POPError => e
39
- @complete_uidl_list += done_uidls
41
+ self.complete_list += done_uidls
40
42
  Popper.log.warn "pop err write uidl"
41
43
  return
42
44
  rescue => e
@@ -45,38 +47,38 @@ module Popper
45
47
  end
46
48
  end
47
49
 
48
- @complete_uidl_list = @current_uidl_list - error_uidls
49
- Popper.log.info "success popper #{@config.name}"
50
+ self.complete_list = current_list - error_uidls
51
+ Popper.log.info "success popper #{config.name}"
50
52
  end
51
53
 
52
54
  def session_start(&block)
53
- pop = Net::POP3.new(@config.login.server, @config.login.port || 110)
55
+ pop = Net::POP3.new(config.login.server, config.login.port || 110)
56
+ pop.enable_ssl if config.login.respond_to?(:ssl) && config.login.ssl
57
+
54
58
  %w(
55
59
  open_timeout
56
60
  read_timeout
57
61
  ).each {|m| pop.instance_variable_set("@#{m}", ENV['POP_TIMEOUT'] || 120) }
58
62
 
59
63
  pop.start(
60
- @config.login.user,
61
- @config.login.password
64
+ config.login.user,
65
+ config.login.password
62
66
  ) do |pop|
63
- Popper.log.info "connect server #{@config.name}"
67
+ Popper.log.info "connect server #{config.name}"
64
68
  block.call(pop)
65
- Popper.log.info "disconnect server #{@config.name}"
69
+ Popper.log.info "disconnect server #{config.name}"
66
70
  end
67
71
  end
68
72
 
69
73
  def process_uidl_list(conn)
70
- uidl_list = @current_uidl_list - @complete_uidl_list
74
+ uidl_list = current_list - complete_list
71
75
  conn.mails.select {|_m|uidl_list.include?(_m.uidl)}
72
76
  end
73
77
 
74
78
  def match_rule?(mail)
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
79
+ config.rule_with_conditions_find do |rule,mail_header,conditions|
80
+ conditions.all? do |condition|
81
+ mail.respond_to?(mail_header) && mail.send(mail_header).to_s.match(/#{condition}/)
80
82
  end
81
83
  end
82
84
  end
@@ -1,3 +1,3 @@
1
1
  module Popper
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: popper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyama86
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-10 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor