Advertisement
Draven

EmailHandler

Aug 26th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1.     public function caughtEmail($full_email)
  2.     {
  3.         global $database;
  4.         global $member;
  5.         global $EmailClass;
  6.  
  7.         # Include email parser  
  8.         require_once('rfc822_addresses.class.php');
  9.         require_once('mime_parser.class.php');
  10.  
  11.         # Create the email parser class
  12.         $mime = new mime_parser_class;
  13.        
  14.         $mime->ignore_syntax_errors = 1;
  15.         $parameters=array(
  16.             'Data'=>$full_email,
  17.         );
  18.  
  19.         $mime->Decode($parameters, $decoded);
  20.  
  21.         for($message = 0; $message < count($decoded); $message++)
  22.         {
  23.             $mime->Analyze($decoded[$message], $results);
  24.  
  25.             if($mime->decode_bodies)
  26.             {
  27.                 $mime->Analyze($decoded[$message], $results);
  28.             }
  29.         }
  30.  
  31.         # Get the name and email of the sender
  32.         $fromName = $results['From'][0]['name'];
  33.         $fromEmail = $results['From'][0]['address'];
  34.  
  35.         # If there is no fromName then fromName becomes fromEmail
  36.         if(!isset($fromName) || empty($fromName))
  37.         {
  38.             $fromName1 = explode('@', $fromEmail);
  39.             $fromName = $fromName1[0];
  40.         }
  41.  
  42.         # Get the name and email of the recipient
  43.         $toName = $results['To'][0]['name'];
  44.         $toEmail = $results['To'][0]['address'];
  45.         if(!isset($toName)) $toName = "";
  46.  
  47.         # Get the subject
  48.         $subject = $results['Subject'];
  49.  
  50.         # Stop script is it's spam
  51.         if(strpos($subject, '***SPAM***' !== FALSE))
  52.         {
  53.             exit;
  54.         }
  55.  
  56.         # If no subject then make it (No Subject)
  57.         if($subject=="") $subject = "(No Subject)";
  58.  
  59.         # Retrieve Email ID from the subject
  60.         preg_match('/\[#(\d+)\]/U', $subject, $subject_ticket_id);
  61.  
  62.         # Get the body
  63.         $body = $results['Alternative'][0]['Data'];
  64.  
  65.         # Retrive the Email ID from the body
  66.         preg_match('/Email ID: (?P<body_ticket_id>\w+)/', $body, $body_ticket_id);
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement