fsf changes, meant to be rebased on upstream
[squirrelmail.git] / plugins / info / options.php
CommitLineData
01c372f1 1<?php
4b4abf93 2
ea5f4b8e 3/**
91e0dccc 4 * options page for IMAP info plugin
5 *
a7b90f05 6 * This is where it all happens :)
91e0dccc 7 *
4b4abf93 8 * @author Jason Munro <jason at stdbev.com>
c997cbe6 9 * @copyright 1999-2021 The SquirrelMail Project Team
b11fe046 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
ea5f4b8e 12 * @package plugins
13 * @subpackage info
a7b90f05 14 */
8d6a115b 15
202bcbcc 16/**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
20require('../../include/init.php');
a7b90f05 21
cdf82d4a 22/* SquirrelMail required files. */
202bcbcc 23require_once(SM_PATH . 'functions/imap_general.php');
a9e1e670 24require_once(SM_PATH . 'functions/forms.php');
cdf82d4a 25require_once(SM_PATH . 'plugins/info/functions.php');
a7b90f05 26
27global $username, $color, $folder_prefix, $default_charset;
28$default_charset = strtoupper($default_charset);
876fdb60 29displayPageHeader($color);
a7b90f05 30$mailbox = 'INBOX';
6a85a764 31
b11fe046 32/**
33 * testing installation
34 *
35 * prevent use of plugin if it is not enabled
36 */
37if (! is_plugin_enabled('info')) {
1b858d86 38 error_box(_("Plugin is disabled."));
39 // display footer (closes html) and stop script execution
40 $oTemplate->display('footer.tpl');
01c372f1 41 exit;
b11fe046 42}
43
6a85a764 44/* GLOBALS */
b587ac51 45sqgetGlobalVar('submit', $submit, SQ_POST);
6a85a764 46
47for($i = 0; $i <= 9; $i++){
b587ac51 48 $varc = 'CHECK_TEST_'.$i;
49 sqgetGlobalVar($varc, $$varc, SQ_POST);
50 $vart = 'TEST_'.$i;
51 sqgetGlobalVar($vart, $$vart, SQ_POST);
6a85a764 52}
53
54/* END GLOBALS */
55
a9805897 56global $imap_stream_options; // in case not defined in config
57$imap_stream = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
a7b90f05 58$caps_array = get_caps($imap_stream);
01c372f1 59$list = array ('TEST_0',
a7b90f05 60 'TEST_1',
61 'TEST_2',
62 'TEST_3',
63 'TEST_4',
64 'TEST_5',
65 'TEST_6',
66 'TEST_7',
67 'TEST_8',
68 'TEST_9');
69
f265009a 70echo '<br /><div style="text-align: center;"><b>'._("IMAP server information")."</b></div><br />\n".
dd0bbc43 71 '<table bgcolor="'.$color[3].'" width="100%" align="center" border="1" cellpadding="2">'.
01c372f1 72 '<tr><td bgcolor="'.$color[3]."\"><br />\n".
dd0bbc43 73 '<table width="95%" align="center" border="1" bgcolor="'.$color[3]."\">\n".
01c372f1 74 '<tr><td bgcolor="'.$color[4].'"><b>'.
75 _("Server Capability response:").
76 "</b><br />\n";
a7b90f05 77
78foreach($caps_array[0] as $value) {
3047e291 79 echo sm_encode_html_special_chars($value);
a7b90f05 80}
81
01c372f1 82echo "</td></tr><tr><td>\n";
a7b90f05 83
84if (!isset($submit) || $submit == 'default') {
01c372f1 85 echo '<br /><p><small><font color="'.$color[6].'">'.
86 _("Select the IMAP commands you would like to run. Most commands require a selected mailbox so the select command is already setup. You can clear all the commands and test your own IMAP command strings. The commands are executed in order. The default values are simple IMAP commands using your default_charset and folder_prefix from SquirrelMail when needed.").
87 "</font></small></p>\n".
88 '<p align="center"><small><b>'.
89 _("NOTE: These commands are live, any changes made will effect your current email account.").
90 "</b></small></p><br />\n";
a7b90f05 91 if (!isset($submit)) {
92 $submit = '';
93 }
94}
95else {
3047e291 96 echo 'folder_prefix = ' . sm_encode_html_special_chars($folder_prefix)."<br />\n" .
97 'default_charset = '.sm_encode_html_special_chars($default_charset)."\n";
a7b90f05 98}
99
dd0bbc43 100echo "<br /></td></tr></table><br />\n";
a7b90f05 101
102
103if ($submit == 'submit') {
104 $type = array();
105 for ($i=0;$i<count($list);$i++) {
106 $type[$list[$i]] = $$list[$i];
107 }
108}
109
110elseif ($submit == 'clear') {
111 for ($i=0;$i<count($list);$i++) {
112 $type[$list[$i]] = '';
113 }
114}
115
116elseif (!$submit || $submit == 'default') {
117 $type = array (
118 'TEST_0' => "SELECT $mailbox",
119 'TEST_1' => "STATUS $mailbox (MESSAGES RECENT)",
120 'TEST_2' => "EXAMINE $mailbox",
121 'TEST_3' => "SEARCH CHARSET \"$default_charset\" ALL *",
122 'TEST_4' => "THREAD REFERENCES $default_charset ALL",
123 'TEST_5' => "SORT (DATE) $default_charset ALL",
124 'TEST_6' => "FETCH 1:* (FLAGS BODY[HEADER.FIELDS (FROM DATE TO)])",
125 'TEST_7' => "LSUB \"$folder_prefix\" \"*%\"",
3f6dd931 126 'TEST_8' => "LIST \"$folder_prefix\" \"*\"",
a7b90f05 127 'TEST_9' => "");
128}
129
01c372f1 130echo "<form action=\"options.php\" method=\"post\">\n".
dd0bbc43 131 "<table border=\"1\" align=\"center\">\n".
01c372f1 132 '<tr><th>'. _("Select").
133 '</th><th>'._("Test Name").
134 '</th><th>'._("IMAP command string")."</th></tr>\n".
135 '<tr><td>';
a7b90f05 136
137foreach($type as $index=>$value) {
01c372f1 138 echo "</td></tr>\n<tr><td width=\"10%\">\n<input type=\"checkbox\" value=\"1\" name=\"CHECK_$index\"";
a7b90f05 139 if ($index == 'TEST_0' && ($submit == 'default' || $submit == '')) {
01c372f1 140 echo ' checked="checked"';
a7b90f05 141 }
142 $check = "CHECK_".$index;
143 if (isset($$check) && $submit != 'clear' && $submit != 'default') {
01c372f1 144 echo ' checked="checked"';
a7b90f05 145 }
01c372f1 146 echo " /></td><td width=\"30%\">$index</td><td width=\"60%\">\n".
147 addInput($index, $value, 60);
a7b90f05 148}
149
dd0bbc43 150echo "</td></tr></table><br />\n".
f265009a 151 '<div style="text-align: center;">'.
01c372f1 152 addSubmit('submit','submit').
dd0bbc43 153 addSubmit('clear','submit',array('id'=>'clear')).
154 addSubmit('default','submit',array('id'=>'default')).
f265009a 155 "</div><br /></form>\n";
a7b90f05 156
157$tests = array();
158
159if ($submit == 'submit') {
160 foreach ($type as $index=>$value) {
161 $check = "CHECK_".$index;
162 if (isset($$check)) {
163 $type[$index] = $$index;
91e0dccc 164 array_push($tests, $index);
a7b90f05 165 }
166 }
167 for ($i=0;$i<count($tests);$i++) {
3f6dd931 168 // make sure that microtime function is available before it is called
169 if (function_exists('microtime')) {
170 list($usec, $sec) = explode(" ", microtime());
171 $starttime = (float)$sec + (float)$usec;
172 }
173
dd0bbc43 174 echo '<table width="95%" align="center" border="0" bgcolor="'.$color[4]."\">\n".
01c372f1 175 '<tr><td><b>'.$tests[$i]."</b></td></tr>\n".
176 '<tr><td><small><b><font color="'.$color[7].'">'.
7431eca9 177 _("Request:")."</font></b></small></td></tr>\n";
178 // imap_test function outputs imap command
179 $response = imap_test($imap_stream, $type[$tests[$i]]);
180 echo '<tr><td><small><b><font color="'.$color[7].'">'.
01c372f1 181 _("Response:")."</font></b></small></td></tr>\n".
182 '<tr><td>';
a7b90f05 183 print_response($response);
3f6dd931 184 echo "</td></tr>\n";
185
186 if (function_exists('microtime')) {
187 // get script execution time
188 list($usec, $sec) = explode(" ", microtime());
189 $endtime = (float)$sec + (float)$usec;
190 // i18n: ms = short for miliseconds
191 echo '<tr><td><small><b><font color="'.$color[7].'">'.
192 _("Execution time:")."</font></b></small></td></tr>\n".
193 '<tr><td>'.sprintf(_("%s ms"),round((($endtime - $starttime)*1000),3))."</td></tr>\n";
194 }
195
dd0bbc43 196 echo "</table><br />\n";
a7b90f05 197 }
198}
dd0bbc43 199echo '</td></tr></table>';
7431eca9 200sqimap_logout($imap_stream);
b11fe046 201
202/**
203 * Optional hook in info plugin
204 *
205 * Hook allows attaching plugin to bottom of info plugin
206 */
6e515418 207do_hook('info_bottom', $null);
a7b90f05 208?>
2128bbc6 209</body></html>