We're living in 2004 now... perl is your friend for these kinds of things :)
[squirrelmail.git] / plugins / info / options.php
CommitLineData
a7b90f05 1<?PHP
2
ea5f4b8e 3/**
4 * options page for IMAP info plugin
82d304a0 5 * Copyright (c) 1999-2004 The SquirrelMail Project Team
a7b90f05 6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * This is where it all happens :)
9 *
10 * Written by: Jason Munro
11 * jason@stdbev.com
6a85a764 12 *
13 * $Id$
ea5f4b8e 14 * @package plugins
15 * @subpackage info
a7b90f05 16 */
8d6a115b 17
ea5f4b8e 18/** @ignore */
8d6a115b 19define('SM_PATH','../../');
a7b90f05 20
cdf82d4a 21/* SquirrelMail required files. */
22require_once(SM_PATH . 'include/validate.php');
23require_once(SM_PATH . 'functions/page_header.php');
24require_once(SM_PATH . 'functions/imap.php');
25require_once(SM_PATH . 'plugins/info/functions.php');
a7b90f05 26
27global $username, $color, $folder_prefix, $default_charset;
28$default_charset = strtoupper($default_charset);
29displayPageHeader($color, 'None');
30$mailbox = 'INBOX';
6a85a764 31
32/* GLOBALS */
b587ac51 33sqgetGlobalVar('username', $username, SQ_SESSION);
34sqgetGlobalVar('key', $key, SQ_COOKIE);
35sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
6a85a764 36
b587ac51 37sqgetGlobalVar('submit', $submit, SQ_POST);
6a85a764 38
39for($i = 0; $i <= 9; $i++){
b587ac51 40 $varc = 'CHECK_TEST_'.$i;
41 sqgetGlobalVar($varc, $$varc, SQ_POST);
42 $vart = 'TEST_'.$i;
43 sqgetGlobalVar($vart, $$vart, SQ_POST);
6a85a764 44}
45
46/* END GLOBALS */
47
a7b90f05 48$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
49$caps_array = get_caps($imap_stream);
50$list = array (
51 'TEST_0',
52 'TEST_1',
53 'TEST_2',
54 'TEST_3',
55 'TEST_4',
56 'TEST_5',
57 'TEST_6',
58 'TEST_7',
59 'TEST_8',
60 'TEST_9');
61
62print "<BR><CENTER><B>IMAP server information</B></CENTER><BR>\n";
63print "<CENTER><TABLE BGCOLOR=".$color[3]." WIDTH=\"100%\" BORDER=1 CELLPADDING=2><TR><TD BGCOLOR=".$color[3]."><BR>\n";
64print "<CENTER><TABLE WIDTH=\"95%\" BORDER=1 BGCOLOR=".$color[3].">\n";
65print "<TR><TD BGCOLOR=".$color[4]."><B>Server Capability response:</B><BR>\n";
66
67foreach($caps_array[0] as $value) {
68 print $value;
69}
70
71print "</TD></TR><TR><TD>\n";
72
73if (!isset($submit) || $submit == 'default') {
74 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";
75 if (!isset($submit)) {
76 $submit = '';
77 }
78}
79else {
80 print "folder_prefix = $folder_prefix<BR>\n";
81 print "default_charset = $default_charset\n";
82}
83
84print "<BR></TD></TR></TABLE></CENTER><BR>\n";
85
86
87if ($submit == 'submit') {
88 $type = array();
89 for ($i=0;$i<count($list);$i++) {
90 $type[$list[$i]] = $$list[$i];
91 }
92}
93
94elseif ($submit == 'clear') {
95 for ($i=0;$i<count($list);$i++) {
96 $type[$list[$i]] = '';
97 }
98}
99
100elseif (!$submit || $submit == 'default') {
101 $type = array (
102 'TEST_0' => "SELECT $mailbox",
103 'TEST_1' => "STATUS $mailbox (MESSAGES RECENT)",
104 'TEST_2' => "EXAMINE $mailbox",
105 'TEST_3' => "SEARCH CHARSET \"$default_charset\" ALL *",
106 'TEST_4' => "THREAD REFERENCES $default_charset ALL",
107 'TEST_5' => "SORT (DATE) $default_charset ALL",
108 'TEST_6' => "FETCH 1:* (FLAGS BODY[HEADER.FIELDS (FROM DATE TO)])",
109 'TEST_7' => "LSUB \"$folder_prefix\" \"*%\"",
110 'TEST_8' => "LIST \"$folder_prefix*\" \"*\"",
111 'TEST_9' => "");
112}
113
114print "<FORM ACTION=\"options.php\" METHOD=POST>\n";
115print "<CENTER><TABLE BORDER=1>\n";
116print "<TR><TH>Select</TH><TH>Test Name</TH><TH>IMAP command string</TH>\n";
117print "</TR><TR><TD>\n";
118
119foreach($type as $index=>$value) {
120 print "</TD></TR><TR><TD WIDTH=\"10%\"><INPUT TYPE=CHECKBOX VALUE=1 NAME=CHECK_$index";
121 if ($index == 'TEST_0' && ($submit == 'default' || $submit == '')) {
122 print " CHECKED";
123 }
124 $check = "CHECK_".$index;
125 if (isset($$check) && $submit != 'clear' && $submit != 'default') {
126 print " CHECKED";
127 }
128 print "></TD><TD WIDTH=\"30%\">$index</TD><TD WIDTH=\"60%\">\n";
129 print "<INPUT TYPE=TEXT NAME=$index VALUE='$value' SIZE=60>\n";
130}
131
132print "</TD></TR></TABLE></CENTER><BR>\n";
133print "<CENTER><INPUT TYPE=SUBMIT NAME=submit value=submit>\n";
134print "<INPUT TYPE=SUBMIT NAME=submit value=clear>\n";
135print "<INPUT TYPE=SUBMIT NAME=submit value=default></CENTER><BR>\n";
136
137$tests = array();
138
139if ($submit == 'submit') {
140 foreach ($type as $index=>$value) {
141 $check = "CHECK_".$index;
142 if (isset($$check)) {
143 $type[$index] = $$index;
144 array_push($tests, $index);
145 }
146 }
147 for ($i=0;$i<count($tests);$i++) {
148 print "<CENTER><TABLE WIDTH=\"95%\" BORDER=0 BGCOLOR=".$color[4].">\n";
149 print "<TR><TD><B>".$tests[$i]."</B></TD><TR>";
150 print "<TR><TD><SMALL><B><FONT COLOR=".$color[7].
151 ">Request:</FONT></SMALL></B></TD></TR>\n";
152 $response = imap_test($imap_stream, $type[$tests[$i]]);
153 print "<TR><TD><SMALL><B><FONT COLOR=".$color[7].
154 ">Response:</FONT></SMALL></B></TD></TR>\n";
155 print "<TR><TD>";
156 print_response($response);
157 print "</TD><TR></TABLE></CENTER><BR>\n";
158 }
159}
dcc1cc82 160 print "</TD></TR></TABLE></CENTER></BODY></HTML>";
a7b90f05 161 sqimap_logout($imap_stream);
162 do_hook('info_bottom');
163?>