summaryrefslogtreecommitdiffstats
path: root/attach.c
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>1998-08-28 00:53:12 +0000
committerThomas Roessler <roessler@does-not-exist.org>1998-08-28 00:53:12 +0000
commitf58938adf13af45527dd59838ba9782ba10d033c (patch)
tree37206dbb14e94a23e81eb7633463fccaab458dff /attach.c
parent4f94f6fbe594c03eebfceef4a5fd908c45bf27ba (diff)
[patch-0.94.4i.tlr.get_attachment.1] Create a new
"get-attachment" function on the compose menu which will copy an attachment to a temporary file.
Diffstat (limited to 'attach.c')
-rw-r--r--attach.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/attach.c b/attach.c
index d0a887e1..275ec3d3 100644
--- a/attach.c
+++ b/attach.c
@@ -40,6 +40,40 @@
#include <string.h>
#include <errno.h>
+int mutt_get_tmp_attachment (BODY *a)
+{
+ char type[STRING];
+ char tempfile[_POSIX_PATH_MAX];
+ rfc1524_entry *entry = rfc1524_new_entry();
+ FILE *fpin = NULL, *fpout = NULL;
+
+ if(a->unlink)
+ return 0;
+
+ snprintf(type, sizeof(type), "%s/%s", TYPE(a), a->subtype);
+ rfc1524_mailcap_lookup(a, type, entry, 0);
+ rfc1524_expand_filename(entry->nametemplate, a->filename,
+ tempfile, sizeof(tempfile));
+
+ rfc1524_free_entry(&entry);
+
+ if((fpin = fopen(a->filename, "r")) && (fpout = safe_fopen(tempfile, "w")))
+ {
+ mutt_copy_stream (fpin, fpout);
+ FREE(&a->filename);
+ a->filename = safe_strdup(tempfile);
+ a->unlink = 1;
+ }
+ else
+ mutt_perror(fpin ? tempfile : a->filename);
+
+ if(fpin) fclose(fpin);
+ if(fpout) fclose(fpout);
+
+ return a->unlink ? 0 : -1;
+}
+
+
/* return 1 if require full screen redraw, 0 otherwise */
int mutt_compose_attachment (BODY *a)
{