Ok, I screwed up. When I put in cram-md5 and digest-md5, I left the alternative...
[squirrelmail.git] / functions / imap_general.php
CommitLineData
59177427 1<?php
bccadd02 2
35586184 3/**
a6fd80f5 4 * imap_general.php
35586184 5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
15e6162e 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
35586184 8 *
15e6162e 9 * This implements all functions that do general imap functions.
35586184 10 *
15e6162e 11 * $Id$
35586184 12 */
13
b68edc75 14require_once(SM_PATH . 'functions/page_header.php');
47a29326 15require_once(SM_PATH . 'functions/auth.php');
16
35586184 17
41600f7d 18global $sqimap_session_id;
19$sqimap_session_id = 1;
71257f8b 20
3411d4ec 21/* Sets an unique session id in order to avoid simultanous sessions crash. */
487daa81 22function sqimap_session_id($unique_id = false) {
41600f7d 23 global $data_dir, $username, $sqimap_session_id;
487daa81 24 if (!$unique_id) {
25 return( sprintf("A%03d", $sqimap_session_id++) );
26 } else {
27 return( sprintf("A%03d", $sqimap_session_id++) . ' UID' );
28 }
9c737111 29}
30
3411d4ec 31/*
32 * Both send a command and accept the result from the command.
33 * This is to allow proper session number handling.
34 */
487daa81 35function sqimap_run_command_list ($imap_stream, $query, $handle_errors, &$response, &$message, $unique_id = false) {
c5809184 36 if ($imap_stream) {
37 $sid = sqimap_session_id($unique_id);
38 fputs ($imap_stream, $sid . ' ' . $query . "\r\n");
39 $read = sqimap_read_data_list ($imap_stream, $sid, $handle_errors, $response, $message, $query );
40 return $read;
41 } else {
42 global $squirrelmail_language, $color;
43 set_up_language($squirrelmail_language);
44 require_once(SM_PATH . 'functions/display_messages.php');
45 $string = "<b><font color=$color[2]>\n" .
46 _("ERROR : No available imapstream.") .
47 "</b></font>\n";
48 error_box($string,$color);
49 return false;
50 }
51
1c72b151 52}
53
487daa81 54function sqimap_run_command ($imap_stream, $query, $handle_errors, &$response, &$message, $unique_id = false) {
c5809184 55 if ($imap_stream) {
56 $sid = sqimap_session_id($unique_id);
57 fputs ($imap_stream, $sid . ' ' . $query . "\r\n");
58 $read = sqimap_read_data ($imap_stream, $sid, $handle_errors, $response, $message, $query);
59 return $read;
60 } else {
61 global $squirrelmail_language, $color;
62 set_up_language($squirrelmail_language);
63 require_once(SM_PATH . 'functions/display_messages.php');
64 $string = "<b><font color=$color[2]>\n" .
65 _("ERROR : No available imapstream.") .
66 "</b></font>\n";
67 error_box($string,$color);
68 return false;
69 }
70
42a07ac1 71}
72
9c737111 73
b8c285ab 74/*
75 * custom fgets function. gets a line from IMAP
76 * no matter how big it may be
77 */
78
79function sqimap_fgets($imap_stream) {
80 $read = '';
81 $buffer = 4096;
82 $results = '';
83 while (strpos($read, "\n") === false) {
84 if (!($read = fgets($imap_stream, $buffer))) {
85 break;
86 }
87 $results .= $read;
88 }
89 return $results;
90}
91
bee165ef 92/*
3411d4ec 93 * Reads the output from the IMAP stream. If handle_errors is set to true,
94 * this will also handle all errors that are received. If it is not set,
95 * the errors will be sent back through $response and $message
bee165ef 96 */
b8c285ab 97
3411d4ec 98function sqimap_read_data_list ($imap_stream, $pre, $handle_errors, &$response, &$message, $query = '') {
9c737111 99 global $color, $squirrelmail_language;
9c737111 100 $read = '';
487daa81 101 $pre_a = explode(' ',trim($pre));
102 $pre = $pre_a[0];
b8c285ab 103 $resultlist = array();
104 $data = array();
105 $read = sqimap_fgets($imap_stream);
106 while (1) {
107 switch (true) {
108 case preg_match("/^$pre (OK|BAD|NO)(.*)$/", $read, $regs):
109 case preg_match('/^\* (BYE \[ALERT\])(.*)$/', $read, $regs):
110 $response = $regs[1];
111 $message = trim($regs[2]);
112 break 2;
113 case preg_match("/^\* (OK \[PARSE\])(.*)$/", $read):
114 $read = sqimap_fgets($imap_stream);
115 break 1;
56afb33f 116 case preg_match('/^\* ([0-9]+) FETCH.*/', $read, $regs):
b8c285ab 117 $fetch_data = array();
118 $fetch_data[] = $read;
119 $read = sqimap_fgets($imap_stream);
863936bb 120 while (!preg_match('/^\* [0-9]+ FETCH.*/', $read) &&
b8c285ab 121 !preg_match("/^$pre (OK|BAD|NO)(.*)$/", $read)) {
122 $fetch_data[] = $read;
863936bb 123 $last = $read;
b8c285ab 124 $read = sqimap_fgets($imap_stream);
9c737111 125 }
863936bb 126 if (isset($last) && preg_match('/^\)/', $last)) {
127 array_pop($fetch_data);
128 }
b8c285ab 129 $resultlist[] = $fetch_data;
130 break 1;
131 default:
132 $data[] = $read;
133 $read = sqimap_fgets($imap_stream);
134 break 1;
9c737111 135 }
b8c285ab 136 }
137 if (!empty($data)) {
9c737111 138 $resultlist[] = $data;
139 }
b8c285ab 140 elseif (empty($resultlist)) {
141 $resultlist[] = array();
142 }
bee165ef 143 if ($handle_errors == false) {
144 return( $resultlist );
b8c285ab 145 }
146 elseif ($response == 'NO') {
147 /* ignore this error from M$ exchange, it is not fatal (aka bug) */
9c737111 148 if (strstr($message, 'command resulted in') === false) {
441f2d33 149 set_up_language($squirrelmail_language);
1f720b34 150 require_once(SM_PATH . 'functions/display_messages.php');
151 $string = "<b><font color=$color[2]>\n" .
b8c285ab 152 _("ERROR : Could not complete request.") .
153 "</b><br>\n" .
9b761dbd 154 _("Query:") . ' ' .
155 htmlspecialchars($query) . '<br>' .
b8c285ab 156 _("Reason Given: ") .
9b761dbd 157 htmlspecialchars($message) . "</font><br>\n";
1f720b34 158 error_box($string,$color);
052e0c26 159 exit;
9c737111 160 }
b8c285ab 161 }
162 elseif ($response == 'BAD') {
9c737111 163 set_up_language($squirrelmail_language);
1f720b34 164 require_once(SM_PATH . 'functions/display_messages.php');
bef6629c 165 $string = "<b><font color=$color[2]>\n" .
b8c285ab 166 _("ERROR : Bad or malformed request.") .
167 "</b><br>\n" .
9b761dbd 168 _("Query:") . ' '.
169 htmlspecialchars($query) . '<br>' .
b8c285ab 170 _("Server responded: ") .
9b761dbd 171 htmlspecialchars($message) . "</font><br>\n";
1f720b34 172 error_box($string,$color);
9c737111 173 exit;
b8c285ab 174 }
175 else {
3411d4ec 176 return $resultlist;
9c737111 177 }
9c737111 178}
179
b3837b0f 180function sqimap_read_data ($imap_stream, $pre, $handle_errors, &$response, &$message, $query = '') {
863936bb 181 $res = sqimap_read_data_list($imap_stream, $pre, $handle_errors, $response, $message, $query);
182
183 /* sqimap_read_data should be called for one response
184 but since it just calls sqimap_read_data_list which
185 handles multiple responses we need to check for that
186 and merge the $res array IF they are seperated and
187 IF it was a FETCH response. */
188
189 if (isset($res[1]) && is_array($res[1]) && isset($res[1][0])
190 && preg_match('/^\* \d+ FETCH/', $res[1][0])) {
191 $result = array();
192 foreach($res as $index=>$value) {
193 $result = array_merge($result, $res["$index"]);
56afb33f 194 }
195 }
863936bb 196 if (isset($result)) {
197 return $result;
56afb33f 198 }
56afb33f 199 else {
863936bb 200 return $res[0];
56afb33f 201 }
202
9c737111 203}
204
3411d4ec 205/*
206 * Logs the user into the imap server. If $hide is set, no error messages
207 * will be displayed. This function returns the imap connection handle.
208 */
9c737111 209function sqimap_login ($username, $password, $imap_server_address, $imap_port, $hide) {
47a29326 210 global $color, $squirrelmail_language, $onetimepad, $use_imap_tls, $imap_auth_mech;
85fc999e 211
bd9829d7 212 $imap_server_address = sqimap_get_user_server($imap_server_address, $username);
47a29326 213 $host=$imap_server_address;
214
215 if (($use_imap_tls == true) and (check_php_version(4,3)) and (extension_loaded('openssl'))) {
216 /* Use TLS by prefixing "tls://" to the hostname */
217 $imap_server_address = 'tls://' . $imap_server_address;
218 }
219
3411d4ec 220 $imap_stream = fsockopen ( $imap_server_address, $imap_port, $error_number, $error_string, 15);
85fc999e 221
3411d4ec 222 /* Do some error correction */
9c737111 223 if (!$imap_stream) {
224 if (!$hide) {
441f2d33 225 set_up_language($squirrelmail_language, true);
1f720b34 226 require_once(SM_PATH . 'functions/display_messages.php');
227 $string = sprintf (_("Error connecting to IMAP server: %s.") .
228 "<br>\r\n", $imap_server_address) .
229 "$error_number : $error_string<br>\r\n";
2f1f7a12 230 logout_error($string,$color);
9c737111 231 }
232 exit;
233 }
052e0c26 234
2f1f7a12 235 $server_info = fgets ($imap_stream, 1024);
236
237 /* Decrypt the password */
238 $password = OneTimePadDecrypt($password, $onetimepad);
239
639c7164 240 if (($imap_auth_mech == 'cram-md5') OR ($imap_auth_mech == 'digest-md5')) {
fe0b18b3 241 // We're using some sort of authentication OTHER than plain or login
47a29326 242 $tag=sqimap_session_id(false);
243 if ($imap_auth_mech == 'digest-md5') {
244 $query = $tag . " AUTHENTICATE DIGEST-MD5\r\n";
245 } elseif ($imap_auth_mech == 'cram-md5') {
246 $query = $tag . " AUTHENTICATE CRAM-MD5\r\n";
247 }
248 fputs($imap_stream,$query);
249 $answer=sqimap_fgets($imap_stream);
250 // Trim the "+ " off the front
251 $response=explode(" ",$answer,3);
252 if ($response[0] == '+') {
253 // Got a challenge back
254 $challenge=$response[1];
255 if ($imap_auth_mech == 'digest-md5') {
256 $reply = digest_md5_response($username,$password,$challenge,'imap',$host);
257 } elseif ($imap_auth_mech == 'cram-md5') {
258 $reply = cram_md5_response($username,$password,$challenge);
259 }
260 fputs($imap_stream,$reply);
261 $read=sqimap_fgets($imap_stream);
262 if ($imap_auth_mech == 'digest-md5') {
263 // DIGEST-MD5 has an extra step..
264 if (substr($read,0,1) == '+') { // OK so far..
265 fputs($imap_stream,"\r\n");
266 $read=sqimap_fgets($imap_stream);
267 }
268 }
269 $results=explode(" ",$read,3);
270 $response=$results[1];
271 $message=$results[2];
272 } else {
273 // Fake the response, so the error trap at the bottom will work
274 $response="BAD";
275 $message='IMAP server does not appear to support the authentication method selected.';
276 $message .= ' Please contact your system administrator.';
277 }
fe0b18b3 278 } elseif ($imap_auth_mech == 'login') {
279 // Original IMAP login code
47a29326 280 $query = 'LOGIN "' . quoteIMAP($username) . '" "' . quoteIMAP($password) . '"';
281 $read = sqimap_run_command ($imap_stream, $query, false, $response, $message);
fe0b18b3 282 } else {
283 // Insert SASL PLAIN code here, if it ever gets implemented
284 }
47a29326 285
286 /* If the connection was not successful, lets see why */
9c737111 287 if ($response != 'OK') {
288 if (!$hide) {
74424a43 289 if ($response != 'NO') {
3411d4ec 290 /* "BAD" and anything else gets reported here. */
9b761dbd 291 $message = htmlspecialchars($message);
9c737111 292 set_up_language($squirrelmail_language, true);
1f720b34 293 require_once(SM_PATH . 'functions/display_messages.php');
9c737111 294 if ($response == 'BAD') {
1f720b34 295 $string = sprintf (_("Bad request: %s")."<br>\r\n", $message);
9c737111 296 } else {
1f720b34 297 $string = sprintf (_("Unknown error: %s") . "<br>\n", $message);
9c737111 298 }
1f720b34 299 $string .= '<br>' . _("Read data:") . "<br>\n";
9c737111 300 if (is_array($read)) {
301 foreach ($read as $line) {
1f720b34 302 $string .= htmlspecialchars($line) . "<br>\n";
9c737111 303 }
304 }
1f720b34 305 error_box($string,$color);
9c737111 306 exit;
165e24a7 307 } else {
3411d4ec 308 /*
309 * If the user does not log in with the correct
1c72b151 310 * username and password it is not possible to get the
311 * correct locale from the user's preferences.
312 * Therefore, apply the same hack as on the login
313 * screen.
3411d4ec 314 *
315 * $squirrelmail_language is set by a cookie when
1c72b151 316 * the user selects language and logs out
bee165ef 317 */
9be8198d 318
9c737111 319 set_up_language($squirrelmail_language, true);
bd9c880b 320 include_once(SM_PATH . 'functions/display_messages.php' );
69146537 321 sqsession_destroy();
bd9c880b 322 logout_error( _("Unknown user or password incorrect.") );
9c737111 323 exit;
052e0c26 324 }
9c737111 325 } else {
052e0c26 326 exit;
9c737111 327 }
328 }
9c737111 329 return $imap_stream;
330}
f1e6f580 331
3411d4ec 332/* Simply logs out the IMAP session */
9c737111 333function sqimap_logout ($imap_stream) {
8d936b0c 334 /* Logout is not valid until the server returns 'BYE'
335 * If we don't have an imap_ stream we're already logged out */
26a2cc8b 336 if(isset($imap_stream) && $imap_stream)
8d936b0c 337 sqimap_run_command($imap_stream, 'LOGOUT', false, $response, $message);
9c737111 338}
339
487daa81 340function sqimap_capability($imap_stream, $capability='') {
9c737111 341 global $sqimap_capabilities;
9c737111 342 if (!is_array($sqimap_capabilities)) {
1c72b151 343 $read = sqimap_run_command($imap_stream, 'CAPABILITY', true, $a, $b);
344
9c737111 345 $c = explode(' ', $read[0]);
346 for ($i=2; $i < count($c); $i++) {
347 $cap_list = explode('=', $c[$i]);
3411d4ec 348 if (isset($cap_list[1])) {
9c737111 349 $sqimap_capabilities[$cap_list[0]] = $cap_list[1];
3411d4ec 350 } else {
9c737111 351 $sqimap_capabilities[$cap_list[0]] = TRUE;
3411d4ec 352 }
f1e6f580 353 }
9c737111 354 }
487daa81 355 if ($capability) {
356 if (isset($sqimap_capabilities[$capability])) {
357 return $sqimap_capabilities[$capability];
358 } else {
359 return false;
360 }
f1e6f580 361 }
487daa81 362 return $sqimap_capabilities;
9c737111 363}
364
3411d4ec 365/* Returns the delimeter between mailboxes: INBOX/Test, or INBOX.Test */
9c737111 366function sqimap_get_delimiter ($imap_stream = false) {
3411d4ec 367 global $sqimap_delimiter, $optional_delimiter;
85fc999e 368
9c737111 369 /* Use configured delimiter if set */
370 if((!empty($optional_delimiter)) && $optional_delimiter != 'detect') {
371 return $optional_delimiter;
372 }
85fc999e 373
9c737111 374 /* Do some caching here */
375 if (!$sqimap_delimiter) {
376 if (sqimap_capability($imap_stream, 'NAMESPACE')) {
3411d4ec 377 /*
378 * According to something that I can't find, this is supposed to work on all systems
379 * OS: This won't work in Courier IMAP.
380 * OS: According to rfc2342 response from NAMESPACE command is:
381 * OS: * NAMESPACE (PERSONAL NAMESPACES) (OTHER_USERS NAMESPACE) (SHARED NAMESPACES)
382 * OS: We want to lookup all personal NAMESPACES...
383 */
1c72b151 384 $read = sqimap_run_command($imap_stream, 'NAMESPACE', true, $a, $b);
f1e6f580 385 if (eregi('\\* NAMESPACE +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL)', $read[0], $data)) {
9c737111 386 if (eregi('^\\( *\\((.*)\\) *\\)', $data[1], $data2)) {
f1e6f580 387 $pn = $data2[1];
9c737111 388 }
f1e6f580 389 $pna = explode(')(', $pn);
9c737111 390 while (list($k, $v) = each($pna)) {
862ff2d3 391 $lst = explode('"', $v);
392 if (isset($lst[3])) {
393 $pn[$lst[1]] = $lst[3];
394 } else {
74424a43 395 $pn[$lst[1]] = '';
862ff2d3 396 }
f1e6f580 397 }
398 }
399 $sqimap_delimiter = $pn[0];
400 } else {
401 fputs ($imap_stream, ". LIST \"INBOX\" \"\"\r\n");
402 $read = sqimap_read_data($imap_stream, '.', true, $a, $b);
403 $quote_position = strpos ($read[0], '"');
404 $sqimap_delimiter = substr ($read[0], $quote_position+1, 1);
405 }
406 }
407 return $sqimap_delimiter;
9c737111 408}
052e0c26 409
410
3411d4ec 411/* Gets the number of messages in the current mailbox. */
9c737111 412function sqimap_get_num_messages ($imap_stream, $mailbox) {
1f720b34 413 $read_ary = sqimap_run_command ($imap_stream, "EXAMINE \"$mailbox\"", false, $result, $message);
9c737111 414 for ($i = 0; $i < count($read_ary); $i++) {
85fc999e 415 if (ereg("[^ ]+ +([^ ]+) +EXISTS", $read_ary[$i], $regs)) {
416 return $regs[1];
417 }
9c737111 418 }
1f720b34 419 return false; //"BUG! Couldn't get number of messages in $mailbox!";
9c737111 420}
421
422
3411d4ec 423/* Returns a displayable email address.
424 * Luke Ehresman <lehresma@css.tayloru.edu>
425 * "Luke Ehresman" <lehresma@css.tayloru.edu>
426 * <lehresma@css.tayloru.edu>
427 * lehresma@css.tayloru.edu (Luke Ehresman)
428 * lehresma@css.tayloru.edu
429 * becomes: lehresma@css.tayloru.edu
430 */
9c737111 431function sqimap_find_email ($string) {
9c737111 432 if (ereg("<([^>]+)>", $string, $regs)) {
433 $string = $regs[1];
3411d4ec 434 } else if (ereg("([^ ]+@[^ ]+)", $string, $regs)) {
435 $string = $regs[1];
9c737111 436 }
437 return trim($string);
438}
439
440
441/*
3411d4ec 442 * Takes the From: field and creates a displayable name.
443 * Luke Ehresman <lkehresman@yahoo.com>
444 * "Luke Ehresman" <lkehresman@yahoo.com>
445 * lkehresman@yahoo.com (Luke Ehresman)
446 * becomes: Luke Ehresman
447 * <lkehresman@yahoo.com>
448 * becomes: lkehresman@yahoo.com
6282af09 449 */
9c737111 450function sqimap_find_displayable_name ($string) {
6282af09 451 $string = trim($string);
2f7bda0a 452
7e3de682 453 if ( ereg('^(.+)<.*>', $string, $regs) ) {
092d4f2c 454 $orig_string = $string;
2f7bda0a 455 $string = str_replace ('"', '', $regs[1] );
092d4f2c 456 if (trim($string) == '') {
457 $string = sqimap_find_email($orig_string);
458 }
33565ec4 459 if( $string == '' || $string == ' ' ){
1ba8cd6b 460 $string = '&nbsp;';
33565ec4 461 }
7e3de682 462 }
463 elseif ( ereg('\((.*)\)', $string, $regs) ) {
9e9c63e4 464 if( ( $regs[1] == '' ) || ( $regs[1] == ' ' ) ){
465 if ( ereg('^(.+) \(', $string, $regs) ) {
466 $string = ereg_replace( ' \(\)$', '', $string );
467 } else {
1ba8cd6b 468 $string = '&nbsp;';
9e9c63e4 469 }
470 } else {
471 $string = $regs[1];
472 }
7e3de682 473 }
474 else {
2f7bda0a 475 $string = str_replace ('"', '', sqimap_find_email($string));
9c737111 476 }
9c737111 477
7e3de682 478 return trim($string);
479}
85fc999e 480
9c737111 481/*
3411d4ec 482 * Returns the number of unseen messages in this folder
483 */
9c737111 484function sqimap_unseen_messages ($imap_stream, $mailbox) {
1f720b34 485 $read_ary = sqimap_run_command ($imap_stream, "STATUS \"$mailbox\" (UNSEEN)", false, $result, $message);
ea7ff111 486 $i = 0;
1f720b34 487 $regs = array(false, false);
ea7ff111 488 while (isset($read_ary[$i])) {
489 if (ereg("UNSEEN ([0-9]+)", $read_ary[$i], $regs)) {
490 break;
491 }
492 $i++;
493 }
9c737111 494 return $regs[1];
495}
496
1f720b34 497/*
498 * Returns the number of unseen/total messages in this folder
499 */
500function sqimap_status_messages ($imap_stream, $mailbox) {
501 $read_ary = sqimap_run_command ($imap_stream, "STATUS \"$mailbox\" (MESSAGES UNSEEN)", false, $result, $message);
502 $i = 0;
503 $messages = $unseen = false;
504 $regs = array(false,false);
505 while (isset($read_ary[$i])) {
506 if (preg_match('/UNSEEN\s+([0-9]+)/i', $read_ary[$i], $regs)) {
507 $unseen = $regs[1];
508 }
509 if (preg_match('/MESSAGES\s+([0-9]+)/i', $read_ary[$i], $regs)) {
510 $messages = $regs[1];
511 }
512 $i++;
513 }
514 return array('MESSAGES' => $messages, 'UNSEEN'=>$unseen);
515}
516
9c737111 517
518/*
3411d4ec 519 * Saves a message to a given folder -- used for saving sent messages
520 */
9c737111 521function sqimap_append ($imap_stream, $sent_folder, $length) {
522 fputs ($imap_stream, sqimap_session_id() . " APPEND \"$sent_folder\" (\\Seen) \{$length}\r\n");
85fc999e 523 $tmp = fgets ($imap_stream, 1024);
9c737111 524}
525
8813fb15 526function sqimap_append_done ($imap_stream, $folder='') {
1f720b34 527 global $squirrelmail_language, $color;
9c737111 528 fputs ($imap_stream, "\r\n");
529 $tmp = fgets ($imap_stream, 1024);
69146537 530 if (preg_match("/(.*)(BAD|NO)(.*)$/", $tmp, $regs)) {
531 set_up_language($squirrelmail_language);
1f720b34 532 require_once(SM_PATH . 'functions/display_messages.php');
8813fb15 533 $reason = $regs[3];
534 if ($regs[2] == 'NO') {
535 $string = "<b><font color=$color[2]>\n" .
536 _("ERROR : Could not append message to") ." $folder." .
537 "</b><br>\n" .
538 _("Server responded: ") .
539 $reason . "<br>\n";
540 if (preg_match("/(.*)(quota)(.*)$/i", $reason, $regs)) {
5296b8ef 541 $string .= _("Solution: ") .
542 _("Remove unneccessary messages from your folder and start with your Trash folder.")
8813fb15 543 ."<br>\n";
544 }
545 $string .= "</font>\n";
546 error_box($string,$color);
547 } else {
548 $string = "<b><font color=$color[2]>\n" .
1f720b34 549 _("ERROR : Bad or malformed request.") .
550 "</b><br>\n" .
551 _("Server responded: ") .
552 $tmp . "</font><br>\n";
8813fb15 553 error_box($string,$color);
554 exit;
555 }
69146537 556 }
9c737111 557}
85fc999e 558
bd9829d7 559function sqimap_get_user_server ($imap_server, $username) {
bd9829d7 560 if (substr($imap_server, 0, 4) != "map:") {
561 return $imap_server;
562 }
bd9829d7 563 $function = substr($imap_server, 4);
564 return $function($username);
565}
566
567/* This is an example that gets imapservers from yellowpages (NIS).
568 * you can simple put map:map_yp_alias in your $imap_server_address
569 * in config.php use your own function instead map_yp_alias to map your
570 * LDAP whatever way to find the users imapserver. */
571
572function map_yp_alias($username) {
573 $yp = `ypmatch $username aliases`;
574 return chop(substr($yp, strlen($username)+1));
575}
576
15e6162e 577?>