Created
June 26, 2017 19:48
-
-
Save Laeeth/e9b6af21250de0f52586f12ffe07f0a8 to your computer and use it in GitHub Desktop.
Make postgrey/spamassassin whitelist
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/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