Displaying format=flowed e-mails (#276)

This commit is contained in:
RainLoop Team 2015-05-08 02:30:03 +04:00
parent 7a9ff78051
commit f63edfa7cc
5 changed files with 61 additions and 8 deletions

View file

@ -601,6 +601,16 @@ END;
return $sResult; return $sResult;
} }
/**
* @param string $sInputValue
*
* @return string
*/
public static function DecodeFlowedFormat($sInputValue)
{
return \preg_replace('/ ([\r]?[\n])/m', ' ', $sInputValue);
}
/** /**
* @param string $sEncodedValue * @param string $sEncodedValue
* @param string $sIncomingCharset = '' * @param string $sIncomingCharset = ''

View file

@ -285,6 +285,22 @@ class BodyStructure
return $bResult; return $bResult;
} }
/**
* @return bool
*/
public function IsFlowedFormat()
{
$bResult = !empty($this->aBodyParams['format']) &&
'flowed' === \strtolower(\trim($this->aBodyParams['format']));
if ($bResult && \in_array(\strtolower($this->MailEncodingName()), array('base64', 'quoted-printable')))
{
$bResult = false;
}
return $bResult;
}
/** /**
* @return array|null * @return array|null
*/ */

View file

@ -751,8 +751,8 @@ class Message
$sCharset = \MailSo\Base\Enumerations\Charset::UTF_8; $sCharset = \MailSo\Base\Enumerations\Charset::UTF_8;
} }
$sHtmlParts = array(); $aHtmlParts = array();
$sPlainParts = array(); $aPlainParts = array();
foreach ($aTextParts as $oPart) foreach ($aTextParts as $oPart)
{ {
@ -782,22 +782,27 @@ class Message
if ('text/html' === $oPart->ContentType()) if ('text/html' === $oPart->ContentType())
{ {
$sHtmlParts[] = $sText; $aHtmlParts[] = $sText;
} }
else else
{ {
$sPlainParts[] = $sText; if ($oPart->IsFlowedFormat())
{
$sText = \MailSo\Base\Utils::DecodeFlowedFormat($sText);
}
$aPlainParts[] = $sText;
} }
} }
} }
if (0 < \count($sHtmlParts)) if (0 < \count($aHtmlParts))
{ {
$this->sHtml = \implode('<br />', $sHtmlParts); $this->sHtml = \implode('<br />', $aHtmlParts);
} }
else else
{ {
$this->sPlain = \trim(\implode("\n", $sPlainParts)); $this->sPlain = \trim(\implode("\n", $aPlainParts));
} }
$aMatch = array(); $aMatch = array();
@ -813,7 +818,7 @@ class Message
$this->bPgpEncrypted = true; $this->bPgpEncrypted = true;
} }
unset($sHtmlParts, $sPlainParts, $aMatch); unset($aHtmlParts, $aPlainParts, $aMatch);
} }
// if (empty($this->sPgpSignature) && 'multipart/signed' === \strtolower($this->sContentType) && // if (empty($this->sPgpSignature) && 'multipart/signed' === \strtolower($this->sContentType) &&

View file

@ -21,6 +21,7 @@ class Parameter
const CHARSET = 'charset'; const CHARSET = 'charset';
const NAME = 'name'; const NAME = 'name';
const FILENAME = 'filename'; const FILENAME = 'filename';
const FORMAT = 'format';
const BOUNDARY = 'boundary'; const BOUNDARY = 'boundary';
const PROTOCOL = 'protocol'; const PROTOCOL = 'protocol';
} }

View file

@ -210,6 +210,27 @@ class Part
\MailSo\Mime\Enumerations\Header::CONTENT_LOCATION)) : ''; \MailSo\Mime\Enumerations\Header::CONTENT_LOCATION)) : '';
} }
/**
* @return bool
*/
public function IsFlowedFormat()
{
$bResult = false;
if ($this->Headers)
{
$bResult = 'flowed' === \trim(\strtolower($this->Headers->ParameterValue(
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
\MailSo\Mime\Enumerations\Parameter::FORMAT)));
if ($bResult && \in_array(\strtolower($this->MailEncodingName()), array('base64', 'quoted-printable')))
{
$bResult = false;
}
}
return $bResult;
}
/** /**
* @return string * @return string
*/ */