Skip to content
Permalink
Browse files Browse the repository at this point in the history
quote imap strings more carefully
Co-authored-by: JerikoOne <jeriko.one@gmx.us>
  • Loading branch information
flatcap and jeriko-one committed Jul 5, 2018
1 parent 9bfab35 commit e523937
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions imap/auth_login.c
Expand Up @@ -65,8 +65,8 @@ enum ImapAuthRes imap_auth_login(struct ImapData *idata, const char *method)

mutt_message(_("Logging in..."));

imap_quote_string(q_user, sizeof(q_user), idata->conn->account.user);
imap_quote_string(q_pass, sizeof(q_pass), idata->conn->account.pass);
imap_quote_string(q_user, sizeof(q_user), idata->conn->account.user, false);
imap_quote_string(q_pass, sizeof(q_pass), idata->conn->account.pass, false);

/* don't print the password unless we're at the ungodly debugging level
* of 5 or higher */
Expand Down
2 changes: 1 addition & 1 deletion imap/command.c
Expand Up @@ -499,7 +499,7 @@ static void cmd_parse_lsub(struct ImapData *idata, char *s)
mutt_str_strfcpy(buf, "mailboxes \"", sizeof(buf));
mutt_account_tourl(&idata->conn->account, &url);
/* escape \ and " */
imap_quote_string(errstr, sizeof(errstr), list.name);
imap_quote_string(errstr, sizeof(errstr), list.name, true);
url.path = errstr + 1;
url.path[strlen(url.path) - 1] = '\0';
if (mutt_str_strcmp(url.user, ImapUser) == 0)
Expand Down
10 changes: 5 additions & 5 deletions imap/imap.c
Expand Up @@ -464,25 +464,25 @@ static int compile_search(struct Context *ctx, const struct Pattern *pat, struct
return -1;
}
*delim = '\0';
imap_quote_string(term, sizeof(term), pat->p.str);
imap_quote_string(term, sizeof(term), pat->p.str, false);
mutt_buffer_addstr(buf, term);
mutt_buffer_addch(buf, ' ');

/* and field */
*delim = ':';
delim++;
SKIPWS(delim);
imap_quote_string(term, sizeof(term), delim);
imap_quote_string(term, sizeof(term), delim, false);
mutt_buffer_addstr(buf, term);
break;
case MUTT_BODY:
mutt_buffer_addstr(buf, "BODY ");
imap_quote_string(term, sizeof(term), pat->p.str);
imap_quote_string(term, sizeof(term), pat->p.str, false);
mutt_buffer_addstr(buf, term);
break;
case MUTT_WHOLE_MSG:
mutt_buffer_addstr(buf, "TEXT ");
imap_quote_string(term, sizeof(term), pat->p.str);
imap_quote_string(term, sizeof(term), pat->p.str, false);
mutt_buffer_addstr(buf, term);
break;
case MUTT_SERVERSEARCH:
Expand All @@ -495,7 +495,7 @@ static int compile_search(struct Context *ctx, const struct Pattern *pat, struct
}
}
mutt_buffer_addstr(buf, "X-GM-RAW ");
imap_quote_string(term, sizeof(term), pat->p.str);
imap_quote_string(term, sizeof(term), pat->p.str, false);
mutt_buffer_addstr(buf, term);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion imap/imap_private.h
Expand Up @@ -328,7 +328,7 @@ char *imap_get_qualifier(char *buf);
int imap_mxcmp(const char *mx1, const char *mx2);
char *imap_next_word(char *s);
void imap_qualify_path(char *dest, size_t len, struct ImapMbox *mx, char *path);
void imap_quote_string(char *dest, size_t dlen, const char *src);
void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick);
void imap_unquote_string(char *s);
void imap_munge_mbox_name(struct ImapData *idata, char *dest, size_t dlen, const char *src);
void imap_unmunge_mbox_name(struct ImapData *idata, char *s);
Expand Down
9 changes: 6 additions & 3 deletions imap/util.c
Expand Up @@ -798,9 +798,12 @@ void imap_qualify_path(char *dest, size_t len, struct ImapMbox *mx, char *path)
*
* Surround string with quotes, escape " and \ with backslash
*/
void imap_quote_string(char *dest, size_t dlen, const char *src)
void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick)
{
static const char quote[] = "\"\\";
const char *quote = "`\"\\";
if (!quote_backtick)
quote++;

char *pt = dest;
const char *s = src;

Expand Down Expand Up @@ -874,7 +877,7 @@ void imap_munge_mbox_name(struct ImapData *idata, char *dest, size_t dlen, const
char *buf = mutt_str_strdup(src);
imap_utf_encode(idata, &buf);

imap_quote_string(dest, dlen, buf);
imap_quote_string(dest, dlen, buf, false);

FREE(&buf);
}
Expand Down

0 comments on commit e523937

Please sign in to comment.