24a642ef1f4df078729d0e007fe48d6cd749e48d
[squirrelmail.git] / src / mailto.php
1 <?php
2
3 /**
4 * mailto.php -- mailto: url handler
5 *
6 * This checks to see if we're logged in. If we are we open up a new
7 * compose window for this email, otherwise we go to login.php
8 * (the above functionality has been disabled, by default you are required to
9 * login first)
10 *
11 * Use the following url to use mailto:
12 * http://<your server>/<squirrelmail base dir>/src/mailto.php?emailaddress=%1
13 * see ../contrib/squirrelmail.mailto.reg for a Windows Registry file
14 * @copyright &copy; 1999-2005 The SquirrelMail Project Team
15 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
16 * @version $Id$
17 * @package squirrelmail
18 */
19
20 /**
21 * Path for SquirrelMail required files.
22 * @ignore
23 */
24 define('SM_PATH','../');
25
26 /* SquirrelMail required files. */
27 require_once(SM_PATH . 'config/config.php');
28 require_once(SM_PATH . 'functions/global.php');
29 require_once(SM_PATH . 'functions/strings.php');
30
31 /* Force users to login each time? */
32 $force_login = true;
33 /* Open only the compose window, meaningless if $force_login is true */
34 $compose_only = false;
35
36 header('Pragma: no-cache');
37
38 $trtable = array('cc' => 'send_to_cc',
39 'bcc' => 'send_to_bcc',
40 'body' => 'body',
41 'subject' => 'subject');
42 $url = '';
43
44 if(sqgetGlobalVar('emailaddress', $emailaddress)) {
45 $emailaddress = trim($emailaddress);
46 if(stristr($emailaddress, 'mailto:')) {
47 $emailaddress = substr($emailaddress, 7);
48 }
49 if(strpos($emailaddress, '?') !== false) {
50 list($emailaddress, $a) = explode('?', $emailaddress, 2);
51 if(strlen(trim($a)) > 0) {
52 $a = explode('=', $a, 2);
53 $url .= $trtable[strtolower($a[0])] . '=' . urlencode($a[1]) . '&';
54 }
55 }
56 $url = 'send_to=' . urlencode($emailaddress) . '&' . $url;
57
58 /* CC, BCC, etc could be any case, so we'll fix them here */
59 foreach($_GET as $k=>$g) {
60 $k = strtolower($k);
61 if(isset($trtable[$k])) {
62 $k = $trtable[$k];
63 $url .= $k . '=' . urlencode($g) . '&';
64 }
65 }
66 $url = substr($url, 0, -1);
67 }
68 sqsession_is_active();
69
70 if($force_login == false && sqsession_is_registered('user_is_logged_in')) {
71 if($compose_only == true) {
72 $redirect = 'compose.php?' . $url;
73 } else {
74 $redirect = 'webmail.php?right_frame=compose.php?' . urlencode($url);
75 }
76 } else {
77 $redirect = 'login.php?mailto=' . urlencode($url);
78 }
79
80 session_write_close();
81 header('Location: ' . get_location() . '/' . $redirect);
82
83 ?>