Happy New Year
[squirrelmail.git] / src / mailto.php
CommitLineData
c67e4479 1<?php
2
3/**
4 * mailto.php -- mailto: url handler
5 *
f0d28f44 6 * This page facilitates handling mailto: links in SquirrelMail. It checks
7 * to see if we're logged in, and if we are, it refers the user to the
8 * compose screen (embedded in a normal, full SquirrelMail interface) with
9 * the mailto: data auto-populated in the corresponding fields. If there
10 * is no user currently logged in, the user is redirected to the login screen
11 * first, but after login, the compose screen is shown with the correct
12 * fields pre-populated.
13 *
14 * If the administrator desires, $compose_only can be set to TRUE, in which
15 * case only a compose screen will show, not embedded in the normal
16 * SquirrelMail interface.
17 *
18 * If the administrator wants to force a re-login every time a mailto: link
19 * is clicked on (no matter if a user was already logged in), set $force_login
20 * to TRUE.
21 *
22 * Use the following URI when configuring a computer to handle mailto: links
23 * by using SquirrelMail:
24 *
25 * http://<your server>/<squirrelmail base dir>/src/mailto.php?emailaddress=%1
26 *
27 * see ../contrib/squirrelmail.mailto.NT2KXP.reg for a Windows Registry file
28 * that will set this up in the most robust manner.
c67e4479 29 *
353d074a 30 * @copyright 1999-2018 The SquirrelMail Project Team
4b4abf93 31 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 32 * @version $Id$
8f6f9ba5 33 * @package squirrelmail
c67e4479 34 */
35
ebd2391c 36/** This is the mailto page */
37define('PAGE_NAME', 'mailto');
38
30967a1e 39/**
202bcbcc 40 * Include the SquirrelMail initialization file.
30967a1e 41 */
202bcbcc 42require('../include/init.php');
c67e4479 43
f0d28f44 44
45// Force users to login each time? Setting this to TRUE does NOT mean
46// that if no user is logged in that it won't require a correct login
47// first! Instead, setting it to TRUE will log out anyone currently
48// logged in and force a re-login. Setting this to FALSE will still
49// require a login if no one is logged in, but it will allow you to go
50// directly to compose your message if you are already logged in.
51//
52// Note, however, that depending on how the client browser manages
53// sessions and how the client operating system is set to handle
54// mailto: links, you may have to log in every time no matter what
55// (IE under WinXP appears to pop up a new window and thus always
56// start a new session; Firefox under WinXP seems to start a new tab
57// which will find a current login if one exists).
58//
59$force_login = FALSE;
60
61
62// Open only the compose window, meaningless if $force_login is TRUE
63//
64$compose_only = FALSE;
65
d69119eb 66
03478654 67// Disable browser caching
68//
69header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
c67e4479 70header('Pragma: no-cache');
03478654 71header('Expires: Sat, 1 Jan 2000 00:00:00 GMT');
c67e4479 72
f0d28f44 73$trtable = array('cc' => 'cc',
74 'bcc' => 'bcc',
c67e4479 75 'body' => 'body',
76 'subject' => 'subject');
77$url = '';
d69119eb 78
7e2ff844 79$data = array();
80
f0d28f44 81if (sqgetGlobalVar('emailaddress', $emailaddress)) {
d69119eb 82 $emailaddress = trim($emailaddress);
f0d28f44 83 if (stristr($emailaddress, 'mailto:')) {
d69119eb 84 $emailaddress = substr($emailaddress, 7);
85 }
f0d28f44 86 if (strpos($emailaddress, '?') !== FALSE) {
d69119eb 87 list($emailaddress, $a) = explode('?', $emailaddress, 2);
f0d28f44 88 if (strlen(trim($a)) > 0) {
d69119eb 89 $a = explode('=', $a, 2);
7e2ff844 90 $data[strtolower($a[0])] = $a[1];
d69119eb 91 }
92 }
7e2ff844 93 $data['to'] = $emailaddress;
d69119eb 94
95 /* CC, BCC, etc could be any case, so we'll fix them here */
96 foreach($_GET as $k=>$g) {
c67e4479 97 $k = strtolower($k);
f0d28f44 98 if (isset($trtable[$k])) {
d69119eb 99 $k = $trtable[$k];
7e2ff844 100 $data[$k] = $g;
d69119eb 101 }
c67e4479 102 }
103}
7e2ff844 104sqsession_is_active();
d69119eb 105
f0d28f44 106if (!$force_login && sqsession_is_registered('user_is_logged_in')) {
107 if ($compose_only) {
7e2ff844 108 $redirect = 'compose.php?mailtodata=' . urlencode(serialize($data));
d69119eb 109 } else {
f0d28f44 110 $redirect = 'webmail.php?right_frame=compose.php&mailtodata=' . urlencode(serialize($data));
d69119eb 111 }
c67e4479 112} else {
7e2ff844 113 $redirect = 'login.php?mailtodata=' . urlencode(serialize($data));
c67e4479 114}
d69119eb 115
c67e4479 116session_write_close();
3ae35858 117header('Location: ' . get_location() . '/' . $redirect);