This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gggeek
committed
Jul 27, 2014
1 parent
de86b18
commit 0ad6061
Showing
6 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* | ||
* @author gaetano.giunta | ||
*/ | ||
|
||
class eZPerfLoggerMailProvider implements eZPerfLoggerProvider | ||
{ | ||
|
||
static public function measure( $output, $returnCode=null ) | ||
{ | ||
return eZPerfLoggerGenericTracer::StdKPIsFromAccumulators( array( | ||
'mail_sent' | ||
), eZPerfLogger::TimeAccumulatorList() | ||
); | ||
} | ||
|
||
public static function supportedVariables() | ||
{ | ||
return array( | ||
'mail_sent' => 'integer', | ||
'mail_sent_t' => 'float (secs, rounded to msec)', | ||
'mail_sent_tmax' => 'float (secs, rounded to msec)', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* Modified mail transport class that traces execution times even with debug off | ||
*/ | ||
|
||
class eZSendmailTracing47Transport extends eZSendmailTransport | ||
{ | ||
function sendMail( eZMail $mail ) | ||
{ | ||
$ini = eZINI::instance(); | ||
$sendmailOptions = ''; | ||
$emailFrom = $mail->sender(); | ||
$emailSender = isset( $emailFrom['email'] ) ? $emailFrom['email'] : false; | ||
if ( !$emailSender || count( $emailSender) <= 0 ) | ||
$emailSender = $ini->variable( 'MailSettings', 'EmailSender' ); | ||
if ( !$emailSender ) | ||
$emailSender = $ini->variable( 'MailSettings', 'AdminEmail' ); | ||
if ( !eZMail::validate( $emailSender ) ) | ||
$emailSender = false; | ||
|
||
$isSafeMode = ini_get( 'safe_mode' ) != 0; | ||
|
||
$sendmailOptionsArray = $ini->variable( 'MailSettings', 'SendmailOptions' ); | ||
if( is_array($sendmailOptionsArray) ) | ||
$sendmailOptions = implode( ' ', $sendmailOptionsArray ); | ||
elseif( !is_string($sendmailOptionsArray) ) | ||
$sendmailOptions = $sendmailOptionsArray; | ||
if ( !$isSafeMode and | ||
$emailSender ) | ||
$sendmailOptions .= ' -f'. $emailSender; | ||
|
||
if ( $isSafeMode and | ||
$emailSender and | ||
$mail->sender() == false ) | ||
$mail->setSenderText( $emailSender ); | ||
|
||
if( function_exists( 'mail' ) ) | ||
{ | ||
$message = $mail->body(); | ||
$sys = eZSys::instance(); | ||
$excludeHeaders = array( 'Subject' ); | ||
// If not Windows PHP mail() implementation, we can not specify a To: header in the $additional_headers parameter, | ||
// because then there will be 2 To: headers in the resulting e-mail. | ||
// However, we can use "undisclosed-recipients:;" in $to. | ||
if ( $sys->osType() != 'win32' ) | ||
{ | ||
$excludeHeaders[] = 'To'; | ||
$receiverEmailText = count( $mail->ReceiverElements ) > 0 ? $mail->receiverEmailText() : 'undisclosed-recipients:;'; | ||
} | ||
// If Windows PHP mail() implementation, we can specify a To: header in the $additional_headers parameter, | ||
// it will be used as the only To: header. | ||
// We can not use "undisclosed-recipients:;" in $to, it will result in a SMTP server response: 501 5.1.3 Bad recipient address syntax | ||
else | ||
{ | ||
$receiverEmailText = $mail->receiverEmailText(); | ||
} | ||
|
||
// If in debug mode, send to debug email address and nothing else | ||
if ( $ini->variable( 'MailSettings', 'DebugSending' ) == 'enabled' ) | ||
{ | ||
$receiverEmailText = $ini->variable( 'MailSettings', 'DebugReceiverEmail' ); | ||
$excludeHeaders[] = 'To'; | ||
$excludeHeaders[] = 'Cc'; | ||
$excludeHeaders[] = 'Bcc'; | ||
} | ||
|
||
$extraHeaders = $mail->headerText( array( 'exclude-headers' => $excludeHeaders ) ); | ||
|
||
eZPerfLogger::accumulatorStart( 'mail_sent' ); | ||
$returnedValue = mail( $receiverEmailText, $mail->subject(), $message, $extraHeaders, $sendmailOptions ); | ||
eZPerfLogger::accumulatorStop( 'mail_sent' ); | ||
|
||
if ( $returnedValue === false ) | ||
{ | ||
eZDebug::writeError( 'An error occurred while sending e-mail. Check the Sendmail error message for further information (usually in /var/log/messages)', | ||
__METHOD__ ); | ||
} | ||
|
||
return $returnedValue; | ||
} | ||
else | ||
{ | ||
eZDebug::writeWarning( "Unable to send mail: 'mail' function is not compiled into PHP.", __METHOD__ ); | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* Modified mail transport class that traces execution times even with debug off | ||
*/ | ||
|
||
class eZSMTPTracing47Transport extends eZSMTPTransport | ||
{ | ||
function sendMail( eZMail $mail ) | ||
{ | ||
$ini = eZINI::instance(); | ||
$parameters = array(); | ||
$parameters['host'] = $ini->variable( 'MailSettings', 'TransportServer' ); | ||
$parameters['helo'] = $ini->variable( 'MailSettings', 'SenderHost' ); | ||
$parameters['port'] = $ini->variable( 'MailSettings', 'TransportPort' ); | ||
$parameters['connectionType'] = $ini->variable( 'MailSettings', 'TransportConnectionType' ); | ||
$user = $ini->variable( 'MailSettings', 'TransportUser' ); | ||
$password = $ini->variable( 'MailSettings', 'TransportPassword' ); | ||
if ( $user and | ||
$password ) | ||
{ | ||
$parameters['auth'] = true; | ||
$parameters['user'] = $user; | ||
$parameters['pass'] = $password; | ||
} | ||
|
||
/* If email sender hasn't been specified or is empty | ||
* we substitute it with either MailSettings.EmailSender or AdminEmail. | ||
*/ | ||
if ( !$mail->senderText() ) | ||
{ | ||
$emailSender = $ini->variable( 'MailSettings', 'EmailSender' ); | ||
if ( !$emailSender ) | ||
$emailSender = $ini->variable( 'MailSettings', 'AdminEmail' ); | ||
|
||
eZMail::extractEmail( $emailSender, $emailSenderAddress, $emailSenderName ); | ||
|
||
if ( !eZMail::validate( $emailSenderAddress ) ) | ||
$emailSender = false; | ||
|
||
if ( $emailSender ) | ||
$mail->setSenderText( $emailSender ); | ||
} | ||
|
||
$excludeHeaders = $ini->variable( 'MailSettings', 'ExcludeHeaders' ); | ||
if ( count( $excludeHeaders ) > 0 ) | ||
$mail->Mail->appendExcludeHeaders( $excludeHeaders ); | ||
|
||
$options = new ezcMailSmtpTransportOptions(); | ||
if( $parameters['connectionType'] ) | ||
{ | ||
$options->connectionType = $parameters['connectionType']; | ||
} | ||
$smtp = new ezcMailSmtpTransport( $parameters['host'], $user, $password, | ||
$parameters['port'], $options ); | ||
|
||
// If in debug mode, send to debug email address and nothing else | ||
if ( $ini->variable( 'MailSettings', 'DebugSending' ) == 'enabled' ) | ||
{ | ||
$mail->Mail->to = array( new ezcMailAddress( $ini->variable( 'MailSettings', 'DebugReceiverEmail' ) ) ); | ||
$mail->Mail->cc = array(); | ||
$mail->Mail->bcc = array(); | ||
} | ||
|
||
// send() from ezcMailSmtpTransport doesn't return anything (it uses exceptions in case | ||
// something goes bad) | ||
try | ||
{ | ||
eZPerfLogger::accumulatorStart( 'mail_sent' ); | ||
$smtp->send( $mail->Mail ); | ||
eZPerfLogger::accumulatorStop( 'mail_sent' ); | ||
} | ||
catch ( ezcMailException $e ) | ||
{ | ||
eZPerfLogger::accumulatorStop( 'mail_send' ); | ||
eZDebug::writeError( $e->getMessage(), __METHOD__ ); | ||
return false; | ||
} | ||
|
||
// return true in case of no exceptions | ||
return true; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters