Class: Popper::Action::ExecCmd

Inherits:
Base
  • Object
show all
Defined in:
lib/popper/action/exec_cmd.rb

Class Method Summary collapse

Methods inherited from Base

do_action?, next_action, next_run, run

Class Method Details

.action_nameObject



27
28
29
# File 'lib/popper/action/exec_cmd.rb', line 27

def self.action_name
  :exec_cmd
end

.check_paramsObject



23
24
25
# File 'lib/popper/action/exec_cmd.rb', line 23

def self.check_params
  @action_config.respond_to?(:cmd)
end

.task(mail, params = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/popper/action/exec_cmd.rb', line 6

def self.task(mail, params = {})
  unless mail.attachments.empty?
    tmps = mail.attachments.map do |a|
      ::Tempfile.open(a.filename) do |f|
        f.write a.body.decoded
        f
      end
    end
  end
  cmd = "#{@action_config.cmd} #{Shellwords.escape(mail.subject)} #{Shellwords.escape(mail.utf_body)} #{Shellwords.escape(mail.from.join(';'))} #{Shellwords.escape(mail.to.join(';'))}"
  cmd += " #{tmps.map { |t| Shellwords.escape(t.path) }.join(' ')}" if tmps && !tmps.empty?
  ::Bundler.with_clean_env do
    system(cmd)
  end
  params
end