[Commits] [SCM] claws branch, master, updated. 3.9.2-106-g21263f8
mones at claws-mail.org
mones at claws-mail.org
Tue Nov 5 01:03:59 CET 2013
The branch master of project "claws" (Claws Mail) has been updated
via 21263f83d92189a8048b9f86fa5479e0503bc864 (commit)
via ab9cadc4a4ea4875fec8a2d4651440780a7922d5 (commit)
from 6c24a52c96905f126c45a30805eb2a277cdc91b6 (commit)
- Log -----------------------------------------------------------------
commit 21263f83d92189a8048b9f86fa5479e0503bc864
Author: Ricardo Mones <ricardo at mones.org>
Date: Tue Nov 5 00:56:11 2013 +0100
Fix bug #2964 'Lack of escaping of nested double-quotes in To: header'
Additionally double quotes are also escaped in other relevant headers.
diff --git a/src/compose.c b/src/compose.c
index c27f6bf..48170ae 100644
--- a/src/compose.c
+++ b/src/compose.c
@@ -4737,7 +4737,7 @@ compose_current_mail_account(void)
#define QUOTE_IF_REQUIRED(out, str) \
{ \
- if (*str != '"' && strpbrk(str, ",.:;[]<>()@\\")) { \
+ if (*str != '"' && strpbrk(str, ",.:;[]<>()@\\\"")) { \
gchar *__tmp; \
gint len; \
\
@@ -4765,7 +4765,7 @@ compose_current_mail_account(void)
#define QUOTE_IF_REQUIRED_NORMAL(out, str, errret) \
{ \
- if (*str != '"' && strpbrk(str, ",.:;[]<>()@\\")) { \
+ if (*str != '"' && strpbrk(str, ",.:;[]<>()@\\\"")) { \
gchar *__tmp; \
gint len; \
\
@@ -4802,10 +4802,13 @@ static void compose_select_account(Compose *compose, PrefsAccount *account,
compose->account = account;
if (account->name && *account->name) {
- gchar *buf;
+ gchar *buf, *qbuf;
QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
+ qbuf = escape_internal_quotes(buf, '"');
from = g_strdup_printf("%s <%s>",
- buf, account->address);
+ qbuf, account->address);
+ if (qbuf != buf)
+ g_free(qbuf);
gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
} else {
from = g_strdup_printf("<%s>",
@@ -6143,12 +6146,14 @@ static gchar *compose_quote_list_of_addresses(gchar *str)
gchar *spec = item->data;
gchar *endofname = strstr(spec, " <");
if (endofname != NULL) {
+ gchar * qqname;
*endofname = '\0';
QUOTE_IF_REQUIRED_NORMAL(qname, spec, return NULL);
+ qqname = escape_internal_quotes(qname, '"');
*endofname = ' ';
- if (*qname != *spec) { /* has been quoted, compute new */
+ if (*qname != *spec || qqname != qname) { /* has been quoted, compute new */
gchar *addr = g_strdup(endofname);
- gchar *name = g_strdup(qname);
+ gchar *name = (qqname != qname)? qqname: g_strdup(qname);
faddr = g_strconcat(name, addr, NULL);
g_free(name);
g_free(addr);
@@ -6339,13 +6344,17 @@ static gchar *compose_get_header(Compose *compose)
if (from_name && *from_name) {
+ gchar *qname;
compose_convert_header
(compose, buf, sizeof(buf), from_name,
strlen("From: "), TRUE);
QUOTE_IF_REQUIRED(name, buf);
+ qname = escape_internal_quotes(name, '"');
g_string_append_printf(header, "From: %s <%s>\n",
- name, from_address);
+ qname, from_address);
+ if (qname != name)
+ g_free(qname);
} else
g_string_append_printf(header, "From: %s\n", from_address);
commit ab9cadc4a4ea4875fec8a2d4651440780a7922d5
Author: Ricardo Mones <ricardo at mones.org>
Date: Tue Nov 5 00:55:10 2013 +0100
New utils function escape_internal_quotes
Searchs for all quotation characters within a string, creating
(only if required) a copy with the quotation characters escaped.
diff --git a/src/common/utils.c b/src/common/utils.c
index 53a9ddb..fb4ba75 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -810,6 +810,47 @@ void extract_quote(gchar *str, gchar quote_chr)
}
}
+/* Returns a newly allocated string with all quote_chr not at the beginning
+ or the end of str escaped with '\' or the given str if not required. */
+gchar *escape_internal_quotes(gchar *str, gchar quote_chr)
+{
+ register gchar *p, *q;
+ gchar *qstr;
+ int k = 0, l = 0;
+
+ if (str == NULL || *str == '\0')
+ return str;
+
+ /* search for unescaped quote_chr */
+ p = str;
+ if (*p == quote_chr)
+ ++p, ++l;
+ while (*p) {
+ if (*p == quote_chr && *(p - 1) != '\\' && *(p + 1) != '\0')
+ ++k;
+ ++p, ++l;
+ }
+ if (!k) /* nothing to escape */
+ return str;
+
+ /* unescaped quote_chr found */
+ qstr = g_malloc(l + k + 1);
+ p = str;
+ q = qstr;
+ if (*p == quote_chr) {
+ *q = quote_chr;
+ ++p, ++q;
+ }
+ while (*p) {
+ if (*p == quote_chr && *(p - 1) != '\\' && *(p + 1) != '\0')
+ *q++ = '\\';
+ *q++ = *p++;
+ }
+ *q = '\0';
+
+ return qstr;
+}
+
void eliminate_address_comment(gchar *str)
{
register gchar *srcp, *destp;
diff --git a/src/common/utils.h b/src/common/utils.h
index b613499..8766ff2 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -338,6 +338,8 @@ void extract_parenthesis (gchar *str,
void extract_quote (gchar *str,
gchar quote_chr);
+gchar *escape_internal_quotes (gchar *str,
+ gchar quote_chr);
void eliminate_address_comment (gchar *str);
gchar *strchr_with_skip_quote (const gchar *str,
gint quote_chr,
-----------------------------------------------------------------------
Summary of changes:
src/common/utils.c | 41 +++++++++++++++++++++++++++++++++++++++++
src/common/utils.h | 2 ++
src/compose.c | 23 ++++++++++++++++-------
3 files changed, 59 insertions(+), 7 deletions(-)
hooks/post-receive
--
Claws Mail
More information about the Commits
mailing list