oops, I did it again: simplify a lot of code :]
[apps/madmutt.git] / attach.c
index d4b1c6f..2b9fb0f 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -45,16 +45,16 @@ int mutt_get_tmp_attachment (BODY * a)
   if (stat (a->filename, &st) == -1)
     return -1;
 
-  if ((fpin = fopen (a->filename, "r")) && (fpout = safe_fopen (tempfile, "w"))) {      /* __FOPEN_CHECKED__ */
+  if ((fpin = fopen (a->filename, "r")) && (fpout = safe_fopen (tempfile, "w"))) {
     mutt_copy_stream (fpin, fpout);
     m_strreplace(&a->filename, tempfile);
     a->unlink = 1;
 
     if (a->stamp >= st.st_mtime)
       mutt_stamp_attachment (a);
-  }
-  else
+  } else {
     mutt_perror(fpin ? tempfile : a->filename);
+  }
 
   m_fclose(&fpin);
   m_fclose(&fpout);
@@ -87,19 +87,18 @@ int mutt_compose_attachment (BODY * a)
           if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES)
               != M_YES)
             goto bailout;
-        }
-        else
+        } else {
           unlink_newfile = 1;
-      }
-      else
+        }
+      } else {
         m_strcpy(newfile, sizeof(newfile), a->filename);
+      }
 
       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");
-      }
-      else {
+      } else {
         int r;
 
         mutt_endwin (NULL);
@@ -159,8 +158,7 @@ int mutt_compose_attachment (BODY * a)
         }
       }
     }
-  }
-  else {
+  } else {
     rfc1524_entry_delete(&entry);
     mutt_message (_("No mailcap compose entry for %s, creating empty file."),
                   type);
@@ -207,20 +205,19 @@ int mutt_edit_attachment (BODY * a)
           if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES)
               != M_YES)
             goto bailout;
-        }
-        else
+        } else {
           unlink_newfile = 1;
-      }
-      else
+        }
+      } else {
         m_strcpy(newfile, sizeof(newfile), a->filename);
+      }
 
       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;
-      }
-      else {
+      } else {
         mutt_endwin (NULL);
         if (mutt_system (command) == -1) {
           mutt_error (_("Error running \"%s\"!"), command);
@@ -232,8 +229,7 @@ int mutt_edit_attachment (BODY * a)
   else if (a->type == TYPETEXT) {
     /* On text, default to editor */
     mutt_edit_file (NONULL (Editor), a->filename);
-  }
-  else {
+  } else {
     rfc1524_entry_delete(&entry);
     mutt_error (_("No mailcap edit entry for %s"), type);
     return 0;
@@ -269,13 +265,11 @@ static int is_mmnoask (const char *buf)
         if (*(q + 1) == '*') {
           if (ascii_strncasecmp (buf, p, q - p) == 0)
             return (1);
-        }
-        else {
+        } else {
           if (ascii_strcasecmp (buf, p) == 0)
             return (1);
         }
-      }
-      else {
+      } else {
         lng = m_strlen(p);
         if (buf[lng] == '/' && m_strncasecmp(buf, p, lng) == 0)
           return (1);
@@ -326,11 +320,11 @@ void mutt_check_lookup_list (BODY * b, char *type, int len)
 int mutt_is_autoview (BODY * b, const char *type)
 {
   string_list_t *t = AutoViewList;
-  char _type[SHORT_STRING];
+  char _type[STRING];
   int i;
 
   if (!type)
-    snprintf (_type, sizeof (_type), "%s/%s", TYPE (b), b->subtype);
+    snprintf(_type, sizeof(_type), "%s/%s", TYPE(b), b->subtype);
   else
     m_strcpy(_type, sizeof(_type), type);
 
@@ -375,7 +369,7 @@ int mutt_view_attachment (FILE * fp, BODY * a, int flag, HEADER * hdr,
   int unlink_tempfile = 0;
   int pagerfd = -1;
 
-  is_message = mutt_is_message_type (a->type, a->subtype);
+  is_message = mutt_is_message_type(a);
   if (is_message && a->hdr && (a->hdr->security & ENCRYPT) &&
       !crypt_valid_passphrase (a->hdr->security))
     return (rc);
@@ -666,7 +660,7 @@ static FILE *mutt_save_attachment_open (char *path, int flags)
    * as safe_fopen returns w/ an error if path exists
    */
   if (flags == M_SAVE_OVERWRITE)
-    return fopen (path, "w");   /* __FOPEN_CHECKED__ */
+    return fopen (path, "w");
 
   return safe_fopen (path, "w");
 }
@@ -683,7 +677,7 @@ int mutt_save_attachment (FILE * fp, BODY * m, char *path, int flags,
         m->hdr &&
         m->encoding != ENCBASE64 &&
         m->encoding != ENCQUOTEDPRINTABLE &&
-        mutt_is_message_type (m->type, m->subtype)) {
+        mutt_is_message_type(m)) {
       /* message type attachments are written to mail folders. */
 
       char buf[HUGE_STRING];
@@ -784,8 +778,6 @@ int mutt_decode_save_attachment (FILE * fp, BODY * m, char *path,
 
   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");
 
@@ -859,6 +851,7 @@ int mutt_print_attachment (FILE * fp, BODY * a)
   pid_t thepid;
   FILE *ifp, *fpout;
   short unlink_newfile = 0;
+  int tok;
 
   snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype);
 
@@ -930,8 +923,8 @@ int mutt_print_attachment (FILE * fp, BODY * a)
     return (1);
   }
 
-  if (!ascii_strcasecmp ("text/plain", type) ||
-      !ascii_strcasecmp ("application/postscript", type)) {
+  tok = mime_which_token(type, -1);
+  if (tok == MIME_TEXT_PLAIN || tok == MIME_APPLICATION_POSTSCRIPT) {
     return (mutt_pipe_attachment (fp, a, NONULL (PrintCmd), NULL));
   }
   else if (mutt_can_decode (a)) {