Created
February 9, 2009 04:03
-
-
Save postpostmodern/60650 to your computer and use it in GitHub Desktop.
Creates qmail aliases (see http://postpostmodern.com/downloadable/quick-email-aliases-on-media-temple/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/ruby | |
require 'fileutils' | |
unless ARGV.size > 1 | |
puts "Usage: #{__FILE__} [email protected] 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