diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ChangeLog.ja | 6 | ||||
-rw-r--r-- | libsylph/utils.c | 80 | ||||
-rw-r--r-- | libsylph/utils.h | 4 | ||||
-rw-r--r-- | src/compose.c | 17 |
5 files changed, 108 insertions, 4 deletions
@@ -1,3 +1,8 @@ +2005-09-14 + + * libsylph/utils.[ch] + src/compose.c: normalize address fields before encoding them. + 2005-09-13 * Makefile.am diff --git a/ChangeLog.ja b/ChangeLog.ja index 74ad375d..f2aaca85 100644 --- a/ChangeLog.ja +++ b/ChangeLog.ja @@ -1,3 +1,9 @@ +2005-09-14 + + * libsylph/utils.[ch] + src/compose.c: アドレスフィールドをエンコードする前に正規化する + ようにした。 + 2005-09-13 * Makefile.am diff --git a/libsylph/utils.c b/libsylph/utils.c index c0c6edff..09632f64 100644 --- a/libsylph/utils.c +++ b/libsylph/utils.c @@ -958,6 +958,86 @@ void extract_list_id_str(gchar *str) g_strstrip(str); } +gchar *normalize_address_field(const gchar *str) +{ + GString *new_str; + GSList *addr_list, *cur; + gchar *addr, *p, *q, *r; + gchar *ret_str; + + addr_list = address_list_append_orig(NULL, str); + + new_str = g_string_new(NULL); + + for (cur = addr_list; cur != NULL; cur = cur->next) { + p = addr = (gchar *)cur->data; + q = strchr_with_skip_quote(p, '"', '<'); + if (q && q > p) { + r = q - 1; + while (r > p && g_ascii_isspace(*r)) + --r; + g_string_append_len(new_str, p, r - p + 1); + g_string_append_c(new_str, ' '); + p = q; + } + if (*p == '<') { + q = strchr(p, '>'); + if (q) { + r = q + 1; + if (*r) { + while (g_ascii_isspace(*r)) + ++r; + g_string_append(new_str, r); + if (new_str->len > 0 && + !g_ascii_isspace + (new_str->str[new_str->len - 1])) + g_string_append_c(new_str, ' '); + } + g_string_append_len(new_str, p, q - p + 1); + } else { + g_string_append(new_str, p); + g_string_append_c(new_str, '>'); + } + } else + g_string_append(new_str, p); + + if (cur->next) + g_string_append(new_str, ", "); + } + + slist_free_strings(addr_list); + ret_str = new_str->str; + g_string_free(new_str, FALSE); + + return ret_str; +} + +GSList *address_list_append_orig(GSList *addr_list, const gchar *str) +{ + const gchar *p = str, *q; + gchar *addr; + + if (!str) return addr_list; + + while (*p) { + if (*p == ',' || g_ascii_isspace(*p)) { + ++p; + } else if ((q = strchr_with_skip_quote(p, '"', ','))) { + addr = g_strndup(p, q - p); + g_strstrip(addr); + addr_list = g_slist_append(addr_list, addr); + p = q + 1; + } else { + addr = g_strdup(p); + g_strstrip(addr); + addr_list = g_slist_append(addr_list, addr); + break; + } + } + + return addr_list; +} + GSList *address_list_append(GSList *addr_list, const gchar *str) { gchar *work; diff --git a/libsylph/utils.h b/libsylph/utils.h index 18b511f1..7301c59b 100644 --- a/libsylph/utils.h +++ b/libsylph/utils.h @@ -310,6 +310,10 @@ gchar *strrchr_with_skip_quote (const gchar *str, void extract_address (gchar *str); void extract_list_id_str (gchar *str); +gchar *normalize_address_field (const gchar *str); + +GSList *address_list_append_orig (GSList *addr_list, + const gchar *str); GSList *address_list_append (GSList *addr_list, const gchar *str); GSList *references_list_prepend (GSList *msgid_list, diff --git a/src/compose.c b/src/compose.c index a2e8e2ff..6a184c7d 100644 --- a/src/compose.c +++ b/src/compose.c @@ -255,7 +255,7 @@ static gint compose_redirect_write_headers (Compose *compose, static void compose_convert_header (Compose *compose, gchar *dest, gint len, - gchar *src, + const gchar *src, gint header_len, gboolean addr_field, const gchar *encoding); @@ -3754,18 +3754,27 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp) #undef IS_IN_CUSTOM_HEADER static void compose_convert_header(Compose *compose, gchar *dest, gint len, - gchar *src, gint header_len, + const gchar *src, gint header_len, gboolean addr_field, const gchar *encoding) { + gchar *src_; + g_return_if_fail(src != NULL); g_return_if_fail(dest != NULL); if (len < 1) return; - g_strchomp(src); + if (addr_field) + src_ = normalize_address_field(src); + else + src_ = g_strdup(src); + g_strchomp(src_); if (!encoding) encoding = conv_get_charset_str(compose->out_encoding); - conv_encode_header(dest, len, src, header_len, addr_field, encoding); + + conv_encode_header(dest, len, src_, header_len, addr_field, encoding); + + g_free(src_); } static void compose_generate_msgid(Compose *compose, gchar *buf, gint len) |