#import std #import nat #import cli usage = -[ blip - block mail containing urls with blacklisted ip addresses Copyright (C) 2008 Dennis Furey usage: blip BLACKLIST MBOXFILE file parameters: BLACKLIST contains one dotted decimal ip address per line MBOXFILE contains mail messages in standard mbox format]- ------------------- function declarations ------------------------ messages = # lexes a mailbox file into a list of messages rlc ~&r; not =]'From '&& sep` ; ~&F; length==7&& ~&w/`@+ ~&th urls = # extracts a list of urls from a message (takewhile ~<'<"> ')*F+ * ->~&t ~&i&& not =]'http://' host_names = # extracts host names a list of urls (~&w/`.)*~+ ~&s+ * skip/7; takewhile -=letters--digits--'.' ip_addresses = # maps a list of host names to their ip addresses *= skip/*9+ =]'Address: '*~+ ~&hm+ ask(bash)/<>+ <.'nslookup '--> blockable = # takes (blacklist,message) and returns a boolean ^|c/~&F ip_addresses+ host_names+ urls ------------------------ main program ----------------------------- #comment usage #executable <'par',''> #optimize+ blip = ~command.files; ~&itBttPZB?\usage!% ~&iNC+ file$[ contents: ~contents*; (not blockable)*~rSL^D/~&h messages+~&th, path: ~&th.path, stamp: &!]