v2.2.0
This commit is contained in:
parent
0a42e00299
commit
0ece5f3a6d
16 changed files with 2342 additions and 785 deletions
161
includes/class-email-message.php
Normal file
161
includes/class-email-message.php
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
/**
|
||||
* Email Message Data Transfer Object
|
||||
*
|
||||
* Type-safe container for email data between Newsletter and queue system.
|
||||
*
|
||||
* @package ROBOTSTXT_SMTP_Newsletter
|
||||
* @since 2.2.0
|
||||
*/
|
||||
|
||||
namespace Robotstxt_SMTP_Newsletter;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Email Message DTO class.
|
||||
*
|
||||
* Encapsulates email message data for type safety and standardization.
|
||||
*/
|
||||
class Email_Message {
|
||||
|
||||
/**
|
||||
* Sender email address.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $from;
|
||||
|
||||
/**
|
||||
* Sender display name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $from_name;
|
||||
|
||||
/**
|
||||
* Recipient email address.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $to;
|
||||
|
||||
/**
|
||||
* Recipient display name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $to_name;
|
||||
|
||||
/**
|
||||
* Email subject.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subject;
|
||||
|
||||
/**
|
||||
* Email body (HTML).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $body;
|
||||
|
||||
/**
|
||||
* Email body (plain text).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $body_text;
|
||||
|
||||
/**
|
||||
* Additional headers.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public $headers;
|
||||
|
||||
/**
|
||||
* Newsletter campaign ID.
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
public $newsletter_id;
|
||||
|
||||
/**
|
||||
* Campaign display name.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $campaign_name;
|
||||
|
||||
/**
|
||||
* Reply-To email address.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $reply_to;
|
||||
|
||||
/**
|
||||
* Email provider identifier.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $provider;
|
||||
|
||||
/**
|
||||
* Create from Newsletter message object.
|
||||
*
|
||||
* Converts TNP_Mailer_Message to our standardized format.
|
||||
*
|
||||
* @param \TNP_Mailer_Message $msg Newsletter message object.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function from_newsletter_message( $msg ) {
|
||||
$instance = new self();
|
||||
|
||||
// Basic sender/recipient.
|
||||
$instance->from = $msg->from ?? '';
|
||||
$instance->from_name = $msg->from_name ?? '';
|
||||
$instance->to = $msg->to ?? '';
|
||||
$instance->to_name = $msg->to_name ?? '';
|
||||
|
||||
// Subject and body.
|
||||
$instance->subject = $msg->subject ?? '';
|
||||
$instance->body = $msg->body ?? '';
|
||||
$instance->body_text = $msg->body_text ?? '';
|
||||
|
||||
// Headers and reply-to.
|
||||
$instance->headers = is_array( $msg->headers ?? null ) ? $msg->headers : array();
|
||||
$instance->reply_to = $msg->reply_to ?? null;
|
||||
|
||||
// Campaign identification.
|
||||
// Newsletter uses 'id' property for the email ID (not campaign).
|
||||
// We'll try to extract campaign info from the message if available.
|
||||
$instance->newsletter_id = $msg->id ?? null;
|
||||
$instance->campaign_name = $msg->subject ?? __( 'Unnamed Campaign', 'robotstxt-smtp-newsletter' );
|
||||
|
||||
// Detect provider.
|
||||
$instance->provider = self::detect_provider();
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect current email provider.
|
||||
*
|
||||
* @return string Provider identifier.
|
||||
*/
|
||||
private static function detect_provider() {
|
||||
if ( ! class_exists( '\Robotstxt_SMTP\Plugin' ) ) {
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
$is_ses = \Robotstxt_SMTP\Plugin::is_amazon_ses_integration_active();
|
||||
|
||||
return $is_ses ? 'amazonses' : 'postfix';
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue