Advertisement
OldManRiver

Email Address Rip Script

May 4th, 2017
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. #! /bin/bash
  2. #set -vx
  3. ################################################################################
  4. # Author: Nyle Davis Created: 16-06-04
  5. # Purpose: Email Address extraction script to get Thunderbird EMail
  6. # addresses from email files.
  7. # Return: VAR containing 1.) Drive Name, 2.) Drive Size
  8. # 3.) Space Available, 4.) Mount Point
  9. # File: get-all-emails.sh
  10. ################################################################################
  11. # Modified: Nyle Davis Mod Date: 17-04-23
  12. # Purpose: Allowed for system scan of parms instead of hardcoding.
  13. ################################################################################
  14.  
  15. function get_parms {
  16. #############################################################################
  17. # Modified: Nyle Davis Mod Date: 17-04-25
  18. # Purpose: Scan for all needed parms.
  19. # Vars: mach_id user_n u_dir
  20. # t_dir t_def def_dir
  21. # m_ray tdir tlen
  22. # sdir
  23. #############################################################################
  24. mach_id=$(hostname);
  25. new_id=$(uname -n); # Should be the same as hostname
  26. user_n=$(id -un); # always shows "root" user
  27. user_n=$(who | cut -d' ' -f1 | uniq);
  28. u_dir="/home/$user_n";
  29. t_dir="$u_dir/.thunderbird";
  30. t_def=$(cat $t_dir/profiles.ini | grep Path= | cut -d'=' -f 2);
  31. def_dir="$t_dir/$t_def";
  32. adr_mst="$def_dir/Address_Master.txt";
  33. declare -a m_ray;
  34. m_ray=$(ls $def_dir/*/ | grep Mail);
  35. slen=${#def_dir};
  36. for dir in ${m_ray[@]}; do
  37. tdir=${dir:slen+1};
  38. tlen=${#tdir};
  39. sdir=${tdir:0:tlen-2};
  40. if [ "$sdir" == "Mail" ]; then
  41. get_LFdirs;
  42. fi
  43. if [ "$sdir" == "ImapMail" ]; then
  44. get_IMdirs;
  45. fi
  46. done
  47. for re in "${im_ray[@]}"; do
  48. echo "RE=> $re";
  49. done
  50. } # end function get_parms
  51.  
  52. get_LFdirs () {
  53. #############################################################################
  54. # Modified: Nyle Davis Mod Date: 17-04-25
  55. # Purpose: Get all "Local Folders" subdirectories
  56. # Vars:
  57. #############################################################################
  58. declare -a lf_ray=();
  59. declare -a lf_dirs=();
  60. lfsub=${dir%:};
  61. xx=0;
  62. SAVEIFS=$IFS;
  63. IFS=$(echo -en "\n\b");
  64. lf_dirs=$(ls -R $lfsub | grep -v ".msf" | grep -v "Local Folders");
  65. for dir in ${lf_dirs[@]}; do
  66. lfdir=${dir%:};
  67. if [ "$lfdir" == "$lfsub" ]; then
  68. continue;
  69. fi
  70. if [ "$lfdir" <> "Local Folders" ]; then
  71. lf_ray[$xx]=${lfsub}"Local Folders/"${lfdir};
  72. echo "LR=> ${lfsub}Local Folders/${lfdir}";
  73. ((xx=xx+1));
  74. fi
  75. done
  76. IFS=$SAVEIFS;
  77. } # end function get_LFdirs
  78.  
  79. get_IMdirs () {
  80. #############################################################################
  81. # Modified: Nyle Davis Mod Date: 17-04-25
  82. # Purpose: Get all "ImapMail" subdirectories
  83. # Vars:
  84. #############################################################################
  85. declare -a im_ray=();
  86. declare -a im_dirs=();
  87. imsub=${dir%:};
  88. xx=0;
  89. SAVEIFS=$IFS;
  90. IFS=$(echo -en "\n\b");
  91. im_dirs=$(ls -R $imsub);
  92. for dir in ${im_dirs[@]}; do
  93. imdir=${dir%:};
  94. imfil=$(basename "$imdir");
  95. imext="${imfil##*.}";
  96. if [[ "$imext" == "msf" ]] ||
  97. [[ "$imext" == "sbd" ]] ||
  98. [[ "$imext" == "dat" ]] ||
  99. [[ "$imext" == "com" ]] ||
  100. [[ "$imext" == "html" ]]; then
  101. continue;
  102. fi
  103. while IFS= read -rd '' path; do
  104. IFS=$SAVEIFS;
  105. if [[ "$imfil" == "$imext" ]]; then
  106. basfil=$(basename "$path");
  107. basext="${basfil##*.}";
  108. if [[ "$basext" == "msf" ]] ||
  109. [[ "$basext" == "sbd" ]] ||
  110. [[ "$basext" == "dat" ]] ||
  111. [[ "$basext" == "com" ]] ||
  112. [[ "$basext" == "html" ]]; then
  113. continue;
  114. fi
  115. if [[ "$basfil" == "$basext" ]]; then
  116. SAVEIFS=$IFS;
  117. IFS=$(echo -en "\n\b");
  118. im_ray+=($path);
  119. #echo ${im_ray[${#im_ray[@]} - 1]};
  120. IFS=$SAVEIFS;
  121. fi
  122. fi
  123. done < <(find "$imsub" -iwholename "${imdir}*" -type f -print0)
  124. done
  125. } # end function get_IMdirs
  126.  
  127. grp_srch="grep '^\(From\|To\|Cc\|CC\Bcc\|BCC\):'";
  128. grp_line="grep -o -E '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}'";
  129. get_parms;
  130. touch $adr_mst;
  131.  
  132. # Process Addresses in the Local Folders
  133. echo "Processing LF_Ray!";
  134. for fil in ${f_ray[@]}; do
  135. echo "Processing File $fil!";
  136. $grp_srch "'$fil'" $grp_line | sort -f | uniq -i >> $adr_mst;
  137. done
  138.  
  139. # Process Addresses in the Imap directories
  140. echo "Processing IM_Ray!";
  141. # HERE HERE HERE HERE HERE HERE HERE HERE HERE
  142. for fil in ${im_ray[@]}; do
  143. echo "Processing File $fil!";
  144. echo $("$grp_srch '$fil' $grp_line | sort -f | uniq -i >> $adr_mst");
  145. "$grp_srch '$fil' $grp_line | sort -f | uniq -i >> $adr_mst";
  146. done
  147.  
  148. #nano $adr_mst;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement