本文整理匯總了PHP中MailSo\Base\Utils::NormalizeCharset方法的典型用法代碼示例。如果您正苦於以下問題:PHP Utils::NormalizeCharset方法的具體用法?PHP Utils::NormalizeCharset怎麽用?PHP Utils::NormalizeCharset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MailSo\Base\Utils
的用法示例。
在下文中一共展示了Utils::NormalizeCharset方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: DecodeHeaderValue
/**
* @param string $sEncodedValue
* @param string $sIncomingCharset = ''
* @param string $sForcedIncomingCharset = ''
*
* @return string
*/
public static function DecodeHeaderValue($sEncodedValue, $sIncomingCharset = '', $sForcedIncomingCharset = '')
{
$sValue = $sEncodedValue;
if (0 < \strlen($sIncomingCharset)) {
$sIncomingCharset = \MailSo\Base\Utils::NormalizeCharsetByValue($sIncomingCharset, $sValue);
$sValue = \MailSo\Base\Utils::ConvertEncoding($sValue, $sIncomingCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
}
$sValue = \preg_replace('/\\?=[\\n\\r\\t\\s]{1,5}=\\?/m', '?==?', $sValue);
$sValue = \preg_replace('/[\\r\\n\\t]+/m', ' ', $sValue);
$aEncodeArray = array('');
$aMatch = array();
\preg_match_all('/=\\?[^\\?]+\\?[q|b|Q|B]\\?[^\\?]*(\\?=)/', $sValue, $aMatch);
if (isset($aMatch[0]) && \is_array($aMatch[0])) {
for ($iIndex = 0, $iLen = \count($aMatch[0]); $iIndex < $iLen; $iIndex++) {
if (isset($aMatch[0][$iIndex])) {
$iPos = @\strpos($aMatch[0][$iIndex], '*');
if (false !== $iPos) {
$aMatch[0][$iIndex][0] = \substr($aMatch[0][$iIndex][0], 0, $iPos);
}
}
}
$aEncodeArray = $aMatch[0];
}
$aParts = array();
$sMainCharset = '';
$bOneCharset = true;
for ($iIndex = 0, $iLen = \count($aEncodeArray); $iIndex < $iLen; $iIndex++) {
$aTempArr = array('', $aEncodeArray[$iIndex]);
if ('=?' === \substr(\trim($aTempArr[1]), 0, 2)) {
$iPos = \strpos($aTempArr[1], '?', 2);
$aTempArr[0] = \substr($aTempArr[1], 2, $iPos - 2);
$sEncType = \strtoupper($aTempArr[1][$iPos + 1]);
switch ($sEncType) {
case 'Q':
$sHeaderValuePart = \str_replace('_', ' ', $aTempArr[1]);
$aTempArr[1] = \quoted_printable_decode(\substr($sHeaderValuePart, $iPos + 3, \strlen($sHeaderValuePart) - $iPos - 5));
break;
case 'B':
$sHeaderValuePart = $aTempArr[1];
$aTempArr[1] = \MailSo\Base\Utils::Base64Decode(\substr($sHeaderValuePart, $iPos + 3, \strlen($sHeaderValuePart) - $iPos - 5));
break;
}
}
if (0 < \strlen($aTempArr[0])) {
$sCharset = 0 === \strlen($sForcedIncomingCharset) ? $aTempArr[0] : $sForcedIncomingCharset;
$sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset, true);
if ('' === $sMainCharset) {
$sMainCharset = $sCharset;
} else {
if ($sMainCharset !== $sCharset) {
$bOneCharset = false;
}
}
}
$aParts[] = array($aEncodeArray[$iIndex], $aTempArr[1], $sCharset);
unset($aTempArr);
}
for ($iIndex = 0, $iLen = \count($aParts); $iIndex < $iLen; $iIndex++) {
if ($bOneCharset) {
$sValue = \str_replace($aParts[$iIndex][0], $aParts[$iIndex][1], $sValue);
} else {
$aParts[$iIndex][2] = \MailSo\Base\Utils::NormalizeCharsetByValue($aParts[$iIndex][2], $aParts[$iIndex][1]);
$sValue = \str_replace($aParts[$iIndex][0], \MailSo\Base\Utils::ConvertEncoding($aParts[$iIndex][1], $aParts[$iIndex][2], \MailSo\Base\Enumerations\Charset::UTF_8), $sValue);
}
}
if ($bOneCharset && 0 < \strlen($sMainCharset)) {
$sMainCharset = \MailSo\Base\Utils::NormalizeCharsetByValue($sMainCharset, $sValue);
$sValue = \MailSo\Base\Utils::ConvertEncoding($sValue, $sMainCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
}
return $sValue;
}
示例2: raw
/**
* @return bool
*/
private function raw($bDownload = true, $bThumbnail = false)
{
$self = $this;
return $this->rawCallback((string) $this->getParamValue('RawKey', ''), function ($oAccount, $sContentType, $sFileName, $rResource, $oHelpdeskUser = null) use($self, $bDownload, $bThumbnail) {
$self->RawOutputHeaders($bDownload, $sContentType, $sFileName);
if (!$bDownload && 'text/html' === $sContentType) {
$sHtml = stream_get_contents($rResource);
if ($sHtml) {
$sCharset = '';
$aMacth = array();
if (preg_match('/charset[\\s]?=[\\s]?([^\\s"\']+)/i', $sHtml, $aMacth) && !empty($aMacth[1])) {
$sCharset = $aMacth[1];
}
if ('' !== $sCharset && \MailSo\Base\Enumerations\Charset::UTF_8 !== $sCharset) {
$sHtml = \MailSo\Base\Utils::ConvertEncoding($sHtml, \MailSo\Base\Utils::NormalizeCharset($sCharset, true), \MailSo\Base\Enumerations\Charset::UTF_8);
}
include_once PSEVEN_APP_ROOT_PATH . 'libraries/other/CssToInlineStyles.php';
$oCssToInlineStyles = new \TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($sHtml);
$oCssToInlineStyles->setEncoding('utf-8');
$oCssToInlineStyles->setUseInlineStylesBlock(true);
echo '<html><head></head><body>' . \MailSo\Base\HtmlUtils::ClearHtmlSimple($oCssToInlineStyles->convert(), true, true) . '</body></html>';
}
} else {
if ($bThumbnail && !$bDownload) {
$self->thumbResource($oAccount ? $oAccount : $oHelpdeskUser, $rResource, $sFileName);
} else {
\MailSo\Base\Utils::FpassthruWithTimeLimitReset($rResource);
}
}
}, !$bDownload);
}
示例3: InitByFetchResponse
/**
* @param string $sRawFolderFullName
* @param \MailSo\Imap\FetchResponse $oFetchResponse
* @param \MailSo\Imap\BodyStructure $oBodyStructure = null
* @param array $aAscPartsIds = array()
*
* @return CApiMailMessage
*/
public function InitByFetchResponse($sRawFolderFullName, $oFetchResponse, $oBodyStructure = null, $sRfc822SubMimeIndex = '', $aAscPartsIds = array())
{
if (!$oBodyStructure) {
$oBodyStructure = $oFetchResponse->GetFetchBodyStructure();
}
$aTextParts = $oBodyStructure ? $oBodyStructure->SearchHtmlOrPlainParts() : array();
$aICalPart = $oBodyStructure ? $oBodyStructure->SearchByContentType('text/calendar') : null;
$oICalPart = is_array($aICalPart) && 0 < count($aICalPart) ? $aICalPart[0] : null;
$aVCardPart = $oBodyStructure ? $oBodyStructure->SearchByContentType('text/vcard') : null;
$aVCardPart = $aVCardPart ? $aVCardPart : ($oBodyStructure ? $oBodyStructure->SearchByContentType('text/x-vcard') : null);
$oVCardPart = is_array($aVCardPart) && 0 < count($aVCardPart) ? $aVCardPart[0] : null;
$sUid = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID);
$sSize = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE);
$sInternalDate = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::INTERNALDATE);
$aFlags = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::FLAGS);
$this->sFolder = $sRawFolderFullName;
$this->iUid = is_numeric($sUid) ? (int) $sUid : 0;
$this->iSize = is_numeric($sSize) ? (int) $sSize : 0;
$this->iTextSize = 0;
$this->aFlags = is_array($aFlags) ? $aFlags : array();
$this->aFlagsLowerCase = array_map('strtolower', $this->aFlags);
$this->iInternalTimeStampInUTC = \MailSo\Base\DateTimeHelper::ParseInternalDateString($sInternalDate);
if ($oICalPart) {
$sICal = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oICalPart->PartID() . ']');
if (!empty($sICal)) {
$sICal = \MailSo\Base\Utils::DecodeEncodingValue($sICal, $oICalPart->MailEncodingName());
$sICal = \MailSo\Base\Utils::ConvertEncoding($sICal, \MailSo\Base\Utils::NormalizeCharset($oICalPart->Charset(), true), \MailSo\Base\Enumerations\Charset::UTF_8);
if (!empty($sICal) && false !== strpos($sICal, 'BEGIN:VCALENDAR')) {
$sICal = preg_replace('/(.*)(BEGIN[:]VCALENDAR(.+)END[:]VCALENDAR)(.*)/ms', '$2', $sICal);
} else {
$sICal = '';
}
if (!empty($sICal)) {
$this->AddExtend('ICAL_RAW', $sICal);
}
}
}
if ($oVCardPart) {
$sVCard = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oVCardPart->PartID() . ']');
if (!empty($sVCard)) {
$sVCard = \MailSo\Base\Utils::DecodeEncodingValue($sVCard, $oVCardPart->MailEncodingName());
$sVCard = \MailSo\Base\Utils::ConvertEncoding($sVCard, \MailSo\Base\Utils::NormalizeCharset($oVCardPart->Charset(), true), \MailSo\Base\Enumerations\Charset::UTF_8);
if (!empty($sVCard) && false !== strpos($sVCard, 'BEGIN:VCARD')) {
$sVCard = preg_replace('/(.*)(BEGIN\\:VCARD(.+)END\\:VCARD)(.*)/ms', '$2', $sVCard);
} else {
$sVCard = '';
}
if (!empty($sVCard)) {
$this->AddExtend('VCARD_RAW', $sVCard);
}
}
}
$sCharset = $oBodyStructure ? $oBodyStructure->SearchCharset() : '';
$sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
$this->sHeaders = trim($oFetchResponse->GetHeaderFieldsValue($sRfc822SubMimeIndex));
if (!empty($this->sHeaders)) {
$oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($this->sHeaders, false, $sCharset);
$sContentTypeCharset = $oHeaders->ParameterValue(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, \MailSo\Mime\Enumerations\Parameter::CHARSET);
if (!empty($sContentTypeCharset)) {
$sCharset = $sContentTypeCharset;
$sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
}
if (!empty($sCharset)) {
$oHeaders->SetParentCharset($sCharset);
}
$bCharsetAutoDetect = 0 === \strlen($sCharset);
$this->sSubject = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::SUBJECT, $bCharsetAutoDetect);
$this->sMessageId = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::MESSAGE_ID);
$this->sContentType = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE);
$aReceived = $oHeaders->ValuesByName(\MailSo\Mime\Enumerations\Header::RECEIVED);
$sReceived = !empty($aReceived[0]) ? trim($aReceived[0]) : '';
$sDate = '';
if (!empty($sReceived)) {
$aParts = explode(';', $sReceived);
if (0 < count($aParts)) {
$aParts = array_reverse($aParts);
foreach ($aParts as $sReceiveLine) {
$sReceiveLine = trim($sReceiveLine);
if (preg_match('/[\\d]{4} [\\d]{2}:[\\d]{2}:[\\d]{2} /', $sReceiveLine)) {
$sDate = $sReceiveLine;
break;
}
}
}
}
if (empty($sDate)) {
$sDate = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::DATE);
}
if (!empty($sDate)) {
$this->iReceivedOrDateTimeStampInUTC = \MailSo\Base\DateTimeHelper::ParseRFC2822DateString($sDate);
}
$this->oFrom = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::FROM_, $bCharsetAutoDetect);
//.........這裏部分代碼省略.........
示例4: InitByFetchResponse
/**
* @param string $sFolder
* @param \MailSo\Imap\FetchResponse $oFetchResponse
* @param \MailSo\Imap\BodyStructure $oBodyStructure = null
*
* @return \MailSo\Mail\Message
*/
public function InitByFetchResponse($sFolder, $oFetchResponse, $oBodyStructure = null)
{
if (!$oBodyStructure) {
$oBodyStructure = $oFetchResponse->GetFetchBodyStructure();
}
$sUid = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID);
$sSize = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE);
$sInternalDate = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::INTERNALDATE);
$aFlags = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::FLAGS);
$this->sFolder = $sFolder;
$this->iUid = \is_numeric($sUid) ? (int) $sUid : 0;
$this->iSize = \is_numeric($sSize) ? (int) $sSize : 0;
$this->aFlags = \is_array($aFlags) ? $aFlags : array();
$this->aFlagsLowerCase = \array_map('strtolower', $this->aFlags);
$this->iInternalTimeStampInUTC = \MailSo\Base\DateTimeHelper::ParseInternalDateString($sInternalDate);
$sCharset = $oBodyStructure ? $oBodyStructure->SearchCharset() : '';
$sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
$sHeaders = $oFetchResponse->GetHeaderFieldsValue();
if (0 < \strlen($sHeaders)) {
$oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($sHeaders, false, $sCharset);
$sContentTypeCharset = $oHeaders->ParameterValue(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, \MailSo\Mime\Enumerations\Parameter::CHARSET);
if (0 < \strlen($sContentTypeCharset)) {
$sCharset = $sContentTypeCharset;
$sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
}
if (0 < \strlen($sCharset)) {
$oHeaders->SetParentCharset($sCharset);
}
$bCharsetAutoDetect = 0 === \strlen($sCharset);
$this->sSubject = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::SUBJECT, $bCharsetAutoDetect);
$this->sMessageId = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::MESSAGE_ID);
$this->sContentType = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE);
$this->oFrom = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::FROM_, $bCharsetAutoDetect);
$this->oTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::TO_, $bCharsetAutoDetect);
$this->oCc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::CC, $bCharsetAutoDetect);
$this->oBcc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::BCC, $bCharsetAutoDetect);
$this->oSender = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::SENDER, $bCharsetAutoDetect);
$this->oReplyTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::REPLY_TO, $bCharsetAutoDetect);
$this->oDeliveredTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::DELIVERED_TO, $bCharsetAutoDetect);
$this->sInReplyTo = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::IN_REPLY_TO);
$this->sReferences = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::REFERENCES);
$sHeaderDate = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::DATE);
$this->sHeaderDate = $sHeaderDate;
$this->iHeaderTimeStampInUTC = \MailSo\Base\DateTimeHelper::ParseRFC2822DateString($sHeaderDate);
// Sensitivity
$this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::NOTHING;
$sSensitivity = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::SENSITIVITY);
switch (\strtolower($sSensitivity)) {
case 'personal':
$this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::PERSONAL;
break;
case 'private':
$this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::PRIVATE_;
break;
case 'company-confidential':
$this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::CONFIDENTIAL;
break;
}
// Priority
$this->iPriority = \MailSo\Mime\Enumerations\MessagePriority::NORMAL;
$sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_MSMAIL_PRIORITY);
if (0 === \strlen($sPriority)) {
$sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::IMPORTANCE);
}
if (0 === \strlen($sPriority)) {
$sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_PRIORITY);
}
if (0 < \strlen($sPriority)) {
switch (\str_replace(' ', '', \strtolower($sPriority))) {
case 'high':
case '1(highest)':
case '2(high)':
case '1':
case '2':
$this->iPriority = \MailSo\Mime\Enumerations\MessagePriority::HIGH;
break;
case 'low':
case '4(low)':
case '5(lowest)':
case '4':
case '5':
$this->iPriority = \MailSo\Mime\Enumerations\MessagePriority::LOW;
break;
}
}
// Delivery Receipt
$this->sDeliveryReceipt = \trim($oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::RETURN_RECEIPT_TO));
// Read Receipt
$this->sReadReceipt = \trim($oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::DISPOSITION_NOTIFICATION_TO));
if (empty($this->sReadReceipt)) {
$this->sReadReceipt = \trim($oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_CONFIRM_READING_TO));
}
$sDraftInfo = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_DRAFT_INFO);
//.........這裏部分代碼省略.........
示例5: ConvertEncoding
/**
* @param string $sInputString
* @param string $sInputFromEncoding
* @param string $sInputToEncoding
*
* @return string
*/
public static function ConvertEncoding($sInputString, $sInputFromEncoding, $sInputToEncoding)
{
$sResult = $sInputString;
$sFromEncoding = \MailSo\Base\Utils::NormalizeCharset($sInputFromEncoding);
$sToEncoding = \MailSo\Base\Utils::NormalizeCharset($sInputToEncoding);
if ('' === \trim($sResult) || $sFromEncoding === $sToEncoding && \MailSo\Base\Enumerations\Charset::UTF_8 !== $sFromEncoding) {
return $sResult;
}
$bUnknown = false;
switch (true) {
default:
$bUnknown = true;
break;
case $sFromEncoding === \MailSo\Base\Enumerations\Charset::ISO_8859_1 && $sToEncoding === \MailSo\Base\Enumerations\Charset::UTF_8 && \function_exists('utf8_encode'):
$sResult = \utf8_encode($sResult);
break;
case $sFromEncoding === \MailSo\Base\Enumerations\Charset::UTF_8 && $sToEncoding === \MailSo\Base\Enumerations\Charset::ISO_8859_1 && \function_exists('utf8_decode'):
$sResult = \utf8_decode($sResult);
break;
case $sFromEncoding === \MailSo\Base\Enumerations\Charset::UTF_7_IMAP && $sToEncoding === \MailSo\Base\Enumerations\Charset::UTF_8:
$sResult = \MailSo\Base\Utils::Utf7ModifiedToUtf8($sResult);
if (false === $sResult) {
$sResult = $sInputString;
}
break;
case $sFromEncoding === \MailSo\Base\Enumerations\Charset::UTF_8 && $sToEncoding === \MailSo\Base\Enumerations\Charset::UTF_7_IMAP:
$sResult = \MailSo\Base\Utils::Utf8ToUtf7Modified($sResult);
if (false === $sResult) {
$sResult = $sInputString;
}
break;
case $sFromEncoding === \MailSo\Base\Enumerations\Charset::UTF_7_IMAP:
$sResult = \MailSo\Base\Utils::ConvertEncoding(\MailSo\Base\Utils::ModifiedToPlainUtf7($sResult), \MailSo\Base\Enumerations\Charset::UTF_7, $sToEncoding);
break;
case \in_array(\strtolower($sFromEncoding), \MailSo\Base\Utils::$SuppostedCharsets):
if (\MailSo\Base\Utils::IsIconvSupported()) {
$sResult = \MailSo\Base\Utils::IconvConvertEncoding($sResult, $sFromEncoding, $sToEncoding);
} else {
if (\MailSo\Base\Utils::IsMbStringSupported()) {
$sResult = \MailSo\Base\Utils::MbConvertEncoding($sResult, $sFromEncoding, $sToEncoding);
}
}
$sResult = false !== $sResult ? $sResult : $sInputString;
break;
}
if ($bUnknown && \MailSo\Base\Utils::IsMbStringSupported()) {
$sResult = @\mb_convert_encoding($sResult, $sToEncoding);
}
return $sResult;
}