Compose, save and sendmail cleanup

release-0.6
thomascube 18 years ago
parent abb32edbeb
commit 41fa0b909a

@ -712,7 +712,7 @@ function show_message($message, $type='notice', $vars=NULL)
return 'this.'.$command; return 'this.'.$command;
else else
$OUTPUT->add_script(sprintf("%s%s.%s", $OUTPUT->add_script(sprintf("%s%s.%s\n",
$framed ? sprintf('if(parent.%s)parent.', $JS_OBJECT_NAME) : '', $framed ? sprintf('if(parent.%s)parent.', $JS_OBJECT_NAME) : '',
$JS_OBJECT_NAME, $JS_OBJECT_NAME,
$command)); $command));
@ -789,6 +789,19 @@ function rcube_remote_response($js_code, $flush=FALSE)
} }
// send correctly formatted response for a request posted to an iframe
function rcube_iframe_response($js_code='')
{
global $OUTPUT, $JS_OBJECT_NAME;
if (!empty($js_code))
$OUTPUT->add_script("if(parent.$JS_OBJECT_NAME){\n" . $js_code . "\n}");
$OUTPUT->write();
exit;
}
// read directory program/localization/ and return a list of available languages // read directory program/localization/ and return a list of available languages
function rcube_list_languages() function rcube_list_languages()
{ {

@ -1678,7 +1678,7 @@ function gethdrids($hdr)
{ {
$a = $this->_parse_address_list($input); $a = $this->_parse_address_list($input);
$out = array(); $out = array();
if (!is_array($a)) if (!is_array($a))
return $out; return $out;
@ -2018,12 +2018,13 @@ function gethdrids($hdr)
{ {
$a = $this->_explode_quoted_string(',', $str); $a = $this->_explode_quoted_string(',', $str);
$result = array(); $result = array();
foreach ($a as $key => $val) foreach ($a as $key => $val)
{ {
$val = str_replace("\"<", "\" <", $val); $val = str_replace("\"<", "\" <", $val);
$sub_a = $this->_explode_quoted_string(' ', $val); $sub_a = $this->_explode_quoted_string(' ', $this->decode_header($val));
$result[$key]['name'] = '';
foreach ($sub_a as $k => $v) foreach ($sub_a as $k => $v)
{ {
if ((strpos($v, '@') > 0) && (strpos($v, '.') > 0)) if ((strpos($v, '@') > 0) && (strpos($v, '.') > 0))
@ -2033,9 +2034,7 @@ function gethdrids($hdr)
} }
if (empty($result[$key]['name'])) if (empty($result[$key]['name']))
$result[$key]['name'] = $result[$key]['address']; $result[$key]['name'] = $result[$key]['address'];
$result[$key]['name'] = $this->decode_header($result[$key]['name']);
} }
return $result; return $result;

@ -33,6 +33,7 @@ class rcube_html_page
var $script_tag_file = "<script type=\"text/javascript\" src=\"%s%s\"></script>\n"; var $script_tag_file = "<script type=\"text/javascript\" src=\"%s%s\"></script>\n";
var $script_tag = "<script type=\"text/javascript\">\n<!--\n%s\n\n//-->\n</script>\n"; var $script_tag = "<script type=\"text/javascript\">\n<!--\n%s\n\n//-->\n</script>\n";
var $default_template = "<html>\n<body></body>\n</html>";
var $title = ''; var $title = '';
var $header = ''; var $header = '';
@ -78,11 +79,12 @@ class rcube_html_page
} }
function set_title() function set_title($t)
{ {
$this->title = $t;
} }
function set_charset($charset) function set_charset($charset)
{ {
global $MBSTRING; global $MBSTRING;
@ -95,16 +97,25 @@ class rcube_html_page
$MBSTRING = FALSE; $MBSTRING = FALSE;
} }
} }
function get_charset() function get_charset()
{ {
return $this->charset; return $this->charset;
} }
function reset()
{
$this->css = new rcube_css();
$this->script_files = array();
$this->scripts = array();
$this->title = '';
}
function write($templ='', $base_path='') function write($templ='', $base_path='')
{ {
$output = trim($templ); $output = empty($templ) ? $this->default_template : trim($templ);
// set default page title // set default page title
if (!strlen($this->title)) if (!strlen($this->title))

@ -18,10 +18,9 @@
var CONTROL_KEY = 1; var CONTROL_KEY = 1;
var SHIFT_KEY = 2; var SHIFT_KEY = 2;
var CONTROL_SHIFT_KEY = 3; var CONTROL_SHIFT_KEY = 3;
var DRAFT_AUTOSAVE = 10; // Minutes var DRAFT_AUTOSAVE = 5; // Minutes
var rcube_webmail_client; var rcube_webmail_client;
var rcube_save_timer;
function rcube_webmail() function rcube_webmail()
{ {
@ -149,8 +148,8 @@ function rcube_webmail()
this.enable_command('add-attachment', 'send-attachment', 'remove-attachment', 'send', true); this.enable_command('add-attachment', 'send-attachment', 'remove-attachment', 'send', true);
if (this.env.spellcheck) if (this.env.spellcheck)
this.enable_command('spellcheck', true); this.enable_command('spellcheck', true);
if (this.env.drafts_mailbox) if (this.env.drafts_mailbox)
this.enable_command('savedraft', true); this.enable_command('savedraft', true);
} }
if (this.env.messagecount) if (this.env.messagecount)
@ -455,7 +454,6 @@ function rcube_webmail()
// start the auto-save timer // start the auto-save timer
this.auto_save_start(); this.auto_save_start();
}; };
this.init_address_input_events = function(obj) this.init_address_input_events = function(obj)
@ -704,17 +702,15 @@ function rcube_webmail()
{ {
var uid = this.get_single_uid(); var uid = this.get_single_uid();
if (uid && (!this.env.uid || uid != this.env.uid)) if (uid && (!this.env.uid || uid != this.env.uid))
{ {
if (this.env.mailbox==this.env.drafts_mailbox) if (this.env.mailbox==this.env.drafts_mailbox)
{ {
this.set_busy(true); this.set_busy(true);
location.href = this.env.comm_path+'&_action=compose&_draft_uid='+uid+'&_mbox='+escape(this.env.mailbox); location.href = this.env.comm_path+'&_action=compose&_draft_uid='+uid+'&_mbox='+escape(this.env.mailbox);
} }
else else
{
this.show_message(uid); this.show_message(uid);
} }
}
} }
else if (this.task=='addressbook') else if (this.task=='addressbook')
{ {
@ -933,33 +929,34 @@ function rcube_webmail()
break; break;
case 'savedraft': case 'savedraft':
// Reset the auto-save timer // Reset the auto-save timer
self.clearTimeout(rcube_save_timer); self.clearTimeout(this.save_timer);
if (!this.gui_objects.messageform) if (!this.gui_objects.messageform)
break; break;
// if saving Drafts is disabled in main.inc.php // if saving Drafts is disabled in main.inc.php
if (!this.env.drafts_mailbox) if (!this.env.drafts_mailbox)
break; break;
this.set_busy(true, 'savingmessage'); this.set_busy(true, 'savingmessage');
var form = this.gui_objects.messageform; var form = this.gui_objects.messageform;
form.target = "savetarget"; form.target = "savetarget";
form.submit(); form.submit();
break; break;
case 'send': case 'send':
if (!this.gui_objects.messageform) if (!this.gui_objects.messageform)
break; break;
if (!this.check_compose_input()) if (!this.check_compose_input())
break; break;
// all checks passed, send message // all checks passed, send message
this.set_busy(true, 'sendingmessage'); this.set_busy(true, 'sendingmessage');
var form = this.gui_objects.messageform; var form = this.gui_objects.messageform;
form._draft.value=''; form.target = "savetarget";
form._draft.value = '';
form.submit(); form.submit();
break; break;
@ -968,7 +965,7 @@ function rcube_webmail()
case 'send-attachment': case 'send-attachment':
// Reset the auto-save timer // Reset the auto-save timer
self.clearTimeout(rcube_save_timer); self.clearTimeout(this.save_timer);
this.upload_file(props) this.upload_file(props)
break; break;
@ -2014,12 +2011,14 @@ function rcube_webmail()
return true; return true;
}; };
this.auto_save_start = function() this.auto_save_start = function()
{ {
rcube_save_timer = self.setTimeout('rcmail.command("savedraft","",this)',DRAFT_AUTOSAVE * 60000); this.save_timer = self.setTimeout('rcmail.command("savedraft","",this)', DRAFT_AUTOSAVE * 60000);
} };
this.compose_field_hash = function() this.compose_field_hash = function()
{ {
// check input fields // check input fields
@ -2190,7 +2189,7 @@ function rcube_webmail()
for (i=0;i<list.length;i++) for (i=0;i<list.length;i++)
if (list[i].id == name) if (list[i].id == name)
this.gui_objects.attachmentlist.removeChild(list[i]); this.gui_objects.attachmentlist.removeChild(list[i]);
} };
this.remove_attachment = function(name) this.remove_attachment = function(name)
{ {
@ -2198,7 +2197,7 @@ function rcube_webmail()
this.http_request('remove-attachment', '_filename='+escape(name)); this.http_request('remove-attachment', '_filename='+escape(name));
return true; return true;
} };
// send remote request to add a new contact // send remote request to add a new contact
this.add_contact = function(value) this.add_contact = function(value)
@ -2230,7 +2229,14 @@ function rcube_webmail()
this.env.search_request = null; this.env.search_request = null;
return true; return true;
}; };
this.sent_successfully = function(msg)
{
this.list_mailbox();
this.display_message(msg, 'confirmation', true);
}
/*********************************************************/ /*********************************************************/
/********* keyboard live-search methods *********/ /********* keyboard live-search methods *********/

@ -50,7 +50,7 @@ rcmail_compose_cleanup();
$_SESSION['compose'] = array('id' => uniqid(rand())); $_SESSION['compose'] = array('id' => uniqid(rand()));
// add some labels to client // add some labels to client
rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'notsentwarning', 'savingmessage', 'savingmessage', 'messagesaved'); rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'notsentwarning', 'savingmessage', 'sendingmessage', 'messagesaved');
if ($_GET['_reply_uid'] || $_GET['_forward_uid'] || $_GET['_draft_uid']) if ($_GET['_reply_uid'] || $_GET['_forward_uid'] || $_GET['_draft_uid'])
@ -411,8 +411,8 @@ function rcmail_compose_body($attrib)
rcube_add_label('checking'); rcube_add_label('checking');
} }
$out .= '<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>'; $out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>';
return $out; return $out;
} }
@ -793,7 +793,5 @@ if ($DB->num_rows($sql_result))
} }
parse_template('compose'); parse_template('compose');
?> ?>

@ -36,7 +36,6 @@ if (!isset($_SESSION['compose']['id']))
/****** message sending functions ********/ /****** message sending functions ********/
function rcmail_get_identity($id) function rcmail_get_identity($id)
{ {
global $DB, $CHARSET, $OUTPUT; global $DB, $CHARSET, $OUTPUT;
@ -63,20 +62,26 @@ function rcmail_get_identity($id)
return FALSE; return FALSE;
} }
if (strlen($_POST['_draft_saveid']) > 3) if (strlen($_POST['_draft_saveid']) > 3)
$olddraftmessageid = get_input_value('_draft_saveid', RCUBE_INPUT_POST); $olddraftmessageid = get_input_value('_draft_saveid', RCUBE_INPUT_POST);
$message_id = sprintf('<%s@%s>', md5(uniqid('rcmail'.rand(),true)), $_SESSION['imap_host']); $message_id = sprintf('<%s@%s>', md5(uniqid('rcmail'.rand(),true)), $_SESSION['imap_host']);
$savedraft = !empty($_POST['_draft']) ? TRUE : FALSE; $savedraft = !empty($_POST['_draft']) ? TRUE : FALSE;
// remove all scripts and act as called in frame
$OUTPUT->reset();
$_framed = TRUE;
/****** check submission and compose message ********/ /****** check submission and compose message ********/
if (empty($_POST['_to']) && empty($_POST['_subject']) && $_POST['_message']) if (empty($_POST['_to']) && empty($_POST['_subject']) && $_POST['_message'])
{ {
show_message("sendingfailed", 'error'); show_message("sendingfailed", 'error');
rcmail_overwrite_action('compose'); //rcmail_overwrite_action('compose');
rcube_iframe_response();
return; return;
} }
@ -274,7 +279,7 @@ if (!$savedraft) {
if (!$sent) if (!$sent)
{ {
show_message("sendingfailed", 'error'); show_message("sendingfailed", 'error');
rcmail_overwrite_action('compose'); rcube_iframe_response();
return; return;
} }
@ -285,6 +290,8 @@ if (!$savedraft) {
} // End of SMTP Delivery Block } // End of SMTP Delivery Block
// Determine which folder to save message // Determine which folder to save message
if ($savedraft) if ($savedraft)
$store_target = 'drafts_mbox'; $store_target = 'drafts_mbox';
@ -312,17 +319,13 @@ if ($CONFIG[$store_target])
// raise error if saving failed // raise error if saving failed
if (!$saved) if (!$saved)
{ {
// clear the "saving message" busy status, and display failure
$errorout = sprintf("parent.%s.display_message('%s', '%s');",
$JS_OBJECT_NAME,
addslashes(rep_specialchars_output(rcube_label(array('name' => 'errorsaving', 'vars' => NULL)))),
'error');
print "<html><script type=\"text/javascript\">$errorout</script></html>";
raise_error(array('code' => 800, raise_error(array('code' => 800,
'type' => 'imap', 'type' => 'imap',
'file' => __FILE__, 'file' => __FILE__,
'message' => "Could not save message in $CONFIG[$store_target]"), TRUE, FALSE); 'message' => "Could not save message in $CONFIG[$store_target]"), TRUE, FALSE);
exit;
show_message('errorsaving', 'error');
rcube_iframe_response($errorout);
} }
if ($olddraftmessageid) if ($olddraftmessageid)
@ -343,24 +346,20 @@ if ($CONFIG[$store_target])
if ($savedraft) if ($savedraft)
{ {
// clear the "saving message" busy status, and display success // clear the "saving message" busy status, and display success
$frameout = sprintf("parent.%s.display_message('%s', '%s');", show_message('messagesaved', 'confirmation');
$JS_OBJECT_NAME,
addslashes(rep_specialchars_output(rcube_label(array('name' => 'messagesaved', 'vars' => NULL)))),
'confirmation');
// update "_draft_saveid" on the page, which is used to delete a previous draft // update "_draft_saveid" on the page, which is used to delete a previous draft
$frameout .= 'var foundid = parent.rcube_find_object("_draft_saveid",parent.document);'; $frameout = "var foundid = parent.rcube_find_object('_draft_saveid', parent.document);\n";
$frameout .= sprintf('foundid.value = "%s";',str_replace(array('<','>'),"",$message_id)); $frameout .= sprintf("foundid.value = '%s';\n", str_replace(array('<','>'), "", $message_id));
// update the "cmp_hash" to prevent "Unsaved changes" warning // update the "cmp_hash" to prevent "Unsaved changes" warning
$frameout .= sprintf("parent.%s.cmp_hash = parent.%s.compose_field_hash();",$JS_OBJECT_NAME,$JS_OBJECT_NAME); $frameout .= sprintf("parent.%s.cmp_hash = parent.%s.compose_field_hash();\n", $JS_OBJECT_NAME, $JS_OBJECT_NAME);
// start the auto-save timer again // start the auto-save timer again
$frameout .= sprintf("parent.%s.auto_save_start();",$JS_OBJECT_NAME); $frameout .= sprintf("parent.%s.auto_save_start();", $JS_OBJECT_NAME);
// send html page with JS calls as response // send html page with JS calls as response
print "<html><script type=\"text/javascript\">$frameout</script></html>"; rcube_iframe_response($frameout);
exit;
} }
else else
{ {
@ -379,8 +378,10 @@ else
fclose($fp); fclose($fp);
} }
} }
show_message('messagesent', 'confirmation');
rcmail_compose_cleanup(); rcmail_compose_cleanup();
rcube_iframe_response(sprintf("parent.$JS_OBJECT_NAME.sent_successfully('%s');",
rep_specialchars_output(rcube_label('messagesent'), 'js')));
} }

@ -53,18 +53,12 @@ foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath)
// send html page with JS calls as response // send html page with JS calls as response
print <<<EOF $frameout = <<<EOF
<html>
<script type="text/javascript">
if (parent.$JS_OBJECT_NAME)
{
$response $response
parent.$JS_OBJECT_NAME.show_attachment_form(false); parent.$JS_OBJECT_NAME.show_attachment_form(false);
parent.$JS_OBJECT_NAME.auto_save_start(); parent.$JS_OBJECT_NAME.auto_save_start();
}
</script>
</html>
EOF; EOF;
exit;
rcube_iframe_response($frameout);
?> ?>

Loading…
Cancel
Save