parseMailServerConnectString() static public method

Parse imap open connect string
static public parseMailServerConnectString ( $value, $forceport = false ) : array
$value string: connect string
$forceport boolean: force compute port if not set (false by default)
return array of parsed arguments (address, port, mailbox, type, ssl, tls, validate-cert norsh, secure and debug) : options are empty if not set and options have boolean values if set
 /**
  * Display a mail server configuration form
  *
  * @param $value String host connect string ex
  *                      {localhost:993/imap/ssl}INBOX
  *
  * @return String type of the server (imap/pop)
  **/
 static function showMailServerConfig($value)
 {
     if (!Config::canUpdate()) {
         return false;
     }
     $tab = Toolbox::parseMailServerConnectString($value);
     echo "<tr class='tab_bg_1'><td>" . __('Server') . "</td>";
     echo "<td><input size='30' type='text' name='mail_server' value=\"" . $tab['address'] . "\">";
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . __('Connection options') . "</td><td>";
     $values = array('' => '', '/imap' => __('IMAP'), '/pop' => __('POP'));
     $svalue = !empty($tab['type']) ? '/' . $tab['type'] : '';
     Dropdown::showFromArray('server_type', $values, array('value' => $svalue, 'width' => '10%'));
     $values = array('' => '', '/ssl' => __('SSL'));
     $svalue = $tab['ssl'] ? '/ssl' : '';
     Dropdown::showFromArray('server_ssl', $values, array('value' => $svalue, 'width' => '10%'));
     $values = array('' => '', '/tls' => __('TLS'), '/notls' => __('NO-TLS'));
     $svalue = '';
     if ($tab['tls'] === true) {
         $svalue = '/tls';
     }
     if ($tab['tls'] === false) {
         $svalue = '/notls';
     }
     Dropdown::showFromArray('server_tls', $values, array('value' => $svalue, 'width' => '14%'));
     $values = array('' => '', '/novalidate-cert' => __('NO-VALIDATE-CERT'), '/validate-cert' => __('VALIDATE-CERT'));
     $svalue = '';
     if ($tab['validate-cert'] === false) {
         $svalue = '/novalidate-cert';
     }
     if ($tab['validate-cert'] === true) {
         $svalue = '/validate-cert';
     }
     Dropdown::showFromArray('server_cert', $values, array('value' => $svalue, 'width' => '20%'));
     $values = array('' => '', '/norsh' => __('NORSH'));
     $svalue = $tab['norsh'] === true ? '/norsh' : '';
     Dropdown::showFromArray('server_rsh', $values, array('value' => $svalue, 'width' => '12%'));
     $values = array('' => '', '/secure' => __('SECURE'));
     $svalue = $tab['secure'] === true ? '/secure' : '';
     Dropdown::showFromArray('server_secure', $values, array('value' => $svalue, 'width' => '12%'));
     $values = array('' => '', '/debug' => __('DEBUG'));
     $svalue = $tab['debug'] === true ? '/debug' : '';
     Dropdown::showFromArray('server_debug', $values, array('value' => $svalue, 'width' => '12%'));
     echo "<input type=hidden name=imap_string value='" . $value . "'>";
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . __('Incoming mail folder (optional, often INBOX)') . "</td>";
     echo "<td><input size='30' type='text' name='server_mailbox' value=\"" . $tab['mailbox'] . "\" >";
     echo "</td></tr>\n";
     //TRANS: for mail connection system
     echo "<tr class='tab_bg_1'><td>" . __('Port (optional)') . "</td>";
     echo "<td><input size='10' type='text' name='server_port' value='" . $tab['port'] . "'></td></tr>\n";
     if (empty($value)) {
         $value = "&nbsp;";
     }
     //TRANS: for mail connection system
     echo "<tr class='tab_bg_1'><td>" . __('Connection string') . "</td>";
     echo "<td class='b'>{$value}</td></tr>\n";
     return $tab['type'];
 }
         } else {
             echo "_PROBLEM";
             $ok = false;
         }
         echo "\n";
     }
 } else {
     echo "No LDAP server\n";
 }
 // Check IMAP Auth connections
 $imap_methods = getAllDatasFromTable('glpi_authmails', '`is_active`=1');
 if (count($imap_methods)) {
     echo "Check IMAP servers:";
     foreach ($imap_methods as $method) {
         echo " " . $method['name'];
         $param = Toolbox::parseMailServerConnectString($method['connect_string'], true);
         if ($param['ssl'] === true) {
             $host = 'ssl://' . $host;
         } else {
             if ($param['tls'] === true) {
                 $host = 'tls://' . $host;
             }
         }
         if ($fp = @fsockopen($host, $param['port'], $errno, $errstr, 1)) {
             echo "_OK";
         } else {
             echo "_PROBLEM";
             $ok = false;
         }
         fclose($fp);
         echo "\n";