bool C_MailcapSanitize; ///< Config: Restrict the possible characters in mailcap expandos
/**
- * rfc1524_expand_command - Expand expandos in a command
+ * mutt_buffer_rfc1524_expand_command - Expand expandos in a command
* @param a Email Body
* @param filename File containing the email text
* @param type Type, e.g. "text/plain"
* @param command Buffer containing command
- * @param clen Length of buffer
* @retval 0 Command works on a file
* @retval 1 Command works on a pipe
*
* %n is the integer number of sub-parts in the multipart
* %F is "content-type filename" repeated for each sub-part
*/
-int rfc1524_expand_command(struct Body *a, const char *filename,
- const char *type, char *command, int clen)
+int mutt_buffer_rfc1524_expand_command(struct Body *a, const char *filename,
+ const char *type, struct Buffer *command)
{
- int x = 0;
int needspipe = true;
- char type2[1024];
struct Buffer *buf = mutt_buffer_pool_get();
struct Buffer *quoted = mutt_buffer_pool_get();
+ struct Buffer *param = NULL;
+ struct Buffer *type2 = NULL;
- mutt_str_strfcpy(type2, type, sizeof(type2));
-
- if (C_MailcapSanitize)
- mutt_file_sanitize_filename(type2, false);
-
- while ((x < clen - 1) && command[x])
+ const char *cptr = mutt_b2s(command);
+ while (*cptr)
{
- if (command[x] == '\\')
+ if (*cptr == '\\')
{
- x++;
- mutt_buffer_addch(buf, command[x++]);
+ cptr++;
+ if (*cptr)
+ mutt_buffer_addch(buf, *cptr++);
}
- else if (command[x] == '%')
+ else if (*cptr == '%')
{
- x++;
- if (command[x] == '{')
+ cptr++;
+ if (*cptr == '{')
{
- char param[256];
- char pvalue[256];
- char *pvalue2 = NULL;
- int z = 0;
+ const char *pvalue2 = NULL;
+
+ if (!param)
+ param = mutt_buffer_pool_get();
+ else
+ mutt_buffer_reset(param);
- x++;
- while (command[x] && (command[x] != '}') && (z < sizeof(param) - 1))
- param[z++] = command[x++];
- param[z] = '\0';
+ /* Copy parameter name into param buffer */
+ cptr++;
+ while (*cptr && (*cptr != '}'))
+ mutt_buffer_addch(param, *cptr++);
/* In send mode, use the current charset, since the message hasn't
* been converted yet. If noconv is set, then we assume the
* charset parameter has the correct value instead. */
- if ((mutt_str_strcasecmp(param, "charset") == 0) && a->charset && !a->noconv)
+ if ((mutt_str_strcasecmp(mutt_b2s(param), "charset") == 0) && a->charset && !a->noconv)
pvalue2 = a->charset;
else
- pvalue2 = mutt_param_get(&a->parameter, param);
- mutt_str_strfcpy(pvalue, pvalue2, sizeof(pvalue));
+ pvalue2 = mutt_param_get(&a->parameter, mutt_b2s(param));
+
+ /* Now copy the parameter value into param buffer */
if (C_MailcapSanitize)
- mutt_file_sanitize_filename(pvalue, false);
+ mutt_buffer_sanitize_filename(param, NONULL(pvalue2), false);
+ else
+ mutt_buffer_strcpy(param, NONULL(pvalue2));
- mutt_buffer_quote_filename(quoted, pvalue, true);
+ mutt_buffer_quote_filename(quoted, mutt_b2s(param), true);
mutt_buffer_addstr(buf, mutt_b2s(quoted));
}
- else if ((command[x] == 's') && filename)
+ else if ((*cptr == 's') && filename)
{
mutt_buffer_quote_filename(quoted, filename, true);
mutt_buffer_addstr(buf, mutt_b2s(quoted));
needspipe = false;
}
- else if (command[x] == 't')
+ else if (*cptr == 't')
{
- mutt_buffer_quote_filename(quoted, type, true);
+ if (!type2)
+ {
+ type2 = mutt_buffer_pool_get();
+ if (C_MailcapSanitize)
+ mutt_buffer_sanitize_filename(type2, type, false);
+ else
+ mutt_buffer_strcpy(type2, type);
+ }
+ mutt_buffer_quote_filename(quoted, mutt_b2s(type2), true);
mutt_buffer_addstr(buf, mutt_b2s(quoted));
}
- x++;
+
+ if (*cptr)
+ cptr++;
}
else
- mutt_buffer_addch(buf, command[x++]);
+ mutt_buffer_addch(buf, *cptr++);
}
- mutt_str_strfcpy(command, mutt_b2s(buf), clen);
+ mutt_buffer_strcpy(command, mutt_b2s(buf));
mutt_buffer_pool_release(&buf);
mutt_buffer_pool_release("ed);
+ mutt_buffer_pool_release(¶m);
+ mutt_buffer_pool_release(&type2);
return needspipe;
}
-/**
- * mutt_buffer_rfc1524_expand_command - Expand expandos in a command
- * @param a Email Body
- * @param filename File containing the email text
- * @param type Type, e.g. "text/plain"
- * @param command Buffer containing command
- * @retval 0 Command works on a file
- * @retval 1 Command works on a pipe
- */
-int mutt_buffer_rfc1524_expand_command(struct Body *a, const char *filename,
- const char *type, struct Buffer *command)
-{
- mutt_buffer_increase_size(command, PATH_MAX);
- int rc = rfc1524_expand_command(a, filename, type, command->data, command->dsize);
- mutt_buffer_fix_dptr(command);
-
- return rc;
-}
-
/**
* get_field - NUL terminate a RFC1524 field
* @param s String to alter