Mail_IMAP
[ class tree: Mail_IMAP ] [ index: Mail_IMAP ] [ all elements ]

Mail_IMAP Connection Wizard

  1. <?php
  2.  
  3.     /**
  4.      * @author      Richard York <rich_y@php.net>
  5.      * @copyright   (c) Copyright 2004, Richard York, All Rights Reserved.
  6.      * @package     Mail_IMAP
  7.      * @subpackage  examples
  8.      **
  9.     */
  10.  
  11.     require_once 'Mail/IMAP.php';
  12.  
  13.     /**
  14.      * Attempts to find the appropriate URI for the user based on common
  15.      * configurations and port settings.  This function is meant to serve
  16.      * as a utility helper to find the correct URI syntax to pass to
  17.      * {@link connect}.
  18.      *
  19.      * @param     string   $server     Remote mail server to connect to.
  20.      * @param     string   $user       Remote mail server user name.
  21.      * @param     string   $pass       Remote mail server password.
  22.      * @param     string   $protocol 
  23.      *       (optional) Mail server protocol, one of imap|pop3|nntp
  24.      * @param     int      $port 
  25.      *       (optional) Mail server port.
  26.      *
  27.      * @return    string|FALSE
  28.      * @todo add SSL/TLS URI testing
  29.      * @see       connect
  30.      **
  31.     */
  32.     function Mail_IMAP_connection_wizard($server$user$pass$protocol = NULL$port = 0)
  33.     {
  34.         // Building/or/attempting to build the connection can take lots of time
  35.         ini_set('max_execution_time'120);
  36.  
  37.         // imap_open throws lots of errors on failed attempts
  38.         error_reporting(0);
  39.  
  40.         $mail =new Mail_IMAP();
  41.  
  42.         $base_uri urlencode($user).':'.$pass.'@'.$server;
  43.  
  44.         if ($protocol == NULL{
  45.  
  46.             $protocol = array('imap''pop3''nntp');
  47.             $port     = array(143110119);
  48.  
  49.             for ($i = 0; $i count($protocol)$i++{
  50.  
  51.                 $uri $protocol[$i].'://'.$base_uri.':'.$port[$i].'/INBOX';
  52.  
  53.                 if (PEAR::isError($mail->connect($uri))) {
  54.  
  55.                     if (!PEAR::isError($mail->connect($uri.'#notls'))) {
  56.                         return $uri;
  57.                     }
  58.  
  59.                 else {
  60.                     return $uri;
  61.                 }
  62.             }
  63.  
  64.         else {
  65.  
  66.             switch($protocol{
  67.                 case 'imap':    $base_uri .= ($port == 0)':143' ':'.$port;  break;
  68.                 case 'pop3':    $base_uri .= ($port == 0)':110' ':'.$port;  break;
  69.                 case 'nntp':    $base_uri .= ($port == 0)':119' ':'.$port;  break;
  70.                 default:        return FALSE;
  71.             }
  72.  
  73.             $uri $protocol.'://'.$base_uri;
  74.  
  75.             if (PEAR::isError($mail->connect($uri))) {
  76.  
  77.                 if (!PEAR::isError($mail->connect($uri.'#notls'))) {
  78.                     return $uri;
  79.                 }
  80.  
  81.             else {
  82.                 return $uri;
  83.             }
  84.         }
  85.  
  86.         return FALSE;
  87.     }
  88.  
  89. ?>

Documentation generated on Mon, 11 Mar 2019 13:52:30 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.