update mailbox cache if new folders are created (first time login when
[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>
47ccfad4 9 * @copyright &copy; 1999-2006 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
ea5f4b8e 16/** @ignore */
8d6a115b 17define('SM_PATH','../../');
a7b90f05 18
cdf82d4a 19/* SquirrelMail required files. */
20require_once(SM_PATH . 'include/validate.php');
21require_once(SM_PATH . 'functions/page_header.php');
22require_once(SM_PATH . 'functions/imap.php');
a9e1e670 23require_once(SM_PATH . 'functions/forms.php');
cdf82d4a 24require_once(SM_PATH . 'plugins/info/functions.php');
a7b90f05 25
26global $username, $color, $folder_prefix, $default_charset;
27$default_charset = strtoupper($default_charset);
28displayPageHeader($color, 'None');
29$mailbox = 'INBOX';
6a85a764 30
b11fe046 31/**
32 * testing installation
33 *
34 * prevent use of plugin if it is not enabled
35 */
36if (! is_plugin_enabled('info')) {
0b20cce0 37 error_box(_("Plugin is disabled."),$color);
38 echo '</body></html>';
01c372f1 39 exit;
b11fe046 40}
41
6a85a764 42/* GLOBALS */
b11fe046 43sqgetGlobalVar('username', $username, SQ_SESSION);
44sqgetGlobalVar('key', $key, SQ_COOKIE);
45sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
6a85a764 46
b587ac51 47sqgetGlobalVar('submit', $submit, SQ_POST);
6a85a764 48
49for($i = 0; $i <= 9; $i++){
b587ac51 50 $varc = 'CHECK_TEST_'.$i;
51 sqgetGlobalVar($varc, $$varc, SQ_POST);
52 $vart = 'TEST_'.$i;
53 sqgetGlobalVar($vart, $$vart, SQ_POST);
6a85a764 54}
55
56/* END GLOBALS */
57
a7b90f05 58$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
59$caps_array = get_caps($imap_stream);
01c372f1 60$list = array ('TEST_0',
a7b90f05 61 'TEST_1',
62 'TEST_2',
63 'TEST_3',
64 'TEST_4',
65 'TEST_5',
66 'TEST_6',
67 'TEST_7',
68 'TEST_8',
69 'TEST_9');
70
01c372f1 71echo '<br /><center><b>'._("IMAP server information")."</b></center><br />\n".
72 '<center><table bgcolor="'.$color[3].'" width="100%" border="1" cellpadding="2">'.
73 '<tr><td bgcolor="'.$color[3]."\"><br />\n".
74 '<center><table width="95%" border="1" bgcolor="'.$color[3]."\">\n".
75 '<tr><td bgcolor="'.$color[4].'"><b>'.
76 _("Server Capability response:").
77 "</b><br />\n";
a7b90f05 78
79foreach($caps_array[0] as $value) {
01c372f1 80 echo htmlspecialchars($value);
a7b90f05 81}
82
01c372f1 83echo "</td></tr><tr><td>\n";
a7b90f05 84
85if (!isset($submit) || $submit == 'default') {
01c372f1 86 echo '<br /><p><small><font color="'.$color[6].'">'.
87 _("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.").
88 "</font></small></p>\n".
89 '<p align="center"><small><b>'.
90 _("NOTE: These commands are live, any changes made will effect your current email account.").
91 "</b></small></p><br />\n";
a7b90f05 92 if (!isset($submit)) {
93 $submit = '';
94 }
95}
96else {
01c372f1 97 echo 'folder_prefix = ' . htmlspecialchars($folder_prefix)."<br />\n" .
98 'default_charset = '.htmlspecialchars($default_charset)."\n";
a7b90f05 99}
100
01c372f1 101echo "<br /></td></tr></table></center><br />\n";
a7b90f05 102
103
104if ($submit == 'submit') {
105 $type = array();
106 for ($i=0;$i<count($list);$i++) {
107 $type[$list[$i]] = $$list[$i];
108 }
109}
110
111elseif ($submit == 'clear') {
112 for ($i=0;$i<count($list);$i++) {
113 $type[$list[$i]] = '';
114 }
115}
116
117elseif (!$submit || $submit == 'default') {
118 $type = array (
119 'TEST_0' => "SELECT $mailbox",
120 'TEST_1' => "STATUS $mailbox (MESSAGES RECENT)",
121 'TEST_2' => "EXAMINE $mailbox",
122 'TEST_3' => "SEARCH CHARSET \"$default_charset\" ALL *",
123 'TEST_4' => "THREAD REFERENCES $default_charset ALL",
124 'TEST_5' => "SORT (DATE) $default_charset ALL",
125 'TEST_6' => "FETCH 1:* (FLAGS BODY[HEADER.FIELDS (FROM DATE TO)])",
126 'TEST_7' => "LSUB \"$folder_prefix\" \"*%\"",
3f6dd931 127 'TEST_8' => "LIST \"$folder_prefix\" \"*\"",
a7b90f05 128 'TEST_9' => "");
129}
130
01c372f1 131echo "<form action=\"options.php\" method=\"post\">\n".
132 "<center><table border=\"1\">\n".
133 '<tr><th>'. _("Select").
134 '</th><th>'._("Test Name").
135 '</th><th>'._("IMAP command string")."</th></tr>\n".
136 '<tr><td>';
a7b90f05 137
138foreach($type as $index=>$value) {
01c372f1 139 echo "</td></tr>\n<tr><td width=\"10%\">\n<input type=\"checkbox\" value=\"1\" name=\"CHECK_$index\"";
a7b90f05 140 if ($index == 'TEST_0' && ($submit == 'default' || $submit == '')) {
01c372f1 141 echo ' checked="checked"';
a7b90f05 142 }
143 $check = "CHECK_".$index;
144 if (isset($$check) && $submit != 'clear' && $submit != 'default') {
01c372f1 145 echo ' checked="checked"';
a7b90f05 146 }
01c372f1 147 echo " /></td><td width=\"30%\">$index</td><td width=\"60%\">\n".
148 addInput($index, $value, 60);
a7b90f05 149}
150
6fd95361 151echo "</td></tr></table></center><br />\n".
01c372f1 152 '<center>'.
153 addSubmit('submit','submit').
154 addSubmit('clear','submit').
155 addSubmit('default','submit').
6fd95361 156 "</center><br /></form>\n";
a7b90f05 157
158$tests = array();
159
160if ($submit == 'submit') {
161 foreach ($type as $index=>$value) {
162 $check = "CHECK_".$index;
163 if (isset($$check)) {
164 $type[$index] = $$index;
91e0dccc 165 array_push($tests, $index);
a7b90f05 166 }
167 }
168 for ($i=0;$i<count($tests);$i++) {
3f6dd931 169 // make sure that microtime function is available before it is called
170 if (function_exists('microtime')) {
171 list($usec, $sec) = explode(" ", microtime());
172 $starttime = (float)$sec + (float)$usec;
173 }
174
01c372f1 175 echo '<center><table width="95%" border="0" bgcolor="'.$color[4]."\">\n".
176 '<tr><td><b>'.$tests[$i]."</b></td></tr>\n".
177 '<tr><td><small><b><font color="'.$color[7].'">'.
7431eca9 178 _("Request:")."</font></b></small></td></tr>\n";
179 // imap_test function outputs imap command
180 $response = imap_test($imap_stream, $type[$tests[$i]]);
181 echo '<tr><td><small><b><font color="'.$color[7].'">'.
01c372f1 182 _("Response:")."</font></b></small></td></tr>\n".
183 '<tr><td>';
a7b90f05 184 print_response($response);
3f6dd931 185 echo "</td></tr>\n";
186
187 if (function_exists('microtime')) {
188 // get script execution time
189 list($usec, $sec) = explode(" ", microtime());
190 $endtime = (float)$sec + (float)$usec;
191 // i18n: ms = short for miliseconds
192 echo '<tr><td><small><b><font color="'.$color[7].'">'.
193 _("Execution time:")."</font></b></small></td></tr>\n".
194 '<tr><td>'.sprintf(_("%s ms"),round((($endtime - $starttime)*1000),3))."</td></tr>\n";
195 }
196
197 echo "</table></center><br />\n";
a7b90f05 198 }
199}
7431eca9 200echo '</td></tr></table></center>';
201sqimap_logout($imap_stream);
b11fe046 202
203/**
204 * Optional hook in info plugin
205 *
206 * Hook allows attaching plugin to bottom of info plugin
207 */
208do_hook('info_bottom');
a7b90f05 209?>
91e0dccc 210</body></html>