diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/addressadd.c | 51 | ||||
-rw-r--r-- | src/addressadd.h | 2 | ||||
-rw-r--r-- | src/addressbook.c | 26 | ||||
-rw-r--r-- | src/addressbook.h | 9 | ||||
-rw-r--r-- | src/addrindex.c | 37 | ||||
-rw-r--r-- | src/addrindex.h | 3 | ||||
-rw-r--r-- | src/compose.c | 75 |
7 files changed, 195 insertions, 8 deletions
diff --git a/src/addressadd.c b/src/addressadd.c index cb5e3ae7..03d79c96 100644 --- a/src/addressadd.c +++ b/src/addressadd.c @@ -51,6 +51,7 @@ #include "addrindex.h" #include "editaddress.h" #include "manage_window.h" +#include "utils.h" typedef struct { AddressBookFile *book; @@ -361,6 +362,9 @@ gboolean addressadd_selection( AddressIndex *addrIndex, const gchar *name, const if( remarks ) gtk_label_set_text( GTK_LABEL(addressadd_dlg.label_remarks ), remarks ); + if( ! name ) + name = ""; + gtk_main(); gtk_widget_hide( addressadd_dlg.window ); @@ -382,6 +386,53 @@ gboolean addressadd_selection( AddressIndex *addrIndex, const gchar *name, const return retVal; } +gboolean addressadd_autoreg(AddressIndex *addrIndex, const gchar *name, + const gchar *address, const gchar *remarks) +{ + ItemPerson *person = NULL; + AddressInterface *interface = NULL; + AddressDataSource *ds = NULL; + AddressBookFile *abf = NULL; + GList *node_ds; + const gchar *ds_name; + + g_return_val_if_fail(address != NULL, FALSE); + + if (!name) + name = ""; + + interface = addrindex_get_interface(addrIndex, ADDR_IF_BOOK); + if (!interface) + return FALSE; + + for (node_ds = interface->listSource; node_ds != NULL; + node_ds = node_ds->next) { + ds = node_ds->data; + ds_name = addrindex_ds_get_name(ds); + if (!ds_name) + continue; + if (strcmp(ds_name, ADDR_DS_AUTOREG) != 0) + continue; + debug_print("addressadd_autoreg: AddressDataSource: %s found\n", ds_name); + + if (!addrindex_ds_get_read_flag(ds)) + addrindex_ds_read_data(ds); + abf = ds->rawDataSource; + } + + if (!abf) + return FALSE; + + person = addrbook_add_contact(abf, NULL, name, address, remarks); + if (person) { + debug_print("addressadd_autoreg: person added: %s <%s>\n", + name, address); + return TRUE; + } + + return FALSE; +} + /* * End of Source. */ diff --git a/src/addressadd.h b/src/addressadd.h index 9206bf98..748d1ef7 100644 --- a/src/addressadd.h +++ b/src/addressadd.h @@ -28,4 +28,6 @@ gboolean addressadd_selection( AddressIndex *addrIndex, const gchar *name, const gchar *address, const gchar *remarks ); +gboolean addressadd_autoreg( AddressIndex *addrIndex, const gchar *name, const gchar *address, const gchar *remarks ); + #endif /* __ADDRESS_ADD_H__ */ diff --git a/src/addressbook.c b/src/addressbook.c index f0559f36..e8b1bf2c 100644 --- a/src/addressbook.c +++ b/src/addressbook.c @@ -1267,6 +1267,9 @@ static void addressbook_menuitem_set_sensitive(void) } else #endif canLookup = TRUE; + if (ads->subType == ADDR_BOOK && pobj->name && + !strcmp(pobj->name, ADDR_DS_AUTOREG)) + canEditTree = FALSE; } else if (pobj->type == ADDR_ITEM_FOLDER) { ds = addressbook_find_datasource(&iter); if (ds) { @@ -2900,9 +2903,11 @@ void addressbook_read_file(void) /* Conversion required */ debug_print("Converting...\n"); if (addressbook_convert(addrIndex)) { + addrindex_create_extra_books(addrIndex); _addressIndex_ = addrIndex; } } else if (addrIndex->retVal == MGU_SUCCESS) { + addrindex_create_extra_books(addrIndex); _addressIndex_ = addrIndex; } else { gchar msg[1024]; @@ -3049,6 +3054,7 @@ static gboolean addressbook_add_object(GtkTreeIter *iter, GtkTreeIter *new_iter, AddressObject *pobj; AddressObjectType otype; AddressTypeControlItem *atci = NULL; + const gchar *name; g_return_val_if_fail(iter != NULL, FALSE); g_return_val_if_fail(obj != NULL, FALSE); @@ -3069,9 +3075,13 @@ static gboolean addressbook_add_object(GtkTreeIter *iter, GtkTreeIter *new_iter, if (atci && atci->showInTree) { /* Add object to tree */ debug_print("addressbook_add_object: obj: %s\n", obj->name); + if (otype == ADDR_BOOK && !strcmp(obj->name, ADDR_DS_AUTOREG)) + name = _("Auto-registered address"); + else + name = obj->name; gtk_tree_store_append(GTK_TREE_STORE(model), &added, iter); gtk_tree_store_set(GTK_TREE_STORE(model), &added, - COL_FOLDER_NAME, obj->name, + COL_FOLDER_NAME, name, COL_OBJ, obj, COL_PIXBUF, atci->icon_pixbuf, COL_PIXBUF_OPEN, atci->icon_open_pixbuf, @@ -4001,7 +4011,7 @@ void addrbookctl_build_ifselect(void) */ gboolean addressbook_add_contact(const gchar *name, const gchar *address, const gchar *remarks) { - debug_print("addressbook_add_contact: name/address: %s - %s\n", name, address); + debug_print("addressbook_add_contact: name/address: %s <%s>\n", name ? name : "", address); if (addressadd_selection(_addressIndex_, name, address, remarks)) { debug_print("addressbook_add_contact - added\n"); addressbook_refresh(); @@ -4009,6 +4019,18 @@ gboolean addressbook_add_contact(const gchar *name, const gchar *address, const return TRUE; } +/* + * This function is used by the automatic address registration. + */ +gboolean addressbook_add_contact_autoreg(const gchar *name, const gchar *address, const gchar *remarks) +{ + debug_print("addressbook_add_contact_autoreg: name/address: %s <%s>\n", name ? name : "", address); + if (addressadd_autoreg(_addressIndex_, name, address, remarks)) { + addressbook_refresh(); + } + return TRUE; +} + /* ********************************************************************** * Address completion support. * *********************************************************************** diff --git a/src/addressbook.h b/src/addressbook.h index d3b8e7a7..70a51da4 100644 --- a/src/addressbook.h +++ b/src/addressbook.h @@ -40,9 +40,12 @@ gint addressbook_obj_name_compare (gconstpointer a, void addressbook_access (void); void addressbook_unaccess (void); -gboolean addressbook_add_contact ( const gchar *name, - const gchar *address, - const gchar *remarks ); +gboolean addressbook_add_contact (const gchar *name, + const gchar *address, + const gchar *remarks); +gboolean addressbook_add_contact_autoreg(const gchar *name, + const gchar *address, + const gchar *remarks); gboolean addressbook_load_completion ( gint (*callBackFunc) ( const gchar *, const gchar *, const gchar * ) ); diff --git a/src/addrindex.c b/src/addrindex.c index 62f1061d..6d47e2a8 100644 --- a/src/addrindex.c +++ b/src/addrindex.c @@ -1637,7 +1637,7 @@ static gboolean addrindex_create_new_book( AddressIndex *addrIndex, gchar *displ * addrIndex. Three files will be created, for the following: * "Common addresses" * "Personal addresses" -* "Gathered addresses" - a new address book. +* "Auto-registered" - a new address book. */ gint addrindex_read_data( AddressIndex *addrIndex ) { g_return_val_if_fail( addrIndex != NULL, -1 ); @@ -1666,7 +1666,7 @@ gint addrindex_read_data( AddressIndex *addrIndex ) { * addrIndex. Three files will be created, for the following: * "Common addresses" * "Personal addresses" -* "Gathered addresses" - a new address book. +* "Auto-registered" - a new address book. */ gint addrindex_create_new_books( AddressIndex *addrIndex ) { gboolean flg; @@ -1676,11 +1676,44 @@ gint addrindex_create_new_books( AddressIndex *addrIndex ) { flg = addrindex_create_new_book( addrIndex, DISP_NEW_COMMON ); if( flg ) { flg = addrindex_create_new_book( addrIndex, DISP_NEW_PERSONAL ); + flg = addrindex_create_new_book( addrIndex, ADDR_DS_AUTOREG ); addrIndex->dirtyFlag = TRUE; } return addrIndex->retVal; } +gint addrindex_create_extra_books( AddressIndex *addrIndex ) { + GList *node_ds; + AddressInterface *interface = NULL; + AddressDataSource *ds = NULL; + const gchar *ds_name; + + g_return_val_if_fail(addrIndex != NULL, -1); + + interface = addrindex_get_interface(addrIndex, ADDR_IF_BOOK); + if (!interface) + return -1; + + for (node_ds = interface->listSource; node_ds != NULL; + node_ds = node_ds->next) { + ds = node_ds->data; + ds_name = addrindex_ds_get_name(ds); + if (!ds_name) + continue; + if (!strcmp(ds_name, ADDR_DS_AUTOREG)) { + debug_print("%s found\n", ADDR_DS_AUTOREG); + return 0; + } + } + + debug_print("%s not found, creating new one\n", ADDR_DS_AUTOREG); + if (addrindex_create_new_book(addrIndex, ADDR_DS_AUTOREG)) { + addrIndex->dirtyFlag = TRUE; + } + + return addrIndex->retVal; +} + /* ********************************************************************** * New interface stuff. * *********************************************************************** diff --git a/src/addrindex.h b/src/addrindex.h index a31ed8e4..f998cbca 100644 --- a/src/addrindex.h +++ b/src/addrindex.h @@ -32,6 +32,8 @@ #define ADDRESSBOOK_INDEX_FILE "addrbook--index.xml" #define ADDRESSBOOK_OLD_FILE "addressbook.xml" +#define ADDR_DS_AUTOREG "@Auto-registered" + typedef enum { ADDR_IF_NONE, ADDR_IF_BOOK, @@ -108,6 +110,7 @@ gint addrindex_write_to ( AddressIndex *addrIndex, const gchar *newFile ); gint addrindex_save_data ( AddressIndex *addrIndex ); gint addrindex_create_new_books ( AddressIndex *addrIndex ); gint addrindex_save_all_books ( AddressIndex *addrIndex ); +gint addrindex_create_extra_books ( AddressIndex *addrIndex ); gboolean addrindex_ds_get_modify_flag ( AddressDataSource *ds ); gboolean addrindex_ds_get_access_flag ( AddressDataSource *ds ); diff --git a/src/compose.c b/src/compose.c index 3b528c19..e538b3f4 100644 --- a/src/compose.c +++ b/src/compose.c @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2009 Hiroyuki Yamamoto + * Copyright (C) 1999-2010 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -265,6 +265,9 @@ static gboolean compose_check_entries (Compose *compose); static gboolean compose_check_attachments (Compose *compose); static gboolean compose_check_recipients (Compose *compose); +static void compose_add_new_recipients_to_addressbook + (Compose *compose); + static gint compose_send (Compose *compose); static gint compose_write_to_file (Compose *compose, const gchar *file, @@ -3296,6 +3299,66 @@ static gboolean compose_check_recipients(Compose *compose) return FALSE; } +static void compose_add_new_recipients_to_addressbook(Compose *compose) +{ + GSList *to_list = NULL, *cur; + const gchar *text; + + if (compose->use_to) { + text = gtk_entry_get_text(GTK_ENTRY(compose->to_entry)); + to_list = address_list_append_orig(NULL, text); + } + if (compose->use_cc) { + text = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry)); + to_list = address_list_append_orig(to_list, text); + } + if (compose->use_bcc) { + text = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry)); + to_list = address_list_append_orig(to_list, text); + } + + for (cur = to_list; cur != NULL; cur = cur->next) { + gchar *orig_addr = cur->data; + gchar *name, *addr; + gchar *compaddr; + gint count, i; + gboolean found = FALSE; + + name = procheader_get_fromname(orig_addr); + addr = g_strdup(orig_addr); + extract_address(addr); + if (!g_ascii_strcasecmp(name, addr)) { + g_free(name); + name = NULL; + } + + count = complete_address(addr); + for (i = 1; i < count; i++) { + compaddr = get_complete_address(i); + if (compaddr) { + g_print("compaddr: %s\n", compaddr); + extract_address(compaddr); + if (!g_ascii_strcasecmp(addr, compaddr)) { + found = TRUE; + break; + } + } + } + clear_completion_cache(); + + if (found) + debug_print("compose_add_new_recipients_to_addressbook: address <%s> already registered.\n", addr); + else + addressbook_add_contact_autoreg(name, addr, NULL); + + g_free(addr); + g_free(name); + } + + slist_free_strings(to_list); + g_slist_free(to_list); +} + void compose_lock(Compose *compose) { compose->lock_count++; @@ -3443,6 +3506,11 @@ static gint compose_send(Compose *compose) folderview_update_item(outbox, TRUE); } } + + /* Add recipients to addressbook automatically */ + if (1) { + compose_add_new_recipients_to_addressbook(compose); + } } g_unlink(tmp); @@ -4233,6 +4301,11 @@ static gint compose_queue(Compose *compose, const gchar *file) folder_item_scan(queue); folderview_update_item(queue, TRUE); + /* Add recipients to addressbook automatically */ + if (1) { + compose_add_new_recipients_to_addressbook(compose); + } + main_window_set_menu_sensitive(main_window_get()); main_window_set_toolbar_sensitive(main_window_get()); |