-#include <lib-lib/mem.h>
+#include <lib-sys/unix.h>
+#include <lib-mime/mime.h>
+#include <lib-ui/lib-ui.h>
+#include <lib-ui/menu.h>
+#include <lib-mx/mx.h>
rfc1524_expand_filename (entry->nametemplate, a->filename,
tempfile, sizeof (tempfile));
rfc1524_expand_filename (entry->nametemplate, a->filename,
tempfile, sizeof (tempfile));
if (rfc1524_expand_filename (entry->nametemplate,
a->filename, newfile, sizeof (newfile))) {
if (rfc1524_expand_filename (entry->nametemplate,
a->filename, newfile, sizeof (newfile))) {
if (safe_symlink (a->filename, newfile) == -1) {
if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES)
!= M_YES)
goto bailout;
if (safe_symlink (a->filename, newfile) == -1) {
if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES)
!= M_YES)
goto bailout;
if (rfc1524_expand_command (a, newfile, type,
command, sizeof (command))) {
/* For now, editing requires a file, no piping */
mutt_error _("Mailcap compose entry requires %%s");
if (rfc1524_expand_command (a, newfile, type,
command, sizeof (command))) {
/* For now, editing requires a file, no piping */
mutt_error _("Mailcap compose entry requires %%s");
if ((fp = safe_fopen (a->filename, "r")) == NULL) {
mutt_perror (_("Failure to open file to parse headers."));
if ((fp = safe_fopen (a->filename, "r")) == NULL) {
mutt_perror (_("Failure to open file to parse headers."));
/* Remove headers by copying out data to another file, then
* copying the file back */
fseeko (fp, b->offset, 0);
/* Remove headers by copying out data to another file, then
* copying the file back */
fseeko (fp, b->offset, 0);
- mutt_mktemp (tempfile);
- if ((tfp = safe_fopen (tempfile, "w")) == NULL) {
+ tfp = m_tempfile(tempfile, sizeof(tempfile), NONULL(mod_core.tmpdir), NULL);
+ if (!tfp) {
mutt_unlink (a->filename);
if (mutt_rename_file (tempfile, a->filename) != 0) {
mutt_perror (_("Failure to rename file."));
mutt_unlink (a->filename);
if (mutt_rename_file (tempfile, a->filename) != 0) {
mutt_perror (_("Failure to rename file."));
if (rfc1524_mailcap_lookup (a, type, entry, M_EDIT)) {
if (entry->editcommand) {
if (rfc1524_mailcap_lookup (a, type, entry, M_EDIT)) {
if (entry->editcommand) {
if (rfc1524_expand_filename (entry->nametemplate,
a->filename, newfile, sizeof (newfile))) {
if (rfc1524_expand_filename (entry->nametemplate,
a->filename, newfile, sizeof (newfile))) {
- debug_print (1, ("oldfile: %s\t newfile: %s\n", a->filename, newfile));
- if (safe_symlink (a->filename, newfile) == -1) {
+ if (safe_symlink (a->filename, newfile) == -1) {
if (rfc1524_expand_command (a, newfile, type,
command, sizeof (command))) {
/* For now, editing requires a file, no piping */
mutt_error _("Mailcap Edit entry requires %%s");
goto bailout;
if (rfc1524_expand_command (a, newfile, type,
command, sizeof (command))) {
/* For now, editing requires a file, no piping */
mutt_error _("Mailcap Edit entry requires %%s");
goto bailout;
mutt_endwin (NULL);
if (mutt_system (command) == -1) {
mutt_error (_("Error running \"%s\"!"), command);
mutt_endwin (NULL);
if (mutt_system (command) == -1) {
mutt_error (_("Error running \"%s\"!"), command);
}
else if (a->type == TYPETEXT) {
/* On text, default to editor */
}
else if (a->type == TYPETEXT) {
/* On text, default to editor */
- mutt_edit_file (NONULL (Editor), a->filename);
- }
- else {
- rfc1524_free_entry (&entry);
+ mutt_edit_file(a->filename);
+ } else {
+ rfc1524_entry_delete(&entry);
p = tmp;
while ((p = strtok (p, ",")) != NULL) {
if ((q = strrchr (p, '/')) != NULL) {
if (*(q + 1) == '*') {
if (ascii_strncasecmp (buf, p, q - p) == 0)
p = tmp;
while ((p = strtok (p, ",")) != NULL) {
if ((q = strrchr (p, '/')) != NULL) {
if (*(q + 1) == '*') {
if (ascii_strncasecmp (buf, p, q - p) == 0)
if ((i > 0 && t->data[i - 1] == '/' && t->data[i] == '*' &&
ascii_strncasecmp (type, t->data, i) == 0) ||
ascii_strcasecmp (type, t->data) == 0) {
if ((i > 0 && t->data[i - 1] == '/' && t->data[i] == '*' &&
ascii_strncasecmp (type, t->data, i) == 0) ||
ascii_strcasecmp (type, t->data) == 0) {
if ((n = mutt_lookup_mime_type (&tmp, b->filename)) != TYPEOTHER) {
snprintf (type, len, "%s/%s",
n == TYPEAUDIO ? "audio" :
if ((n = mutt_lookup_mime_type (&tmp, b->filename)) != TYPEOTHER) {
snprintf (type, len, "%s/%s",
n == TYPEAUDIO ? "audio" :
n == TYPEMULTIPART ? "multipart" :
n == TYPETEXT ? "text" :
n == TYPEVIDEO ? "video" : "other", tmp.subtype);
n == TYPEMULTIPART ? "multipart" :
n == TYPETEXT ? "text" :
n == TYPEVIDEO ? "video" : "other", tmp.subtype);
- snprintf (_type, sizeof (_type), "%s/%s", TYPE (b), b->subtype);
+ snprintf(_type, sizeof(_type), "%s/%s", TYPE(b), b->subtype);
if ((i > 0 && t->data[i - 1] == '/' && t->data[i] == '*' &&
ascii_strncasecmp (type, t->data, i) == 0) ||
ascii_strcasecmp (type, t->data) == 0)
if ((i > 0 && t->data[i - 1] == '/' && t->data[i] == '*' &&
ascii_strncasecmp (type, t->data, i) == 0) ||
ascii_strcasecmp (type, t->data) == 0)
- is_message = mutt_is_message_type (a->type, a->subtype);
- if (WithCrypto && is_message && a->hdr && (a->hdr->security & ENCRYPT) &&
- !crypt_valid_passphrase (a->hdr->security))
- return (rc);
+ is_message = mutt_is_message_type(a);
snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype);
if (use_mailcap) {
snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype);
if (use_mailcap) {
if (!rfc1524_mailcap_lookup (a, type, entry, 0)) {
if (flag == M_REGULAR) {
/* fallback to view as text */
if (!rfc1524_mailcap_lookup (a, type, entry, 0)) {
if (flag == M_REGULAR) {
/* fallback to view as text */
if (rfc1524_expand_filename (entry->nametemplate, fname,
tempfile, sizeof (tempfile))) {
if (rfc1524_expand_filename (entry->nametemplate, fname,
tempfile, sizeof (tempfile))) {
/* send case: the file is already there */
if (safe_symlink (a->filename, tempfile) == -1) {
if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES)
== M_YES)
/* send case: the file is already there */
if (safe_symlink (a->filename, tempfile) == -1) {
if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES)
== M_YES)
- if (fp && !use_mailcap && a->filename) {
- /* recv case */
- strfcpy (pagerfile, a->filename, sizeof (pagerfile));
- mutt_adv_mktemp (NULL, pagerfile, sizeof (pagerfile));
- }
- else
- mutt_mktemp (pagerfile);
+ /* recv case */
+ pagerfd = m_tempfd(pagerfile, sizeof(pagerfile), NONULL(mod_core.tmpdir),
+ fp && !use_mailcap ? a->filename : NULL);
/* just let me see the raw data */
if (mutt_save_attachment (fp, a, pagerfile, 0, NULL))
goto return_error;
/* just let me see the raw data */
if (mutt_save_attachment (fp, a, pagerfile, 0, NULL))
goto return_error;
/* Use built-in handler */
set_option (OPTVIEWATTACH); /* disable the "use 'v' to view this part"
* message in case of error */
/* Use built-in handler */
set_option (OPTVIEWATTACH); /* disable the "use 'v' to view this part"
* message in case of error */
- if (mutt_decode_save_attachment (fp, a, pagerfile, M_DISPLAY, 0)) {
+ if (mutt_decode_save_attachment (fp, a, pagerfd, M_DISPLAY)) {
else if (a->filename)
snprintf (descrip, sizeof (descrip), "---Attachment: %s : %s",
a->filename, type);
else if (a->filename)
snprintf (descrip, sizeof (descrip), "---Attachment: %s : %s",
a->filename, type);
- pager_t info;
-
- memset (&info, 0, sizeof (info));
- info.fp = fp;
- info.bdy = a;
- info.ctx = Context;
- info.idx = idx;
- info.idxlen = idxlen;
- info.hdr = hdr;
-
- rc = mutt_do_pager (descrip, pagerfile,
- M_PAGER_ATTACHMENT | (is_message ? M_PAGER_MESSAGE :
- 0), &info);
+ pager_t info = { Context, hdr, a, fp, idx, idxlen };
+ rc = mutt_pager(descrip, pagerfile,
+ M_PAGER_ATTACHMENT | (is_message ? M_PAGER_MESSAGE : 0),
+ &info);
-int mutt_pipe_attachment (FILE * fp, BODY * b, const char *path,
- char *outfile)
+int mutt_pipe_attachment(FILE * fp, BODY * b, const char *path, int out)
- memset (&s, 0, sizeof (STATE));
-
- if (outfile && *outfile)
- thepid =
- mutt_create_filter_fd (path, &s.fpout, NULL, NULL, -1, out, -1);
+ if (out >= 0)
+ thepid = mutt_create_filter_fd(path, &s.fpout, NULL, NULL, -1, out, -1);
- thepid = mutt_create_filter (path, &s.fpout, NULL, NULL);
+ thepid = mutt_create_filter(path, &s.fpout, NULL, NULL);
- if (outfile && *outfile)
- thepid = mutt_create_filter_fd (path, &ofp, NULL, NULL, -1, out, -1);
+ if (out >= 0)
+ thepid = mutt_create_filter_fd(path, &ofp, NULL, NULL, -1, out, -1);
- thepid = mutt_create_filter (path, &ofp, NULL, NULL);
+ thepid = mutt_create_filter(path, &ofp, NULL, NULL);
chflags = CH_FROM;
chflags |= (ctx.magic == M_MAILDIR ? CH_NOSTATUS : CH_UPDATE);
if (_mutt_copy_message (msg->fp, fp, hn, hn->content, 0, chflags) == 0
chflags = CH_FROM;
chflags |= (ctx.magic == M_MAILDIR ? CH_NOSTATUS : CH_UPDATE);
if (_mutt_copy_message (msg->fp, fp, hn, hn->content, 0, chflags) == 0
}
fseeko ((s.fpin = fp), m->offset, 0);
mutt_decode_attachment (m, &s);
}
fseeko ((s.fpin = fp), m->offset, 0);
mutt_decode_attachment (m, &s);
/* In send mode, just copy file */
FILE *ofp, *nfp;
if ((ofp = fopen (m->filename, "r")) == NULL) {
mutt_perror ("fopen");
/* In send mode, just copy file */
FILE *ofp, *nfp;
if ((ofp = fopen (m->filename, "r")) == NULL) {
mutt_perror ("fopen");
}
if (mutt_copy_stream (ofp, nfp) == -1) {
mutt_error _("Write fault!");
}
if (mutt_copy_stream (ofp, nfp) == -1) {
mutt_error _("Write fault!");
-int mutt_decode_save_attachment (FILE * fp, BODY * m, char *path,
- int displaying, int flags)
+int mutt_decode_save_attachment (FILE * fp, BODY * m, int pathfd,
+ int displaying)
{
STATE s;
unsigned int saved_encoding = 0;
BODY *saved_parts = NULL;
HEADER *saved_hdr = NULL;
{
STATE s;
unsigned int saved_encoding = 0;
BODY *saved_parts = NULL;
HEADER *saved_hdr = NULL;
-
- if (flags == M_SAVE_APPEND)
- s.fpout = fopen (path, "a");
- else if (flags == M_SAVE_OVERWRITE)
- s.fpout = safe_fopen (path, "w"); /* __FOPEN_CHECKED__ */
- else
- s.fpout = safe_fopen (path, "w");
+ s.fpout = fdopen (pathfd, "w");
snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype);
snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype);
rfc1524_mailcap_lookup (a, type, entry, M_PRINT);
if (rfc1524_expand_filename (entry->nametemplate, a->filename,
newfile, sizeof (newfile))) {
rfc1524_mailcap_lookup (a, type, entry, M_PRINT);
if (rfc1524_expand_filename (entry->nametemplate, a->filename,
newfile, sizeof (newfile))) {
if (safe_symlink (a->filename, newfile) == -1) {
if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES)
!= M_YES) {
if (safe_symlink (a->filename, newfile) == -1) {
if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES)
!= M_YES) {
if (fp)
mutt_save_attachment (fp, a, newfile, 0, NULL);
if (fp)
mutt_save_attachment (fp, a, newfile, 0, NULL);
- strfcpy (command, entry->printcommand, sizeof (command));
- piped =
- rfc1524_expand_command (a, newfile, type, command, sizeof (command));
+ m_strcpy(command, sizeof(command), entry->printcommand);
+ piped = rfc1524_expand_command(a, newfile, type, command,
+ sizeof(command));
}
if ((thepid = mutt_create_filter (command, &fpout, NULL, NULL)) < 0) {
mutt_perror (_("Can't create filter"));
}
if ((thepid = mutt_create_filter (command, &fpout, NULL, NULL)) < 0) {
mutt_perror (_("Can't create filter"));
- if (!ascii_strcasecmp ("text/plain", type) ||
- !ascii_strcasecmp ("application/postscript", type)) {
- return (mutt_pipe_attachment (fp, a, NONULL (PrintCmd), NULL));
+ tok = mime_which_token(type, -1);
+ if (tok == MIME_TEXT_PLAIN || tok == MIME_APPLICATION_POSTSCRIPT) {
+ return mutt_pipe_attachment(fp, a, NONULL (PrintCmd), -1);
- mutt_mktemp (newfile);
- if (mutt_decode_save_attachment (fp, a, newfile, M_PRINTING, 0) == 0) {
-
- debug_print (2, ("successfully decoded %s type attachment to %s\n",
- type, newfile));
+ newfile_fd = m_tempfd(newfile, sizeof(newfile), NONULL(mod_core.tmpdir), NULL);
+ if (mutt_decode_save_attachment (fp, a, newfile_fd, M_PRINTING) == 0) {
mutt_endwin (NULL);
if ((thepid =
mutt_create_filter (NONULL (PrintCmd), &fpout, NULL, NULL)) < 0) {
mutt_endwin (NULL);
if ((thepid =
mutt_create_filter (NONULL (PrintCmd), &fpout, NULL, NULL)) < 0) {
- debug_print (2, ("Filter created.\n"));
-
- mutt_copy_stream (ifp, fpout);
-
- safe_fclose (&fpout);
- safe_fclose (&ifp);
+ mutt_copy_stream(ifp, fpout);
+ m_fclose(&fpout);
+ m_fclose(&ifp);
if (!hdr || !hdr->content || !((regex_t*) AttachRemindRegexp.rx) ||
(fp = safe_fopen (hdr->content->filename, "r")) == NULL)
if (!hdr || !hdr->content || !((regex_t*) AttachRemindRegexp.rx) ||
(fp = safe_fopen (hdr->content->filename, "r")) == NULL)