Skip to content

Instantly share code, notes, and snippets.

@Laeeth
Created June 26, 2017 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Laeeth/e9b6af21250de0f52586f12ffe07f0a8 to your computer and use it in GitHub Desktop.
Save Laeeth/e9b6af21250de0f52586f12ffe07f0a8 to your computer and use it in GitHub Desktop.
Make postgrey/spamassassin whitelist
#!/usr/bin/dmd
import std.stdio;
import std.string;
import std.process;
import std.algorithm;
import std.array:array;
import std.typecons:Tuple;
import std.file:exists;
enum whitelists=[ "/etc/mail/spamassassin/sent_whitelist.txt",
"/etc/mail/spamassassin/vcard_whitelist.txt"
];
enum postgreyWhitelistPath="/etc/postfix/postgrey_whitelist_clients.local";
int main(string[] args)
{
bool all=(args.length==2 && args[1]=="--all");
string result;
foreach(file;whitelists)
{
result~=(cast(string)std.file.read(file))
.splitLines
.map!(a=>a.extractDomain)
.array
.sort
.uniq
.filter!(a=>(a.length>0))
.join("\n");
}
std.file.write(postgreyWhitelistPath,result);
return 0;
}
string extractDomain(string entry)
{
auto i=entry.indexOf("@");
if ((i==-1)||(i==entry.length-1))
return "";
return entry[i+1..$].strip;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment