mutt_debug(2, "nm_uri_from_query (%s)\n", buf);
struct NmCtxData *data = get_ctxdata(ctx);
char uri[_POSIX_PATH_MAX + LONG_STRING + 32]; /* path to DB + query + URI "decoration" */
+ int added;
if (data)
- snprintf(uri, sizeof(uri), "notmuch://%s?query=%s", get_db_filename(data), buf);
+ added = snprintf(uri, sizeof(uri), "notmuch://%s?query=", get_db_filename(data));
else if (NotmuchDefaultUri)
- snprintf(uri, sizeof(uri), "%s?query=%s", NotmuchDefaultUri, buf);
+ added = snprintf(uri, sizeof(uri), "%s?query=", NotmuchDefaultUri);
else if (Maildir)
- snprintf(uri, sizeof(uri), "notmuch://%s?query=%s", Maildir, buf);
+ added = snprintf(uri, sizeof(uri), "notmuch://%s?query=", Maildir);
else
return NULL;
+ if (added >= sizeof(uri))
+ {
+ // snprintf output was truncated, so can't create URI
+ return NULL;
+ }
+
+ url_pct_encode(&uri[added], sizeof(uri) - added, buf);
+
strncpy(buf, uri, bufsz);
buf[bufsz - 1] = '\0';
return ciss_parse_userhost(ciss, tmp);
}
-static void url_pct_encode(char *dst, size_t l, const char *src)
+void url_pct_encode(char *dst, size_t l, const char *src)
{
static const char *alph = "0123456789ABCDEF";
l--;
while (src && *src && l)
{
- if (strchr("/:%", *src) && l > 3)
+ if (strchr("/:&%", *src) && l > 3)
{
*dst++ = '%';
*dst++ = alph[(*src >> 4) & 0xf];
int url_ciss_tostring(struct CissUrl *ciss, char *dest, size_t len, int flags);
int url_parse_mailto(struct Envelope *e, char **body, const char *src);
int url_pct_decode(char *s);
+void url_pct_encode(char *dest, size_t len, const char *src);
#endif /* _MUTT_URL_H */