Пример #1
0
/**
 * Add person and address data to cache.
 * \param cache     Cache.
 * \param folder    Folder where to add person, or NULL for root folder.
 * \param name      Common name.
 * \param address   EMail address.
 * \param remarks   Remarks.
 * \return Person added. Do not *NOT* to use the 
 *         <code>addrbook_free_xxx()</code> functions...; this will destroy
 *         the address book data.
 */
ItemPerson *addrcache_add_contact(
		AddressCache *cache, ItemFolder *folder, const gchar *name,
		const gchar *address, const gchar *remarks )
{
	ItemPerson *person = NULL;
	ItemEMail *email = NULL;
	ItemFolder *f = folder;

	cm_return_val_if_fail( cache != NULL, NULL );

	if( ! f ) f = cache->rootFolder;

	/* Create person object */
	person = addritem_create_item_person();
	addritem_person_set_common_name( person, name );
	addrcache_id_person( cache, person );
	addrcache_folder_add_person( cache, f, person );

	/* Create email object */
	email = addritem_create_item_email();
	addritem_email_set_address( email, address );
	addritem_email_set_remarks( email, remarks );
	addrcache_id_email( cache, email );
	addritem_person_add_email( person, email );
	cache->dirtyFlag = TRUE;

	return person;
}
Пример #2
0
static GList* restore_or_add_email_address(AddressBookFile *abf,
																					 ItemPerson *item, GList *savedList,
																					 const gchar *email)
{
	ItemEMail *itemMail = NULL;
	GList *walk;
	gboolean found;
	gchar *addr;

	if(!email)
		return savedList;

	found = FALSE;
	for (walk = savedList; walk; walk = walk->next) {
		itemMail = walk->data;
		if(itemMail && itemMail->address) {
			addr = g_strchomp(g_strdup(itemMail->address));
			if (!strcmp(addr, email))
				found = TRUE;
			g_free(addr);
			if (found)
				break;
		}
	}

	if (found) {
		addritem_person_add_email(item, itemMail);
		savedList = g_list_delete_link(savedList, walk);
	}
	/* something's fishy here */
	else {
		ItemEMail *newEMail;
		newEMail = addritem_create_item_email();
		addritem_email_set_address(newEMail, email);
		addrcache_id_email(abf->addressCache, newEMail);
		addritem_person_add_email(item, newEMail);
		addrbook_set_dirty(abf,TRUE);
	}

	return savedList;
}
Пример #3
0
/*
* Add EMail address to person.
* return: TRUE if item added.
*/
gboolean addrcache_person_add_email( AddressCache *cache, ItemPerson *person, ItemEMail *email ) {
	gboolean retVal = FALSE;

	cm_return_val_if_fail( cache != NULL, FALSE );
	cm_return_val_if_fail( person != NULL, FALSE );
	cm_return_val_if_fail( email != NULL, FALSE );

	retVal = addrcache_hash_add_email( cache, email );
	if( retVal ) {
		addritem_person_add_email( person, email );
		cache->dirtyFlag = TRUE;
	}
	return retVal;
}
Пример #4
0
/**
 * Build an address list entry and append to list of address items. Name is formatted
 * as "<first-name> <last-name>".
 *
 * \param  cache     Address cache to load.
 * \param  qry Query object to process.
 * \param  dn        DN for entry found on server.
 * \param  listName  List of common names for entry; see notes below.
 * \param  listAddr  List of EMail addresses for entry.
 * \param  listFirst List of first names for entry.
 * \param  listLast  List of last names for entry.
 *
 * \return List of ItemEMail objects.
 *
 * Notes:
 * 1) Each LDAP server entry may have multiple LDAP attributes with the same
 *    name. For example, a single entry for a person may have more than one
 *    common name, email address, etc.
*
 * 2) The DN for the entry is unique for the server.
 */
static GList *ldapqry_build_items_fl(
		AddressCache *cache, LdapQuery *qry, gchar *dn,
		GSList *listName, GSList *listAddr, GSList *listFirst,
		GSList *listLast, GSList *listDisplay, GSList *attributes )
{
	GSList *nodeAddress, *cur;
	gchar *firstName = NULL, *lastName = NULL, *fullName = NULL;
	gboolean allocated = FALSE;
	ItemPerson *person;
	ItemEMail *email;
	ItemFolder *folder;
	gchar *picfile = NULL;
	GList *listReturn = NULL;

	folder = ADDRQUERY_FOLDER(qry);
	if( folder == NULL ) return listReturn;
	if( listAddr == NULL ) return listReturn;

	if ( listDisplay ) {
		allocated = FALSE;
		fullName = listDisplay->data;
	}

	/* Find longest first name in list */
	firstName = mgu_slist_longest_entry( listFirst );

	/* Format last name */
	if( listLast ) {
		lastName = listLast->data;
	}

	if ( fullName == NULL ) {
		/* Find longest common name */
		allocated = FALSE;
		fullName = mgu_slist_longest_entry( listName );
		if( fullName == NULL ) {
			/* Format a full name from first and last names */
			if( firstName ) {
				if( lastName ) {
					fullName = g_strdup_printf( "%s %s", firstName, lastName );
				}
				else {
					fullName = g_strdup_printf( "%s", firstName );
				}
			}
			else {
				if( lastName ) {
					fullName = g_strdup_printf( "%s", lastName );
				}
			}
			if( fullName ) {
				g_strstrip( fullName );
				allocated = TRUE;
			}
		}
	}

	/* Add person into folder */		
	person = addritem_create_item_person();
	addritem_person_set_common_name( person, fullName );
	addritem_person_set_first_name( person, firstName );
	addritem_person_set_last_name( person, lastName );
	addritem_person_set_nick_name( person, fullName );
	addrcache_id_person( cache, person );
	addritem_person_set_external_id( person, dn );
	
	for (cur = attributes; cur; cur = cur->next) {
		UserAttribute *attrib = addritem_copy_attribute((UserAttribute *)cur->data);
		if (attrib->name && strcmp(attrib->name, "jpegPhoto")) {
			addritem_person_add_attribute( person, attrib );
		} else {
			if (qry->server && qry->server->control) {
				gchar *dir = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, 
							ADDRBOOK_DIR, G_DIR_SEPARATOR_S, NULL );
				gchar *filename = g_strdup_printf("%s-%s-%s",
					qry->server->control->hostName?qry->server->control->hostName:"nohost", 
					qry->server->control->baseDN?qry->server->control->baseDN:"nobase", 
					dn);
				picfile = g_strdup_printf("%s%s.png", dir, filename);
				addritem_person_set_picture( person, filename );
				rename_force(attrib->value, picfile);
				g_free(filename);
				g_free(picfile);
				g_free(dir);
			}
		}
	}
	
	addrcache_folder_add_person( cache, ADDRQUERY_FOLDER(qry), person );

	qry->entriesRead++;

	/* Add each address item */
	nodeAddress = listAddr;
	while( nodeAddress ) {
		email = addritem_create_item_email();
		addritem_email_set_address( email, nodeAddress->data );
		addrcache_id_email( cache, email );
		addrcache_person_add_email( cache, person, email );
		addritem_person_add_email( person, email );
		/*if (debug_get_mode()) {
			addritem_print_item_email(email, stdout);
		}*/
		listReturn = g_list_append( listReturn, email );
		nodeAddress = g_slist_next( nodeAddress );
	}

	/* Free any allocated memory */
	if( allocated ) {
		g_free( fullName );
	}
	fullName = firstName = lastName = NULL;

	return listReturn;
}