Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- # Script Name: get-all-emails.sh
- # Email Address extraction script to get Thunderbird EMail addresses from email files.
- # Get current directory
- DIR="$( cd -P "$( dirname "$0" )" && pwd )"
- curdir="$DIR";
- suser="myuser";
- regx1='^\(From\|To\|Cc\|CC\Bcc\|BCC\):';
- regx2='[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}';
- #file1="/home/${suser}/myfiles/all-addresses.txt";
- #file2="/home/${suser}/myfiles/all-addresses.old.txt";
- file1="/home/path/TBird/Rules/all-addresses.txt";
- file2="/home/path/TBird/Rules/all-addresses.old.txt";
- file3="/home/path/TBird/Rules/lf-addresses.txt";
- file4="/home/path/TBird/Rules/g0-addresses.txt";
- file5="/home/path/TBird/Rules/g1-addresses.txt";
- #echo "C=>$curdir";
- # Declare the Default Thunderbird dir
- tbdir="/home/${suser}/.thunderbird";
- tbfnd=`find /home/${suser}/ -type f -iname ".*" | grep thunderbird`;
- tbidx=`expr index "$tbfnd" '.'`;
- tbidx=$(($tbidx+12));
- # echo "FD=> ${tbfnd} PS=> ${tbidx}";
- tbnst=${tbfnd:${tbidx}};
- tbsdx=`expr index "$tbnst" '.'`;
- tbsdx=$(($tbsdx+7));
- # echo "NS=> ${tbnst} SS=> ${tbsdx}";
- tbpdr=${tbnst:0:${tbsdx}};
- #echo "DR=> ${tbpdr}";
- tbfdr="${tbdir}/${tbpdr}";
- #echo "FD=> ${tbfdr}";
- # Declare the "Local Folders" dir
- lcmail="${tbfdr}/Mail/Local Folders";
- #echo "LF=> ${lcmail}";
- cd "${lcmail}";
- echo "Processing Local Folders!";
- # Run the grep statement to get the addresses
- grep $regx1 * | grep -o -E $regx2 | sort -f | uniq -i > $file3;
- grep $regx1 Archives | grep -o -E $regx2 | sort -f | uniq -i >> $file3;
- grep $regx1 Drafts | grep -o -E $regx2 | sort -f | uniq -i >> $file3;
- grep $regx1 Sent | grep -o -E $regx2 | sort -f | uniq -i >> $file3;
- grep $regx1 Trash | grep -o -E $regx2 | sort -f | uniq -i >> $file3;
- grep $regx1 'Unsent Messages' | grep -o -E $regx2 | sort -f | uniq -i >> $file3;
- # Declare the gmail.com dir for Thunderbird
- gm0="${tbfdr}/ImapMail/imap.googlemail.com";
- #echo "GM0=> ${gm0}";
- cd "${gm0}";
- echo "Processing GMail 0!";
- grep $regx1 * | grep -o -E $regx2 | sort -f | uniq -i > $file4;
- grep $regx1 INBOX | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 Junk | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 Sent-1 | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- gm0g="${tbfdr}/ImapMail/imap.googlemail.com/[Gmail].sbd";
- #echo "GMG=> ${gm0g}";
- cd "${gm0g}";
- grep $regx1 * | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 '@Corp' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 '@Marketing' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'All Mail' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Blogs' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Bots &- Scrubs' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Customers' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Drafts' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Fiduciary &- Legal' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Important' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Job Search' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Ministry' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Partner &- Subcontract Sources' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Personal' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Projects' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Sent Mail' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'SEO &- SMO Sources' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Support' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Telecom Tech Jobs' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Training &- Education' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Trash' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- grep $regx1 'Work' | grep -o -E $regx2 | sort -f | uniq -i >> $file4;
- # Declare the IMapMail dir for Thunderbird
- gm1="${tbfdr}/ImapMail/imap.googlemail-1.com";
- echo "GM1=> ${gm1}";
- cd "${gm1}";
- echo "Processing GMail 1!";
- grep $regx1 * | grep -o -E $regx2 | sort -f | uniq -i > $file5;
- grep $regx1 INBOX | grep -o -E $regx2 | sort -f | uniq -i >> $file5;
- gm1g="${tbfdr}/ImapMail/imap.googlemail-1.com/[Gmail].sbd";
- echo "GMG=> ${gm1g}";
- cd "${gm1g}";
- grep $regx1 * | grep -o -E $regx2 | sort -f | uniq -i >> $file5;
- grep $regx1 '@Marketing' | grep -o -E $regx2 | sort -f | uniq -i >> $file5;
- grep $regx1 'All Mail' | grep -o -E $regx2 | sort -f | uniq -i >> $file5;
- grep $regx1 'C-Level' | grep -o -E $regx2 | sort -f | uniq -i >> $file5;
- grep $regx1 'DaviSoft Recruiting' | grep -o -E $regx2 | sort -f | uniq -i >> $file5;
- grep $regx1 'Drafts' | grep -o -E $regx2 | sort -f | uniq -i >> $file5;
- grep $regx1 'Important' | grep -o -E $regx2 | sort -f | uniq -i >> $file5;
- grep $regx1 'Ministry' | grep -o -E $regx2 | sort -f | uniq -i >> $file5;
- grep $regx1 'Products &- Vendors' | grep -o -E $regx2 | sort -f | uniq -i >> $file5;
- grep $regx1 'Sent Mail' | grep -o -E $regx2 | sort -f | uniq -i >> $file5;
- # Sort the output for unique addresses
- cat $file3 $file4 $file5 > $file2;
- sort $file2 | uniq -u > $file1;
- # Change back to current directory
- cd "$curdir";
- echo "Output in ${file1}";
- nano ${file1};
- Extra Code:
- # Get all pertainent directories
- t_filter='(googlemail|gmail|"local folders")';
- t_exclude='dropbox'
- ray_cnt=0;
- declare -a output;
- dirs=$(find / -type d | grep -i thunderbird | grep -i "${t_filter}" | grep -iEv ${t_exclude});
- for dir in ${dirs}; do
- output[${ray_cnt}]=${dir};
- let ray_cnt=$ray_cnt+1;
- done;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement