#ifdef USE_NNTP
MUTT_NEWSGROUPS, ///< Pattern matches newsgroup
#endif
-
- MUTT_SAVE_APPEND, ///< Append to existing file - mutt_save_attachment()
- MUTT_SAVE_OVERWRITE, ///< Overwrite existing file - mutt_save_attachment()
};
/* flags for parse_spam_list */
{
/* recv case: we need to save the attachment to a file */
FREE(&fname);
- if (mutt_save_attachment(fp, a, tempfile, 0, NULL) == -1)
+ if (mutt_save_attachment(fp, a, tempfile, MUTT_SAVE_NO_FLAGS, NULL) == -1)
goto return_error;
mutt_file_chmod(tempfile, S_IRUSR);
}
* mutt_decode_attachment() since it assumes the content-encoding has
* already been applied
*/
- if (mutt_save_attachment(fp, a, pagerfile, 0, NULL))
+ if (mutt_save_attachment(fp, a, pagerfile, MUTT_SAVE_NO_FLAGS, NULL))
goto return_error;
}
}
/* Use built-in handler */
OptViewAttach = true; /* disable the "use 'v' to view this part"
* message in case of error */
- if (mutt_decode_save_attachment(fp, a, pagerfile, MUTT_DISPLAY, 0))
+ if (mutt_decode_save_attachment(fp, a, pagerfile, MUTT_DISPLAY, MUTT_SAVE_NO_FLAGS))
{
OptViewAttach = false;
goto return_error;
/**
* save_attachment_open - Open a file to write an attachment to
- * @param path Path to file to open
- * @param flags Flags, e.g. #MUTT_SAVE_APPEND
+ * @param path Path to file to open
+ * @param opt Save option, see #SaveAttach
* @retval ptr File handle to attachment file
*/
-static FILE *save_attachment_open(char *path, int flags)
+static FILE *save_attachment_open(char *path, enum SaveAttach opt)
{
- if (flags == MUTT_SAVE_APPEND)
+ if (opt == MUTT_SAVE_APPEND)
return fopen(path, "a");
- if (flags == MUTT_SAVE_OVERWRITE)
+ if (opt == MUTT_SAVE_OVERWRITE)
return fopen(path, "w");
return mutt_file_fopen(path, "w");
/**
* mutt_save_attachment - Save an attachment
- * @param fp Source file stream. Can be NULL
- * @param m Email Body
- * @param path Where to save the attachment
- * @param flags Flags, e.g. #MUTT_SAVE_APPEND
- * @param e Current Email. Can be NULL
+ * @param fp Source file stream. Can be NULL
+ * @param m Email Body
+ * @param path Where to save the attachment
+ * @param opt Save option, see #SaveAttach
+ * @param e Current Email. Can be NULL
* @retval 0 Success
* @retval -1 Error
*/
-int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct Email *e)
+int mutt_save_attachment(FILE *fp, struct Body *m, char *path,
+ enum SaveAttach opt, struct Email *e)
{
if (!m)
return -1;
struct State s = { 0 };
- s.fp_out = save_attachment_open(path, flags);
+ s.fp_out = save_attachment_open(path, opt);
if (!s.fp_out)
{
mutt_perror("fopen");
return -1;
}
- FILE *fp_new = save_attachment_open(path, flags);
+ FILE *fp_new = save_attachment_open(path, opt);
if (!fp_new)
{
mutt_perror("fopen");
* @param m Attachment
* @param path Path to save the Attachment to
* @param displaying Flags, e.g. #MUTT_DISPLAY
- * @param flags Flags, e.g. #MUTT_SAVE_APPEND
+ * @param opt Save option, see #SaveAttach
* @retval 0 Success
* @retval -1 Error
*/
-int mutt_decode_save_attachment(FILE *fp, struct Body *m, char *path, int displaying, int flags)
+int mutt_decode_save_attachment(FILE *fp, struct Body *m, char *path,
+ int displaying, enum SaveAttach opt)
{
struct State s = { 0 };
unsigned int saved_encoding = 0;
s.flags = displaying;
- if (flags == MUTT_SAVE_APPEND)
+ if (opt == MUTT_SAVE_APPEND)
s.fp_out = fopen(path, "a");
- else if (flags == MUTT_SAVE_OVERWRITE)
+ else if (opt == MUTT_SAVE_OVERWRITE)
s.fp_out = fopen(path, "w");
else
s.fp_out = mutt_file_fopen(path, "w");
}
/* in recv mode, save file to newfile first */
- if (fp && (mutt_save_attachment(fp, a, newfile, 0, NULL) != 0))
+ if (fp && (mutt_save_attachment(fp, a, newfile, MUTT_SAVE_NO_FLAGS, NULL) != 0))
return 0;
mutt_str_strfcpy(cmd, entry->printcommand, sizeof(cmd));
fp_out = NULL;
mutt_mktemp(newfile, sizeof(newfile));
- if (mutt_decode_save_attachment(fp, a, newfile, MUTT_PRINTING, 0) == 0)
+ if (mutt_decode_save_attachment(fp, a, newfile, MUTT_PRINTING, MUTT_SAVE_NO_FLAGS) == 0)
{
mutt_debug(LL_DEBUG2, "successfully decoded %s type attachment to %s\n", type, newfile);
MUTT_VA_AS_TEXT, ///< Force viewing as text
};
+/**
+ * enum SaveAttach - Options for saving attachments
+ *
+ * @sa mutt_save_attachment(), mutt_decode_save_attachment(),
+ * save_attachment_open(), mutt_check_overwrite()
+ */
+enum SaveAttach
+{
+ MUTT_SAVE_NO_FLAGS = 0, ///< No flags set
+ MUTT_SAVE_APPEND, ///< Append to existing file
+ MUTT_SAVE_OVERWRITE, ///< Overwrite existing file
+};
+
int attach_tag(struct Menu *menu, int sel, int act);
int mutt_attach_display_loop(struct Menu *menu, int op, struct Email *e,
struct AttachCtx *actx, bool recv);
void mutt_check_lookup_list(struct Body *b, char *type, size_t len);
int mutt_compose_attachment(struct Body *a);
-int mutt_decode_save_attachment(FILE *fp, struct Body *m, char *path, int displaying, int flags);
+int mutt_decode_save_attachment(FILE *fp, struct Body *m, char *path, int displaying, enum SaveAttach opt);
int mutt_edit_attachment(struct Body *a);
int mutt_get_tmp_attachment(struct Body *a);
int mutt_pipe_attachment(FILE *fp, struct Body *b, const char *path, char *outfile);
int mutt_print_attachment(FILE *fp, struct Body *a);
-int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct Email *e);
+int mutt_save_attachment(FILE *fp, struct Body *m, char *path, enum SaveAttach opt, struct Email *e);
/* small helper functions to handle temporary attachment files */
void mutt_add_temp_attachment(char *filename);
}
mutt_adv_mktemp(tmp, sizeof(tmp));
- if (mutt_save_attachment(fp, src, tmp, 0, NULL) == -1)
+ if (mutt_save_attachment(fp, src, tmp, MUTT_SAVE_NO_FLAGS, NULL) == -1)
return -1;
*tgt = mutt_body_new();
* @param[in] path Path to save the file
* @param[out] fname Buffer for filename
* @param[out] flen Length of buffer
- * @param[out] append Flags set to #MUTT_SAVE_APPEND or #MUTT_SAVE_OVERWRITE
+ * @param[out] opt Save option, see #SaveAttach
* @param[out] directory Directory to save under (OPTIONAL)
* @retval 0 Success
* @retval -1 Abort
* @retval 1 Error
*/
int mutt_check_overwrite(const char *attname, const char *path, char *fname,
- size_t flen, int *append, char **directory)
+ size_t flen, enum SaveAttach *opt, char **directory)
{
struct stat st;
mutt_path_concat(fname, path, tmp, flen);
}
- if (*append == 0 && access(fname, F_OK) == 0)
+ if ((*opt == MUTT_SAVE_NO_FLAGS) && access(fname, F_OK) == 0)
{
switch (
mutt_multi_choice(_("File exists, (o)verwrite, (a)ppend, or (c)ancel?"),
return 1;
case 2: /* append */
- *append = MUTT_SAVE_APPEND;
+ *opt = MUTT_SAVE_APPEND;
break;
case 1: /* overwrite */
- *append = MUTT_SAVE_OVERWRITE;
+ *opt = MUTT_SAVE_OVERWRITE;
break;
}
}
#include <stdio.h>
#include "mutt.h"
#include "format_flags.h"
+#include "mutt_attach.h"
struct Address;
struct Body;
void mutt_adv_mktemp(char *s, size_t l);
void mutt_buffer_adv_mktemp (struct Buffer *buf);
void mutt_buffer_mktemp_full(struct Buffer *buf, const char *prefix, const char *suffix, const char *src, int line);
-int mutt_check_overwrite(const char *attname, const char *path, char *fname, size_t flen, int *append, char **directory);
+int mutt_check_overwrite(const char *attname, const char *path, char *fname, size_t flen, enum SaveAttach *opt, char **directory);
void mutt_encode_path(char *dest, size_t dlen, const char *src);
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, MuttFormatFlags flags);
char * mutt_expand_path(char *s, size_t slen);
return 0;
mutt_mktemp(tempfile, sizeof(tempfile));
- if (mutt_decode_save_attachment(fp, b, tempfile, 0, 0) != 0)
+ if (mutt_decode_save_attachment(fp, b, tempfile, 0, MUTT_SAVE_NO_FLAGS) != 0)
{
unlink(tempfile);
return 0;
return 0;
mutt_mktemp(tempfile, sizeof(tempfile));
- if (mutt_decode_save_attachment(fp, b, tempfile, 0, 0) != 0)
+ if (mutt_decode_save_attachment(fp, b, tempfile, 0, MUTT_SAVE_NO_FLAGS) != 0)
{
unlink(tempfile);
return 0;
{
char *prompt = NULL;
char buf[PATH_MAX], tfile[PATH_MAX];
- int append = 0;
+ enum SaveAttach opt = MUTT_SAVE_NO_FLAGS;
int rc;
if (body->filename)
}
else
{
- rc = mutt_check_overwrite(body->filename, buf, tfile, sizeof(tfile), &append, directory);
+ rc = mutt_check_overwrite(body->filename, buf, tfile, sizeof(tfile), &opt, directory);
if (rc == -1)
return -1;
else if (rc == 1)
}
mutt_message(_("Saving..."));
- if (mutt_save_attachment(fp, body, tfile, append, (e || !is_message) ? e : body->email) == 0)
+ if (mutt_save_attachment(fp, body, tfile, opt, (e || !is_message) ? e : body->email) == 0)
{
mutt_message(_("Attachment saved"));
return 0;
{
if (!buf[0])
{
- int append = 0;
+ enum SaveAttach opt = MUTT_SAVE_NO_FLAGS;
mutt_str_strfcpy(buf, mutt_path_basename(NONULL(top->filename)), sizeof(buf));
prepend_savedir(buf, sizeof(buf));
return;
}
mutt_expand_path(buf, sizeof(buf));
- if (mutt_check_overwrite(top->filename, buf, tfile, sizeof(tfile), &append, NULL))
+ if (mutt_check_overwrite(top->filename, buf, tfile, sizeof(tfile), &opt, NULL))
return;
- rc = mutt_save_attachment(fp, top, tfile, append, e);
+ rc = mutt_save_attachment(fp, top, tfile, opt, e);
if ((rc == 0) && C_AttachSep && (fp_out = fopen(tfile, "a")))
{
fprintf(fp_out, "%s", C_AttachSep);
FILE *fp_in = NULL;
mutt_mktemp(newfile, sizeof(newfile));
- if (mutt_decode_save_attachment(fp, top, newfile, MUTT_PRINTING, 0) == 0)
+ if (mutt_decode_save_attachment(fp, top, newfile, MUTT_PRINTING,
+ MUTT_SAVE_NO_FLAGS) == 0)
{
if (!state->fp_out)
{