1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Test extends Horde_Test
24: {
25: 26:
27: protected $_moduleList = array(
28: 'openssl' => array(
29: 'descrip' => 'OpenSSL Support',
30: 'error' => 'The OpenSSL extension is required for S/MIME support and to securely connect to the remote IMAP/POP3 server.'
31: )
32: );
33:
34: 35:
36: protected $_settingsList = array(
37: 'file_uploads' => array(
38: 'error' => 'file_uploads must be enabled to use various features of IMP. See the INSTALL file for more information.',
39: 'setting' => true
40: )
41: );
42:
43: 44:
45: protected $_pearList = array();
46:
47: 48:
49: protected $_appList = array(
50: 'ingo' => array(
51: 'error' => 'Ingo provides mail filtering capabilities to IMP.',
52: 'version' => '3.0'
53: ),
54: 'kronolith' => array(
55: 'error' => 'Kronolith provides calendaring capabilities to IMP.',
56: 'version' => '4.0'
57: ),
58: 'nag' => array(
59: 'error' => 'Nag allows tasks to be directly created from e-mail data.',
60: 'version' => '4.0'
61: ),
62: 'turba' => array(
63: 'error' => 'Turba provides addressbook/contacts capabilities to IMP.',
64: 'version' => '4.0'
65: )
66: );
67:
68: 69:
70: public function __construct()
71: {
72: parent::__construct();
73:
74: $this->_fileList += array(
75: 'config/backends.php' => null,
76: 'config/mime_drivers.php' => null,
77: 'config/prefs.php' => null
78: );
79: }
80:
81: 82:
83: public function appTests()
84: {
85: $ret = '<h1>Mail Server Support Test</h1>';
86:
87: $vars = Horde_Variables::getDefaultVariables();
88: if ($vars->user && $vars->passwd) {
89: $ret .= $this->_doConnectionTest($vars);
90: }
91:
92: $self_url = Horde::selfUrl()->add('app', 'imp');
93:
94: Horde::startBuffer();
95: require IMP_TEMPLATES . '/test/mailserver.inc';
96:
97: return $ret . Horde::endBuffer();
98: }
99:
100: 101: 102: 103: 104: 105: 106:
107: protected function _doConnectionTest($vars)
108: {
109: $imap_config = array(
110: 'username' => $vars->user,
111: 'password' => $vars->passwd,
112: 'hostspec' => $vars->server,
113: 'port' => $vars->port,
114: 'secure' => $vars->encrypt ? 'tls' : false
115: );
116:
117: $driver = ($vars->server_type == 'imap')
118: ? 'Horde_Imap_Client_Socket'
119: : 'Horde_Imap_Client_Socket_Pop3';
120:
121: try {
122: $imap_client = new $driver($imap_config);
123: } catch (Horde_Imap_Client_Exception $e) {
124: return $this->_errorMsg($e);
125: }
126:
127: $ret = '<strong>Attempting to login to the server:</strong> ';
128:
129: try {
130: try {
131: $imap_client->login();
132: } catch (Horde_Imap_Client_Exception $e) {
133: if ($vars->encrypt) {
134: $imap_client->setParam('secure', 'ssl');
135: $imap_client->login();
136: } else {
137: throw $e;
138: }
139: }
140: } catch (Horde_Imap_Client_Exception $e) {
141: return $this->_errorMsg($e);
142: }
143:
144: $ret .= '<span style="color:green">SUCCESS</span><p />'.
145: '<strong>Secure connection:</strong> <tt>' .
146: (($tmp = $imap_client->getParam('secure')) ? $tmp : 'none') .
147: '</tt><p />';
148:
149: if ($driver == 'Horde_Imap_Client_Socket') {
150: $ret .= '<strong>The following IMAP server information was discovered from the server:</strong>' .
151: '<blockquote><em>Namespace Information</em><blockquote><pre>';
152:
153: try {
154: $namespaces = $imap_client->getNamespaces(
155: array(),
156: array('ob_return' => true)
157: );
158: foreach ($namespaces as $val) {
159: switch ($val->type) {
160: case $val::NS_PERSONAL:
161: $type = 'Personal';
162: break;
163:
164: case $val::NS_OTHER:
165: $type = 'Other Users\'';
166: break;
167:
168: case $val::NS_SHARED:
169: $type = 'Shared';
170: break;
171: }
172:
173: $ret .= 'NAMESPACE: "' . htmlspecialchars($val->name) . "\"\n" .
174: 'DELIMITER: ' . htmlspecialchars($val->delimiter) . "\n" .
175: 'TYPE: ' . htmlspecialchars($type) . "\n\n";
176: }
177: } catch (Horde_Imap_Client_Exception $e) {
178: $this->_errorMsg($e);
179: }
180:
181: $ret .= '</pre></blockquote></blockquote>' .
182: '<blockquote><em>IMAP server capabilities:</em><blockquote><pre>';
183:
184: try {
185: foreach ($imap_client->capability() as $key => $val) {
186: if (is_array($val)) {
187: foreach ($val as $val2) {
188: $ret .= htmlspecialchars($key) . '=' . htmlspecialchars($val2) . "\n";
189: }
190: } else {
191: $ret .= htmlspecialchars($key) . "\n";
192: }
193: }
194: } catch (Horde_Imap_Client_Exception $e) {
195: $this->_errorMsg($e);
196: }
197:
198: $ret .= '</pre></blockquote></blockquote>' .
199: '<blockquote><em>Does IMAP server support UTF-8 in search queries?</em> ';
200:
201: if ($imap_client->validSearchCharset('UTF-8')) {
202: $ret .= '<span style="color:green">YES</span>';
203: } else {
204: $ret .= '<span style="color:red">NO</span>';
205: }
206:
207: $ret .= '</blockquote>';
208:
209: try {
210: $id_info = $imap_client->getID();
211: if (!empty($id_info)) {
212: $ret .= '<blockquote><em>IMAP server information:</em><blockquote><pre>';
213: foreach ($id_info as $key => $val) {
214: $ret .= htmlspecialchars("$key: $val") . "\n";
215: }
216: $ret .= '</pre></blockquote></blockquote>';
217: }
218: } catch (Horde_Imap_Client_Exception $e) {
219:
220: }
221: } else {
222: $ret .= '<strong>Checking for the UIDL capability:</strong> ';
223:
224: if ($imap_client->queryCapability('UIDL')) {
225: $ret .= '<span style="color:green">SUCCESS</span><p />';
226: } else {
227: return $this->_errorMsg(new Exception('The POP3 server does not support the *REQUIRED* UIDL capability.'));
228: }
229: }
230:
231: return $ret;
232: }
233:
234: 235: 236: 237: 238:
239: protected function _errorMsg($e)
240: {
241: return '<span style="color:red">ERROR</span> - The server returned the following error message:' .
242: '<pre>' . $e->getMessage() . '</pre><p />';
243: }
244:
245: }
246: