| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
E_MISSING_ARG=87 |
| 10 |
if [ -z "$1" ] |
| 11 |
then |
| 12 |
echo "Usage: $0 mailbox-file" |
| 13 |
exit $E_MISSING_ARG |
| 14 |
fi |
| 15 |
|
| 16 |
mbox_grep() |
| 17 |
{ |
| 18 |
declare -i body=0 match=0 |
| 19 |
declare -a date sender |
| 20 |
declare mail header value |
| 21 |
|
| 22 |
|
| 23 |
while IFS= read -r mail |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
do |
| 28 |
if [[ $mail =~ ^From ]] |
| 29 |
then |
| 30 |
(( body = 0 )) |
| 31 |
(( match = 0 )) |
| 32 |
unset date |
| 33 |
|
| 34 |
elif (( body )) |
| 35 |
then |
| 36 |
(( match )) |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
elif [[ $mail ]]; then |
| 42 |
IFS=: read -r header value <<< "$mail" |
| 43 |
|
| 44 |
|
| 45 |
case "$header" in |
| 46 |
[Ff][Rr][Oo][Mm] ) [[ $value =~ "$2" ]] && (( match++ )) ;; |
| 47 |
|
| 48 |
[Dd][Aa][Tt][Ee] ) read -r -a date <<< "$value" ;; |
| 49 |
|
| 50 |
|
| 51 |
[Rr][Ee][Cc][Ee][Ii][Vv][Ee][Dd] ) read -r -a sender <<< "$value" ;; |
| 52 |
|
| 53 |
|
| 54 |
esac |
| 55 |
|
| 56 |
else |
| 57 |
(( body++ )) |
| 58 |
(( match )) && |
| 59 |
echo "MESSAGE ${date:+of: ${date[*]} }" |
| 60 |
|
| 61 |
echo "IP address of sender: ${sender[1]}" |
| 62 |
|
| 63 |
|
| 64 |
fi |
| 65 |
|
| 66 |
|
| 67 |
done < "$1" |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
mbox_grep "$1" |
| 72 |
|
| 73 |
exit $? |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
$ mailbox_grep.sh scam_mail |
| 84 |
MESSAGE of Thu, 5 Jan 2006 08:00:56 -0500 (EST) |
| 85 |
IP address of sender: 196.3.62.4 |