Sha256: 40bc55560a2918ec194ca7142af4310b90477e1b1407a02c94535aa61f624c0f

Contents?: true

Size: 732 Bytes

Versions: 1

Compression:

Stored size: 732 Bytes

Contents

require 'open3'
require 'shellwords'

module PostfixAdmin
  class Doveadm
    def self.schemes
      result = `#{self.command_name} -l`
      result.split
    end

    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
      end
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
postfix_admin-0.2.0 lib/postfix_admin/doveadm.rb