2010-12-02 23:34:41 +00:00
< ? php
/**
2011-02-04 20:38:49 +00:00
* class . spool . php
* @ package workflow . engine . classes
2010-12-02 23:34:41 +00:00
*
* ProcessMaker Open Source Edition
2011-02-01 12:49:40 +00:00
* Copyright ( C ) 2004 - 2011 Colosa Inc .
2010-12-02 23:34:41 +00:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*
* For more information , contact Colosa Inc , 2566 Le Jeune Rd . ,
* Coral Gables , FL , 33134 , USA , or email info @ colosa . com .
*
*/
/**
2012-06-21 12:46:19 -04:00
* spoolRun - brief send email from the spool database , and see if we have all the addresses we send to .
2010-12-02 23:34:41 +00:00
* @ author Ian K Armstrong < ika @ [ REMOVE_THESE_CAPITALS ] openmail . cc >
* @ copyright Copyright ( c ) 2007 , Ian K Armstrong
* @ license http :// www . opensource . org / licenses / gpl - 3.0 . html GNU Public License
* @ link http :// www . openmail . cc
*/
/**
* LOG FIXES
* =========
*
* 24 - 03 - 2010 Erik A . O . < erik @ colosa . com >
2012-06-21 12:46:19 -04:00
* class : the $ExceptionCode and $aWarnings class attributes were added
2010-12-02 23:34:41 +00:00
* function handleFrom () : Validations for invalid data for { $this -> fileData [ 'from_email' ]} were added
* function resendEmails () : handler for warnings was added and fixes
* function getWarnings () : added
2012-06-21 12:46:19 -04:00
* function sendMail () : now is handling the exception
2010-12-02 23:34:41 +00:00
*/
require_once ( 'classes/model/AppMessage.php' );
2011-01-22 12:20:08 +00:00
/**
2011-02-01 12:49:40 +00:00
* @ package workflow . engine . ProcessMaker
2011-01-22 12:20:08 +00:00
*/
2010-12-02 23:34:41 +00:00
class spoolRun {
private $config ;
private $fileData ;
private $spool_id ;
public $status ;
public $error ;
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
private $ExceptionCode = Array (); //Array to define the Expetion codes
private $aWarnings = Array (); //Array to store the warning that were throws by the class
private $longMailEreg ;
private $mailEreg ;
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
/**
* Class constructor - iniatilize default values
* @ param none
* @ return none
*/
function __construct () {
$this -> config = array ();
$this -> fileData = array ();
$this -> spool_id = '' ;
$this -> status = 'pending' ;
$this -> error = '' ;
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
$this -> ExceptionCode [ 'FATAL' ] = 1 ;
$this -> ExceptionCode [ 'WARNING' ] = 2 ;
$this -> ExceptionCode [ 'NOTICE' ] = 3 ;
2012-02-14 10:32:48 -04:00
$this -> longMailEreg = '/(.*)(<([\w\-\.]+@[\w\-_\.]+\.\w{2,3})+>)/' ;
$this -> mailEreg = '/^([\w\-_\.]+@[\w\-_\.]+\.\w{2,3}+)$/' ;
2010-12-02 23:34:41 +00:00
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
/**
* get all files into spool in a list
* @ param none
* @ return none
*/
public function getSpoolFilesList () {
$sql = " SELECT * FROM APP_MESSAGE WHERE APP_MSG_STATUS ='pending' " ;
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
$con = Propel :: getConnection ( " workflow " );
$stmt = $con -> prepareStatement ( $sql );
$rs = $stmt -> executeQuery ();
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
while ( $rs -> next () ) {
$this -> spool_id = $rs -> getString ( 'APP_MSG_UID' );
$this -> fileData [ 'subject' ] = $rs -> getString ( 'APP_MSG_SUBJECT' );
$this -> fileData [ 'from' ] = $rs -> getString ( 'APP_MSG_FROM' );
$this -> fileData [ 'to' ] = $rs -> getString ( 'APP_MSG_TO' );
$this -> fileData [ 'body' ] = $rs -> getString ( 'APP_MSG_BODY' );
$this -> fileData [ 'date' ] = $rs -> getString ( 'APP_MSG_DATE' );
$this -> fileData [ 'cc' ] = $rs -> getString ( 'APP_MSG_CC' );
$this -> fileData [ 'bcc' ] = $rs -> getString ( 'APP_MSG_BCC' );
$this -> fileData [ 'template' ] = $rs -> getString ( 'APP_MSG_TEMPLATE' );
$this -> fileData [ 'attachments' ] = array (); //$rs->getString('APP_MSG_ATTACH');
if ( $this -> config [ 'MESS_ENGINE' ] == 'OPENMAIL' ) {
if ( $this -> config [ 'MESS_SERVER' ] != '' ) {
if ( ( $sAux = @ gethostbyaddr ( $this -> config [ 'MESS_SERVER' ])) ) {
$this -> fileData [ 'domain' ] = $sAux ;
} else {
$this -> fileData [ 'domain' ] = $this -> config [ 'MESS_SERVER' ];
}
} else {
$this -> fileData [ 'domain' ] = gethostbyaddr ( '127.0.0.1' );
}
}
$this -> sendMail ();
}
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
/**
* create a msg record for spool
* @ param array $aData
* @ return none
*/
public function create ( $aData ) {
2011-04-19 17:16:12 -04:00
$sUID = $this -> db_insert ( $aData );
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
$aData [ 'app_msg_date' ] = isset ( $aData [ 'app_msg_date' ]) ? $aData [ 'app_msg_date' ] : '' ;
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
if ( isset ( $aData [ 'app_msg_status' ]) ) {
$this -> status = strtolower ( $aData [ 'app_msg_status' ]);
}
2012-06-21 12:46:19 -04:00
2011-08-08 18:51:04 -04:00
$this -> setData ( $sUID , $aData [ 'app_msg_subject' ], $aData [ 'app_msg_from' ], $aData [ 'app_msg_to' ], $aData [ 'app_msg_body' ], $aData [ 'app_msg_date' ], $aData [ 'app_msg_cc' ], $aData [ 'app_msg_bcc' ], $aData [ 'app_msg_template' ], $aData [ 'app_msg_attach' ]);
2010-12-02 23:34:41 +00:00
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
/**
* set configuration
* @ param array $aConfig
* @ return none
*/
public function setConfig ( $aConfig ) {
$this -> config = $aConfig ;
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
/**
* set email parameters
* @ param string $sAppMsgUid , $sSubject , $sFrom , $sTo , $sBody , $sDate , $sCC , $sBCC , $sTemplate
* @ return none
*/
2012-06-21 12:46:19 -04:00
public function setData ( $sAppMsgUid , $sSubject , $sFrom , $sTo , $sBody , $sDate = '' , $sCC = '' , $sBCC = '' , $sTemplate = '' , $aAttachment = array ()) {
2010-12-02 23:34:41 +00:00
$this -> spool_id = $sAppMsgUid ;
$this -> fileData [ 'subject' ] = $sSubject ;
$this -> fileData [ 'from' ] = $sFrom ;
$this -> fileData [ 'to' ] = $sTo ;
$this -> fileData [ 'body' ] = $sBody ;
$this -> fileData [ 'date' ] = ( $sDate != '' ? $sDate : date ( 'Y-m-d H:i:s' ));
$this -> fileData [ 'cc' ] = $sCC ;
$this -> fileData [ 'bcc' ] = $sBCC ;
$this -> fileData [ 'template' ] = $sTemplate ;
2012-06-21 12:46:19 -04:00
$this -> fileData [ 'attachments' ] = is_array ( $aAttachment ) ? $aAttachment : ( $aAttachment != '' ? explode ( ',' , $aAttachment ) : array ());
$this -> fileData [ 'envelope_to' ] = array ();
2010-12-02 23:34:41 +00:00
if ( $this -> config [ 'MESS_ENGINE' ] == 'OPENMAIL' ) {
if ( $this -> config [ 'MESS_SERVER' ] != '' ) {
if ( ( $sAux = @ gethostbyaddr ( $this -> config [ 'MESS_SERVER' ])) ) {
$this -> fileData [ 'domain' ] = $sAux ;
} else {
$this -> fileData [ 'domain' ] = $this -> config [ 'MESS_SERVER' ];
}
} else {
$this -> fileData [ 'domain' ] = gethostbyaddr ( '127.0.0.1' );
}
}
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
/**
* send mail
* @ param none
* @ return boolean true or exception
*/
public function sendMail () {
try {
$this -> handleFrom ();
$this -> handleEnvelopeTo ();
$this -> handleMail ();
$this -> updateSpoolStatus ();
return true ;
} catch ( Exception $e ) {
throw $e ;
}
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
/**
* update the status to spool
* @ param none
* @ return none
*/
private function updateSpoolStatus () {
$oAppMessage = AppMessagePeer :: retrieveByPK ( $this -> spool_id );
$oAppMessage -> setappMsgstatus ( $this -> status );
$oAppMessage -> setappMsgsenddate ( date ( 'Y-m-d H:i:s' ));
$oAppMessage -> save ();
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
/**
2012-06-21 12:46:19 -04:00
* handle the email that was set in " TO " parameter
2010-12-02 23:34:41 +00:00
* @ param none
* @ return boolean true or exception
*/
private function handleFrom () {
2012-06-21 12:46:19 -04:00
if ( strpos ( $this -> fileData [ 'from' ], '<' ) !== false ) {
2010-12-02 23:34:41 +00:00
//to validate complex email address i.e. Erik A. O <erik@colosa.com>
preg_match ( $this -> longMailEreg , $this -> fileData [ 'from' ], $matches );
if ( isset ( $matches [ 1 ]) && $matches [ 1 ] != '' ) {
//drop the " characters if they exist
$this -> fileData [ 'from_name' ] = trim ( str_replace ( '"' , '' , $matches [ 1 ]));
2012-06-21 12:46:19 -04:00
}
2012-02-14 10:32:48 -04:00
else { //if the from name was not set
$this -> fileData [ 'from_name' ] = '' ;
2010-12-02 23:34:41 +00:00
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
if ( ! isset ( $matches [ 3 ]) ) {
throw new Exception ( 'Invalid email address in FROM parameter (' . $this -> fileData [ 'from' ] . ')' , $this -> ExceptionCode [ 'WARNING' ]);
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
$this -> fileData [ 'from_email' ] = trim ( $matches [ 3 ]);
2012-06-21 12:46:19 -04:00
}
2012-02-14 10:32:48 -04:00
else {
2010-12-02 23:34:41 +00:00
//to validate simple email address i.e. erik@colosa.com
preg_match ( $this -> mailEreg , $this -> fileData [ 'from' ], $matches );
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
if ( ! isset ( $matches [ 0 ]) ) {
throw new Exception ( 'Invalid email address in FROM parameter (' . $this -> fileData [ 'from' ] . ')' , $this -> ExceptionCode [ 'WARNING' ]);
}
2012-06-21 12:46:19 -04:00
2012-02-14 10:32:48 -04:00
$this -> fileData [ 'from_name' ] = '' ;
2010-12-02 23:34:41 +00:00
$this -> fileData [ 'from_email' ] = $matches [ 0 ];
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
/**
* handle all recipients to compose the mail
* @ param none
* @ return boolean true or exception
*/
private function handleEnvelopeTo () {
$hold = array ();
2011-01-19 15:19:32 +00:00
$holdcc = array ();
$holdbcc = array ();
2010-12-02 23:34:41 +00:00
$text = trim ( $this -> fileData [ 'to' ]);
2012-06-21 12:46:19 -04:00
2011-01-26 21:30:05 +00:00
$textcc = '' ;
2012-06-21 12:46:19 -04:00
$textbcc = '' ;
2010-12-02 23:34:41 +00:00
if ( isset ( $this -> fileData [ 'cc' ]) && trim ( $this -> fileData [ 'cc' ]) != '' ) {
2011-01-19 15:19:32 +00:00
$textcc = trim ( $this -> fileData [ 'cc' ]);
2010-12-02 23:34:41 +00:00
}
2011-01-19 15:19:32 +00:00
2010-12-02 23:34:41 +00:00
if ( isset ( $this -> fileData [ 'bcc' ]) && trim ( $this -> fileData [ 'bcc' ]) != '' ) {
2011-01-19 15:19:32 +00:00
$textbcc = trim ( $this -> fileData [ 'bcc' ]);
2010-12-02 23:34:41 +00:00
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
if ( false !== ( strpos ( $text , ',' )) ) {
$hold = explode ( ',' , $text );
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
foreach ( $hold as $val ) {
if ( strlen ( $val ) > 0 ) {
$this -> fileData [ 'envelope_to' ][] = " $val " ;
}
}
2011-04-19 17:16:12 -04:00
} else if ( $text != '' ) {
2010-12-02 23:34:41 +00:00
$this -> fileData [ 'envelope_to' ][] = " $text " ;
2011-04-19 17:16:12 -04:00
} else {
$this -> fileData [ 'envelope_to' ] = Array ();
2010-12-02 23:34:41 +00:00
}
2012-06-21 12:46:19 -04:00
2011-04-19 17:16:12 -04:00
//CC
if ( false !== ( strpos ( $textcc , ',' )) ) {
2011-01-19 15:19:32 +00:00
$holdcc = explode ( ',' , $textcc );
foreach ( $holdcc as $valcc ) {
if ( strlen ( $valcc ) > 0 ) {
$this -> fileData [ 'envelope_cc' ][] = " $valcc " ;
}
}
2011-04-19 17:16:12 -04:00
} else if ( $textcc != '' ) {
2011-01-19 15:19:32 +00:00
$this -> fileData [ 'envelope_cc' ][] = " $textcc " ;
2011-04-19 17:16:12 -04:00
} else {
$this -> fileData [ 'envelope_cc' ] = Array ();
2011-01-19 15:19:32 +00:00
}
2012-06-21 12:46:19 -04:00
2011-04-19 17:16:12 -04:00
//BCC
if ( false !== ( strpos ( $textbcc , ',' )) ) {
2011-01-19 15:19:32 +00:00
$holdbcc = explode ( ',' , $textbcc );
foreach ( $holdbcc as $valbcc ) {
if ( strlen ( $valbcc ) > 0 ) {
$this -> fileData [ 'envelope_bcc' ][] = " $valbcc " ;
}
}
2011-04-19 17:16:12 -04:00
} else if ( $textbcc != '' ) {
2011-01-19 15:19:32 +00:00
$this -> fileData [ 'envelope_bcc' ][] = " $textbcc " ;
2012-06-21 12:46:19 -04:00
} else {
2011-04-19 17:16:12 -04:00
$this -> fileData [ 'envelope_bcc' ] = Array ();
2011-01-19 15:19:32 +00:00
}
2010-12-02 23:34:41 +00:00
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
/**
* handle and compose the email content and parameters
* @ param none
* @ return none
*/
private function handleMail () {
if ( count ( $this -> fileData [ 'envelope_to' ]) > 0 ) {
switch ( $this -> config [ 'MESS_ENGINE' ] ) {
case 'MAIL' :
G :: LoadThirdParty ( 'phpmailer' , 'class.phpmailer' );
$oPHPMailer = new PHPMailer ();
$oPHPMailer -> Mailer = 'mail' ;
$oPHPMailer -> SMTPAuth = ( isset ( $this -> config [ 'SMTPAuth' ]) ? $this -> config [ 'SMTPAuth' ] : '' );
$oPHPMailer -> Host = $this -> config [ 'MESS_SERVER' ];
$oPHPMailer -> Port = $this -> config [ 'MESS_PORT' ];
$oPHPMailer -> Username = $this -> config [ 'MESS_ACCOUNT' ];
2012-02-14 10:32:48 -04:00
$passwd = $this -> config [ 'MESS_PASSWORD' ];
2012-03-07 18:01:37 -04:00
$passwdDec = G :: decrypt ( $passwd , 'EMAILENCRYPT' );
if ( strpos ( $passwdDec , 'hash:' ) !== false ) {
2012-06-21 12:46:19 -04:00
list ( $hash , $pass ) = explode ( " : " , $passwdDec );
2012-03-26 19:13:29 -04:00
$this -> config [ 'MESS_PASSWORD' ] = $pass ;
2011-12-22 10:16:52 -04:00
}
2010-12-02 23:34:41 +00:00
$oPHPMailer -> Password = $this -> config [ 'MESS_PASSWORD' ];
$oPHPMailer -> From = $this -> fileData [ 'from_email' ];
$oPHPMailer -> FromName = utf8_decode ( $this -> fileData [ 'from_name' ]);
$oPHPMailer -> Subject = utf8_decode ( $this -> fileData [ 'subject' ]);
$oPHPMailer -> Body = utf8_decode ( $this -> fileData [ 'body' ]);
2011-08-17 10:41:06 -04:00
if ( is_array ( $this -> fileData [ 'attachments' ])){
foreach ( $this -> fileData [ 'attachments' ] as $key => $fileAttach ){
2012-02-16 15:28:06 -04:00
$oPHPMailer -> AddAttachment ( $fileAttach , is_int ( $key ) ? '' : $key );
2011-08-17 10:41:06 -04:00
}
}
2010-12-02 23:34:41 +00:00
foreach ( $this -> fileData [ 'envelope_to' ] as $sEmail ) {
if ( strpos ( $sEmail , '<' ) !== false ) {
preg_match ( $this -> longMailEreg , $sEmail , $matches );
$sTo = trim ( $matches [ 3 ]);
$sToName = trim ( $matches [ 1 ]);
$oPHPMailer -> AddAddress ( $sTo , $sToName );
} else {
$oPHPMailer -> AddAddress ( $sEmail );
}
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
$oPHPMailer -> IsHTML ( true );
if ( $oPHPMailer -> Send () ) {
$this -> error = '' ;
$this -> status = 'sent' ;
} else {
$this -> error = $oPHPMailer -> ErrorInfo ;
$this -> status = 'failed' ;
}
break ;
case 'PHPMAILER' :
G :: LoadThirdParty ( 'phpmailer' , 'class.phpmailer' );
2011-04-19 17:16:12 -04:00
$oPHPMailer = new PHPMailer ( true );
2010-12-02 23:34:41 +00:00
$oPHPMailer -> Mailer = 'smtp' ;
$oPHPMailer -> SMTPAuth = ( isset ( $this -> config [ 'SMTPAuth' ]) ? $this -> config [ 'SMTPAuth' ] : '' );
2012-06-21 12:46:19 -04:00
2011-04-19 17:16:12 -04:00
/**
* Posible Options for SMTPSecure are : " " , " ssl " or " tls "
*/
2011-07-08 19:06:32 -04:00
if ( isset ( $this -> config [ 'SMTPSecure' ]) && preg_match ( '/^(ssl|tls)$/' , $this -> config [ 'SMTPSecure' ])) {
2011-04-19 17:16:12 -04:00
$oPHPMailer -> SMTPSecure = $this -> config [ 'SMTPSecure' ];
}
2011-08-15 17:13:40 -04:00
$oPHPMailer -> CharSet = " UTF-8 " ;
$oPHPMailer -> Encoding = " 8bit " ;
2010-12-02 23:34:41 +00:00
$oPHPMailer -> Host = $this -> config [ 'MESS_SERVER' ];
$oPHPMailer -> Port = $this -> config [ 'MESS_PORT' ];
$oPHPMailer -> Username = $this -> config [ 'MESS_ACCOUNT' ];
2012-02-14 10:32:48 -04:00
$passwd = $this -> config [ 'MESS_PASSWORD' ];
2012-03-07 18:01:37 -04:00
$passwdDec = G :: decrypt ( $passwd , 'EMAILENCRYPT' );
if ( strpos ( $passwdDec , 'hash:' ) !== false ) {
2012-06-21 12:46:19 -04:00
list ( $hash , $pass ) = explode ( " : " , $passwdDec );
2012-03-26 19:13:29 -04:00
$this -> config [ 'MESS_PASSWORD' ] = $pass ;
2011-12-22 10:16:52 -04:00
}
2010-12-02 23:34:41 +00:00
$oPHPMailer -> Password = $this -> config [ 'MESS_PASSWORD' ];
$oPHPMailer -> From = $this -> fileData [ 'from_email' ];
2012-06-21 12:46:19 -04:00
$oPHPMailer -> FromName = utf8_decode ( $this -> fileData [ 'from_name' ]);
2011-08-15 17:13:40 -04:00
$msSubject = $this -> fileData [ 'subject' ];
2011-08-15 17:21:18 -04:00
if ( ! ( mb_detect_encoding ( $msSubject , " UTF-8 " ) == " UTF-8 " )) {
$msSubject = utf8_encode ( $msSubject );
}
2012-06-21 12:46:19 -04:00
$oPHPMailer -> Subject = $msSubject ;
2011-08-15 17:13:40 -04:00
$msBody = $this -> fileData [ 'body' ];
2011-08-15 17:21:18 -04:00
if ( ! ( mb_detect_encoding ( $msBody , " UTF-8 " ) == " UTF-8 " )) {
$msBody = utf8_encode ( $msBody );
2012-06-21 12:46:19 -04:00
}
2011-08-15 17:13:40 -04:00
$oPHPMailer -> Body = $msBody ;
2012-06-21 12:46:19 -04:00
2011-08-17 10:41:06 -04:00
if ( is_array ( $this -> fileData [ 'attachments' ])){
foreach ( $this -> fileData [ 'attachments' ] as $key => $fileAttach ){
2012-02-16 15:28:06 -04:00
$oPHPMailer -> AddAttachment ( $fileAttach , is_int ( $key ) ? '' : $key );
2011-08-17 10:41:06 -04:00
}
}
2010-12-02 23:34:41 +00:00
foreach ( $this -> fileData [ 'envelope_to' ] as $sEmail ) {
2012-06-21 12:46:19 -04:00
$evalMail = strpos ( $sEmail , '<' );
2010-12-02 23:34:41 +00:00
if ( strpos ( $sEmail , '<' ) !== false ) {
preg_match ( $this -> longMailEreg , $sEmail , $matches );
$sTo = trim ( $matches [ 3 ]);
$sToName = trim ( $matches [ 1 ]);
$oPHPMailer -> AddAddress ( $sTo , $sToName );
} else {
$oPHPMailer -> AddAddress ( $sEmail );
}
}
2012-06-21 12:46:19 -04:00
2011-04-19 17:16:12 -04:00
//CC
foreach ( $this -> fileData [ 'envelope_cc' ] as $sEmail ) {
2011-01-19 15:19:32 +00:00
$evalMail = strpos ( $sEmail , '<' );
if ( strpos ( $sEmail , '<' ) !== false ) {
preg_match ( $this -> longMailEreg , $sEmail , $matches );
$sTo = trim ( $matches [ 3 ]);
$sToName = trim ( $matches [ 1 ]);
$oPHPMailer -> AddCC ( $sTo , $sToName );
} else {
$oPHPMailer -> AddCC ( $sEmail );
}
}
2012-06-21 12:46:19 -04:00
2011-04-19 17:16:12 -04:00
//BCC
foreach ( $this -> fileData [ 'envelope_bcc' ] as $sEmail ) {
2011-01-19 15:19:32 +00:00
$evalMail = strpos ( $sEmail , '<' );
if ( strpos ( $sEmail , '<' ) !== false ) {
preg_match ( $this -> longMailEreg , $sEmail , $matches );
$sTo = trim ( $matches [ 3 ]);
$sToName = trim ( $matches [ 1 ]);
$oPHPMailer -> AddBCC ( $sTo , $sToName );
} else {
$oPHPMailer -> AddBCC ( $sEmail );
}
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
$oPHPMailer -> IsHTML ( true );
if ( $oPHPMailer -> Send () ) {
$this -> error = '' ;
$this -> status = 'sent' ;
} else {
$this -> error = $oPHPMailer -> ErrorInfo ;
$this -> status = 'failed' ;
}
break ;
case 'OPENMAIL' :
G :: LoadClass ( 'package' );
G :: LoadClass ( 'smtp' );
$pack = new package ( $this -> fileData );
$header = $pack -> returnHeader ();
$body = $pack -> returnBody ();
$send = new smtp ();
$send -> setServer ( $this -> config [ 'MESS_SERVER' ]);
$send -> setPort ( $this -> config [ 'MESS_PORT' ]);
$send -> setUsername ( $this -> config [ 'MESS_ACCOUNT' ]);
2012-06-21 12:46:19 -04:00
2012-02-14 10:32:48 -04:00
$passwd = $this -> config [ 'MESS_PASSWORD' ];
2012-03-07 18:01:37 -04:00
$passwdDec = G :: decrypt ( $passwd , 'EMAILENCRYPT' );
if ( strpos ( $passwdDec , 'hash:' ) !== false ) {
2012-06-21 12:46:19 -04:00
list ( $hash , $pass ) = explode ( " : " , $passwdDec );
2012-03-26 19:13:29 -04:00
$this -> config [ 'MESS_PASSWORD' ] = $pass ;
2011-12-22 10:16:52 -04:00
}
2010-12-02 23:34:41 +00:00
$send -> setPassword ( $this -> config [ 'MESS_PASSWORD' ]);
$send -> setReturnPath ( $this -> fileData [ 'from_email' ]);
$send -> setHeaders ( $header );
$send -> setBody ( $body );
$send -> setEnvelopeTo ( $this -> fileData [ 'envelope_to' ]);
if ( $send -> sendMessage () ) {
$this -> error = '' ;
$this -> status = 'sent' ;
} else {
$this -> error = implode ( ', ' , $send -> returnErrors ());
$this -> status = 'failed' ;
}
break ;
}
}
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
/**
* try resend the emails from spool
* @ param none
* @ return none or exception
*/
function resendEmails () {
2012-05-04 12:01:42 -04:00
require_once ( " classes/model/Configuration.php " );
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
$oConfiguration = new Configuration ();
2012-06-21 12:46:19 -04:00
2012-05-04 12:01:42 -04:00
$aConfiguration = $oConfiguration -> load ( " Emails " , " " , " " , " " , " " );
2012-06-21 12:46:19 -04:00
2012-05-04 12:01:42 -04:00
$aConfiguration = unserialize ( $aConfiguration [ " CFG_VALUE " ]);
$passwd = $aConfiguration [ " MESS_PASSWORD " ];
$passwdDec = G :: decrypt ( $passwd , " EMAILENCRYPT " );
2012-06-21 12:46:19 -04:00
2012-05-04 12:01:42 -04:00
if ( strpos ( $passwdDec , " hash: " ) !== false ) {
list ( $hash , $pass ) = explode ( " : " , $passwdDec );
$aConfiguration [ " MESS_PASSWORD " ] = $pass ;
2011-12-22 10:16:52 -04:00
}
2012-06-21 12:46:19 -04:00
2012-05-04 12:01:42 -04:00
if ( $aConfiguration [ " MESS_ENABLED " ] == " 1 " ) {
$this -> setConfig ( array (
2012-06-21 12:46:19 -04:00
" MESS_ENGINE " => $aConfiguration [ " MESS_ENGINE " ],
" MESS_SERVER " => $aConfiguration [ " MESS_SERVER " ],
" MESS_PORT " => $aConfiguration [ " MESS_PORT " ],
" MESS_ACCOUNT " => $aConfiguration [ " MESS_ACCOUNT " ],
2012-05-04 12:01:42 -04:00
" MESS_PASSWORD " => $aConfiguration [ " MESS_PASSWORD " ],
" SMTPAuth " => $aConfiguration [ " MESS_RAUTH " ],
" SMTPSecure " => $aConfiguration [ " SMTPSecure " ]
2010-12-02 23:34:41 +00:00
));
2012-06-21 12:46:19 -04:00
2012-05-04 12:01:42 -04:00
///////
require_once ( " classes/model/AppMessage.php " );
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
$oCriteria = new Criteria ( 'workflow' );
$oCriteria -> add ( AppMessagePeer :: APP_MSG_STATUS , 'sent' , Criteria :: NOT_EQUAL );
$oDataset = AppMessagePeer :: doSelectRS ( $oCriteria );
$oDataset -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
while ( $oDataset -> next () ) {
$aRow = $oDataset -> getRow ();
try {
2012-06-21 12:46:19 -04:00
$this -> setData ( $aRow [ 'APP_MSG_UID' ], $aRow [ 'APP_MSG_SUBJECT' ], $aRow [ 'APP_MSG_FROM' ], $aRow [ 'APP_MSG_TO' ], $aRow [ 'APP_MSG_BODY' ], date ( 'Y-m-d H:i:s' ), $aRow [ 'APP_MSG_CC' ], $aRow [ 'APP_MSG_BCC' ], $aRow [ 'APP_MSG_TEMPLATE' ], $aRow [ 'APP_MSG_ATTACH' ]);
2010-12-02 23:34:41 +00:00
$this -> sendMail ();
} catch ( Exception $oException ) {
if ( $oException -> getCode () == $this -> ExceptionCode [ 'WARNING' ] ) {
array_push ( $this -> aWarnings , 'Spool::resendEmails(): Using ' . $aConfiguration [ 'MESS_ENGINE' ] . ' for APP_MGS_UID=' . $aRow [ 'APP_MSG_UID' ] . ' -> With message: ' . $oException -> getMessage ());
continue ;
} else {
throw $oException ;
}
}
}
}
}
2012-06-21 12:46:19 -04:00
2010-12-02 23:34:41 +00:00
/**
* gets all warnings
* @ param none
2012-06-21 12:46:19 -04:00
* @ return string $this -> aWarnings
2010-12-02 23:34:41 +00:00
*/
function getWarnings () {
if ( sizeof ( $this -> aWarnings ) != 0 ) {
return $this -> aWarnings ;
}
return false ;
}
2012-06-21 12:46:19 -04:00
2011-04-19 17:16:12 -04:00
/**
* db_insert
*
* @ param array $db_spool
* @ return string $sUID ;
*/
public function db_insert ( $db_spool )
{
$sUID = G :: generateUniqueID ();
$spool = new AppMessage ();
$spool -> setAppMsgUid ( $sUID );
$spool -> setMsgUid ( $db_spool [ 'msg_uid' ]);
$spool -> setAppUid ( $db_spool [ 'app_uid' ]);
$spool -> setDelIndex ( $db_spool [ 'del_index' ]);
$spool -> setAppMsgType ( $db_spool [ 'app_msg_type' ]);
$spool -> setAppMsgSubject ( $db_spool [ 'app_msg_subject' ]);
$spool -> setAppMsgFrom ( $db_spool [ 'app_msg_from' ]);
$spool -> setAppMsgTo ( $db_spool [ 'app_msg_to' ]);
$spool -> setAppMsgBody ( $db_spool [ 'app_msg_body' ]);
$spool -> setAppMsgDate ( date ( 'Y-m-d H:i:s' ));
$spool -> setAppMsgCc ( $db_spool [ 'app_msg_cc' ]);
$spool -> setAppMsgBcc ( $db_spool [ 'app_msg_bcc' ]);
$spool -> setappMsgAttach ( $db_spool [ 'app_msg_attach' ]);
$spool -> setAppMsgTemplate ( $db_spool [ 'app_msg_template' ]);
$spool -> setAppMsgStatus ( $db_spool [ 'app_msg_status' ]);
$spool -> setAppMsgSendDate ( date ( 'Y-m-d H:i:s' )); // Add by Ankit
if ( ! $spool -> validate ()) {
$errors = $spool -> getValidationFailures ();
$this -> status = 'error' ;
foreach ( $errors as $key => $value ) {
echo " Validation error - " . $value -> getMessage ( $key ) . " \n " ;
}
}
else {
//echo "Saving - validation ok\n";
$this -> status = 'success' ;
$spool -> save ();
}
return $sUID ;
}
2010-12-02 23:34:41 +00:00
}
2012-06-21 12:46:19 -04:00
?>