Advertisement
OldManRiver

EMail Script Conversion

Feb 3rd, 2015
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.57 KB | None | 0 0
  1. File: get-all-emails.sh
  2. /*******************/
  3.  
  4. #! /bin/bash
  5.  
  6. # Email Address extraction script to get Thunderbird EMail addresses from email files.
  7.  
  8. # Get current directory
  9. DIR="$( cd -P "$( dirname "$0" )" && pwd )"
  10. curdir="$DIR";
  11. user=username;
  12. tbpath='profile.default';
  13. old_fil='/home/$user/myfiles/all-addresses.old.txt';
  14. out_fil='/home/$user/myfiles/all-addresses.txt';
  15. grpfl1='^\(From\|To\|Cc\|CC\Bcc\|BCC\):';
  16. grpfl2='[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}';
  17.  
  18. # Declare the first gmail.com dir for Thunderbird
  19. tbdir="/home/$user/.thunderbird/$tbpath/ImapMail/imap.googlemail.com/[Gmail].sbd";
  20.  
  21. # Change to First TB directory
  22. echo "$tbdir";
  23. cd "$tbdir";
  24.  
  25. # Run the grep statement to get the addresses
  26. grep $grpfl1 'All Mail' | grep -o -E $grpfl2 | sort -f | uniq -i > $outfil
  27.  
  28. # Declare the second gmail.com dir for Thunderbird
  29. tbdir="/home/$user/.thunderbird/"$tbpath"/ImapMail/imap.googlemail-1.com/[Gmail].sbd";
  30. echo "Processing Dir=> $tbdir";
  31. cd "$tbdir";
  32.  
  33. # Run the grep statement to get the addresses
  34. grep $grpfl1 'All Mail' | grep -o -E $grpfl2 | sort -f | uniq -i > $outfil
  35.  
  36. # Declare the third gmail.com dir for Thunderbird
  37. tbdir="/home/$user/.thunderbird/$tbpath/ImapMail/imap.googlemail-2.com/[Gmail].sbd";
  38. echo "Processing Dir=> $tbdir";
  39. cd "$tbdir";
  40.  
  41. # Run the grep statement to get the addresses
  42. grep $grpfl1 'All Mail' | grep -o -E $grpfl2 | sort -f | uniq -i > $outfil
  43.  
  44. # Declare the forth gmail.com dir for Thunderbird
  45. tbdir="/home/$user/.thunderbird/$tbpath/ImapMail/imap.googlemail-3.com/[Gmail].sbd";
  46. echo "Processing Dir=> $tbdir";
  47. cd "$tbdir";
  48.  
  49. # Run the grep statement to get the addresses
  50. grep $grpfl1 'All Mail' | grep -o -E $grpfl2 | sort -f | uniq -i > $outfil
  51.  
  52. # Declare the fifth gmail.com dir for Thunderbird
  53. tbdir="/home/$user/.thunderbird/$tbpath/ImapMail/imap.googlemail-4.com/[Gmail].sbd";
  54. echo "Processing Dir=> $tbdir";
  55. cd "$tbdir";
  56.  
  57. # Run the grep statement to get the addresses
  58. grep $grpfl1 'All Mail' | grep -o -E $grpfl2 | sort -f | uniq -i > $outfil
  59.  
  60. # Sort the output for unique addresses
  61. cp $out_fil $old_fil;
  62. sort $old_fil | uniq -u > $out_fil
  63.  
  64. # Change back to current directory
  65. cd "$curdir";
  66. nano $out_fil;
  67. /*******************/
  68.  
  69.  
  70. File: get-all-emails.php
  71. /*******************/
  72.  
  73. <?php
  74. /***************************************************************************/
  75. /* Name: get-all-emails.php */
  76. /* Author: Nyle E. Davis Create Date: 15/01/30 */
  77. /* Purpose: This file contains the processing to read all Thunderbird */
  78. /* email db and collect all address into the 'outfil' specified. */
  79. /***************************************************************************/
  80. include_once ( 'config.php' );
  81. include_once ( EM_DIR."/em_objects.php" );
  82. include_once ( EM_DIR."/em_stdio/em_stdio.php" );
  83. include_once ( EM_DIR."/em_stdio/em_directory.php" );
  84.  
  85. $cur_dir = getcwd();
  86. $new_ray = array();
  87. $pth_stm = "/home/$p_user/.thunderbird/";
  88. $out_fil = "/home/$p_user/myfiles/all-addresses.txt";
  89. $old_fil = "/home/$p_user/myfiles/all-addresses.old.txt";
  90. $grpfl1 = '^\(From\|To\|Cc\|CC\Bcc\|BCC\):';
  91. $grpfl2 = '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}';
  92. $em_dir = new em_directory();
  93. $fil_ray = $em_dir->read_dir ( $pth_stm, '.sbd' );
  94. foreach ( $fil_ray as $dir ) {
  95. if ( !is_dir ( $dir ) ) { continue; }
  96. $good_dir = strip_tail ( $dir );
  97. $last_11 = substr ( $good_dir, -11 );
  98. if ( $last_11 === '[Gmail].sbd' ) {
  99. if ( !in_array ( $good_dir, $new_ray ) ) {
  100. $new_ray[] = $good_dir;
  101. } // end if
  102. } else { continue; }
  103. } // end foreach $fil_ray
  104. echo exec ( "rm -fR $out_fil" );
  105. echo exec ( "touch $out_fil" );
  106. $fil_ray = sort ( $new_ray );
  107. foreach ( $new_ray as $pdir ) {
  108. echo "Processing Dir=> $pdir \n";
  109. echo exec ( chdir ( "$pdir" ) );
  110. $prc_cmd = "grep $grpfl1 'All Mail' | grep -o -E $grpfl2 ".
  111. "| sort -f | uniq -i > $out_fil";
  112. echo exec ( "$prc_cmd" );
  113. } // end foreach $fil_ray
  114. echo exec ( chdir ( "$cur_dir" ) );
  115. echo exec ( "cp $out_fil $old_fil" );
  116. echo exec ( "sort $old_fil | uniq -u $out_fil" );
  117. echo exec ( "nano $out_fil" );
  118.  
  119. function strip_tail ( $mydir ) {
  120. $l2 = substr ( $mydir, -2 );
  121. if ( $l2 == '/.' ) { $mydir = substr ( $mydir,0,strlen ($mydir)-2 ); }
  122. $l3 = substr ( $mydir, -3 );
  123. if ( $l3 == '/..' ) { $mydir = substr ( $mydir,0,strlen ($mydir)-3 ); }
  124. return $mydir;
  125. } // end function strip_tail
  126.  
  127. ?>
  128.  
  129. /*******************/
  130.  
  131.  
  132. File: config.php
  133. /*******************/
  134.  
  135. <?php
  136. /***************************************************************************/
  137. /* Author: Nyle E. Davis Create Date: 08/14/10 */
  138. /* E-Mail: davisoftaec@gmail.com Revision: unknown */
  139. /* Purpose: This file contains the preset vars and definitions that */
  140. /* direct the calling and processing for the current process. */
  141. /***************************************************************************/
  142. /* Mod by: Nyle E. Davis Mod Date: 12/08/30 */
  143. /* Change: Added this header to this file for proper tracking and */
  144. /* documentation of changes to the file. */
  145. /***************************************************************************/
  146. /* Mod by: Nyle E. Davis Mod Date: 12/09/05 */
  147. /* Change: Added debug vars of: */
  148. /* DBUG_ME ==> Does array and var dumps, */
  149. /* INFO_ME ==> Allow run of phpinfo() statements, */
  150. /* PRUN_ME ==> Does other process run debugging. */
  151. /* SHOW_ME ==> Shows/echos all set vars, */
  152. /* STOP_ME ==> Stop processing with a die() statement. */
  153. /* $et_ray ==> Error array that is called by/within the modules. */
  154. /* Requires a one line call to be set just before the */
  155. /* "return" statement or other "end of module" call */
  156. /* so processing errors in $_GET and $_POST and other */
  157. /* system vars can be displayed. */
  158. /* Notes: The debug var PRUN_ME can be assigned values of 0-9 where 0 is */
  159. /* off and the other values can turn on upto 9 debugging tests. */
  160. /***************************************************************************/
  161.  
  162. // Define the constants for debugging
  163. define ( 'DBUG_ME', 1 ); // 0=off, 1=on
  164. define ( 'INFO_ME', 0 ); // 0=off, 1=on
  165. define ( 'PRUN_ME', 0 ); // 0=off, 1-9=on by test type
  166. define ( 'SHOW_ME', 1 ); // 0=off, 1=on
  167. define ( 'STOP_ME', 0 ); // 0=off, 1=on end where set in code.
  168. $et_ray = array(); // Add the module names to test in this array
  169. // End debugging constants
  170.  
  171. // Define the PAGE constants
  172. if ( !defined('TITLE1') ) {
  173. define('TITLE1', 'Interactive Topical Bible');
  174. $_GET['TITLE1'] = TITLE1;
  175. } // end if !isset TITLE1
  176. if ( !defined('TITLE2') ) {
  177. define('TITLE2', 'A better Bible Resource');
  178. $_GET['TITLE2'] = TITLE2;
  179. } // end if !isset TITLE1
  180. if ( !defined('TITLE3') ) {
  181. define('TITLE3', 'Topic Search');
  182. } // end if !isset TITLE1
  183. $_GET['TITLE3'] = TITLE3;
  184. // End PAGE constants
  185.  
  186. // Get the Default DIR constants
  187. $mode = php_sapi_name();
  188. if ($mode=='cli') {
  189. $droot = '/var/www';
  190. $lnbrk = '\n';
  191. $lnfmt = '';
  192. $lnumt = '';
  193. } else {
  194. $droot = $_SERVER['DOCUMENT_ROOT'];
  195. $lnbrk = '<br>';
  196. $lnfmt = '<pre>';
  197. $lnumt = '<pre>';
  198. } // end if $mode
  199. $emdir = $droot.'/Frameworks/EM/';
  200. $fcdir = $droot.'/functions/';
  201. define ('EM_DIR', $emdir);
  202. include_once (EM_DIR."em_stdio/em_directory.php");
  203. $edir = new em_directory();
  204. $froot = $edir->froot;
  205. $nroot = $edir->nroot;
  206. $proot = $edir->proot;
  207. $sroot = $edir->sroot;
  208. $crdir = getcwd().'/';
  209. // Set the directory constants
  210. define ('DOC_DIR', $droot);
  211. define ('FNC_DIR', $froot);
  212. define ('NET_DIR', $nroot);
  213. define ('PTH_DIR', $proot);
  214. define ('SCP_DIR', $sroot);
  215. define ('CUR_DIR', $crdir);
  216.  
  217. // Open EM Standard IO
  218. include_once (EM_DIR."em_stdio/em_stdio.php");
  219. $emio = new em_io();
  220.  
  221. // Define the Process constants
  222. $p_user = 'username';
  223. define ( 'FIL_DIR', "/media/$p_user/3a582561-dd48-4822-b4dd-37375f6e6a24/".
  224. "backups/DB_Backups/mysql_backup/" );
  225. define ( 'MAIL_DIR', "/home/$p_user/.thunderbird/" );
  226.  
  227. // Define the DB constants
  228. define('DB_ENG', 'mysql'); // Set the DB engine
  229. define('DB_HST', 'localhost'); // Set the DB Host
  230. define('DB_PRF', 'cb_'); // Set the DB Table Prefix
  231. define('DB_PRT', '3306'); // Set the DB Port
  232. define('DB_USE', 'forecasts'); // Set the DB to use
  233. $sys = gethostname();
  234. if (strpos($sys,'Aspire')) {
  235. define('DB_USR', 'oldmanriver');
  236. define('DB_PWD', 'domains4meNU2');
  237. } elseif ($sys=='New-Off-DT') {
  238. //define('DB_USR', 'oldmanriver');
  239. //define('DB_PWD', 'domains4meNU2');
  240. define('DB_USR', 'ndavis');
  241. define('DB_PWD', 'nomened1497');
  242. } // end if $sys
  243. include_once (EM_DIR."em_dio/em_dio.php");
  244. $edb = new em_dio();
  245. // End DB constants
  246.  
  247. if (SHOW_ME==2) {
  248. echo "H=> ".DB_HST." <br>";
  249. echo "U=> ".DB_USR." <br>";
  250. echo "P=> ".DB_PWD." <br>";
  251. echo "CR=> ".CUR_DIR." <br>";
  252. echo "DR=> ".DOC_DIR." <br>";
  253. echo "FR=> ".FNC_DIR." <br>";
  254. echo "NR=> ".NET_DIR." <br>";
  255. echo "PR=> ".PTH_DIR." <br>";
  256. echo "SR=> ".SCP_DIR." <br>";
  257. echo "SN=> $sys <br>";
  258. }
  259.  
  260. // end definitions
  261.  
  262. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement