Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- #set -vx
- ################################################################################
- # Author: Nyle Davis Created: 16-06-04
- # Purpose: Email Address extraction script to get Thunderbird EMail
- # addresses from email files.
- # Return: VAR containing 1.) Drive Name, 2.) Drive Size
- # 3.) Space Available, 4.) Mount Point
- # File: get-all-emails.sh
- ################################################################################
- # Modified: Nyle Davis Mod Date: 17-04-23
- # Purpose: Allowed for system scan of parms instead of hardcoding.
- ################################################################################
- function get_parms {
- #############################################################################
- # Modified: Nyle Davis Mod Date: 17-04-25
- # Purpose: Scan for all needed parms.
- # Vars: mach_id user_n u_dir
- # t_dir t_def def_dir
- # m_ray tdir tlen
- # sdir
- #############################################################################
- mach_id=$(hostname);
- new_id=$(uname -n); # Should be the same as hostname
- user_n=$(id -un); # always shows "root" user
- user_n=$(who | cut -d' ' -f1 | uniq);
- u_dir="/home/$user_n";
- t_dir="$u_dir/.thunderbird";
- t_def=$(cat $t_dir/profiles.ini | grep Path= | cut -d'=' -f 2);
- def_dir="$t_dir/$t_def";
- adr_mst="$def_dir/Address_Master.txt";
- declare -a m_ray;
- m_ray=$(ls $def_dir/*/ | grep Mail);
- slen=${#def_dir};
- for dir in ${m_ray[@]}; do
- tdir=${dir:slen+1};
- tlen=${#tdir};
- sdir=${tdir:0:tlen-2};
- if [ "$sdir" == "Mail" ]; then
- get_LFdirs;
- fi
- if [ "$sdir" == "ImapMail" ]; then
- get_IMdirs;
- fi
- done
- for re in "${im_ray[@]}"; do
- echo "RE=> $re";
- done
- } # end function get_parms
- get_LFdirs () {
- #############################################################################
- # Modified: Nyle Davis Mod Date: 17-04-25
- # Purpose: Get all "Local Folders" subdirectories
- # Vars:
- #############################################################################
- declare -a lf_ray=();
- declare -a lf_dirs=();
- lfsub=${dir%:};
- xx=0;
- SAVEIFS=$IFS;
- IFS=$(echo -en "\n\b");
- lf_dirs=$(ls -R $lfsub | grep -v ".msf" | grep -v "Local Folders");
- for dir in ${lf_dirs[@]}; do
- lfdir=${dir%:};
- if [ "$lfdir" == "$lfsub" ]; then
- continue;
- fi
- if [ "$lfdir" <> "Local Folders" ]; then
- lf_ray[$xx]=${lfsub}"Local Folders/"${lfdir};
- echo "LR=> ${lfsub}Local Folders/${lfdir}";
- ((xx=xx+1));
- fi
- done
- IFS=$SAVEIFS;
- } # end function get_LFdirs
- get_IMdirs () {
- #############################################################################
- # Modified: Nyle Davis Mod Date: 17-04-25
- # Purpose: Get all "ImapMail" subdirectories
- # Vars:
- #############################################################################
- declare -a im_ray=();
- declare -a im_dirs=();
- imsub=${dir%:};
- xx=0;
- SAVEIFS=$IFS;
- IFS=$(echo -en "\n\b");
- im_dirs=$(ls -R $imsub);
- for dir in ${im_dirs[@]}; do
- imdir=${dir%:};
- imfil=$(basename "$imdir");
- imext="${imfil##*.}";
- if [[ "$imext" == "msf" ]] ||
- [[ "$imext" == "sbd" ]] ||
- [[ "$imext" == "dat" ]] ||
- [[ "$imext" == "com" ]] ||
- [[ "$imext" == "html" ]]; then
- continue;
- fi
- while IFS= read -rd '' path; do
- IFS=$SAVEIFS;
- if [[ "$imfil" == "$imext" ]]; then
- basfil=$(basename "$path");
- basext="${basfil##*.}";
- if [[ "$basext" == "msf" ]] ||
- [[ "$basext" == "sbd" ]] ||
- [[ "$basext" == "dat" ]] ||
- [[ "$basext" == "com" ]] ||
- [[ "$basext" == "html" ]]; then
- continue;
- fi
- if [[ "$basfil" == "$basext" ]]; then
- SAVEIFS=$IFS;
- IFS=$(echo -en "\n\b");
- im_ray+=($path);
- #echo ${im_ray[${#im_ray[@]} - 1]};
- IFS=$SAVEIFS;
- fi
- fi
- done < <(find "$imsub" -iwholename "${imdir}*" -type f -print0)
- done
- } # end function get_IMdirs
- grp_srch="grep '^\(From\|To\|Cc\|CC\Bcc\|BCC\):'";
- grp_line="grep -o -E '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}'";
- get_parms;
- touch $adr_mst;
- # Process Addresses in the Local Folders
- echo "Processing LF_Ray!";
- for fil in ${f_ray[@]}; do
- echo "Processing File $fil!";
- $grp_srch "'$fil'" $grp_line | sort -f | uniq -i >> $adr_mst;
- done
- # Process Addresses in the Imap directories
- echo "Processing IM_Ray!";
- # HERE HERE HERE HERE HERE HERE HERE HERE HERE
- for fil in ${im_ray[@]}; do
- echo "Processing File $fil!";
- echo $("$grp_srch '$fil' $grp_line | sort -f | uniq -i >> $adr_mst");
- "$grp_srch '$fil' $grp_line | sort -f | uniq -i >> $adr_mst";
- done
- #nano $adr_mst;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement