aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/imap/camel-imap-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'camel/providers/imap/camel-imap-utils.c')
-rw-r--r--camel/providers/imap/camel-imap-utils.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/camel/providers/imap/camel-imap-utils.c b/camel/providers/imap/camel-imap-utils.c
index 0b947e07da..05c9d01d5e 100644
--- a/camel/providers/imap/camel-imap-utils.c
+++ b/camel/providers/imap/camel-imap-utils.c
@@ -687,3 +687,38 @@ imap_parse_astring (char **str_p, int *len)
*str_p += *len;
return p;
}
+
+/**
+ * imap_quote_string:
+ * @str: the string to quote, which must not contain CR or LF
+ *
+ * Return value: an IMAP "quoted" corresponding to the string, which
+ * the caller must free.
+ **/
+char *
+imap_quote_string (const char *str)
+{
+ const char *p;
+ char *quoted, *q;
+ int len;
+
+ len = strlen (str);
+ p = str;
+ while ((p = strpbrk (p, "\"\\"))) {
+ len++;
+ p++;
+ }
+
+ quoted = q = g_malloc (len + 3);
+ *q++ = '"';
+ while ((p = strpbrk (str, "\"\\"))) {
+ memcpy (q, str, p - str);
+ q += p - str;
+ *q++ = '\\';
+ *q++ = *p++;
+ str = p;
+ }
+ sprintf (q, "%s\"", str);
+
+ return quoted;
+}