Added IMAP server information plugin called 'info'. See the README for details :)
authorjmunro <jmunro@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 17 May 2002 14:27:42 +0000 (14:27 +0000)
committerjmunro <jmunro@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 17 May 2002 14:27:42 +0000 (14:27 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2846 7612ce4b-ef26-0410-bec9-ea0150e637f0

plugins/info/README [new file with mode: 0644]
plugins/info/functions.php [new file with mode: 0644]
plugins/info/options.php [new file with mode: 0644]
plugins/info/setup.php [new file with mode: 0644]

diff --git a/plugins/info/README b/plugins/info/README
new file mode 100644 (file)
index 0000000..812d0bf
--- /dev/null
@@ -0,0 +1,41 @@
+README for the info plugin for Squirrelmail
+
+  This plugin is designed to aid a system admin
+or Squirrelmail developer troubleshoot IMAP commands
+and responses.
+
+IMPORTANT NOTE:
+
+*****************************************************
+* THIS PLUGIN IS NOT MEANT FOR END USERS. IT ALLOWS *
+* UNVALIDATED DATA TO BE PASSED TO THE IMAP SERVER. *
+* IT IS BY NO MEANS SECURE AND SHOULD ONLY BE USED  *
+* FOR TESTING, TROUBLESHOOTING AND DEVELOPMENT.     *
+*****************************************************
+
+You have been warned :) 
+
+Ok, now to the good stuff. Enable this plugin as you would any other.
+Its called 'info'. You will then have an "IMAP server information"  section
+on your options page. This will take you to an IMAP command workshop
+where you can select pre-made commands, send them to the IMAP server
+and see the response. All selected commands will be run one at a time
+starting with the first selected command and working down.
+
+Commands can be modified however you like, but remember, you are
+performing these commands on the account you are logged into, so
+any command that changes the contents of  your mailbox will ..er..
+change the contents of your mailbox :)
+
+Changes and custom commands are maintained as long as you are on 
+the IMAP server options page (even after submitting tests). 
+Once you leave this page and return then the commmands are reset
+to the defaults. You can manually reset the commands using the 
+'default' button, or clear the contents of all the commands with 
+the 'clear' button.
+
+Questions, problems, comments welcome at
+
+jason@stdbev.com
+Jason Munro
+
diff --git a/plugins/info/functions.php b/plugins/info/functions.php
new file mode 100644 (file)
index 0000000..92f666d
--- /dev/null
@@ -0,0 +1,50 @@
+<?PHP
+
+/* functions for info plugin
+ * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * Here are two functions for the info plugin
+ * The first gets the CAPABILITY response from your IMAP server.
+ * The second runs the passed IMAP test and returns the results 
+ * The third prints the results of the IMAP command
+ * to options.php.
+ * by: Jason Munro jason@stdbev.com
+ */
+
+function get_caps($imap_stream) {
+    $sid = sqimap_session_id();
+    $query = "$sid CAPABILITY\r\n";
+    fputs ($imap_stream, $query);
+    $responses = sqimap_read_data_list($imap_stream, $sid, true, $responses, $message);
+    return $responses;
+}
+
+function imap_test($imap_stream, $string) {
+    global $default_charset;
+    $message = '';
+    $responses = array ();
+    $sid = sqimap_session_id();
+    $results = array();
+    $query = "$sid ".trim($string)."\r\n";
+    print "<TR><TD>".$query."</TD></TR>";
+    fputs ($imap_stream, $query);
+    $response = sqimap_read_data_list($imap_stream, $sid, false, $responses, $message);
+    array_push($response, $message);
+    return $response;
+}
+
+function print_response($response) {
+    foreach($response as $index=>$value) {
+        if (is_array($value)) {
+            print_response($value);
+        }
+        else {
+            $value = preg_replace("/</", "&lt;", $value);
+            $value = preg_replace("/>/", "&gt;", $value);
+            print $value."<BR>\n";
+        }
+    }
+}
+                                                                                        
+?>
diff --git a/plugins/info/options.php b/plugins/info/options.php
new file mode 100644 (file)
index 0000000..0578ffc
--- /dev/null
@@ -0,0 +1,138 @@
+<?PHP
+
+/* options page for IMAP info plugin 
+ * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *   
+ * This is where it all happens :)
+ *
+ * Written by: Jason Munro 
+ * jason@stdbev.com
+ */
+
+chdir ('..');
+  require_once('../src/validate.php');
+  require_once('../functions/page_header.php');
+  require_once('../functions/imap.php');
+  require_once('../plugins/info/functions.php');
+
+global $username, $color, $folder_prefix, $default_charset;
+$default_charset = strtoupper($default_charset);
+displayPageHeader($color, 'None');
+$mailbox = 'INBOX';
+$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
+$caps_array = get_caps($imap_stream);
+$list = array (
+               'TEST_0',
+               'TEST_1',
+               'TEST_2',
+               'TEST_3',
+               'TEST_4',
+               'TEST_5',
+               'TEST_6',
+               'TEST_7',
+               'TEST_8',
+               'TEST_9');
+
+print "<BR><CENTER><B>IMAP server information</B></CENTER><BR>\n";
+print "<CENTER><TABLE BGCOLOR=".$color[3]." WIDTH=\"100%\" BORDER=1 CELLPADDING=2><TR><TD BGCOLOR=".$color[3]."><BR>\n";
+print "<CENTER><TABLE WIDTH=\"95%\" BORDER=1 BGCOLOR=".$color[3].">\n";
+print "<TR><TD BGCOLOR=".$color[4]."><B>Server Capability response:</B><BR>\n";
+
+foreach($caps_array[0] as $value) {
+    print $value;
+}
+
+print "</TD></TR><TR><TD>\n";
+
+if (!isset($submit) || $submit == 'default') {
+    print "<BR><SMALL><FONT COLOR=".$color[6].">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.<BR><BR><B><CENTER>NOTE: These commands are live, any changes made will effect your current email account.</B></CENTER></FONT></SMALL><BR>\n";
+    if (!isset($submit)) {
+        $submit = '';
+    }
+}
+else {
+    print "folder_prefix = $folder_prefix<BR>\n";
+    print "default_charset = $default_charset\n";
+}
+
+print "<BR></TD></TR></TABLE></CENTER><BR>\n";
+
+
+if ($submit == 'submit') {
+    $type = array();
+    for ($i=0;$i<count($list);$i++) {
+        $type[$list[$i]] = $$list[$i];
+    }
+}
+
+elseif ($submit == 'clear') {
+    for ($i=0;$i<count($list);$i++) {
+        $type[$list[$i]] = '';
+    }
+}
+
+elseif (!$submit || $submit == 'default')  {
+    $type = array (
+        'TEST_0' => "SELECT $mailbox",
+        'TEST_1' => "STATUS $mailbox (MESSAGES RECENT)",
+        'TEST_2' => "EXAMINE $mailbox",
+        'TEST_3' => "SEARCH CHARSET \"$default_charset\" ALL *",
+        'TEST_4' => "THREAD REFERENCES $default_charset ALL",
+        'TEST_5' => "SORT (DATE) $default_charset ALL",
+        'TEST_6' => "FETCH 1:* (FLAGS BODY[HEADER.FIELDS (FROM DATE TO)])",
+        'TEST_7' => "LSUB \"$folder_prefix\" \"*%\"",
+        'TEST_8' => "LIST \"$folder_prefix*\" \"*\"",
+        'TEST_9' => "");
+}
+
+print "<FORM ACTION=\"options.php\" METHOD=POST>\n";
+print "<CENTER><TABLE BORDER=1>\n";
+print "<TR><TH>Select</TH><TH>Test Name</TH><TH>IMAP command string</TH>\n";
+print "</TR><TR><TD>\n";
+
+foreach($type as $index=>$value) {
+    print "</TD></TR><TR><TD WIDTH=\"10%\"><INPUT TYPE=CHECKBOX VALUE=1 NAME=CHECK_$index";
+    if ($index == 'TEST_0' && ($submit == 'default' || $submit == '')) {
+        print " CHECKED";
+    }
+    $check = "CHECK_".$index;
+    if (isset($$check) && $submit != 'clear' && $submit != 'default') {
+        print " CHECKED";
+    }
+    print "></TD><TD WIDTH=\"30%\">$index</TD><TD WIDTH=\"60%\">\n";
+    print "<INPUT TYPE=TEXT NAME=$index VALUE='$value' SIZE=60>\n"; 
+}
+
+print "</TD></TR></TABLE></CENTER><BR>\n";
+print "<CENTER><INPUT TYPE=SUBMIT NAME=submit value=submit>\n";
+print "<INPUT TYPE=SUBMIT NAME=submit value=clear>\n";
+print "<INPUT TYPE=SUBMIT NAME=submit value=default></CENTER><BR>\n";
+
+$tests = array();
+
+if ($submit == 'submit') {
+    foreach ($type as $index=>$value) {
+        $check = "CHECK_".$index;
+        if (isset($$check)) {
+            $type[$index] = $$index;
+            array_push($tests, $index); 
+        }
+    }
+    for ($i=0;$i<count($tests);$i++) {
+        print "<CENTER><TABLE WIDTH=\"95%\" BORDER=0 BGCOLOR=".$color[4].">\n";
+        print "<TR><TD><B>".$tests[$i]."</B></TD><TR>";
+        print "<TR><TD><SMALL><B><FONT COLOR=".$color[7].
+              ">Request:</FONT></SMALL></B></TD></TR>\n";
+        $response = imap_test($imap_stream, $type[$tests[$i]]);
+        print "<TR><TD><SMALL><B><FONT COLOR=".$color[7].
+              ">Response:</FONT></SMALL></B></TD></TR>\n";
+        print "<TR><TD>";
+        print_response($response);
+        print "</TD><TR></TABLE></CENTER><BR>\n";
+    }
+}
+    print "</TD></TR></TABLE></CENTER></BODY></HTML>";
+    sqimap_logout($imap_stream);
+    do_hook('info_bottom');
+?>
diff --git a/plugins/info/setup.php b/plugins/info/setup.php
new file mode 100644 (file)
index 0000000..6973aaa
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+/* setup file for the IMAP server info plugin
+ * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *   
+ * by: Jason Munro jason@stdbev.com
+ *
+ */
+
+require_once ('../plugins/info/functions.php');
+
+function squirrelmail_plugin_init_info() {
+    global $squirrelmail_plugin_hooks;
+    $squirrelmail_plugin_hooks['optpage_register_block']['info'] = 'info_opt';
+}
+
+function info_opt() {
+    global $optpage_blocks;
+
+    $optpage_blocks[] = array(
+        'name' => _("IMAP server information"),
+        'url'  => '../plugins/info/options.php',
+        'desc' => _("Run some test IMAP commands, displaying both the command and the result. These tests use the Squirrelmail IMAP commands and your current Squirrelmail configuration. Custom command strings can be used."),
+        'js'   => false
+    );
+}
+
+?>