Cleaned up some formatting
[squirrelmail.git] / src / mailto.php
CommitLineData
c67e4479 1<?php
2
3/**
4 * mailto.php -- mailto: url handler
5 *
6 * Copyright (c) 1999-2003 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:
d69119eb 15 * http://<your server>/<squirrelmail base dir>/src/mailto.php?emailaddress=%1
c67e4479 16 * see ../contrib/squirrelmail.mailto.reg for a Windows Registry file
8f6f9ba5 17 * @package squirrelmail
c67e4479 18 */
19
8f6f9ba5 20/** Path for SquirrelMail required files. */
c67e4479 21define('SM_PATH','../');
22
23/* SquirrelMail required files. */
24require_once(SM_PATH . 'config/config.php');
25require_once(SM_PATH . 'functions/global.php');
3ae35858 26require_once(SM_PATH . 'functions/strings.php');
c67e4479 27
d69119eb 28/* Force users to login each time? */
29$force_login = true;
30/* Open only the compose window, meaningless if $force_login is true */
31$compose_only = false;
32
c67e4479 33header('Pragma: no-cache');
c67e4479 34
d69119eb 35$trtable = array('cc' => 'send_to_cc',
c67e4479 36 'bcc' => 'send_to_bcc',
37 'body' => 'body',
38 'subject' => 'subject');
39$url = '';
d69119eb 40
41if(sqgetGlobalVar('emailaddress', $emailaddress)) {
42 $emailaddress = trim($emailaddress);
43 if(stristr($emailaddress, 'mailto:')) {
44 $emailaddress = substr($emailaddress, 7);
45 }
46 if(strpos($emailaddress, '?') !== false) {
47 list($emailaddress, $a) = explode('?', $emailaddress, 2);
48 if(strlen(trim($a)) > 0) {
49 $a = explode('=', $a, 2);
50 $url .= $trtable[strtolower($a[0])] . '=' . urlencode($a[1]) . '&';
51 }
52 }
53 $url = 'send_to=' . urlencode($emailaddress) . '&' . $url;
54
55 /* CC, BCC, etc could be any case, so we'll fix them here */
56 foreach($_GET as $k=>$g) {
c67e4479 57 $k = strtolower($k);
d69119eb 58 if(isset($trtable[$k])) {
59 $k = $trtable[$k];
60 $url .= $k . '=' . urlencode($g) . '&';
61 }
c67e4479 62 }
d69119eb 63 $url = substr($url, 0, -1);
c67e4479 64}
c67e4479 65sqsession_is_active();
d69119eb 66
67if($force_login == false && sqsession_is_registered('user_is_logged_in')) {
68 if($compose_only == true) {
69 $redirect = 'compose.php?' . $url;
70 } else {
71 $redirect = 'webmail.php?right_frame=compose.php?' . urlencode($url);
72 }
c67e4479 73} else {
d69119eb 74 $redirect = 'login.php?mailto=' . urlencode($url);
c67e4479 75}
d69119eb 76
c67e4479 77session_write_close();
3ae35858 78header('Location: ' . get_location() . '/' . $redirect);
d69119eb 79?>