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