* SPDX-License-Identifier: AGPL-3.0-only
************************************/
/**
* This class provides structured way of accessing details of email.
*/
class Vtenext_MailRecord {//crmv@207843
// FROM address(es) list
var $_from;
// TO address(es) list
var $_to;
//var $_replyto;
// CC address(es) list
var $_cc;
// BCC address(es) list
var $_bcc;
// DATE
var $_date;
// SUBJECT
var $_subject;
// BODY (either HTML / PLAIN message)
var $_body;
// CHARSET of the body content
var $_charset;
// If HTML message was set as body content
var $_isbodyhtml;
// PLAIN message of the original email
var $_plainmessage = false;
// HTML message of the original email
var $_htmlmessage = false;
// ATTACHMENTS list of the email
var $_attachments = false;
// UNIQUEID associated with the email
var $_uniqueid = false;
var $_xuid = false; //crmv@56233
var $_folder = false; //crmv@56233
// Flag to avoid re-parsing the email body.
var $_bodyparsed = false;
var $eml = null; //crmv@178441
/** DEBUG Functionality. */
var $debug = false;
function log($message=false) {
if(!$message) $message = $this->__toString();
global $log;
if($log && $this->debug) { $log->debug($message); }
else if($this->debug) {
echo var_export($message, true) . "\n";
}
}
/**
* String representation of the object.
*/
function __toString() {
$tostring = '';
$tostring .= 'FROM: ['. implode(',', $this->_from) . ']';
$tostring .= ',TO: [' . implode(',', $this->_to) . ']';
if(!empty($this->_cc)) $tostring .= ',CC: [' . implode(',', $this->_cc) . ']';
if(!empty($this->_bcc))$tostring .= ',BCC: [' . implode(',', $this->_bcc) . ']';
$tostring .= ',DATE: ['. $this->_date . ']';
$tostring .= ',SUBJECT: ['. $this->_subject . ']';
return $tostring;
}
/**
* Constructor.
*/
function __construct($imap, $folder, $messageid, $fetchbody=true, $is_pec=false) { //crmv@56233 crmv@178441
$this->__parseHeader($imap, $messageid);
//crmv@178441
if ($is_pec) {
$this->__parseBody($imap, $messageid);
if (!empty($this->eml)) $this->__initObjectFromEml();
}
if ($fetchbody && !$this->_bodyparsed) {
$this->__parseBody($imap, $messageid);
if (!empty($this->eml) && $this->checkCertifiedEmailMessage()) $this->__initObjectFromEml();
}
//crmv@178441e
$this->_folder = $folder; //crmv@56233
}
/**
* Get body content as Text.
*/
function getBodyText($striptags=true) {
$bodytext = $this->_body;
if($this->_plainmessage) {
$bodytext = $this->_plainmessage;
} else if($this->_isbodyhtml) {
// TODO This conversion can added multiple lines if
// content is displayed directly on HTML page
$bodytext = preg_replace("#
#i", "\n", $bodytext); // crmv@120786
//crmv@81643
$bodytext = preg_replace("/