Happy New Year
[squirrelmail.git] / src / mailto.php
... / ...
CommitLineData
1<?php
2
3/**
4 * mailto.php -- mailto: url handler
5 *
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.
29 *
30 * @copyright 1999-2018 The SquirrelMail Project Team
31 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
32 * @version $Id$
33 * @package squirrelmail
34 */
35
36/** This is the mailto page */
37define('PAGE_NAME', 'mailto');
38
39/**
40 * Include the SquirrelMail initialization file.
41 */
42require('../include/init.php');
43
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
66
67// Disable browser caching
68//
69header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
70header('Pragma: no-cache');
71header('Expires: Sat, 1 Jan 2000 00:00:00 GMT');
72
73$trtable = array('cc' => 'cc',
74 'bcc' => 'bcc',
75 'body' => 'body',
76 'subject' => 'subject');
77$url = '';
78
79$data = array();
80
81if (sqgetGlobalVar('emailaddress', $emailaddress)) {
82 $emailaddress = trim($emailaddress);
83 if (stristr($emailaddress, 'mailto:')) {
84 $emailaddress = substr($emailaddress, 7);
85 }
86 if (strpos($emailaddress, '?') !== FALSE) {
87 list($emailaddress, $a) = explode('?', $emailaddress, 2);
88 if (strlen(trim($a)) > 0) {
89 $a = explode('=', $a, 2);
90 $data[strtolower($a[0])] = $a[1];
91 }
92 }
93 $data['to'] = $emailaddress;
94
95 /* CC, BCC, etc could be any case, so we'll fix them here */
96 foreach($_GET as $k=>$g) {
97 $k = strtolower($k);
98 if (isset($trtable[$k])) {
99 $k = $trtable[$k];
100 $data[$k] = $g;
101 }
102 }
103}
104sqsession_is_active();
105
106if (!$force_login && sqsession_is_registered('user_is_logged_in')) {
107 if ($compose_only) {
108 $redirect = 'compose.php?mailtodata=' . urlencode(serialize($data));
109 } else {
110 $redirect = 'webmail.php?right_frame=compose.php&mailtodata=' . urlencode(serialize($data));
111 }
112} else {
113 $redirect = 'login.php?mailtodata=' . urlencode(serialize($data));
114}
115
116session_write_close();
117header('Location: ' . get_location() . '/' . $redirect);