[turba] LDAP multiple e-mail display patches

John Dalbec jpdalbec at ysu.edu
Fri Apr 4 13:24:10 PST 2003


I realize many of you see no need to support multiple e-mail addresses 
since turba has distribution lists now.  However, I have an LDAP 
directory where some users have multiple valid e-mail addresses.  These 
patches cause the addresses to be converted into separate working links 
rather than a single link that doesn't work.  This is different from a 
distribution list in that you only send e-mail to the address that you 
click.
John
-------------- next part --------------
--- /var/www/html/horde-RELENG/turba/templates/browse/contactrow.inc	Sun Feb  9 21:05:57 2003
+++ ./contactrow.inc	Fri Apr  4 12:59:29 2003
@@ -6,21 +6,32 @@
     if ($ob->hasValue($column)) {
         $show[$column] = htmlspecialchars($ob->getValue($column));
         if ($GLOBALS['attributes'][$column]['type'] == 'email') {
-            // Format the address according to RFC822.
-            $mailbox_host = explode('@', $show[$column]);
-            if (!isset($mailbox_host[1])) {
-                $mailbox_host[1] = '';
+            $vals = explode(',', $show[$column]);
+            $values = false;
+            foreach ($vals as $val) {
+                $val = trim($val);
+                // Format the address according to RFC822.
+                $mailbox_host = explode('@', $val);
+                if (!isset($mailbox_host[1])) {
+                    $mailbox_host[1] = '';
+                }
+                $name = $ob->getValue('name');
+                $address = imap_rfc822_write_address($mailbox_host[0], $mailbox_host[1], $name);
+                // Get rid of the trailing @ (when no host is included in the email address).
+                $address = str_replace('@>', '>', $address);
+                $mail_link = $GLOBALS['registry']->link('mail/compose', array('to' => addslashes($address)));
+                if (PEAR::isError($mail_link)) {
+                    $mail_link = 'mailto:' . urlencode($address);
+                }
+    
+                $value = '<a href="' . $mail_link . '">' . htmlspecialchars($val) . '</a>';
+                if ( $values ) {
+                    $values .= ', ' . $value;
+                } else {
+                    $values = $value;
+                }
             }
-            $name = $ob->getValue('name');
-            $address = imap_rfc822_write_address($mailbox_host[0], $mailbox_host[1], $name);
-            // Get rid of the trailing @ (when no host is included in the email address).
-            $address = str_replace('@>', '>', $address);
-            $mail_link = $GLOBALS['registry']->link('mail/compose', array('to' => addslashes($address)));
-            if (PEAR::isError($mail_link)) {
-                $mail_link = 'mailto:' . urlencode($address);
-            }
-
-            $show[$column] = '<a href="' . $mail_link . '">' . htmlspecialchars($show[$column]) . '</a>';
+            $show[$column] = $values;
         }
     } else {
         $show[$column] = '&nbsp;';
-------------- next part --------------
--- /var/www/html/horde-RELENG/turba/templates/display/display.inc	Sun Mar  2 18:20:29 2003
+++ ./display.inc	Fri Apr  4 11:17:39 2003
@@ -36,21 +36,32 @@
     if (empty($val)) {
         $value = '&nbsp;';
     } elseif ($field['type'] == 'email') {
-        // Format the address according to RFC822.
-        $mailbox_host = explode('@', $val);
-        if (!isset($mailbox_host[1])) {
-            $mailbox_host[1] = '';
+        $vals = explode(',', $val);
+        $values = false;
+        foreach ($vals as $val) {
+            $val = trim($val);
+            // Format the address according to RFC822.
+            $mailbox_host = explode('@', $val);
+            if (!isset($mailbox_host[1])) {
+                $mailbox_host[1] = '';
+            }
+            $name = $this->object->getValue('name');
+            $address = imap_rfc822_write_address($mailbox_host[0], $mailbox_host[1], $name);
+            // Get rid of the trailing @ (when no host is included in the email address).
+            $address = str_replace('@>', '>', $address);
+            $mail_link = $GLOBALS['registry']->link('mail/compose', array('to' => $address, 'label' => $val));
+            if (PEAR::isError($mail_link)) {
+                $mail_link = 'mailto:' . urlencode($address);
+            }
+    
+            $value = Horde::link($mail_link, sprintf(_("Send mail to %s"), $name)) . $val . '</a>';
+            if ( $values ) {
+                $values .= ', ' . $value;
+            } else {
+                $values = $value;
+            }
         }
-        $name = $this->object->getValue('name');
-        $address = imap_rfc822_write_address($mailbox_host[0], $mailbox_host[1], $name);
-        // Get rid of the trailing @ (when no host is included in the email address).
-        $address = str_replace('@>', '>', $address);
-        $mail_link = $GLOBALS['registry']->link('mail/compose', array('to' => $address, 'label' => $this->object->getvalue($key)));
-        if (PEAR::isError($mail_link)) {
-            $mail_link = 'mailto:' . urlencode($address);
-        }
-
-        $value = Horde::link($mail_link, sprintf(_("Send mail to %s"), $name)) . $this->object->getvalue($key) . '</a>';
+        $value = $values;
     } elseif ($field['type'] == 'date') {
         $value = date('d. m. Y', $this->object->getValue($key));
     } else {


More information about the turba mailing list