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