*/ 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'; } }