diff options
Diffstat (limited to 'Postman/Postman-Email-Log')
-rw-r--r-- | Postman/Postman-Email-Log/PostmanEmailLogService.php | 65 |
1 files changed, 20 insertions, 45 deletions
diff --git a/Postman/Postman-Email-Log/PostmanEmailLogService.php b/Postman/Postman-Email-Log/PostmanEmailLogService.php index 2538700..624342d 100644 --- a/Postman/Postman-Email-Log/PostmanEmailLogService.php +++ b/Postman/Postman-Email-Log/PostmanEmailLogService.php @@ -4,6 +4,7 @@ if ( ! defined( 'ABSPATH' ) ) { } require_once dirname(__DIR__ ) . '/PostmanLogFields.php'; +require_once POST_SMTP_PATH . '/Postman/Extensions/Core/Notifications/PostmanNotify.php'; if ( ! class_exists( 'PostmanEmailLog' ) ) { class PostmanEmailLog { @@ -56,6 +57,9 @@ if ( ! class_exists( 'PostmanEmailLogService' ) ) { */ private function __construct() { $this->logger = new PostmanLogger( get_class( $this ) ); + + add_action('post_smtp_on_success', array( $this, 'write_success_log' ), 10, 4 ); + add_action('post_smtp_on_failed', array( $this, 'write_failed_log' ), 10, 5 ); } /** @@ -69,6 +73,20 @@ if ( ! class_exists( 'PostmanEmailLogService' ) ) { return $inst; } + public function write_success_log($log, $message, $transcript, $transport) { + $options = PostmanOptions::getInstance(); + if ( $options->getRunMode() == PostmanOptions::RUN_MODE_PRODUCTION || $options->getRunMode() == PostmanOptions::RUN_MODE_LOG_ONLY ) { + $this->writeSuccessLog( $log, $message, $transcript, $transport ); + } + } + + public function write_failed_log($log, $message, $transcript, $transport, $statusMessage) { + $options = PostmanOptions::getInstance(); + if ( $options->getRunMode() == PostmanOptions::RUN_MODE_PRODUCTION || $options->getRunMode() == PostmanOptions::RUN_MODE_LOG_ONLY ) { + $this->writeFailureLog( $log, $message, $transcript, $transport, $statusMessage ); + } + } + /** * Logs successful email attempts * @@ -118,7 +136,6 @@ if ( ! class_exists( 'PostmanEmailLogService' ) ) { $options = PostmanOptions::getInstance(); - $this->checkForLogErrors( $log ,$message ); $new_status = $log->statusMessage; if ( $options->is_fallback && empty( $log->statusMessage ) ) { @@ -129,6 +146,8 @@ if ( ! class_exists( 'PostmanEmailLogService' ) ) { $new_status = '( ** Fallback ** ) ' . $log->statusMessage; } + $new_status = apply_filters( 'post_smtp_log_status', $new_status, $log, $message ); + // nothing here is sanitized as WordPress should take care of // making database writes safe $my_post = array( @@ -187,50 +206,6 @@ if ( ! class_exists( 'PostmanEmailLogService' ) ) { $purger->truncateLogItems( PostmanOptions::getInstance()->getMailLoggingMaxEntries() ); } - private function checkForLogErrors( PostmanEmailLog $log, $postMessage ) { - $message = __( 'You getting this message because an error detected while delivered your email.', 'post-smtp' ); - $message .= "\r\n" . sprintf( __( 'For the domain: %1$s','post-smtp' ), get_bloginfo('url') ); - $message .= "\r\n" . __( 'The log to paste when you open a support issue:', 'post-smtp' ) . "\r\n"; - - if ( $log->statusMessage && ! empty( $log->statusMessage ) ) { - require_once POST_SMTP_PATH . '/Postman/notifications/PostmanNotify.php'; - - $message = $message . $log->statusMessage; - - $notification_service = PostmanOptions::getInstance()->getNotificationService(); - switch ($notification_service) { - case 'default': - $notifyer = new PostmanMailNotify; - break; - case 'pushover': - $notifyer = new PostmanPushoverNotify; - break; - case 'slack': - $notifyer = new PostmanSlackNotify; - break; - default: - $notifyer = new PostmanMailNotify; - } - - $notifyer = apply_filters( 'post_smtp_notifier', $notifyer, $notification_service ); - - // Notifications - $notify = new PostmanNotify( $notifyer ); - $notify->send($message, $log); - $notify->push_to_chrome($log->statusMessage); - } - - /** - * @todo - * After commented by me, check if it was needed. - */ - preg_match_all( '/(.*)From/s', $log->sessionTranscript, $matches ); - - if ( isset( $matches[1][0] ) && ! empty( $matches[1][0] ) && strpos( strtolower( $matches[1][0] ), 'error' ) !== false ) { - $message = $message . $log->sessionTranscript; - } - } - /** * Creates a Log object for use by writeToEmailLog() * |