Skip to content

Commit

Permalink
Fix bug where inline images in a composed message could get lost on p…
Browse files Browse the repository at this point in the history
…age refresh
  • Loading branch information
alecpl committed Jun 25, 2023
1 parent b8c83aa commit 54cdba2
Showing 1 changed file with 55 additions and 14 deletions.
69 changes: 55 additions & 14 deletions program/actions/mail/compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ public function run($args = [])
$rcmail->output->send('compose');
}

// process compose request parameters
/**
* process compose request parameters
*/
public static function process_compose_params(&$COMPOSE)
{
if (!empty($COMPOSE['param']['to'])) {
Expand Down Expand Up @@ -441,6 +443,9 @@ public static function process_compose_params(&$COMPOSE)
}
}

/**
* Decide whether to use HTML or plain text
*/
public static function compose_editor_mode()
{
static $useHtml;
Expand Down Expand Up @@ -476,31 +481,36 @@ public static function compose_editor_mode()
return $useHtml;
}

/**
* Check whether user prefers HTML and the message has HTML content
*/
public static function message_is_html()
{
return rcmail::get_instance()->config->get('prefer_html')
&& (self::$MESSAGE instanceof rcube_message)
&& self::$MESSAGE->has_html_part(true);
}

/**
* Initialize spellchecker
*/
public static function spellchecker_init()
{
$rcmail = rcmail::get_instance();

// Set language list
if ($rcmail->config->get('enable_spellcheck')) {
$spellchecker = new rcube_spellchecker();
}
else {
if (!$rcmail->config->get('enable_spellcheck')) {
return;
}

$spellchecker = new rcube_spellchecker();

// Set language list
$spellcheck_langs = $spellchecker->languages();

if (empty($spellcheck_langs)) {
if ($err = $spellchecker->error()) {
rcube::raise_error(['code' => 500,
'file' => __FILE__, 'line' => __LINE__,
rcube::raise_error([
'code' => 500, 'file' => __FILE__, 'line' => __LINE__,
'message' => "Spell check engine error: " . trim($err)],
true, false
);
Expand Down Expand Up @@ -552,6 +562,9 @@ public static function spellchecker_init()
}
}

/**
* Prepare composed message body
*/
public static function prepare_message_body()
{
$rcmail = rcmail::get_instance();
Expand Down Expand Up @@ -783,6 +796,9 @@ public static function compose_part_body($part, $isHtml = false)
return $body;
}

/**
* Template object for the message body composition element
*/
public static function compose_body($attrib)
{
list($form_start, $form_end) = self::$SENDMAIL->form_tags($attrib);
Expand Down Expand Up @@ -830,6 +846,9 @@ public static function compose_body($attrib)
return "$form_start\n$content\n$form_end\n";
}

/**
* Prepare the message body in reply mode
*/
public static function create_reply_body($body, $bodyIsHtml)
{
$rcmail = rcmail::get_instance();
Expand Down Expand Up @@ -887,6 +906,9 @@ public static function create_reply_body($body, $bodyIsHtml)
return $prefix . $body . $suffix;
}

/**
* Get reply header for the composed message body
*/
public static function get_reply_header($message)
{
if (empty($message->headers)) {
Expand All @@ -906,11 +928,17 @@ public static function get_reply_header($message)
]);
}

/**
* Prepare the message body in forward mode
*/
public static function create_forward_body($body, $bodyIsHtml)
{
return self::get_forward_header(self::$MESSAGE, $bodyIsHtml) . trim($body, "\r\n");
}

/**
* Get forward header for the composed message body
*/
public static function get_forward_header($message, $bodyIsHtml = false, $extended = true)
{
if (empty($message->headers)) {
Expand Down Expand Up @@ -967,13 +995,18 @@ public static function get_forward_header($message, $bodyIsHtml = false, $extend
return $prefix;
}

/**
* Prepare the message body in draft mode
*/
public static function create_draft_body($body, $bodyIsHtml)
{
// Return the draft body as-is
return $body;
}

// Clean up HTML content of Draft/Reply/Forward (part of the message)
/**
* Clean up HTML content of Draft/Reply/Forward (part of the message)
*/
public static function prepare_html_body($body, $wash_params = [])
{
static $part_no;
Expand Down Expand Up @@ -1014,7 +1047,9 @@ public static function prepare_html_body($body, $wash_params = [])
return $body;
}

// Removes signature from the message body
/**
* Removes signature from the message body
*/
public static function remove_signature($body)
{
$rcmail = rcmail::get_instance();
Expand All @@ -1035,9 +1070,12 @@ public static function remove_signature($body)
return $body;
}

/**
* Handle inline attachments in the message body
*/
public static function write_compose_attachments(&$message, $bodyIsHtml, &$message_body)
{
if (!empty($message->pgp_mime) || !empty(self::$COMPOSE['forward_attachments'])) {
if (!empty($message->pgp_mime)) {
return;
}

Expand Down Expand Up @@ -1126,8 +1164,6 @@ public static function write_compose_attachments(&$message, $bodyIsHtml, &$messa
}
}
}

self::$COMPOSE['forward_attachments'] = true;
}

/**
Expand Down Expand Up @@ -1165,7 +1201,9 @@ public static function cid_map($message)
return $map;
}

// Creates attachment(s) from the forwarded message(s)
/**
* Creates attachment(s) from the forwarded message(s)
*/
public static function write_forward_attachments()
{
if (!empty(self::$MESSAGE->pgp_mime)) {
Expand Down Expand Up @@ -1633,6 +1671,9 @@ public static function compose_responses_list($attrib)
return $list->show();
}

/**
* Save the specified message (or message part) as an attachment
*/
public static function save_attachment($message, $pid, $compose_id, $params = [])
{
$rcmail = rcmail::get_instance();
Expand Down

0 comments on commit 54cdba2

Please sign in to comment.