summaryrefslogtreecommitdiff
path: root/Postman/Postman-Email-Log
diff options
context:
space:
mode:
authoryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2019-11-25 09:25:43 +0000
committeryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2019-11-25 09:25:43 +0000
commitb5fd728e37aa2a9c7a5f37e8dead0a95117d541b (patch)
treea7158edc5e4e576e0377f078dabc87c699315c62 /Postman/Postman-Email-Log
parentc61784411988d36d9bbd93cd3a97e773990af342 (diff)
downloadPost-SMTP-b5fd728e37aa2a9c7a5f37e8dead0a95117d541b.zip
phpmailer delivery improvments
bug fixes add option to disable notifications fix Invalid “Reply-To” e-mail address
Diffstat (limited to 'Postman/Postman-Email-Log')
-rw-r--r--Postman/Postman-Email-Log/PostmanEmailLogService.php65
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()
*