[dev] IMP::serverString()

Nuno Loureiro nuno@co.eth.pt
13 Jun 2002 14:47:04 +0100


On Thu, 2002-06-13 at 06:28, Jon Parise wrote:
> On Wed, Jun 12, 2002 at 08:29:40PM +0100, Nuno Loureiro wrote:
> 
> >    I'd like to include this little patch in IMP HEAD, since that,
> > according to PHP Manual the port number and the protocol are optional i=
n
> > the mailbox name used in imap_open() and other imap functions.
> 
> [snip]
> 
> > -        return '{' . $imp['server'] . ':' . $imp['port'] . '/' . $prot=
ocol . '}';
> > +        (empty($imp['port'])) ? $port_str = '' : $port_str = ':' .=
 $imp['port'];
> > +        (empty($protocol)) ? $protocol_str = '' : $protocol_str = =
'/' . $protocol;
> > +        return '{' . $imp['server'] . $port_str . $protocol_str . '}';
> 
> No objection to the patch in principle, but please expand the new code
> a bit more to improve readable, and a comment explaining the rationale
> is also in order.

How about this one?

Index: IMP.php
===================================================================
RCS file: /repository/imp/lib/IMP.php,v
retrieving revision 1.277
diff -u -u -r1.277 IMP.php
--- IMP.php	11 Jun 2002 21:20:30 -0000	1.277
+++ IMP.php	13 Jun 2002 13:45:28 -0000
@@ -422,10 +422,24 @@
     {
         global $imp;
 
+        $srvstr = '{' . $imp['server'];
+        
+        /* If port is not specified, don't include it in Server String */
+        if (!empty($imp['port'])) { 
+            $srvstr .= ':' . $imp['port'];
+        }
+        
         if (!isset($protocol)) {
             $protocol = $imp['protocol'];
         }
-        return '{' . $imp['server'] . ':' . $imp['port'] . '/' . $protocol . '}';
+        
+        /* If protocol is not specified, don't include it in Server String */
+        if (!empty($protocol)) { 
+            $srvstr .= '/' . $protocol;
+        }
+
+        $srvstr .= '}';
+        return $srvstr;
     }
 
     /**


-- 
Nuno Loureiro <nuno@eth.pt>
Ethernet, Soluções Informáticas, LDA
http://www.eth.pt