Created
July 9, 2012 19:55
-
-
Save boncey/3078523 to your computer and use it in GitHub Desktop.
Rudimentary script to convert my qmail/vpopmail mail forwarding rules to exim
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/bin/env ruby | |
def addr(file) | |
if (file =~ /.qmail-default/) | |
address = "*" | |
elsif (file =~ /.qmail-(.+)/) | |
address = $1 | |
end | |
address | |
end | |
def dest(rules) | |
dest_addr = nil | |
if (rules.lines.count == 1) | |
if (rules =~ /\| .+vdelivermail '' ([A-Z0-9+_.-]+@[A-Z0-9.-]+)/i) | |
dest_addr = $1 | |
elsif (rules =~ /^([A-Z0-9+_.-]+@[A-Z0-9.-]+)$/i) | |
dest_addr = $1 | |
elsif (rules =~ /^&([A-Z0-9+_.-]+@[A-Z0-9.-]+)$/i) | |
dest_addr = $1 | |
elsif (rules =~ /\| .+vdelivermail '' delete/i) | |
dest_addr = ":blackhole:" | |
elsif (rules.strip == "#") | |
dest_addr = ":blackhole:" | |
end | |
end | |
dest_addr | |
end | |
if ARGV.size != 1 | |
puts("Usage: qmail-to-exim <qmail dir>") | |
exit | |
end | |
path = ARGV[0] | |
$stderr.puts("Reading files from #{path}") | |
Dir.glob("#{path}/.qmail-*").each do |file| | |
name = addr(file) | |
rules = File.read(file) | |
dest_addr = dest(rules) | |
if (dest_addr) | |
exim_rule = "#{name}: #{dest_addr}" | |
puts exim_rule | |
else | |
$stderr.puts("Unable to parse address from #{file}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment