#include "addressbook.h"
#include "main.h"
-#define LOG_MESSAGE \
- debug_mode == 0 ? (debug_mode == debug_mode) : debug_print
-
/* How it works:
*
* The address book is read into memory. We set up an address list
g_completion_add_items(g_completion, g_completion_list);
}
g_ref_count++;
- LOG_MESSAGE("start_address_completion ref count %d\n", g_ref_count);
+ debug_print("start_address_completion ref count %d\n", g_ref_count);
return g_list_length(g_completion_list);
}
wchar_t *wtext;
wchar_t *wp;
wchar_t rfc_mail_sep;
+ wchar_t quote;
+ wchar_t lt;
+ gboolean in_quote = FALSE;
gchar *str;
+ if (mbtowc(&rfc_mail_sep, ",", 1) < 0) return NULL;
+ if (mbtowc("e, "\"", 1) < 0) return NULL;
+ if (mbtowc(<, "<", 1) < 0) return NULL;
+
edit_text = gtk_entry_get_text(entry);
if (edit_text == NULL) return NULL;
cur_pos = gtk_editable_get_position(GTK_EDITABLE(entry));
- if (mbtowc(&rfc_mail_sep, ",", 1) < 0) {
- g_free(wtext);
- return NULL;
- }
-
/* scan for a separator. doesn't matter if walk points at null byte. */
- for (wp = wtext + cur_pos; wp > wtext && *wp != rfc_mail_sep; wp--)
- ;
+ for (wp = wtext + cur_pos; wp > wtext; wp--) {
+ if (!in_quote && *wp == rfc_mail_sep)
+ break;
+ if (*wp == quote)
+ in_quote ^= TRUE;
+ }
/* have something valid */
if (wcslen(wp) == 0) {
return NULL;
}
-#define IS_VALID_CHAR(x) (iswalnum(x) || ((x) > 0x7f))
+#define IS_VALID_CHAR(x) \
+ (iswalnum(x) || (x) == quote || (x) == lt || ((x) > 0x7f))
/* now scan back until we hit a valid character */
for (; *wp && !IS_VALID_CHAR(*wp); wp++)
gchar *get_complete_address(gint index)
{
const address_entry *p;
-
+ gchar *address = NULL;
+
if (index < g_completion_count) {
if (index == 0)
- return g_strdup(g_completion_prefix);
+ address = g_strdup(g_completion_prefix);
else {
/* get something from the unique addresses */
p = (address_entry *)g_slist_nth_data
(g_completion_addresses, index - 1);
- if (p == NULL)
- return NULL;
- else
- return g_strdup_printf
- ("%s <%s>", p->name, p->address);
+ if (p != NULL) {
+ if (!p->name || p->name[0] == '\0')
+ address = g_strdup_printf(p->address);
+ else if (strchr_with_skip_quote(p->name, '"', ','))
+ address = g_strdup_printf
+ ("\"%s\" <%s>", p->name, p->address);
+ else
+ address = g_strdup_printf
+ ("%s <%s>", p->name, p->address);
+ }
}
- } else
- return NULL;
+ }
+
+ return address;
}
gchar *get_next_complete_address(void)
{
if (g_ref_count) {
/* simply the same as start_address_completion() */
- LOG_MESSAGE("Invalidation request for address completion\n");
+ debug_print("Invalidation request for address completion\n");
free_all();
init_all();
read_address_book();
if (0 == --g_ref_count)
free_all();
- LOG_MESSAGE("end_address_completion ref count %d\n", g_ref_count);
+ debug_print("end_address_completion ref count %d\n", g_ref_count);
return g_ref_count;
}