mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-21 23:43:17 +01:00
* Mail REST Api: respect user preference to compose in HTML and convert plain body from REST Api call to HTML (bodyHtml attribute forces HTML)
This commit is contained in:
parent
b175b14294
commit
4ce3298241
@ -595,4 +595,15 @@ class Html
|
||||
//error_log(__METHOD__.__LINE__.array2string($html2ret));
|
||||
return $html2ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert plain text into HTML replacing empty lines (double newline) with paragraphs and single newlines with <br>
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
public static function convertTextToHtml($text)
|
||||
{
|
||||
return '<p>'.implode("</p>\n<p>", array_map('nl2br', preg_split("/\r?\n\r?\n/", $text)))."</p>\n";
|
||||
}
|
||||
}
|
@ -1025,7 +1025,7 @@ class mail_compose
|
||||
{
|
||||
if ($_REQUEST['preset']['mimeType'] === 'plain')
|
||||
{
|
||||
$_REQUEST['preset']['body'] = '<p>'.nl2br($_REQUEST['preset']['body'])."</p>\n";
|
||||
$_REQUEST['preset']['body'] = Mail\Html::convertTextToHtml($_REQUEST['preset']['body']);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -109,9 +109,19 @@ class ApiHandler extends Api\CalDAV\Handler
|
||||
}
|
||||
}
|
||||
|
||||
// determine to use html or plain-text based on user preference and what's supplied in REST API call
|
||||
$type = $GLOBALS['egw_info']['user']['preferences']['mail']['composeOptions'] === 'html' ||
|
||||
!empty($data['bodyHtml']) ? 'html' : 'plain';
|
||||
$body = $data['bodyHtml'] ?? null ?: $data['body'] ?? '';
|
||||
// if user wants html, but REST API caller supplied plain --> convert to html
|
||||
if (!empty($body) && empty($data['bodyHtml']))
|
||||
{
|
||||
$body = Api\Mail\Html::convertTextToHtml($body);
|
||||
}
|
||||
|
||||
$preset = array_filter(array_intersect_key($data, array_flip(['to', 'cc', 'bcc', 'replyto', 'subject', 'priority', 'reply_id']))+[
|
||||
'body' => $data['bodyHtml'] ?? null ?: $data['body'] ?? '',
|
||||
'mimeType' => !empty($data['bodyHtml']) ? 'html' : 'plain',
|
||||
'body' => $body,
|
||||
'mimeType' => $type,
|
||||
'identity' => $ident_id,
|
||||
]+self::prepareAttachments($data['attachments'] ?? [], $data['attachmentType'] ?? 'attach',
|
||||
$data['shareExpiration'], $data['sharePassword'], $do_compose));
|
||||
|
Loading…
Reference in New Issue
Block a user