/* Returns TRUE iff name and addr is duplicate. If not, stores the * name/addr pair in order to detect subsequent duplicates. */ static notmuch_bool_t is_duplicate (const search_context_t *ctx, const char *name, const char *addr) { char *key; GList *list, *l; mailbox_t *mailbox; list = g_hash_table_lookup (ctx->addresses, addr); if (list) { mailbox_t find = { .name = name, .addr = addr, }; l = g_list_find_custom (list, &find, mailbox_compare); if (l) { mailbox = l->data; mailbox->count++; return TRUE; } mailbox = new_mailbox (ctx->format, name, addr); if (! mailbox) return FALSE; /* * XXX: It would be more efficient to prepend to the list, but * then we'd have to store the changed list head back to the * hash table. This check is here just to avoid the compiler * warning for unused result. */ if (list != g_list_append (list, mailbox)) INTERNAL_ERROR ("appending to list changed list head\n"); return FALSE; } key = talloc_strdup (ctx->format, addr); if (! key) return FALSE; mailbox = new_mailbox (ctx->format, name, addr); if (! mailbox) return FALSE; list = g_list_append (NULL, mailbox); if (! list) return FALSE; g_hash_table_insert (ctx->addresses, key, list); return FALSE; }
struct mailbox* make_agent(pthread_t *thread, bool (*handler) (struct message*)) { struct agent_args *args = (struct agent_args*) malloc(sizeof(struct agent_args)); if (args == NULL) { myperror("malloc"); return NULL; } args->inbox = new_mailbox(); if (args->inbox == NULL) { free(args); return NULL; } args->handler = handler; int err = pthread_create(thread, NULL, agent, args); if (err != 0) { myerror(err, "pthread_create"); delete_mailbox(args->inbox); free(args); return NULL; } return args->inbox; }