Update docs only
[squirrelmail.git] / src / squirrelmail_rpc.php
CommitLineData
482956f2 1<?php
2
3/**
85ae8774 4 * squirrelmail_rpc.php
482956f2 5 *
6 * This file contains the entry point to the "SquirrelMail API" -- the
7 * remote procedure call request receiver.
8 *
a49f857e 9 * @copyright &copy; 1999-2008 The SquirrelMail Project Team
482956f2 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 * @since 1.5.2
14 *
15 */
ebd2391c 16
17/** This is the squirrelmail_rpc page */
85ae8774 18define('PAGE_NAME', 'squirrelmail_rpc');
ebd2391c 19
482956f2 20//FIXME: If we decide to route ALL requests, even normal page
21// requests through this file, need to change page requests
22// to something like this
85ae8774 23//http://example.org/squirrelmail/src/squirrelmail_rpc.php?page=read_body&passed_id=47633...
482956f2 24// This file would then add ".php" to the "page" variable
25// and pass the request on to that page by simply require()ing
26// that page and exiting.
27// Does this present problems, security or otherwise? What
28// problems are created by the fact that the page request
29// is always the same thing (some parts of the code and some
30// plugins switch functionality based on $PHP_SELF and other
31// $_SERVER variables that look for specific page names -- those
32// can be fixed by looking at the "page" GET argument, but what
33// other issues are created)? What about plugins? How would
34// they work in this scheme? Would they be a lot more difficult
35// to develop?
36//NOTE: It is not entirely clear if doing the above is even desirable.
37// Initial conversations on the squirrelmail-devel list were
38// inconclusive. On one hand, doing so would give us one master
39// file that handles any and all incoming requests, no matter
40// where they came from or what format/type they are. On the
41// other, keeping page requests out of this file keeps this file
42// lean and specific to one technology: our RPC interface.
43
44
45/**
46 * Include the SquirrelMail initialization file.
47 */
48//FIXME: init.php assumes it is being called by a browser, so some error
49// conditions are handled by immediately calling error_box() or
50// otherwise trying to push something to the browser, which should
51// be avoided at all costs. This is also pervasive in the whole
52// core and must be cleaned up entirely before this can be a very
53// functional RPC interface
54require('../include/init.php');
55
56
57
a49f857e 58//FIXME: do we need to put this list somewhere else?
59//FIXME: do we want to use constants instead? probably not a bad idea, although plugins probably won't, so we still want to try to keep track of the plugin error codes too if possible (new plugin website should help)
60/**
61 * Known core error codes:
62 *
63 * 1 - No RPC action was given in request (please use "rpc_action")
64 * 2 - RPC action was not understood (perhaps a needed plugin is
65 * not installed and activated?)
66 *
67 * Known plugin error codes:
68 *
cd60d608 69 * 500 - Empty Folders plugin empty_folders_purge_trash action failed
70 * 501 - Empty Folders plugin empty_folders_purge_all action failed
71 * 502 - Empty Folders plugin empty_folders_delete_all action failed
5ca6518a 72 * 503 - Mark Read plugin mark_read_read_all action failed
73 * 504 - Mark Read plugin mark_read_unread_all action failed
a49f857e 74 *
75 */
76
77
78
482956f2 79/**
80 * Get RPC Action (can be in either GET or POST)
81 *
82 */
83if (!sqGetGlobalVar('rpc_action', $rpc_action, SQ_FORM)) {
a49f857e 84 sm_rpc_return_error(1, _("No RPC action given"));
482956f2 85}
86
87
88
89/**
90 * No matter what our response is, the headers
91 * will not change.
92 *
93 */
94$oTemplate->header('Content-Type: text/xml');
95$oTemplate->header('Content-Type: application/xml'); // required by IE
96//FIXME: which anti-cache headers do we want to use?
97$oTemplate->header('Cache-Control: no-cache');
98// $oTemplate->header("Expires: Sat, 1 Jan 2000 00:00:00 GMT");
99// $oTemplate->header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
100// $oTemplate->header("Cache-Control: no-cache, must-revalidate");
101// $oTemplate->header("Pragma: no-cache");
102
103
104
105/**
106 * Allow plugins to add their own RPC action
107 * or modify behavior of SM core RPC actions...
108 *
109 * A plugin that handles a custom RPC action must
110 * return TRUE to the hook so that it knows that
111 * the action was handled and was not an unknown
112 * action. If the action was not handled, the plugin
113 * should return FALSE to the hook.
114 *
115 * Developer note: the $rpc_action parameter is passed
116 * in an array in case we can think of more parameters
117 * to add in the future.
118 *
a49f857e 119 * Known users of this hook:
120 * empty_folders
5ca6518a 121 * mark_read
a49f857e 122 *
482956f2 123 */
beb1a2f1 124$temp = array(&$rpc_action);
125$handled_by_plugin = boolean_hook_function('squirrelmail_rpc', $temp, 1);
482956f2 126
127
128
129/**
130 * Go take care of each RPC action (unless plugin already did)
131 *
132 */
133if (!$handled_by_plugin) switch (strtolower($rpc_action)) {
134
135 /**
136 * Delete Messages
137 *
138 */
139 case 'delete_messages':
140
141 require_once(SM_PATH . 'functions/mailbox_display.php');
142 require_once(SM_PATH . 'functions/imap.php');
143
144 if (!sqGetGlobalVar('delete_ids', $delete_ids, SQ_FORM)) {
145 sm_rpc_return_error(99, _("No deletion ID given"));
146 }
147 $delete_ids = explode(',', $delete_ids);
148 if (!sqGetGlobalVar('mailbox', $mailbox, SQ_FORM)) {
149 sm_rpc_return_error(99, _("No mailbox given"));
150 }
151 if (sqGetGlobalVar('startMessage', $startMessage, SQ_INORDER, 1)) {
152 $startMessage = (int) $startMessage;
153 }
154 sqGetGlobalVar('what', $what, SQ_FORM, 0);
155 if (sqGetGlobalVar('account', $iAccount, SQ_GET, 0)) {
156 $iAccount = (int) $iAccount;
157 }
158//FIXME: need to grab the bypass trash variable here too! probably other vars...
159
160/* FIXME: --- The following code was just experimental/proof-of-concept; the rest
161 of the implementation of this functionality still needs to be done "for real"
162 $oImapMessage = new IMAP_Message(0, $mailbox, $startMessage, $what, $iAccount);
163 foreach ($delete_ids as $id) {
164 $oImapMessage->setUid($id);
165 //FIXME: establish constants for $hide values (the 3 below indicates not to show errors, but to return any error string)
166 $result = $oImapMessage->deleteMessage(3);
167 if ($result !== TRUE) {
168 sm_rpc_return_error(99, $result);
169 }
170 }
171--- */
172
173 sm_rpc_return_success();
174 //FIXME: Just for testing the line above can be changed to something like this:
175 //sm_rpc_return_success(0, 'Hooray! Message(s) deleted. Refresh your message list and make sure.');
176 break;
177
178
179 /**
180 * Default: error out
181 *
182 */
183 default:
a49f857e 184 sm_rpc_return_error(2, _("RPC action not understood"));
482956f2 185 break;
186
187}
188
189
190
191/**
192 * Returns an error message to the RPC caller and exits
193 *
194 * NOTE that this function exits and will never return
195 *
196 * @param int $error_code The error code for the current error condition
197 * @param string $error_text Any error message associated with the error
198 * condition (OPTIONAL; default empty string)
199 *
200 */
201function sm_rpc_return_error($error_code, $error_text='') {
202
203 global $oTemplate;
204 $oTemplate->assign('error_code', $error_code);
205 $oTemplate->assign('error_text', $error_text);
206
207 $oTemplate->display('rpc_response_error.tpl');
208
209 exit;
210
211}
212
213
214
215/**
216 * Returns a standard success result to the RPC caller and exits
217 *
218 * NOTE that this function exits and will never return
219 *
220 * @param int $result_code The result code (OPTIONAL; default 0)
221 * @param string $result_text Any result message (OPTIONAL; default
222 * empty string)
223 *
224 */
225function sm_rpc_return_success($result_code=0, $result_text='') {
226
227 global $oTemplate;
228 $oTemplate->assign('result_code', $result_code);
229 $oTemplate->assign('result_text', $result_text);
230
231 $oTemplate->display('rpc_response_success.tpl');
232
233 exit;
234
235}
236
237
238