#!/bin/sh # # getmails.sh - valid e-mail addresses extractor # # Developed by Ondrej Jombik # and Lubomir Host # Copyright (c) 2001-2003 Platon SDG, http://platon.sk/ # Licensed under terms of GNU General Public License. # All rights reserved. # # $Platon: getmails.sh,v 1.4 2002/06/18 18:24:38 host8 Exp $ # # Changelog: # ??/??/2000 - initial release # 17/04/2001 - improvements # 04/02/2002 - import to CVS # 18/06/2003 - faster version coded in "awk" # 04/11/2003 - headers update, etc. # # Poznamky: (mnohe z nich su out-of-context, su vytiahnute z ineho skriptu) # adresa sa musi zacinat pismenom (cislom); ak nie, osekame predchadzajuce znaky # adresa sa musi koncit pismenom; ak nie, vysekame zvysne znaky # vlavo od znaku '@' je najviac jeden znak '.' # vpravo od znaku '@' je najmenej jeden znak '.' # ak vlavo od znaku @ je viac ako 6 cisiel, adresa je neplatna # domena je max 3 znakova a min 2 znakova a obsahovat moze iba pismena # filter with awk {{{ use_awk() { awk ' BEGIN { OFS="\n" } // { $0 = tolower($0); } # convert char. to lowercase /message-id:/ { next; } # ignore lines matching this /content-id:/ { next; } # ignore lines matching this /received:/ { next; } # ignore lines matching this /in-reply-to:/ { next; } # ignore lines matching this /references:/ { next; } # ignore lines matching this /^[ \t]*id / { next; } # ignore lines matching this /@/ { # lines containing @ fields = split ($0, array, /[^a-z0-9@\.-]+/); for (i=1; i<= fields; i++) { # go over all fields if (match(array[i], /^([^\.]+\.[^\.]+|[^\.]+)@(([^\.]+\.)+)[a-z][a-z][a-z]?$/)) print array[i]; } } ' \ | sort -u } # }}} # filter with grep, tr, sed {{{ use_grep() { grep -i -v "Message-ID:" \ | grep -i -v "Content-ID:" \ | grep -i -v "Received:" \ | grep -i -v "In-Reply-To:" \ | grep -i -v "References:" \ | tr '[:upper:]' '[:lower:]' \ | tr -c "0-9a-z.@_-" "[\n*]" \ | sed 's/^[^0-9a-z]*//' \ | sed 's/[^a-z]*$//' \ | grep @ \ | grep -E -v '^.*([0-9].*){6,}.*[@].*$' \ | grep -E "^([^\.]+\.[^\.]+|[^\.]+)[@]([^\.]+\.){1,}[a-z][a-z][a-z]?$" \ | sort -u } # }}} # functions for testing speed {{{ test_awk() { for i in 1 2 3 4 5 6 7 8 9 10; do cat ~/mbox | use_awk > /dev/null; done } test_grep() { for i in 1 2 3 4 5 6 7 8 9 10; do cat ~/mbox | use_grep > /dev/null; done } make_test() { echo "testing use_awk: "; time test_awk; echo; echo; echo "testing use_grep:"; time test_grep; echo; echo; } # }}} # Please specify, which version you want to use use_awk #use_grep ################################################################### # TEST: # use_awk: 0.56s user 0.16s system 62% cpu 1.149 total # use_grep: 3.56s user 0.84s system 61% cpu 7.174 total # RESULT: use_awk is 6.24 fastes as use_grep # Modeline {{{ # vim:set ts=4: # vim600:fdm=marker fdl=0 fdc=3 vb t_vb=: # }}}