Skip to content

Commit

Permalink
Merge pull request #453 from kroky/bugfix/drafts
Browse files Browse the repository at this point in the history
attempt to fix draft versions, missing attachments when sending email
  • Loading branch information
jasonmunro committed Feb 15, 2021
2 parents 2a9060a + 04759c1 commit f335220
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
3 changes: 2 additions & 1 deletion modules/imap/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ public function process() {
'no_encoding' => true,
'size' => strlen($content)
);
$draft_id = count($this->session->get('compose_drafts', array()));
$draft_id = next_draft_key($this->session);
attach_file($content, $file, $filepath, $draft_id, $this);
$this->out('compose_draft_id', $draft_id);
}
}

Expand Down
45 changes: 30 additions & 15 deletions modules/smtp/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function process() {
Hm_Msgs::add('ERRYou need at least one configured SMTP server to send outbound messages');
}
$draft = array();
$draft_id = count($this->session->get('compose_drafts', array()));
$draft_id = next_draft_key($this->session);
$reply_type = false;
if (array_key_exists('reply', $this->request->get) && $this->request->get['reply']) {
$reply_type = 'reply';
Expand All @@ -204,6 +204,10 @@ public function process() {
}
elseif (array_key_exists('forward', $this->request->get) && $this->request->get['forward']) {
$reply_type = 'forward';
$draft_id = $this->get('compose_draft_id', -1);
if ($draft_id >= 0) {
$draft = get_draft($draft_id, $this->session);
}
}
elseif (array_key_exists('draft_id', $this->request->get)) {
$draft = get_draft($this->request->get['draft_id'], $this->session);
Expand Down Expand Up @@ -578,11 +582,10 @@ protected function output() {
Hm_Image_Sources::$doc.'" title="'.$this->trans('Drafts').'" alt="'.$this->trans('Drafts').'" />';
$res .= '<div class="draft_list">';
foreach ($drafts as $id => $draft) {
if (trim($draft['draft_subject'])) {
$res .= '<div class="draft_'.$this->html_safe($id).'"><a class="draft_link" href="?page=compose&draft_id='.
$this->html_safe($id).'">'.$this->html_safe($draft['draft_subject']).'</a> '.
'<img class="delete_draft" width="16" height="16" data-id="'.$this->html_safe($id).'" src="'.Hm_Image_Sources::$circle_x.'" /></div>';
}
$subject = trim($draft['draft_subject']) ? trim($draft['draft_subject']) : 'Draft '.($id+1);
$res .= '<div class="draft_'.$this->html_safe($id).'"><a class="draft_link" href="?page=compose&draft_id='.
$this->html_safe($id).'">'.$this->html_safe($subject).'</a> '.
'<img class="delete_draft" width="16" height="16" data-id="'.$this->html_safe($id).'" src="'.Hm_Image_Sources::$circle_x.'" /></div>';
}
$res .= '</div>';
return $res;
Expand Down Expand Up @@ -1097,17 +1100,11 @@ function delete_draft($id, $session) {
*/
if (!hm_exists('save_draft')) {
function save_draft($atts, $id, $session) {
if (!trim($atts['draft_subject'])) {
return false;
}
$drafts = $session->get('compose_drafts', array());
if ($id !== false) {
$drafts[$id] = $atts;
}
else {
$drafts[] = $atts;
$id = count($drafts) - 1;
if ($id === false) {
$id = next_draft_key($session);
}
$drafts[$id] = $atts;
$session->set('compose_drafts', $drafts);
return $id;
}}
Expand Down Expand Up @@ -1136,12 +1133,30 @@ function attach_file($content, $file, $filepath, $draft_id, $mod) {
$file['filename'] = $filepath.'/'.$filename;
$file['basename'] = $filename;
save_uploaded_file($draft_id, $file, $mod->session);
if (!get_draft($draft_id, $mod->session)) {
save_draft(array('draft_smtp' => '', 'draft_to' => '', 'draft_body' => '',
'draft_subject' => '', 'draft_cc' => '', 'draft_bcc' => '',
'draft_in_reply_to' => ''), $draft_id, $mod->session);
}
$mod->out('upload_file_details', $file);
return true;
}
return false;
}}

/**
* @subpackage smtp/functions
*/
if (!hm_exists('next_draft_key')) {
function next_draft_key($session) {
$drafts = $session->get('compose_drafts', array());
if (count($drafts)) {
return max(array_keys($drafts))+1;
} else {
return 0;
}
}}

/**
* @subpackage smtp/functions
*/
Expand Down
5 changes: 5 additions & 0 deletions modules/smtp/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,10 @@ $(function() {
if (window.location.href.search('&reply=1') !== -1 || window.location.href.search('&reply_all=1') !== -1) {
replace_cursor_positon ($('textarea[name="compose_body"]'));
}
if (window.location.href.search('&forward=1') !== -1) {
setTimeout(function() {
save_compose_state();
}, 100);
}
}
});

0 comments on commit f335220

Please sign in to comment.