From: pdontthink Date: Thu, 11 Jan 2007 08:05:51 +0000 (+0000) Subject: Adding initial RPC baseline functionality. The delete message request does in fact... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=482956f2594e185bf7fa3ba7c2efbb674525943f;p=squirrelmail.git Adding initial RPC baseline functionality. The delete message request does in fact work in any RPC (such as AJAX) environment, but does not actually delete messages. SM core needs a lot of reworking before this functionality can be fully fleshed out. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@12111 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/src/squirrelmail_rpc.php b/src/squirrelmail_rpc.php new file mode 100644 index 00000000..6b0f179c --- /dev/null +++ b/src/squirrelmail_rpc.php @@ -0,0 +1,211 @@ +header('Content-Type: text/xml'); +$oTemplate->header('Content-Type: application/xml'); // required by IE +//FIXME: which anti-cache headers do we want to use? +$oTemplate->header('Cache-Control: no-cache'); +// $oTemplate->header("Expires: Sat, 1 Jan 2000 00:00:00 GMT"); +// $oTemplate->header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT"); +// $oTemplate->header("Cache-Control: no-cache, must-revalidate"); +// $oTemplate->header("Pragma: no-cache"); + + + +/** + * Allow plugins to add their own RPC action + * or modify behavior of SM core RPC actions... + * + * A plugin that handles a custom RPC action must + * return TRUE to the hook so that it knows that + * the action was handled and was not an unknown + * action. If the action was not handled, the plugin + * should return FALSE to the hook. + * + * Developer note: the $rpc_action parameter is passed + * in an array in case we can think of more parameters + * to add in the future. + * + */ +$handled_by_plugin = boolean_hook_function('squirrelmail_rpc', + $temp=array(&$rpc_action), + 1); + + + +/** + * Go take care of each RPC action (unless plugin already did) + * + */ +if (!$handled_by_plugin) switch (strtolower($rpc_action)) { + + /** + * Delete Messages + * + */ + case 'delete_messages': + + require_once(SM_PATH . 'functions/mailbox_display.php'); + require_once(SM_PATH . 'functions/imap.php'); + + if (!sqGetGlobalVar('delete_ids', $delete_ids, SQ_FORM)) { + sm_rpc_return_error(99, _("No deletion ID given")); + } + $delete_ids = explode(',', $delete_ids); + if (!sqGetGlobalVar('mailbox', $mailbox, SQ_FORM)) { + sm_rpc_return_error(99, _("No mailbox given")); + } + if (sqGetGlobalVar('startMessage', $startMessage, SQ_INORDER, 1)) { + $startMessage = (int) $startMessage; + } + sqGetGlobalVar('what', $what, SQ_FORM, 0); + if (sqGetGlobalVar('account', $iAccount, SQ_GET, 0)) { + $iAccount = (int) $iAccount; + } +//FIXME: need to grab the bypass trash variable here too! probably other vars... + +/* FIXME: --- The following code was just experimental/proof-of-concept; the rest + of the implementation of this functionality still needs to be done "for real" + $oImapMessage = new IMAP_Message(0, $mailbox, $startMessage, $what, $iAccount); + foreach ($delete_ids as $id) { + $oImapMessage->setUid($id); + //FIXME: establish constants for $hide values (the 3 below indicates not to show errors, but to return any error string) + $result = $oImapMessage->deleteMessage(3); + if ($result !== TRUE) { + sm_rpc_return_error(99, $result); + } + } +--- */ + + sm_rpc_return_success(); + //FIXME: Just for testing the line above can be changed to something like this: + //sm_rpc_return_success(0, 'Hooray! Message(s) deleted. Refresh your message list and make sure.'); + break; + + + /** + * Default: error out + * + */ + default: + sm_rpc_return_error(99, _("RPC action not understood")); + break; + +} + + + +/** + * Returns an error message to the RPC caller and exits + * + * NOTE that this function exits and will never return + * + * @param int $error_code The error code for the current error condition + * @param string $error_text Any error message associated with the error + * condition (OPTIONAL; default empty string) + * + */ +function sm_rpc_return_error($error_code, $error_text='') { + + global $oTemplate; + $oTemplate->assign('error_code', $error_code); + $oTemplate->assign('error_text', $error_text); + + $oTemplate->display('rpc_response_error.tpl'); + + exit; + +} + + + +/** + * Returns a standard success result to the RPC caller and exits + * + * NOTE that this function exits and will never return + * + * @param int $result_code The result code (OPTIONAL; default 0) + * @param string $result_text Any result message (OPTIONAL; default + * empty string) + * + */ +function sm_rpc_return_success($result_code=0, $result_text='') { + + global $oTemplate; + $oTemplate->assign('result_code', $result_code); + $oTemplate->assign('result_text', $result_text); + + $oTemplate->display('rpc_response_success.tpl'); + + exit; + +} + + + diff --git a/templates/default/rpc_response_error.tpl b/templates/default/rpc_response_error.tpl new file mode 100644 index 00000000..4e2dd3b0 --- /dev/null +++ b/templates/default/rpc_response_error.tpl @@ -0,0 +1,35 @@ +';*/ +echo ''; +?> + + ERROR + + + diff --git a/templates/default/rpc_response_success.tpl b/templates/default/rpc_response_success.tpl new file mode 100644 index 00000000..b89575f7 --- /dev/null +++ b/templates/default/rpc_response_success.tpl @@ -0,0 +1,35 @@ +';*/ +echo ''; +?> + + OK + + +