Presented during a hacker meetup at Songkick headquarters in London on April 18, 2008, this presentation takes a walk through some code to show how Ursala thinks.
code. email messages in a file with mbox format some junk mail contains urls in the message body disposable host names persistent ip addresses delete messages from the file by this criterion extract host names from urls look up ip addresses match against a known blacklist Dennis Furey, Ph.D. A mail filter application in Ursala
3 sections . . . front matter #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]- . . . Dennis Furey, Ph.D. A mail filter application in Ursala
3 sections . . . user defined utilities ------------------- 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 Dennis Furey, Ph.D. A mail filter application in Ursala
like this blacklist 139.91.201.35 217.74.65.162 220.113.33.113 220.113.33.40 61.188.87.42 61.188.87.54 205.188.96.215 205.188.98.215 205.188.224.215 205.188.97.215 205.188.99.215 89.187.46.24 Dennis Furey, Ph.D. A mail filter application in Ursala
from the lines of a mailbox file, split it into a list of lists of strings. rlc ~&r; not =]’From ’&& sep‘ ; ~&F; length==7&& ~&w/‘@+ ~&th Dennis Furey, Ph.D. A mail filter application in Ursala
from the lines of a mailbox file, split it into a list of lists of strings. rlc ~&r; not =]’From ’&& sep‘ ; ~&F; length==7&& ~&w/‘@+ ~&th infer that consecutive lines belong to the same message iff Dennis Furey, Ph.D. A mail filter application in Ursala
from the lines of a mailbox file, split it into a list of lists of strings. rlc ~&r; not =]’From ’&& sep‘ ; ~&F; length==7&& ~&w/‘@+ ~&th infer that consecutive lines belong to the same message iff the latter line does not Dennis Furey, Ph.D. A mail filter application in Ursala
from the lines of a mailbox file, split it into a list of lists of strings. rlc ~&r; not =]’From ’&& sep‘ ; ~&F; length==7&& ~&w/‘@+ ~&th infer that consecutive lines belong to the same message iff the latter line does not begin with the word ’From’ and Dennis Furey, Ph.D. A mail filter application in Ursala
from the lines of a mailbox file, split it into a list of lists of strings. rlc ~&r; not =]’From ’&& sep‘ ; ~&F; length==7&& ~&w/‘@+ ~&th infer that consecutive lines belong to the same message iff the latter line does not begin with the word ’From’ and contain seven non-empty space delimited fields Dennis Furey, Ph.D. A mail filter application in Ursala
from the lines of a mailbox file, split it into a list of lists of strings. rlc ~&r; not =]’From ’&& sep‘ ; ~&F; length==7&& ~&w/‘@+ ~&th infer that consecutive lines belong to the same message iff the latter line does not begin with the word ’From’ and contain seven non-empty space delimited fields of which the second contains the @ character Dennis Furey, Ph.D. A mail filter application in Ursala
in a mail message, extract the urls. (takewhile ~<’<"> ’)*F+ * ->~&t ~&i&& not =]’http://’ for each line in the message Dennis Furey, Ph.D. A mail filter application in Ursala
in a mail message, extract the urls. (takewhile ~<’<"> ’)*F+ * ->~&t ~&i&& not =]’http://’ for each line in the message take the tail while this is true Dennis Furey, Ph.D. A mail filter application in Ursala
in a mail message, extract the urls. (takewhile ~<’<"> ’)*F+ * ->~&t ~&i&& not =]’http://’ for each line in the message take the tail while this is true the line is non-empty and Dennis Furey, Ph.D. A mail filter application in Ursala
in a mail message, extract the urls. (takewhile ~<’<"> ’)*F+ * ->~&t ~&i&& not =]’http://’ for each line in the message take the tail while this is true the line is non-empty and it does not start witn ’http://’ Dennis Furey, Ph.D. A mail filter application in Ursala
in a mail message, extract the urls. (takewhile ~<’<"> ’)*F+ * ->~&t ~&i&& not =]’http://’ for each line in the message take the tail while this is true the line is non-empty and it does not start witn ’http://’ for each remaining non-empty line Dennis Furey, Ph.D. A mail filter application in Ursala
in a mail message, extract the urls. (takewhile ~<’<"> ’)*F+ * ->~&t ~&i&& not =]’http://’ for each line in the message take the tail while this is true the line is non-empty and it does not start witn ’http://’ for each remaining non-empty line accumulate the maximum prefix Dennis Furey, Ph.D. A mail filter application in Ursala
in a mail message, extract the urls. (takewhile ~<’<"> ’)*F+ * ->~&t ~&i&& not =]’http://’ for each line in the message take the tail while this is true the line is non-empty and it does not start witn ’http://’ for each remaining non-empty line accumulate the maximum prefix not containing angle brackets, double quotes, or spaces Dennis Furey, Ph.D. A mail filter application in Ursala
strings representing urls, extract the host names. (~&w/‘.)*~+ ~&s+ * skip/7; takewhile -=letters--digits--’.’ Dennis Furey, Ph.D. A mail filter application in Ursala
strings representing urls, extract the host names. (~&w/‘.)*~+ ~&s+ * skip/7; takewhile -=letters--digits--’.’ for each url Dennis Furey, Ph.D. A mail filter application in Ursala
strings representing urls, extract the host names. (~&w/‘.)*~+ ~&s+ * skip/7; takewhile -=letters--digits--’.’ for each url delete the seven character ’http://’ prefix Dennis Furey, Ph.D. A mail filter application in Ursala
strings representing urls, extract the host names. (~&w/‘.)*~+ ~&s+ * skip/7; takewhile -=letters--digits--’.’ for each url delete the seven character ’http://’ prefix accumulate the maximal remaining prefix Dennis Furey, Ph.D. A mail filter application in Ursala
strings representing urls, extract the host names. (~&w/‘.)*~+ ~&s+ * skip/7; takewhile -=letters--digits--’.’ for each url delete the seven character ’http://’ prefix accumulate the maximal remaining prefix containing only letters, digits, and periods Dennis Furey, Ph.D. A mail filter application in Ursala
strings representing urls, extract the host names. (~&w/‘.)*~+ ~&s+ * skip/7; takewhile -=letters--digits--’.’ for each url delete the seven character ’http://’ prefix accumulate the maximal remaining prefix containing only letters, digits, and periods eliminate duplicate host names Dennis Furey, Ph.D. A mail filter application in Ursala
strings representing urls, extract the host names. (~&w/‘.)*~+ ~&s+ * skip/7; takewhile -=letters--digits--’.’ for each url delete the seven character ’http://’ prefix accumulate the maximal remaining prefix containing only letters, digits, and periods eliminate duplicate host names retain only those containing at least one period Dennis Furey, Ph.D. A mail filter application in Ursala
of each host name in a list. *= skip/*9+ =]’Address: ’*~+ ~&hm+ ask(bash)/<>+ <.’nslookup ’--> for each host name Dennis Furey, Ph.D. A mail filter application in Ursala
of each host name in a list. *= skip/*9+ =]’Address: ’*~+ ~&hm+ ask(bash)/<>+ <.’nslookup ’--> for each host name construct an nslookup shell command Dennis Furey, Ph.D. A mail filter application in Ursala
of each host name in a list. *= skip/*9+ =]’Address: ’*~+ ~&hm+ ask(bash)/<>+ <.’nslookup ’--> for each host name construct an nslookup shell command launch it in a bash session Dennis Furey, Ph.D. A mail filter application in Ursala
of each host name in a list. *= skip/*9+ =]’Address: ’*~+ ~&hm+ ask(bash)/<>+ <.’nslookup ’--> for each host name construct an nslookup shell command launch it in a bash session filter the address lines from the output transcript Dennis Furey, Ph.D. A mail filter application in Ursala
of each host name in a list. *= skip/*9+ =]’Address: ’*~+ ~&hm+ ask(bash)/<>+ <.’nslookup ’--> for each host name construct an nslookup shell command launch it in a bash session filter the address lines from the output transcript delete the nine character ’Address: ’ prefixes Dennis Furey, Ph.D. A mail filter application in Ursala
blacklisted addresses. ˆ |c/~&F ip_addresses+ host_names+ urls take urls from the message take host names from the urls Dennis Furey, Ph.D. A mail filter application in Ursala
blacklisted addresses. ˆ |c/~&F ip_addresses+ host_names+ urls take urls from the message take host names from the urls get ip addresses from the host names Dennis Furey, Ph.D. A mail filter application in Ursala
blacklisted addresses. ˆ |c/~&F ip_addresses+ host_names+ urls take urls from the message take host names from the urls get ip addresses from the host names take the non-empty black list items Dennis Furey, Ph.D. A mail filter application in Ursala
blacklisted addresses. ˆ |c/~&F ip_addresses+ host_names+ urls take urls from the message take host names from the urls get ip addresses from the host names take the non-empty black list items test whether the intersection is non-empty Dennis Furey, Ph.D. A mail filter application in Ursala
files, construct the contents of the filtered output mailbox file. ~contents*; (not blockable)*~rSLˆD/~&h messages+~&th Dennis Furey, Ph.D. A mail filter application in Ursala
files, construct the contents of the filtered output mailbox file. ~contents*; (not blockable)*~rSLˆD/~&h messages+~&th take the contents of the input files Dennis Furey, Ph.D. A mail filter application in Ursala
files, construct the contents of the filtered output mailbox file. ~contents*; (not blockable)*~rSLˆD/~&h messages+~&th take the contents of the input files split the mailbox file contents into messages Dennis Furey, Ph.D. A mail filter application in Ursala
files, construct the contents of the filtered output mailbox file. ~contents*; (not blockable)*~rSLˆD/~&h messages+~&th take the contents of the input files split the mailbox file contents into messages put a copy of the black list together with each message Dennis Furey, Ph.D. A mail filter application in Ursala
files, construct the contents of the filtered output mailbox file. ~contents*; (not blockable)*~rSLˆD/~&h messages+~&th take the contents of the input files split the mailbox file contents into messages put a copy of the black list together with each message filter out the non-blockable pairs Dennis Furey, Ph.D. A mail filter application in Ursala
files, construct the contents of the filtered output mailbox file. ~contents*; (not blockable)*~rSLˆD/~&h messages+~&th take the contents of the input files split the mailbox file contents into messages put a copy of the black list together with each message filter out the non-blockable pairs take the messages out of the remaining pairs Dennis Furey, Ph.D. A mail filter application in Ursala
files, construct the contents of the filtered output mailbox file. ~contents*; (not blockable)*~rSLˆD/~&h messages+~&th take the contents of the input files split the mailbox file contents into messages put a copy of the black list together with each message filter out the non-blockable pairs take the messages out of the remaining pairs flatten the list of messages into a list of strings Dennis Furey, Ph.D. A mail filter application in Ursala
comments for each line of code that makes it more readable and still shorter than C++ No one will? see Knuth’s essays on literate programming should languages force programmers to do things? More info on http://www.basis.uklinux.net/ursala or Google for Ursala. Dennis Furey, Ph.D. A mail filter application in Ursala