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

Source for file IMAP.connection_wizard.php

Documentation is available at IMAP.connection_wizard.php

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

Documentation generated on Mon, 11 Mar 2019 10:15:01 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.