options.php 6.7 KB

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