X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=blobdiff_plain;f=src%2Faddrbook.c;h=138b9b62e4110bb1ab7c9f430f5a86eb362613f8;hp=3fbef002e8ca39d8117075fa8b538bdae91e7d84;hb=4fd905f07b9bef159cfbbf2a863323fe560dc6e2;hpb=8fa18fb744f18992946100bc61954010ff965789;ds=sidebyside diff --git a/src/addrbook.c b/src/addrbook.c index 3fbef002e..138b9b62e 100644 --- a/src/addrbook.c +++ b/src/addrbook.c @@ -1214,19 +1214,24 @@ void addrbook_update_address_list( listGroup = addrcache_get_group_for_person( book->addressCache, person ); if( listGroup ) { GHashTable *hashEMail; + GHashTable *hashEMailAlias; GList *nodeGrp; /* Load hash table with new address entries */ hashEMail = g_hash_table_new( g_str_hash, g_str_equal ); + hashEMailAlias = g_hash_table_new( g_str_hash, g_str_equal ); node = listEMail; while( node ) { ItemEMail *email = node->data; gchar *addr = g_strdup( email->address ); - + gchar *alias = email->obj.name ; g_strdown( addr ); if( ! g_hash_table_lookup( hashEMail, addr ) ) { g_hash_table_insert( hashEMail, addr, email ); } + if ( *alias != '\0' && ! g_hash_table_lookup( hashEMailAlias, alias ) ) { + g_hash_table_insert( hashEMailAlias, alias, email ); + } node = g_list_next( node ); } @@ -1246,16 +1251,27 @@ void addrbook_update_address_list( if( ADDRITEM_PARENT(emailGrp) == ADDRITEM_OBJECT(person) ) { /* Found an email address for this person */ ItemEMail *emailNew = NULL; - gchar *addr = g_strdup( emailGrp->address ); - + gchar *addr = g_strdup( emailGrp->address ); + gchar *alias = emailGrp->obj.name; g_strdown( addr ); emailNew = ( ItemEMail * ) g_hash_table_lookup( hashEMail, addr ); g_free( addr ); + /* If no match by e-mail, try to match by e-mail alias */ + if( ! emailNew && *alias != '\0' ) { + emailNew = ( ItemEMail * ) + g_hash_table_lookup( hashEMailAlias, alias); + } + if( emailNew ) { /* Point to this entry */ nodeGrpEM->data = emailNew; } + else if(g_hash_table_size(hashEMail)==1) { + /* If the person has just one e-mail address, then + change e-mail address in group list */ + nodeGrpEM->data = listEMail->data; + } else { /* Mark for removal */ listRemove = g_list_append( listRemove, emailGrp ); @@ -1285,6 +1301,8 @@ void addrbook_update_address_list( hashEMail, ( GHRFunc ) addrbook_free_simple_hash_vis, NULL ); g_hash_table_destroy( hashEMail ); hashEMail = NULL; + g_hash_table_destroy( hashEMailAlias ); + hashEMailAlias = NULL; g_list_free( listGroup ); listGroup = NULL; }