mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-22 16:03:47 +01:00
z-push requires text-parts to be in utf-8, not eg. iso-8859-1
This commit is contained in:
parent
3209a6671c
commit
6969120d8b
@ -934,7 +934,8 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
|
||||
//SYNC_BODYPREFERENCE_MIME
|
||||
ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." bodypreference 4 requested");
|
||||
$output->asbody->type = SYNC_BODYPREFERENCE_MIME;//4;
|
||||
$Body = $this->mail->getMessageRawBody($id, '', $_folderName);
|
||||
// use egw_mailer::convert to convert charset of all text parts to utf-8, which is a z-push or AS requirement!
|
||||
$Body = egw_mailer::convert($this->mail->getMessageRawBody($id, '', $_folderName));
|
||||
if ($this->debugLevel>2) debugLog(__METHOD__.__LINE__." Setting Mailobjectcontent to output:".$Body);
|
||||
$output->asbody->data = $Body;
|
||||
}
|
||||
|
@ -52,7 +52,8 @@ class egw_mailer extends Horde_Mime_Mail
|
||||
/**
|
||||
* Constructor: always throw exceptions instead of echoing errors and EGw pathes
|
||||
*
|
||||
* @param int|emailadmin_account $account =null mail account to use, default use emailadmin_account::get_default($smtp=true)
|
||||
* @param int|emailadmin_account|boolean $account =null mail account to use, default use emailadmin_account::get_default($smtp=true)
|
||||
* false: no NOT initialise account and set other EGroupware specific headers, used to parse mails (not sending them!)
|
||||
*/
|
||||
function __construct($account=null)
|
||||
{
|
||||
@ -60,16 +61,20 @@ class egw_mailer extends Horde_Mime_Mail
|
||||
common::setlocale(LC_MESSAGES);
|
||||
|
||||
parent::__construct();
|
||||
$this->_headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
|
||||
|
||||
$this->setAccount($account);
|
||||
if ($account !== false)
|
||||
{
|
||||
$this->_headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
|
||||
|
||||
$this->is_html = false;
|
||||
$this->setAccount($account);
|
||||
|
||||
$this->clearAllRecipients();
|
||||
$this->clearReplyTos();
|
||||
$this->is_html = false;
|
||||
|
||||
$this->clearParts();
|
||||
$this->clearAllRecipients();
|
||||
$this->clearReplyTos();
|
||||
|
||||
$this->clearParts();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -640,6 +645,49 @@ class egw_mailer extends Horde_Mime_Mail
|
||||
$this->getBasePart()->toString(array('canonical' => true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert charset of text-parts of message to utf-8
|
||||
*
|
||||
* @param string|resource $message
|
||||
* @param boolean $stream =false return stream or string (default)
|
||||
* @param string $charset ='utf-8' charset to convert to
|
||||
* @param boolean &$converted =false on return if conversation was necessary
|
||||
* @return string|stream
|
||||
*/
|
||||
static function convert($message, $stream=false, $charset='utf-8', &$converted=false)
|
||||
{
|
||||
$mailer = new egw_mailer(false); // false = no default headers and mail account
|
||||
$mailer->addHeaders(Horde_Mime_Headers::parseHeaders($message));
|
||||
$base = Horde_Mime_Part::parseMessage($message);
|
||||
foreach($base->partIterator() as $part)
|
||||
{
|
||||
if ($part->getPrimaryType()== 'text')
|
||||
{
|
||||
$charset = $part->getContentTypeParameter('charset');
|
||||
if ($charset && $charset != 'utf-8')
|
||||
{
|
||||
$content = translation::convert($part->toString(array(
|
||||
'encode' => Horde_Mime_Part::ENCODE_BINARY, // otherwise we cant recode charset
|
||||
)), $charset, 'utf-8');
|
||||
$part->setContents($content);
|
||||
$part->setContentTypeParameter('charset', 'utf-8');
|
||||
if ($part === $base) $mailer->addHeader('Content-Type', $base->getType(true));
|
||||
$converted = true;
|
||||
}
|
||||
}
|
||||
elseif ($part->getType() == 'message/rfc822')
|
||||
{
|
||||
$part->setContents(self::convert($part->toString(), $stream, $charset, $converted));
|
||||
}
|
||||
}
|
||||
if ($converted)
|
||||
{
|
||||
$mailer->setBasePart($base);
|
||||
return $mailer->getRaw($stream);
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find body: 1. part with mimetype "text/$subtype"
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user