4 * options page for IMAP info plugin
6 * This is where it all happens :)
8 * @author Jason Munro <jason at stdbev.com>
9 * @copyright © 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
17 define('SM_PATH','../../');
19 /* SquirrelMail required files. */
20 require_once(SM_PATH
. 'include/validate.php');
21 require_once(SM_PATH
. 'functions/page_header.php');
22 require_once(SM_PATH
. 'functions/imap.php');
23 require_once(SM_PATH
. 'functions/forms.php');
24 require_once(SM_PATH
. 'plugins/info/functions.php');
26 global $username, $color, $folder_prefix, $default_charset;
27 $default_charset = strtoupper($default_charset);
28 displayPageHeader($color, 'None');
32 * testing installation
34 * prevent use of plugin if it is not enabled
36 if (! is_plugin_enabled('info')) {
37 error_box(_("Plugin is disabled."),$color);
38 echo '</body></html>';
43 sqgetGlobalVar('username', $username, SQ_SESSION
);
44 sqgetGlobalVar('key', $key, SQ_COOKIE
);
45 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
47 sqgetGlobalVar('submit', $submit, SQ_POST
);
49 for($i = 0; $i <= 9; $i++
){
50 $varc = 'CHECK_TEST_'.$i;
51 sqgetGlobalVar($varc, $
$varc, SQ_POST
);
53 sqgetGlobalVar($vart, $
$vart, SQ_POST
);
58 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
59 $caps_array = get_caps($imap_stream);
60 $list = array ('TEST_0',
71 echo '<br /><div style="text-align: center;"><b>'._("IMAP server information")."</b></div><br />\n".
72 '<div style="text-align: center;"><table bgcolor="'.$color[3].'" width="100%" border="1" cellpadding="2">'.
73 '<tr><td bgcolor="'.$color[3]."\"><br />\n".
74 '<div style="text-align: center;"><table width="95%" border="1" bgcolor="'.$color[3]."\">\n".
75 '<tr><td bgcolor="'.$color[4].'"><b>'.
76 _("Server Capability response:").
79 foreach($caps_array[0] as $value) {
80 echo htmlspecialchars($value);
83 echo "</td></tr><tr><td>\n";
85 if (!isset($submit) ||
$submit == 'default') {
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";
92 if (!isset($submit)) {
97 echo 'folder_prefix = ' . htmlspecialchars($folder_prefix)."<br />\n" .
98 'default_charset = '.htmlspecialchars($default_charset)."\n";
101 echo "<br /></td></tr></table></div><br />\n";
104 if ($submit == 'submit') {
106 for ($i=0;$i<count($list);$i++
) {
107 $type[$list[$i]] = $
$list[$i];
111 elseif ($submit == 'clear') {
112 for ($i=0;$i<count($list);$i++
) {
113 $type[$list[$i]] = '';
117 elseif (!$submit ||
$submit == 'default') {
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\" \"*%\"",
127 'TEST_8' => "LIST \"$folder_prefix\" \"*\"",
131 echo "<form action=\"options.php\" method=\"post\">\n".
132 "<div style=\"text-align: center;\"><table border=\"1\">\n".
133 '<tr><th>'. _("Select").
134 '</th><th>'._("Test Name").
135 '</th><th>'._("IMAP command string")."</th></tr>\n".
138 foreach($type as $index=>$value) {
139 echo "</td></tr>\n<tr><td width=\"10%\">\n<input type=\"checkbox\" value=\"1\" name=\"CHECK_$index\"";
140 if ($index == 'TEST_0' && ($submit == 'default' ||
$submit == '')) {
141 echo ' checked="checked"';
143 $check = "CHECK_".$index;
144 if (isset($
$check) && $submit != 'clear' && $submit != 'default') {
145 echo ' checked="checked"';
147 echo " /></td><td width=\"30%\">$index</td><td width=\"60%\">\n".
148 addInput($index, $value, 60);
151 echo "</td></tr></table></div><br />\n".
152 '<div style="text-align: center;">'.
153 addSubmit('submit','submit').
154 addSubmit('clear','submit').
155 addSubmit('default','submit').
156 "</div><br /></form>\n";
160 if ($submit == 'submit') {
161 foreach ($type as $index=>$value) {
162 $check = "CHECK_".$index;
163 if (isset($
$check)) {
164 $type[$index] = $
$index;
165 array_push($tests, $index);
168 for ($i=0;$i<count($tests);$i++
) {
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;
175 echo '<div style="text-align: 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].'">'.
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].'">'.
182 _("Response:")."</font></b></small></td></tr>\n".
184 print_response($response);
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";
197 echo "</table></div><br />\n";
200 echo '</td></tr></table></div>';
201 sqimap_logout($imap_stream);
204 * Optional hook in info plugin
206 * Hook allows attaching plugin to bottom of info plugin
208 do_hook('info_bottom');