[balsa] LDAP address book: use all email attributes



commit 03bf588a429818baf3a4bfc989a09256fd2da37f
Author: Albrecht Dreß <albrecht dress arcor de>
Date:   Wed Jan 30 09:49:19 2019 -0500

    LDAP address book: use all email attributes
    
    * libbalsa_address_book_ldap_get_address(): assign the GList
      of all mail attribute strings to LibBalsaAddress instead of the
      first one only;
    * lbabl_get_internet_address(): append separate InternetAddress
      to a GList instead on returning the first one only.
    
    Signed-off-by: Peter Bloomfield <PeterBloomfield bellsouth net>

 ChangeLog                    | 10 ++++++++++
 libbalsa/address-book-ldap.c | 42 ++++++++++++++++++++----------------------
 2 files changed, 30 insertions(+), 22 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 60a0573a2..6efab295c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2018-01-30  Albrecht Dreß  <albrecht dress arcor de>
+
+       LDAP address book: use all email attributes
+
+       * libbalsa_address_book_ldap_get_address(): assign the GList
+         of all mail attribute strings to LibBalsaAddress instead of the
+         first one only;
+       * lbabl_get_internet_address(): append separate InternetAddress
+         to a GList instead on returning the first one only.
+
 2018-01-24  Albrecht Dreß  <albrecht dress arcor de>
 
        * libbalsa/html.c (lbh_web_process_terminated_cb): new signal in
diff --git a/libbalsa/address-book-ldap.c b/libbalsa/address-book-ldap.c
index 67c404530..e13481ea3 100644
--- a/libbalsa/address-book-ldap.c
+++ b/libbalsa/address-book-ldap.c
@@ -448,7 +448,8 @@ libbalsa_address_book_ldap_get_address(LibBalsaAddressBook * ab,
                                       LDAPMessage * e)
 {
     LibBalsaAddressBookLdap *ldap_ab;
-    gchar *email = NULL, *cn = NULL, *org = NULL, *uid = NULL;
+    GList *email = NULL;
+    gchar *cn = NULL, *org = NULL, *uid = NULL;
     gchar *first = NULL, *last = NULL;
     LibBalsaAddress *address = NULL;
     char *attr;
@@ -475,8 +476,8 @@ libbalsa_address_book_ldap_get_address(LibBalsaAddressBook * ab,
                    org = g_strndup(vals[i]->bv_val, vals[i]->bv_len);
                if ((g_ascii_strcasecmp(attr, "uid") == 0) && (!uid))
                    uid = g_strndup(vals[i]->bv_val, vals[i]->bv_len);
-               if ((g_ascii_strcasecmp(attr, "mail") == 0) && (!email))
-                   email = g_strndup(vals[i]->bv_val, vals[i]->bv_len);
+               if (g_ascii_strcasecmp(attr, "mail") == 0)
+                   email = g_list_prepend(email, g_strndup(vals[i]->bv_val, vals[i]->bv_len));
            }
            ldap_value_free_len(vals);
        }
@@ -485,7 +486,7 @@ libbalsa_address_book_ldap_get_address(LibBalsaAddressBook * ab,
     /*
      * Record will have e-mail (searched)
      */
-    if(email == NULL) email = g_strdup("none");
+    if(email == NULL) email = g_list_prepend(email, g_strdup("none"));
     g_return_val_if_fail(email != NULL, NULL);
 
     address = libbalsa_address_new();
@@ -500,20 +501,21 @@ libbalsa_address_book_ldap_get_address(LibBalsaAddressBook * ab,
     address->last_name = last;
     address->nick_name = uid;
     address->organization = org;
-    address->address_list = g_list_prepend(address->address_list, email);
+    address->address_list = email;
 
     return address;
 }
 
-static InternetAddress*
-lbabl_get_internet_address(LDAP *dir, LDAPMessage * e)
+static GList *
+lbabl_get_internet_address(GList *addrs, LDAP *dir, LDAPMessage * e)
 {
-    InternetAddress *ia;
     BerElement *ber = NULL;
     char *attr;
     struct berval **vals;
     int i;
-    gchar *email = NULL, *sn = NULL, *cn = NULL, *first = NULL;
+    GList *email = NULL;
+    GList *p;
+    gchar *sn = NULL, *cn = NULL, *first = NULL;
 
     for (attr = ldap_first_attribute(dir, e, &ber);
         attr != NULL; 
@@ -529,25 +531,23 @@ lbabl_get_internet_address(LDAP *dir, LDAPMessage * e)
                    cn = g_strndup(vals[i]->bv_val, vals[i]->bv_len);
                if ((g_ascii_strcasecmp(attr, "givenName") == 0) && (!first))
                    first = g_strndup(vals[i]->bv_val, vals[i]->bv_len);
-               if ((g_ascii_strcasecmp(attr, "mail") == 0) && (!email))
-                   email = g_strndup(vals[i]->bv_val, vals[i]->bv_len);
+               if (g_ascii_strcasecmp(attr, "mail") == 0)
+                   email = g_list_prepend(email, g_strndup(vals[i]->bv_val, vals[i]->bv_len));
            }
            ldap_value_free_len(vals);
        }
         ldap_memfree(attr);
     }
-    /*
-     * Record will have e-mail (searched)
-     */
-    if(email == NULL) email = g_strdup("none");
-    g_return_val_if_fail(email != NULL, NULL);
 
     if(!cn)
         cn = create_name(first, sn);
-    ia = internet_address_mailbox_new(cn, email);
-    g_free(email); g_free(sn); g_free(cn); g_free(first);
+    for (p = email; p != NULL; p = p->next) {
+       addrs = g_list_prepend(addrs, internet_address_mailbox_new(cn, (const gchar *) p->data));
+    }
+    g_list_free_full(email, g_free);
+    g_free(sn); g_free(cn); g_free(first);
 
-    return ia;
+    return addrs;
 }
 /*
  * create_name()
@@ -953,7 +953,6 @@ libbalsa_address_book_ldap_alias_complete(LibBalsaAddressBook * ab,
 {
     static struct timeval timeout = { 15, 0 }; /* 15 sec timeout */
     LibBalsaAddressBookLdap *ldap_ab;
-    InternetAddress *addr;
     GList *res = NULL;
     gchar* filter;
     gchar* ldap;
@@ -996,8 +995,7 @@ libbalsa_address_book_ldap_alias_complete(LibBalsaAddressBook * ab,
        if (result)
            for(e = ldap_first_entry(ldap_ab->directory, result);
                e != NULL; e = ldap_next_entry(ldap_ab->directory, e)) {
-               addr = lbabl_get_internet_address(ldap_ab->directory, e);
-               res = g_list_prepend(res, addr);
+               res = lbabl_get_internet_address(res, ldap_ab->directory, e);
            }
     case LDAP_SIZELIMIT_EXCEEDED:
     case LDAP_TIMELIMIT_EXCEEDED:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]