source: subversion/trunk/roundcubemail/index.php @ 593

Last change on this file since 593 was 593, checked in by estadtherr, 6 years ago

fixed HTML->Plain conversion

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.2 KB
Line 
1<?php
2/*
3 +-----------------------------------------------------------------------+
4 | RoundCube Webmail IMAP Client                                         |
5 | Version 0.1-20070518                                                  |
6 |                                                                       |
7 | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland                 |
8 | Licensed under the GNU GPL                                            |
9 |                                                                       |
10 | Redistribution and use in source and binary forms, with or without    |
11 | modification, are permitted provided that the following conditions    |
12 | are met:                                                              |
13 |                                                                       |
14 | o Redistributions of source code must retain the above copyright      |
15 |   notice, this list of conditions and the following disclaimer.       |
16 | o Redistributions in binary form must reproduce the above copyright   |
17 |   notice, this list of conditions and the following disclaimer in the |
18 |   documentation and/or other materials provided with the distribution.|
19 | o The names of the authors may not be used to endorse or promote      |
20 |   products derived from this software without specific prior written  |
21 |   permission.                                                         |
22 |                                                                       |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |
24 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |
25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |
27 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |
29 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
30 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |
32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |
34 |                                                                       |
35 +-----------------------------------------------------------------------+
36 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
37 +-----------------------------------------------------------------------+
38
39 $Id$
40
41*/
42
43// application constants
44define('RCMAIL_VERSION', '0.1-20070517');
45define('RCMAIL_CHARSET', 'UTF-8');
46define('JS_OBJECT_NAME', 'rcmail');
47
48// define global vars
49$OUTPUT_TYPE = 'html';
50$INSTALL_PATH = dirname(__FILE__);
51$MAIN_TASKS = array('mail','settings','addressbook','logout');
52
53if (empty($INSTALL_PATH))
54  $INSTALL_PATH = './';
55else
56  $INSTALL_PATH .= '/';
57
58
59// make sure path_separator is defined
60if (!defined('PATH_SEPARATOR'))
61  define('PATH_SEPARATOR', (eregi('win', PHP_OS) ? ';' : ':'));
62
63
64// RC include folders MUST be included FIRST to avoid other
65// possible not compatible libraries (i.e PEAR) to be included
66// instead the ones provided by RC
67ini_set('include_path', $INSTALL_PATH.PATH_SEPARATOR.$INSTALL_PATH.'program'.PATH_SEPARATOR.$INSTALL_PATH.'program/lib'.PATH_SEPARATOR.ini_get('include_path'));
68
69ini_set('session.name', 'sessid');
70ini_set('session.use_cookies', 1);
71ini_set('session.gc_maxlifetime', 21600);
72ini_set('session.gc_divisor', 500);
73ini_set('error_reporting', E_ALL&~E_NOTICE); 
74
75// increase maximum execution time for php scripts
76// (does not work in safe mode)
77if (!ini_get('safe_mode')) @set_time_limit(120);
78
79// include base files
80require_once('include/rcube_shared.inc');
81require_once('include/rcube_imap.inc');
82require_once('include/bugs.inc');
83require_once('include/main.inc');
84require_once('include/cache.inc');
85require_once('lib/html2text.inc');
86require_once('PEAR.php');
87
88
89// set PEAR error handling
90// PEAR::setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_NOTICE);
91
92
93// catch some url/post parameters
94$_task = strip_quotes(get_input_value('_task', RCUBE_INPUT_GPC));
95$_action = strip_quotes(get_input_value('_action', RCUBE_INPUT_GPC));
96$_framed = (!empty($_GET['_framed']) || !empty($_POST['_framed']));
97
98// use main task if empty or invalid value
99if (empty($_task) || !in_array($_task, $MAIN_TASKS))
100  $_task = 'mail';
101
102
103// set output buffering
104if ($_action != 'get' && $_action != 'viewsource')
105{
106  // use gzip compression if supported
107  if (function_exists('ob_gzhandler') && ini_get('zlib.output_compression'))
108    ob_start('ob_gzhandler');
109  else
110    ob_start();
111}
112
113
114// start session with requested task
115rcmail_startup($_task);
116
117// set session related variables
118$COMM_PATH = sprintf('./?_task=%s', $_task);
119$SESS_HIDDEN_FIELD = '';
120
121
122// add framed parameter
123if ($_framed)
124{
125  $COMM_PATH .= '&_framed=1';
126  $SESS_HIDDEN_FIELD .= "\n".'<input type="hidden" name="_framed" value="1" />';
127}
128
129
130// init necessary objects for GUI
131rcmail_load_gui();
132
133
134// check DB connections and exit on failure
135if ($err_str = $DB->is_error())
136{
137  raise_error(array(
138    'code' => 603,
139    'type' => 'db',
140    'message' => $err_str), FALSE, TRUE);
141}
142
143
144// error steps
145if ($_action=='error' && !empty($_GET['_code']))
146  raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE);
147
148
149// handle HTML->text conversion
150if ($_action=='html2text')
151{
152    $htmlText = $HTTP_RAW_POST_DATA;
153    $converter = new html2text($htmlText);
154
155        // TODO possibly replace with rcube_remote_response()
156        header('Content-Type: text/plain');
157        $plaintext = $converter->get_text();
158        print $plaintext;
159
160        exit;
161}
162
163
164// try to log in
165if ($_action=='login' && $_task=='mail')
166{
167  $host = rcmail_autoselect_host();
168 
169  // check if client supports cookies
170  if (empty($_COOKIE))
171  {
172    $OUTPUT->show_message("cookiesdisabled", 'warning');
173  }
174  else if ($_SESSION['temp'] && !empty($_POST['_user']) && isset($_POST['_pass']) &&
175           rcmail_login(get_input_value('_user', RCUBE_INPUT_POST),
176              get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-8859-1'), $host))
177  {
178    // create new session ID
179    unset($_SESSION['temp']);
180    sess_regenerate_id();
181
182    // send auth cookie if necessary
183    rcmail_authenticate_session();
184
185    // send redirect
186    header("Location: $COMM_PATH");
187    exit;
188  }
189  else
190  {
191    $OUTPUT->show_message("loginfailed", 'warning');
192    $_SESSION['user_id'] = '';
193  }
194}
195
196// end session
197else if (($_task=='logout' || $_action=='logout') && isset($_SESSION['user_id']))
198{
199  $OUTPUT->show_message('loggedout');
200  rcmail_kill_session();
201}
202
203// check session and auth cookie
204else if ($_action != 'login' && $_SESSION['user_id'] && $_action != 'send')
205{
206  if (!rcmail_authenticate_session())
207  {
208    $OUTPUT->show_message('sessionerror', 'error');
209    rcmail_kill_session();
210  }
211}
212
213
214// log in to imap server
215if (!empty($_SESSION['user_id']) && $_task=='mail')
216{
217  $conn = $IMAP->connect($_SESSION['imap_host'], $_SESSION['username'], decrypt_passwd($_SESSION['password']), $_SESSION['imap_port'], $_SESSION['imap_ssl']);
218  if (!$conn)
219  {
220    $OUTPUT->show_message('imaperror', 'error');
221    $_SESSION['user_id'] = '';
222  }
223  else
224    rcmail_set_imap_prop();
225}
226
227
228// not logged in -> set task to 'login
229if (empty($_SESSION['user_id']))
230{
231  if ($OUTPUT->ajax_call)
232    $OUTPUT->remote_response("setTimeout(\"location.href='\"+this.env.comm_path+\"'\", 2000);");
233 
234  $_task = 'login';
235}
236
237
238
239// set task and action to client
240$OUTPUT->set_env('task', $_task);
241if (!empty($_action))
242  $OUTPUT->set_env('action', $_action);
243
244
245
246// not logged in -> show login page
247if (!$_SESSION['user_id'])
248{
249  $OUTPUT->task = 'login';
250  $OUTPUT->send('login');
251  exit;
252}
253
254
255// handle keep-alive signal
256if ($_action=='keep-alive')
257{
258  $OUTPUT->reset();
259  $OUTPUT->send('');
260  exit;
261}
262
263// include task specific files
264if ($_task=='mail')
265{
266  include_once('program/steps/mail/func.inc');
267 
268  if ($_action=='show' || $_action=='preview' || $_action=='print')
269    include('program/steps/mail/show.inc');
270
271  if ($_action=='get')
272    include('program/steps/mail/get.inc');
273
274  if ($_action=='moveto' || $_action=='delete')
275    include('program/steps/mail/move_del.inc');
276
277  if ($_action=='mark')
278    include('program/steps/mail/mark.inc');
279
280  if ($_action=='viewsource')
281    include('program/steps/mail/viewsource.inc');
282
283  if ($_action=='send')
284    include('program/steps/mail/sendmail.inc');
285
286  if ($_action=='upload')
287    include('program/steps/mail/upload.inc');
288
289  if ($_action=='compose' || $_action=='remove-attachment')
290    include('program/steps/mail/compose.inc');
291
292  if ($_action=='addcontact')
293    include('program/steps/mail/addcontact.inc');
294
295  if ($_action=='expunge' || $_action=='purge')
296    include('program/steps/mail/folders.inc');
297
298  if ($_action=='check-recent')
299    include('program/steps/mail/check_recent.inc');
300
301  if ($_action=='getunread')
302    include('program/steps/mail/getunread.inc');
303   
304  if ($_action=='list' && isset($_REQUEST['_remote']))
305    include('program/steps/mail/list.inc');
306
307   if ($_action=='search')
308     include('program/steps/mail/search.inc');
309     
310  if ($_action=='spell')
311    include('program/steps/mail/spell.inc');
312
313  if ($_action=='rss')
314    include('program/steps/mail/rss.inc');
315   
316  if ($_action=='quotadisplay')
317    include('program/steps/mail/quotadisplay.inc');
318
319
320  // make sure the message count is refreshed
321  $IMAP->messagecount($_SESSION['mbox'], 'ALL', TRUE);
322}
323
324
325// include task specific files
326if ($_task=='addressbook')
327{
328  include_once('program/steps/addressbook/func.inc');
329
330  if ($_action=='save')
331    include('program/steps/addressbook/save.inc');
332 
333  if ($_action=='edit' || $_action=='add')
334    include('program/steps/addressbook/edit.inc');
335 
336  if ($_action=='delete')
337    include('program/steps/addressbook/delete.inc');
338
339  if ($_action=='show')
340    include('program/steps/addressbook/show.inc'); 
341
342  if ($_action=='list' && $_REQUEST['_remote'])
343    include('program/steps/addressbook/list.inc');
344
345  if ($_action=='search')
346    include('program/steps/addressbook/search.inc');
347
348  if ($_action=='copy')
349    include('program/steps/addressbook/copy.inc');
350
351  if ($_action=='mailto')
352    include('program/steps/addressbook/mailto.inc');
353}
354
355
356// include task specific files
357if ($_task=='settings')
358{
359  include_once('program/steps/settings/func.inc');
360
361  if ($_action=='save-identity')
362    include('program/steps/settings/save_identity.inc');
363
364  if ($_action=='add-identity' || $_action=='edit-identity')
365    include('program/steps/settings/edit_identity.inc');
366
367  if ($_action=='delete-identity')
368    include('program/steps/settings/delete_identity.inc');
369 
370  if ($_action=='identities')
371    include('program/steps/settings/identities.inc'); 
372
373  if ($_action=='save-prefs')
374    include('program/steps/settings/save_prefs.inc'); 
375
376  if ($_action=='folders' || $_action=='subscribe' || $_action=='unsubscribe' ||
377      $_action=='create-folder' || $_action=='rename-folder' || $_action=='delete-folder')
378    include('program/steps/settings/manage_folders.inc');
379
380}
381
382
383// parse main template
384$OUTPUT->send($_task);
385
386
387// if we arrive here, something went wrong
388raise_error(array(
389  'code' => 404,
390  'type' => 'php',
391  'line' => __LINE__,
392  'file' => __FILE__,
393  'message' => "Invalid request"), TRUE, TRUE);
394                     
395?>
Note: See TracBrowser for help on using the repository browser.