popper 0.2.8 → 0.2.9
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/README.md +4 -2
 - data/lib/popper/action.rb +5 -4
 - data/lib/popper/action/base.rb +12 -11
 - data/lib/popper/action/exec_cmd.rb +18 -0
 - data/lib/popper/action/ghe.rb +0 -1
 - data/lib/popper/action/git.rb +1 -2
 - data/lib/popper/action/slack.rb +0 -1
 - data/lib/popper/cli.rb +5 -8
 - data/lib/popper/config.rb +48 -36
 - data/lib/popper/init.rb +0 -1
 - data/lib/popper/mail_account.rb +26 -17
 - data/lib/popper/version.rb +1 -1
 - metadata +4 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 3bf4501b5c03655837fa6f91f609315df3577a21
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: cc12464e2003de2852826154f3c978f692421e00
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: eb915ab4ce61eb8bc11353c848639fa953d41ce85608830696505dee7ebced3602325ee88b3dc2ac5ba1d35e82562b70241582d3cbeb2e9261875a44aaa97e9d
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 61a374239c807012c5ff25c137e7237d590cb47f7e63cb9e746af2a5d5f82ac5d56edb8f982f70def8135c9ea3599fdbad23704cd6028de0ff7d307c0e73fdc7
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -7,6 +7,7 @@ 
     | 
|
| 
       7 
7 
     | 
    
         
             
            To post a variety of services by analyzing the email
         
     | 
| 
       8 
8 
     | 
    
         
             
            * slack notification
         
     | 
| 
       9 
9 
     | 
    
         
             
            * create issue to github.com or ghe
         
     | 
| 
      
 10 
     | 
    
         
            +
            * exec arbitrary commands
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
       11 
12 
     | 
    
         
             
            # install
         
     | 
| 
       12 
13 
     | 
    
         
             
              $ gem install popper
         
     | 
| 
         @@ -30,7 +31,6 @@ systmd service config: https://github.com/pyama86/popper/tree/master/init_script 
     | 
|
| 
       30 
31 
     | 
    
         
             
            ## ~/popper/popper.conf
         
     | 
| 
       31 
32 
     | 
    
         
             
            ```
         
     | 
| 
       32 
33 
     | 
    
         
             
            include = ["/etc/popper/*.conf"]
         
     | 
| 
       33 
     | 
    
         
            -
            [global]
         
     | 
| 
       34 
34 
     | 
    
         
             
            interval = 60         # fetch interbal default:60
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
            [default.condition]
         
     | 
| 
         @@ -74,9 +74,11 @@ mentions = ["@user"] 
     | 
|
| 
       74 
74 
     | 
    
         
             
            message = "webmailer error mail"
         
     | 
| 
       75 
75 
     | 
    
         | 
| 
       76 
76 
     | 
    
         
             
            [example.rules.normal_log.action.git]
         
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
77 
     | 
    
         
             
            repo = "example/fuu"
         
     | 
| 
       79 
78 
     | 
    
         | 
| 
      
 79 
     | 
    
         
            +
            [example.rules.normal_log.action.exec_cmd]
         
     | 
| 
      
 80 
     | 
    
         
            +
            repo = "/path/to/other_command.rb"
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
       80 
82 
     | 
    
         
             
            [example2.login]
         
     | 
| 
       81 
83 
     | 
    
         
             
            user = "example2@example.com"
         
     | 
| 
       82 
84 
     | 
    
         
             
            ...
         
     | 
    
        data/lib/popper/action.rb
    CHANGED
    
    | 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Popper::Action
         
     | 
| 
       2 
     | 
    
         
            -
              autoload :Base, 
     | 
| 
       3 
     | 
    
         
            -
              autoload :Slack, 
     | 
| 
       4 
     | 
    
         
            -
              autoload :Ghe, 
     | 
| 
       5 
     | 
    
         
            -
              autoload :Git, 
     | 
| 
      
 2 
     | 
    
         
            +
              autoload :Base,    "popper/action/base"
         
     | 
| 
      
 3 
     | 
    
         
            +
              autoload :Slack,   "popper/action/slack"
         
     | 
| 
      
 4 
     | 
    
         
            +
              autoload :Ghe,     "popper/action/ghe"
         
     | 
| 
      
 5 
     | 
    
         
            +
              autoload :Git,     "popper/action/git"
         
     | 
| 
      
 6 
     | 
    
         
            +
              autoload :ExecCmd, "popper/action/exec_cmd"
         
     | 
| 
       6 
7 
     | 
    
         
             
            end
         
     | 
    
        data/lib/popper/action/base.rb
    CHANGED
    
    | 
         @@ -1,19 +1,18 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Popper::Action
         
     | 
| 
       2 
2 
     | 
    
         
             
              class Base
         
     | 
| 
       3 
3 
     | 
    
         
             
                @next_action = nil
         
     | 
| 
       4 
     | 
    
         
            -
                @action = nil
         
     | 
| 
       5 
4 
     | 
    
         
             
                @action_config = nil
         
     | 
| 
       6 
5 
     | 
    
         | 
| 
       7 
6 
     | 
    
         
             
                def self.run(config, mail, params={})
         
     | 
| 
       8 
     | 
    
         
            -
                  @action_config = config.send( 
     | 
| 
      
 7 
     | 
    
         
            +
                  @action_config = config.send(action_name) if config.respond_to?(action_name)
         
     | 
| 
       9 
8 
     | 
    
         
             
                  begin
         
     | 
| 
       10 
     | 
    
         
            -
                    Popper.log.info "run action #{ 
     | 
| 
      
 9 
     | 
    
         
            +
                    Popper.log.info "run action #{action_name}"
         
     | 
| 
       11 
10 
     | 
    
         
             
                    params = task(mail, params)
         
     | 
| 
       12 
     | 
    
         
            -
                    Popper.log.info "exit action #{ 
     | 
| 
      
 11 
     | 
    
         
            +
                    Popper.log.info "exit action #{action_name}"
         
     | 
| 
       13 
12 
     | 
    
         
             
                  rescue => e
         
     | 
| 
       14 
13 
     | 
    
         
             
                    Popper.log.warn e
         
     | 
| 
       15 
14 
     | 
    
         
             
                    Popper.log.warn e.backtrace
         
     | 
| 
       16 
     | 
    
         
            -
                  end if  
     | 
| 
      
 15 
     | 
    
         
            +
                  end if do_action?
         
     | 
| 
       17 
16 
     | 
    
         
             
                  next_run(config, mail, params)
         
     | 
| 
       18 
17 
     | 
    
         
             
                end
         
     | 
| 
       19 
18 
     | 
    
         | 
| 
         @@ -22,18 +21,20 @@ module Popper::Action 
     | 
|
| 
       22 
21 
     | 
    
         
             
                  @next_action
         
     | 
| 
       23 
22 
     | 
    
         
             
                end
         
     | 
| 
       24 
23 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
                def self.action(action=nil)
         
     | 
| 
       26 
     | 
    
         
            -
                  @action = action if action
         
     | 
| 
       27 
     | 
    
         
            -
                  @action
         
     | 
| 
       28 
     | 
    
         
            -
                end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
24 
     | 
    
         
             
                def self.next_run(config, mail, params={})
         
     | 
| 
       31 
25 
     | 
    
         
             
                  @next_action.run(config, mail, params) if @next_action
         
     | 
| 
       32 
26 
     | 
    
         
             
                end
         
     | 
| 
       33 
27 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                def self. 
     | 
| 
      
 28 
     | 
    
         
            +
                def self.do_action?
         
     | 
| 
       35 
29 
     | 
    
         
             
                  @action_config && check_params
         
     | 
| 
       36 
30 
     | 
    
         
             
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                def self.action_name
         
     | 
| 
      
 33 
     | 
    
         
            +
                  self.name.split('::').last.downcase.to_sym
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
       37 
38 
     | 
    
         
             
                def self.check_params; end
         
     | 
| 
       38 
39 
     | 
    
         
             
              end
         
     | 
| 
       39 
40 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,18 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Popper::Action
         
     | 
| 
      
 2 
     | 
    
         
            +
              class ExecCmd < Base
         
     | 
| 
      
 3 
     | 
    
         
            +
                def self.task(mail, params={})
         
     | 
| 
      
 4 
     | 
    
         
            +
                  system(@action_config.cmd, mail.subject, mail.utf_body)
         
     | 
| 
      
 5 
     | 
    
         
            +
                  params
         
     | 
| 
      
 6 
     | 
    
         
            +
                end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                def self.check_params
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @action_config.respond_to?(:cmd)
         
     | 
| 
      
 10 
     | 
    
         
            +
                end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                def self.action_name
         
     | 
| 
      
 13 
     | 
    
         
            +
                  :exec_cmd
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                next_action(Git)
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/popper/action/ghe.rb
    CHANGED
    
    
    
        data/lib/popper/action/git.rb
    CHANGED
    
    | 
         @@ -8,7 +8,7 @@ module Popper::Action 
     | 
|
| 
       8 
8 
     | 
    
         
             
                    mail.subject,
         
     | 
| 
       9 
9 
     | 
    
         
             
                    mail.utf_body
         
     | 
| 
       10 
10 
     | 
    
         
             
                  )
         
     | 
| 
       11 
     | 
    
         
            -
                  params["#{ 
     | 
| 
      
 11 
     | 
    
         
            +
                  params["#{action_name}_url".to_sym] = url[:html_url] if url
         
     | 
| 
       12 
12 
     | 
    
         
             
                  params
         
     | 
| 
       13 
13 
     | 
    
         
             
                end
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
         @@ -23,6 +23,5 @@ module Popper::Action 
     | 
|
| 
       23 
23 
     | 
    
         
             
                end
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
                next_action(Ghe)
         
     | 
| 
       26 
     | 
    
         
            -
                action(:git)
         
     | 
| 
       27 
26 
     | 
    
         
             
              end
         
     | 
| 
       28 
27 
     | 
    
         
             
            end
         
     | 
    
        data/lib/popper/action/slack.rb
    CHANGED
    
    
    
        data/lib/popper/cli.rb
    CHANGED
    
    | 
         @@ -20,16 +20,13 @@ module Popper 
     | 
|
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
                  Popper.load_config(options)
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                  accounts = Popper.configure.accounts.map  
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                             else
         
     | 
| 
       28 
     | 
    
         
            -
                               60
         
     | 
| 
       29 
     | 
    
         
            -
                             end
         
     | 
| 
      
 23 
     | 
    
         
            +
                  accounts = Popper.configure.accounts.map do |account|
         
     | 
| 
      
 24 
     | 
    
         
            +
                    MailAccount.new(account)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end.compact
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
       30 
27 
     | 
    
         
             
                  while true
         
     | 
| 
       31 
28 
     | 
    
         
             
                    accounts.each(&:run)
         
     | 
| 
       32 
     | 
    
         
            -
                    sleep(interval)
         
     | 
| 
      
 29 
     | 
    
         
            +
                    sleep(Popper.configure.interval)
         
     | 
| 
       33 
30 
     | 
    
         
             
                  end
         
     | 
| 
       34 
31 
     | 
    
         | 
| 
       35 
32 
     | 
    
         
             
                  rescue => e
         
     | 
    
        data/lib/popper/config.rb
    CHANGED
    
    | 
         @@ -3,45 +3,56 @@ require 'ostruct' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require 'logger'
         
     | 
| 
       4 
4 
     | 
    
         
             
            module Popper
         
     | 
| 
       5 
5 
     | 
    
         
             
              class Config
         
     | 
| 
       6 
     | 
    
         
            -
                attr_reader : 
     | 
| 
      
 6 
     | 
    
         
            +
                attr_reader :default, :accounts, :interval
         
     | 
| 
       7 
7 
     | 
    
         
             
                def initialize(config_path)
         
     | 
| 
       8 
8 
     | 
    
         
             
                  raise "configure not fond #{config_path}" unless File.exist?(config_path)
         
     | 
| 
       9 
     | 
    
         
            -
                  config =  
     | 
| 
       10 
     | 
    
         
            -
                  if config.key?("include")
         
     | 
| 
       11 
     | 
    
         
            -
                    content = config["include"].map {|p| Dir.glob(p).map {|f|File.read(f)}}.join("\n")
         
     | 
| 
       12 
     | 
    
         
            -
                    config.delete("include")
         
     | 
| 
       13 
     | 
    
         
            -
                    config.deep_merge!(TOML::Parser.new(content).parsed)
         
     | 
| 
       14 
     | 
    
         
            -
                  end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                  @global  = AccountAttributes.new(config["global"]) if config["global"]
         
     | 
| 
       17 
     | 
    
         
            -
                  @default = AccountAttributes.new(config["default"]) if config["default"]
         
     | 
| 
       18 
     | 
    
         
            -
                  @accounts = []
         
     | 
| 
      
 9 
     | 
    
         
            +
                  config = read_file(config_path)
         
     | 
| 
       19 
10 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
                   
     | 
| 
      
 11 
     | 
    
         
            +
                  @interval = config.key?("interval") ? config["interval"].to_i : 60
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @default = config["default"] if config["default"]
         
     | 
| 
      
 13 
     | 
    
         
            +
                  @accounts = config.select {|k,v| v.is_a?(Hash) && v.key?("login") }.map do |account|
         
     | 
| 
       21 
14 
     | 
    
         
             
                    _account = AccountAttributes.new(account[1])
         
     | 
| 
       22 
15 
     | 
    
         
             
                    _account.name = account[0]
         
     | 
| 
       23 
     | 
    
         
            -
                     
     | 
| 
      
 16 
     | 
    
         
            +
                    _account
         
     | 
| 
       24 
17 
     | 
    
         
             
                  end
         
     | 
| 
       25 
18 
     | 
    
         
             
                end
         
     | 
| 
       26 
19 
     | 
    
         | 
| 
      
 20 
     | 
    
         
            +
                def read_file(file)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  config = TOML.load_file(file)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  if config.key?("include")
         
     | 
| 
      
 23 
     | 
    
         
            +
                    content = config["include"].map {|p| Dir.glob(p).map {|f|File.read(f)}}.join("\n")
         
     | 
| 
      
 24 
     | 
    
         
            +
                    config.deep_merge!(TOML::Parser.new(content).parsed)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
                  config
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                %w(
         
     | 
| 
      
 30 
     | 
    
         
            +
                  condition
         
     | 
| 
      
 31 
     | 
    
         
            +
                  action
         
     | 
| 
      
 32 
     | 
    
         
            +
                ).each do |name|
         
     | 
| 
      
 33 
     | 
    
         
            +
                  define_method("default_#{name}") {
         
     | 
| 
      
 34 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 35 
     | 
    
         
            +
                      default[name]
         
     | 
| 
      
 36 
     | 
    
         
            +
                    rescue
         
     | 
| 
      
 37 
     | 
    
         
            +
                      {}
         
     | 
| 
      
 38 
     | 
    
         
            +
                    end
         
     | 
| 
      
 39 
     | 
    
         
            +
                  }
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
       27 
41 
     | 
    
         
             
              end
         
     | 
| 
       28 
42 
     | 
    
         | 
| 
       29 
43 
     | 
    
         
             
              class AccountAttributes < OpenStruct
         
     | 
| 
       30 
44 
     | 
    
         
             
                def initialize(hash=nil)
         
     | 
| 
       31 
45 
     | 
    
         
             
                  @table = {}
         
     | 
| 
       32 
     | 
    
         
            -
                  @ 
     | 
| 
      
 46 
     | 
    
         
            +
                  @hash = hash
         
     | 
| 
       33 
47 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                   
     | 
| 
       35 
     | 
    
         
            -
                     
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                      new_ostruct_member(k)
         
     | 
| 
       39 
     | 
    
         
            -
                    end
         
     | 
| 
       40 
     | 
    
         
            -
                  end
         
     | 
| 
      
 48 
     | 
    
         
            +
                  hash.each do |k,v|
         
     | 
| 
      
 49 
     | 
    
         
            +
                    @table[k.to_sym] = (v.is_a?(Hash) ? self.class.new(v) : v)
         
     | 
| 
      
 50 
     | 
    
         
            +
                    new_ostruct_member(k)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  end if hash
         
     | 
| 
       41 
52 
     | 
    
         
             
                end
         
     | 
| 
       42 
53 
     | 
    
         | 
| 
       43 
54 
     | 
    
         
             
                def to_h
         
     | 
| 
       44 
     | 
    
         
            -
                  @ 
     | 
| 
      
 55 
     | 
    
         
            +
                  @hash
         
     | 
| 
       45 
56 
     | 
    
         
             
                end
         
     | 
| 
       46 
57 
     | 
    
         | 
| 
       47 
58 
     | 
    
         
             
                [
         
     | 
| 
         @@ -49,7 +60,7 @@ module Popper 
     | 
|
| 
       49 
60 
     | 
    
         
             
                  %w(each each),
         
     | 
| 
       50 
61 
     | 
    
         
             
                ].each do |arr|
         
     | 
| 
       51 
62 
     | 
    
         
             
                  define_method("rule_with_conditions_#{arr[0]}") do |&blk|
         
     | 
| 
       52 
     | 
    
         
            -
                     
     | 
| 
      
 63 
     | 
    
         
            +
                    @hash["rules"].keys.send(arr[0]) do |rule|
         
     | 
| 
       53 
64 
     | 
    
         
             
                      self.condition_by_rule(rule).to_h.send(arr[1]) do |mail_header,conditions|
         
     | 
| 
       54 
65 
     | 
    
         
             
                        blk.call(rule, mail_header, conditions)
         
     | 
| 
       55 
66 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -61,32 +72,33 @@ module Popper 
     | 
|
| 
       61 
72 
     | 
    
         
             
                  condition
         
     | 
| 
       62 
73 
     | 
    
         
             
                  action
         
     | 
| 
       63 
74 
     | 
    
         
             
                ).each do |name|
         
     | 
| 
       64 
     | 
    
         
            -
                  define_method("global_default_#{name}") {
         
     | 
| 
       65 
     | 
    
         
            -
                    begin
         
     | 
| 
       66 
     | 
    
         
            -
                      Popper.configure.default.send(name).to_h
         
     | 
| 
       67 
     | 
    
         
            -
                    rescue
         
     | 
| 
       68 
     | 
    
         
            -
                      {}
         
     | 
| 
       69 
     | 
    
         
            -
                    end
         
     | 
| 
       70 
     | 
    
         
            -
                  }
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
75 
     | 
    
         
             
                  define_method("account_default_#{name}") {
         
     | 
| 
       73 
76 
     | 
    
         
             
                    begin
         
     | 
| 
       74 
     | 
    
         
            -
                       
     | 
| 
      
 77 
     | 
    
         
            +
                      @hash["default"][name]
         
     | 
| 
       75 
78 
     | 
    
         
             
                    rescue
         
     | 
| 
       76 
79 
     | 
    
         
             
                      {}
         
     | 
| 
       77 
80 
     | 
    
         
             
                    end
         
     | 
| 
       78 
81 
     | 
    
         
             
                  }
         
     | 
| 
       79 
82 
     | 
    
         | 
| 
       80 
     | 
    
         
            -
                  # merge  
     | 
| 
      
 83 
     | 
    
         
            +
                  # merge default and account default
         
     | 
| 
       81 
84 
     | 
    
         
             
                  define_method("#{name}_by_rule") do |rule|
         
     | 
| 
       82 
     | 
    
         
            -
                    hash =  
     | 
| 
       83 
     | 
    
         
            -
                    hash = hash.deep_merge(self.send("account_default_#{name}") 
     | 
| 
       84 
     | 
    
         
            -
                    hash = hash.deep_merge( 
     | 
| 
      
 85 
     | 
    
         
            +
                    hash = Popper.configure.send("default_#{name}")
         
     | 
| 
      
 86 
     | 
    
         
            +
                    hash = hash.deep_merge(self.send("account_default_#{name}")) if self.send("account_default_#{name}")
         
     | 
| 
      
 87 
     | 
    
         
            +
                    hash = hash.deep_merge(rule_by_name(rule)[name]) if rule_by_name(rule).key?(name)
         
     | 
| 
       85 
88 
     | 
    
         | 
| 
       86 
89 
     | 
    
         
             
                    # replace body to utf_body
         
     | 
| 
       87 
90 
     | 
    
         
             
                    AccountAttributes.new(Hash[hash.map {|k,v| [k.to_s.gsub(/^body$/, "utf_body").to_sym, v]}])
         
     | 
| 
       88 
91 
     | 
    
         
             
                  end
         
     | 
| 
       89 
92 
     | 
    
         
             
                end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                def rule_by_name(name)
         
     | 
| 
      
 95 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 96 
     | 
    
         
            +
                    @hash["rules"][name]
         
     | 
| 
      
 97 
     | 
    
         
            +
                  rescue
         
     | 
| 
      
 98 
     | 
    
         
            +
                    {}
         
     | 
| 
      
 99 
     | 
    
         
            +
                  end
         
     | 
| 
      
 100 
     | 
    
         
            +
                end
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
       90 
102 
     | 
    
         
             
              end
         
     | 
| 
       91 
103 
     | 
    
         | 
| 
       92 
104 
     | 
    
         
             
              def self.load_config(options)
         
     | 
    
        data/lib/popper/init.rb
    CHANGED
    
    
    
        data/lib/popper/mail_account.rb
    CHANGED
    
    | 
         @@ -28,15 +28,7 @@ module Popper 
     | 
|
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
                  process_uidl_list(conn).each do |m|
         
     | 
| 
       30 
30 
     | 
    
         
             
                    begin
         
     | 
| 
       31 
     | 
    
         
            -
                       
     | 
| 
       32 
     | 
    
         
            -
                      Popper.log.info "check mail:#{mail.date.to_s} #{mail.subject}"
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                      if rule = match_rule?(mail)
         
     | 
| 
       35 
     | 
    
         
            -
                        Popper.log.info "do action:#{mail.subject}"
         
     | 
| 
       36 
     | 
    
         
            -
                        Popper::Action::Git.run(config.action_by_rule(rule), mail) if config.action_by_rule(rule)
         
     | 
| 
       37 
     | 
    
         
            -
                      end
         
     | 
| 
       38 
     | 
    
         
            -
                      done_uidls << m.uidl
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
                      done_uidls << check_and_action(m)
         
     | 
| 
       40 
32 
     | 
    
         
             
                    rescue Net::POPError => e
         
     | 
| 
       41 
33 
     | 
    
         
             
                      self.complete_list += done_uidls
         
     | 
| 
       42 
34 
     | 
    
         
             
                      Popper.log.warn "pop err write uidl"
         
     | 
| 
         @@ -51,25 +43,42 @@ module Popper 
     | 
|
| 
       51 
43 
     | 
    
         
             
                  Popper.log.info "success popper #{config.name}"
         
     | 
| 
       52 
44 
     | 
    
         
             
                end
         
     | 
| 
       53 
45 
     | 
    
         | 
| 
      
 46 
     | 
    
         
            +
                def check_and_action(m)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  mail = EncodeMail.new(m.mail)
         
     | 
| 
      
 48 
     | 
    
         
            +
                  Popper.log.info "check mail:#{mail.date.to_s} #{mail.subject}"
         
     | 
| 
      
 49 
     | 
    
         
            +
                  if rule = match_rule?(mail)
         
     | 
| 
      
 50 
     | 
    
         
            +
                    Popper.log.info "do action:#{mail.subject}"
         
     | 
| 
      
 51 
     | 
    
         
            +
                    Popper::Action::ExecCmd.run(config.action_by_rule(rule), mail) if config.action_by_rule(rule)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                  m.uidl
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
       54 
57 
     | 
    
         
             
                def session_start(&block)
         
     | 
| 
       55 
58 
     | 
    
         
             
                  pop = Net::POP3.new(config.login.server, config.login.port || 110)
         
     | 
| 
       56 
     | 
    
         
            -
                  pop 
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
                  %w(
         
     | 
| 
       59 
     | 
    
         
            -
                    open_timeout
         
     | 
| 
       60 
     | 
    
         
            -
                    read_timeout
         
     | 
| 
       61 
     | 
    
         
            -
                  ).each {|m| pop.instance_variable_set("@#{m}", ENV['POP_TIMEOUT'] || 120) }
         
     | 
| 
      
 59 
     | 
    
         
            +
                  pop = set_pop_option(pop)
         
     | 
| 
       62 
60 
     | 
    
         | 
| 
       63 
61 
     | 
    
         
             
                  pop.start(
         
     | 
| 
       64 
62 
     | 
    
         
             
                    config.login.user,
         
     | 
| 
       65 
63 
     | 
    
         
             
                    config.login.password
         
     | 
| 
       66 
     | 
    
         
            -
                  ) do | 
     | 
| 
      
 64 
     | 
    
         
            +
                  ) do |conn|
         
     | 
| 
       67 
65 
     | 
    
         
             
                    Popper.log.info "connect server #{config.name}"
         
     | 
| 
       68 
     | 
    
         
            -
                    block.call( 
     | 
| 
      
 66 
     | 
    
         
            +
                    block.call(conn)
         
     | 
| 
       69 
67 
     | 
    
         
             
                    Popper.log.info "disconnect server #{config.name}"
         
     | 
| 
       70 
68 
     | 
    
         
             
                  end
         
     | 
| 
       71 
69 
     | 
    
         
             
                end
         
     | 
| 
       72 
70 
     | 
    
         | 
| 
      
 71 
     | 
    
         
            +
                def set_pop_option(pop)
         
     | 
| 
      
 72 
     | 
    
         
            +
                  pop.enable_ssl if config.login.respond_to?(:ssl) && config.login.ssl
         
     | 
| 
      
 73 
     | 
    
         
            +
                  %w(
         
     | 
| 
      
 74 
     | 
    
         
            +
                    open_timeout
         
     | 
| 
      
 75 
     | 
    
         
            +
                    read_timeout
         
     | 
| 
      
 76 
     | 
    
         
            +
                  ).each do |m|
         
     | 
| 
      
 77 
     | 
    
         
            +
                    pop.instance_variable_set("@#{m}", ENV['POP_TIMEOUT'] || 120)
         
     | 
| 
      
 78 
     | 
    
         
            +
                  end
         
     | 
| 
      
 79 
     | 
    
         
            +
                  pop
         
     | 
| 
      
 80 
     | 
    
         
            +
                end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
       73 
82 
     | 
    
         
             
                def process_uidl_list(conn)
         
     | 
| 
       74 
83 
     | 
    
         
             
                  uidl_list = current_list - complete_list
         
     | 
| 
       75 
84 
     | 
    
         
             
                  conn.mails.select {|_m|uidl_list.include?(_m.uidl)}
         
     | 
    
        data/lib/popper/version.rb
    CHANGED
    
    
    
        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 
     | 
    
         
            +
              version: 0.2.9
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - pyama86
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-03-21 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: thor
         
     | 
| 
         @@ -143,6 +143,7 @@ files: 
     | 
|
| 
       143 
143 
     | 
    
         
             
            - lib/popper.rb
         
     | 
| 
       144 
144 
     | 
    
         
             
            - lib/popper/action.rb
         
     | 
| 
       145 
145 
     | 
    
         
             
            - lib/popper/action/base.rb
         
     | 
| 
      
 146 
     | 
    
         
            +
            - lib/popper/action/exec_cmd.rb
         
     | 
| 
       146 
147 
     | 
    
         
             
            - lib/popper/action/ghe.rb
         
     | 
| 
       147 
148 
     | 
    
         
             
            - lib/popper/action/git.rb
         
     | 
| 
       148 
149 
     | 
    
         
             
            - lib/popper/action/slack.rb
         
     | 
| 
         @@ -172,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       172 
173 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       173 
174 
     | 
    
         
             
            requirements: []
         
     | 
| 
       174 
175 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       175 
     | 
    
         
            -
            rubygems_version: 2. 
     | 
| 
      
 176 
     | 
    
         
            +
            rubygems_version: 2.4.5.1
         
     | 
| 
       176 
177 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       177 
178 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       178 
179 
     | 
    
         
             
            summary: email notification tool
         
     |