Class: PostfixAdmin::Doveadm

Inherits:
Object
  • Object
show all
Defined in:
lib/postfix_admin/doveadm.rb

Class Method Summary collapse

Class Method Details

.command_nameObject



23
24
25
26
27
28
29
30
# File 'lib/postfix_admin/doveadm.rb', line 23

def self.command_name
  begin
    Open3.capture3("doveadm pw -l")[2].exited?
    "doveadm pw"
  rescue Errno::ENOENT
    "dovecotpw"
  end
end

.password(in_password, in_scheme) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/postfix_admin/doveadm.rb', line 12

def self.password(in_password, in_scheme)
  password = Shellwords.escape(in_password)
  scheme  = Shellwords.escape(in_scheme)
  stdin, stdout, stderr = Open3.popen3("#{self.command_name} -s #{scheme} -p #{password}")
  if stderr.readlines.to_s =~ /Fatal:/
    raise Error, stderr.readlines
  else
    stdout.readlines.first.chomp.gsub("{#{scheme}}", "")
  end
end

.schemesObject



7
8
9
10
# File 'lib/postfix_admin/doveadm.rb', line 7

def self.schemes
  result = `#{self.command_name} -l`
  result.split
end