Uses regexp pattern as originally defined from http://w3.org/International/questions/qa-forms-utf-8.html
and modified by chris@w3style.co.uk for efficiency.
public static IsContainsUtf8 ( string $strString ) : boolean | ||
$strString | string | |
return | boolean | whether or not the string contains any UTF-8 characters |
/** * Given the way this object is set up, it will return two-index string array containing the correct * SMTP Message Header and Message Body for this object. * * This will make changes, cleanup and any additional setup to the HeaderArray in order to complete its task * * @param string $strEncodingType the encoding type to use (if null, then it uses QApplication's) * @param QDateTime $dttSendDate the optional QDateTime to use for the Date field or NULL if you want to use Now() * @return string[] index 0 is the Header and index 1 is the Body */ public function CalculateMessageHeaderAndBody($strEncodingType = null, QDateTime $dttSendDate = null) { // Setup Headers $this->RemoveHeader('Message-Id'); $this->SetHeader('From', $this->From); $this->SetHeader('To', $this->To); if ($dttSendDate) { $this->SetHeader('Date', $dttSendDate->ToString(QDateTime::FormatRfc5322)); } else { $this->SetHeader('Date', QDateTime::NowToString(QDateTime::FormatRfc5322)); } // Setup Encoding Type (default to QApplication's if not specified) if (!$strEncodingType) { $strEncodingType = QApplication::$EncodingType; } // Additional "Optional" Headers if ($this->Subject) { // Encode to UTF8 Subject if Applicable if (QString::IsContainsUtf8($this->Subject)) { $strSubject = QString::QuotedPrintableEncode($this->Subject); $strSubject = str_replace("=\r\n", "", $strSubject); $strSubject = str_replace('?', '=3F', $strSubject); $this->SetHeader('Subject', sprintf("=?%s?Q?%s?=", $strEncodingType, $strSubject)); } else { $this->SetHeader('Subject', $this->Subject); } } if ($this->Cc) { $this->SetHeader('Cc', $this->Cc); } // Setup for MIME and Content Encoding $strBoundaryArray = $this->SetupMimeHeaders($strEncodingType); $strBoundary = $strBoundaryArray[0]; $strAltBoundary = $strBoundaryArray[1]; // Generate MessageHeader $strHeader = $this->CalculateMessageHeader(); // Generate MessageBody $strBody = $this->CalculateMessageBody($strEncodingType, $strBoundary, $strAltBoundary); return array($strHeader, $strBody); }