Skip to content

Instantly share code, notes, and snippets.

@postpostmodern
Created February 9, 2009 04:03
Show Gist options
  • Save postpostmodern/60650 to your computer and use it in GitHub Desktop.
Save postpostmodern/60650 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
require 'fileutils'
unless ARGV.size > 1
puts "Usage: #{__FILE__} alias@domain.com email [ email ] ..."
exit
end
QMAIL_DIR = "/var/qmail/mailnames"
alias_address = ARGV.shift
domain = alias_address.match(/[^@]+$/).to_s
path = File.join(QMAIL_DIR, domain)
alias_name = alias_address.match(/^\w+/).to_s
file_name = File.join(path,".qmail-#{alias_name}")
unless File.directory?(path)
puts "The domain #{domain} doesn't exist! Aborted."
puts "#{path} doesn't exist!"
exit
end
if File.exists?(file_name)
puts "This alias already forwards to:"
puts IO.read(file_name)
print "Add, Overwrite, Cancel? [Aoc]"
input = STDIN.gets.chomp.strip
end
case input
when "c", "C"
puts " Cancelled"
exit
when "O", "o"
FileUtils.rm_f(file_name)
end
ARGV.each do |email|
`echo "&#{email}" >> #{file_name}`
end
FileUtils.chmod(0600, file_name)
FileUtils.chown('popuser', 'popuser', file_name)
puts "Alias added"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment