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 * Path for SquirrelMail required files.
20 require('../../include/init.php');
22 /* SquirrelMail required files. */
23 require_once(SM_PATH
. 'functions/imap_general.php');
24 require_once(SM_PATH
. 'functions/forms.php');
25 require_once(SM_PATH
. 'plugins/info/functions.php');
27 global $username, $color, $folder_prefix, $default_charset;
28 $default_charset = strtoupper($default_charset);
29 displayPageHeader($color, 'None');
33 * testing installation
35 * prevent use of plugin if it is not enabled
37 if (! is_plugin_enabled('info')) {
38 error_box(_("Plugin is disabled."),$color);
39 echo '</body></html>';
44 sqgetGlobalVar('username', $username, SQ_SESSION
);
45 sqgetGlobalVar('key', $key, SQ_COOKIE
);
46 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
48 sqgetGlobalVar('submit', $submit, SQ_POST
);
50 for($i = 0; $i <= 9; $i++
){
51 $varc = 'CHECK_TEST_'.$i;
52 sqgetGlobalVar($varc, $
$varc, SQ_POST
);
54 sqgetGlobalVar($vart, $
$vart, SQ_POST
);
59 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
60 $caps_array = get_caps($imap_stream);
61 $list = array ('TEST_0',
72 echo '<br /><div style="text-align: center;"><b>'._("IMAP server information")."</b></div><br />\n".
73 '<table bgcolor="'.$color[3].'" width="100%" align="center" border="1" cellpadding="2">'.
74 '<tr><td bgcolor="'.$color[3]."\"><br />\n".
75 '<table width="95%" align="center" border="1" bgcolor="'.$color[3]."\">\n".
76 '<tr><td bgcolor="'.$color[4].'"><b>'.
77 _("Server Capability response:").
80 foreach($caps_array[0] as $value) {
81 echo htmlspecialchars($value);
84 echo "</td></tr><tr><td>\n";
86 if (!isset($submit) ||
$submit == 'default') {
87 echo '<br /><p><small><font color="'.$color[6].'">'.
88 _("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.").
89 "</font></small></p>\n".
90 '<p align="center"><small><b>'.
91 _("NOTE: These commands are live, any changes made will effect your current email account.").
92 "</b></small></p><br />\n";
93 if (!isset($submit)) {
98 echo 'folder_prefix = ' . htmlspecialchars($folder_prefix)."<br />\n" .
99 'default_charset = '.htmlspecialchars($default_charset)."\n";
102 echo "<br /></td></tr></table><br />\n";
105 if ($submit == 'submit') {
107 for ($i=0;$i<count($list);$i++
) {
108 $type[$list[$i]] = $
$list[$i];
112 elseif ($submit == 'clear') {
113 for ($i=0;$i<count($list);$i++
) {
114 $type[$list[$i]] = '';
118 elseif (!$submit ||
$submit == 'default') {
120 'TEST_0' => "SELECT $mailbox",
121 'TEST_1' => "STATUS $mailbox (MESSAGES RECENT)",
122 'TEST_2' => "EXAMINE $mailbox",
123 'TEST_3' => "SEARCH CHARSET \"$default_charset\" ALL *",
124 'TEST_4' => "THREAD REFERENCES $default_charset ALL",
125 'TEST_5' => "SORT (DATE) $default_charset ALL",
126 'TEST_6' => "FETCH 1:* (FLAGS BODY[HEADER.FIELDS (FROM DATE TO)])",
127 'TEST_7' => "LSUB \"$folder_prefix\" \"*%\"",
128 'TEST_8' => "LIST \"$folder_prefix\" \"*\"",
132 echo "<form action=\"options.php\" method=\"post\">\n".
133 "<table border=\"1\" align=\"center\">\n".
134 '<tr><th>'. _("Select").
135 '</th><th>'._("Test Name").
136 '</th><th>'._("IMAP command string")."</th></tr>\n".
139 foreach($type as $index=>$value) {
140 echo "</td></tr>\n<tr><td width=\"10%\">\n<input type=\"checkbox\" value=\"1\" name=\"CHECK_$index\"";
141 if ($index == 'TEST_0' && ($submit == 'default' ||
$submit == '')) {
142 echo ' checked="checked"';
144 $check = "CHECK_".$index;
145 if (isset($
$check) && $submit != 'clear' && $submit != 'default') {
146 echo ' checked="checked"';
148 echo " /></td><td width=\"30%\">$index</td><td width=\"60%\">\n".
149 addInput($index, $value, 60);
152 echo "</td></tr></table><br />\n".
153 '<div style="text-align: center;">'.
154 addSubmit('submit','submit').
155 addSubmit('clear','submit',array('id'=>'clear')).
156 addSubmit('default','submit',array('id'=>'default')).
157 "</div><br /></form>\n";
161 if ($submit == 'submit') {
162 foreach ($type as $index=>$value) {
163 $check = "CHECK_".$index;
164 if (isset($
$check)) {
165 $type[$index] = $
$index;
166 array_push($tests, $index);
169 for ($i=0;$i<count($tests);$i++
) {
170 // make sure that microtime function is available before it is called
171 if (function_exists('microtime')) {
172 list($usec, $sec) = explode(" ", microtime());
173 $starttime = (float)$sec +
(float)$usec;
176 echo '<table width="95%" align="center" border="0" bgcolor="'.$color[4]."\">\n".
177 '<tr><td><b>'.$tests[$i]."</b></td></tr>\n".
178 '<tr><td><small><b><font color="'.$color[7].'">'.
179 _("Request:")."</font></b></small></td></tr>\n";
180 // imap_test function outputs imap command
181 $response = imap_test($imap_stream, $type[$tests[$i]]);
182 echo '<tr><td><small><b><font color="'.$color[7].'">'.
183 _("Response:")."</font></b></small></td></tr>\n".
185 print_response($response);
188 if (function_exists('microtime')) {
189 // get script execution time
190 list($usec, $sec) = explode(" ", microtime());
191 $endtime = (float)$sec +
(float)$usec;
192 // i18n: ms = short for miliseconds
193 echo '<tr><td><small><b><font color="'.$color[7].'">'.
194 _("Execution time:")."</font></b></small></td></tr>\n".
195 '<tr><td>'.sprintf(_("%s ms"),round((($endtime - $starttime)*1000),3))."</td></tr>\n";
198 echo "</table><br />\n";
201 echo '</td></tr></table>';
202 sqimap_logout($imap_stream);
205 * Optional hook in info plugin
207 * Hook allows attaching plugin to bottom of info plugin
209 do_hook('info_bottom');