aboutsummaryrefslogtreecommitdiff
path: root/libsylph/imap.c
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2013-03-26 08:38:31 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2013-03-26 08:38:31 +0000
commitefbaaa3bac7a8918861f9803b7933efa56ef0532 (patch)
treea4c9e2af1f2851e0266176b4222840540538b447 /libsylph/imap.c
parent95c2d951daae088d33526c0a18abba48aa3a6d91 (diff)
properly escape folder/username/password which include double-quote or backslash.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@3235 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph/imap.c')
-rw-r--r--libsylph/imap.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/libsylph/imap.c b/libsylph/imap.c
index 8750b27c..f844ba57 100644
--- a/libsylph/imap.c
+++ b/libsylph/imap.c
@@ -1,6 +1,6 @@
/*
* LibSylph -- E-Mail client library
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2013 Hiroyuki Yamamoto
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -63,13 +63,25 @@
#define QUOTE_IF_REQUIRED(out, str) \
{ \
- if (*str != '"' && strpbrk(str, " \t(){}[]%&*") != NULL) { \
+ if (!str || *str == '\0') { \
+ Xstrdup_a(out, "\"\"", return IMAP_ERROR); \
+ } else if (strpbrk(str, " \t(){}[]%&*\"\\") != NULL) { \
gchar *__tmp; \
gint len; \
+ const gchar *p; \
+ gchar *tp; \
\
- len = strlen(str) + 3; \
+ len = strlen(str) * 2 + 3; \
Xalloca(__tmp, len, return IMAP_ERROR); \
- g_snprintf(__tmp, len, "\"%s\"", str); \
+ tp = __tmp; \
+ *tp++ = '\"'; \
+ for (p = str; *p != '\0'; p++) { \
+ if (*p == '\"' || *p == '\\') \
+ *tp++ = '\\'; \
+ *tp++ = *p; \
+ } \
+ *tp++ = '\"'; \
+ *tp = '\0'; \
out = __tmp; \
} else { \
Xstrdup_a(out, str, return IMAP_ERROR); \
@@ -3984,8 +3996,8 @@ static gint imap_cmd_list(IMAPSession *session, const gchar *ref,
{
gchar *ref_, *mailbox_;
- if (!ref) ref = "\"\"";
- if (!mailbox) mailbox = "\"\"";
+ if (!ref) ref = "";
+ if (!mailbox) mailbox = "";
QUOTE_IF_REQUIRED(ref_, ref);
QUOTE_IF_REQUIRED(mailbox_, mailbox);