Removed mhn, as it was already replaced by mhlist/mhshow/mhstore.
[mmh] / uip / mhstoresbr.c
index f1b0162..7c91184 100644 (file)
@@ -2,7 +2,9 @@
 /*
  * mhstoresbr.c -- routines to save/store the contents of MIME messages
  *
- * $Id$
+ * This code is Copyright (c) 2002, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
  */
 
 #include <h/mh.h>
 #include <errno.h>
 #include <setjmp.h>
 #include <signal.h>
-#include <mts/generic/mts.h>
+#include <h/mts.h>
 #include <h/tws.h>
 #include <h/mime.h>
 #include <h/mhparse.h>
+#include <h/utils.h>
 
-extern int errno;
 
 /*
  * The list of top-level contents to display
@@ -71,7 +73,6 @@ static int store_external (CT);
 static int ct_compar (CT *, CT *);
 static int store_content (CT, CT);
 static int output_content_file (CT, int);
-static int check_folder (char *);
 static int output_content_folder (char *, char *);
 static int parse_format_string (CT, char *, char *, int, char *);
 static void get_storeproc (CT);
@@ -222,8 +223,8 @@ store_application (CT ct)
 
        for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
            /* check for "type=tar" attribute */
-           if (!strcasecmp (*ap, "type")) {
-               if (strcasecmp (*ep, "tar"))
+           if (!mh_strcasecmp (*ap, "type")) {
+               if (mh_strcasecmp (*ep, "tar"))
                    break;
 
                tarP = 1;
@@ -231,14 +232,14 @@ store_application (CT ct)
            }
 
            /* check for "conversions=compress" attribute */
-           if ((!strcasecmp (*ap, "conversions") || !strcasecmp (*ap, "x-conversions"))
-               && (!strcasecmp (*ep, "compress") || !strcasecmp (*ep, "x-compress"))) {
+           if ((!mh_strcasecmp (*ap, "conversions") || !mh_strcasecmp (*ap, "x-conversions"))
+               && (!mh_strcasecmp (*ep, "compress") || !mh_strcasecmp (*ep, "x-compress"))) {
                zP = 1;
                continue;
            }
            /* check for "conversions=gzip" attribute */
-           if ((!strcasecmp (*ap, "conversions") || !strcasecmp (*ap, "x-conversions"))
-               && (!strcasecmp (*ep, "gzip") || !strcasecmp (*ep, "x-gzip"))) {
+           if ((!mh_strcasecmp (*ap, "conversions") || !mh_strcasecmp (*ap, "x-conversions"))
+               && (!mh_strcasecmp (*ep, "gzip") || !mh_strcasecmp (*ep, "x-gzip"))) {
                gzP = 1;
                continue;
            }
@@ -479,7 +480,7 @@ ct_compar (CT *a, CT *b)
 static int
 store_content (CT ct, CT p)
 {
-    int appending = 0, msgnum;
+    int appending = 0, msgnum = 0;
     int is_partial = 0, first_partial = 0;
     int last_partial = 0;
     char *cp, buffer[BUFSIZ];
@@ -531,8 +532,8 @@ store_content (CT ct, CT p)
      * Get storage formatting string.
      *
      * 1) If we have storeproc defined, then use that
-     * 2) Else check for a mhn-store-<type>/<subtype> entry
-     * 3) Else check for a mhn-store-<type> entry
+     * 2) Else check for a mhstore-store-<type>/<subtype> entry
+     * 3) Else check for a mhstore-store-<type> entry
      * 4) Else if content is "message", use "+" (current folder)
      * 5) Else use string "%m%P.%s".
      */
@@ -557,18 +558,17 @@ store_content (CT ct, CT p)
        char *tmpfilenam, *folder;
 
        /* Store content in temporary file for now */
-       tmpfilenam = m_scratch ("", invo_name);
+       tmpfilenam = m_mktemp(invo_name, NULL, NULL);
        ct->c_storage = add (tmpfilenam, NULL);
 
        /* Get the folder name */
        if (cp[1])
-           folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
+           folder = pluspath (cp);
        else
            folder = getfolder (1);
 
        /* Check if folder exists */
-       if (check_folder (folder) == NOTOK)
-           return NOTOK;
+       create_folder(m_mailpath(folder), 0, exit);
 
        /* Record the folder name */
        ct->c_folder = add (folder, NULL);
@@ -860,47 +860,6 @@ losing:
 
 
 /*
- * Check if folder exists, and create
- * if necessary.
- */
-
-static int
-check_folder (char *folder)
-{
-    char *folderdir;
-    struct stat st;
-
-    /* expand path to the folder */
-    folderdir = m_mailpath (folder);
-
-    /* Check if folder exists */
-    if (stat (folderdir, &st) == NOTOK) {
-       int answer;
-       char *ep;
-
-       if (errno != ENOENT) {
-           advise (folderdir, "error on folder");
-           return NOTOK;
-       }
-
-       ep = concat ("Create folder \"", folderdir, "\"? ", NULL);
-       answer = getanswer (ep);
-       free (ep);
-
-       if (!answer)
-           return NOTOK;
-
-       if (!makedir (folderdir)) {
-           advise (NULL, "unable to create folder %s", folderdir);
-           return NOTOK;
-       }
-    }
-
-    return OK;
-}
-
-
-/*
  * Add a file to a folder.
  *
  * Return the new message number of the file
@@ -917,7 +876,7 @@ output_content_folder (char *folder, char *filename)
     /* Read the folder. */
     if ((mp = folder_read (folder))) {
        /* Link file into folder */
-       msgnum = folder_addmsg (&mp, filename, 0, 0, 0);
+       msgnum = folder_addmsg (&mp, filename, 0, 0, 0, 0, (char *)0);
     } else {
        advise (NULL, "unable to read folder %s", folder);
        return NOTOK;
@@ -1080,7 +1039,7 @@ get_storeproc (CT ct)
      * the storeproc.
      */
     for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
-       if (!strcasecmp (*ap, "name")
+       if (!mh_strcasecmp (*ap, "name")
            && *(cp = *ep) != '/'
            && *cp != '.'
            && *cp != '|'
@@ -1111,10 +1070,10 @@ copy_some_headers (FILE *out, CT ct)
         * messages are not copied.
         */
        if (!uprf (hp->name, XXX_FIELD_PRF)
-               && strcasecmp (hp->name, VRSN_FIELD)
-               && strcasecmp (hp->name, "Subject")
-               && strcasecmp (hp->name, "Encrypted")
-               && strcasecmp (hp->name, "Message-ID"))
+               && mh_strcasecmp (hp->name, VRSN_FIELD)
+               && mh_strcasecmp (hp->name, "Subject")
+               && mh_strcasecmp (hp->name, "Encrypted")
+               && mh_strcasecmp (hp->name, "Message-ID"))
            fprintf (out, "%s:%s", hp->name, hp->value);
        hp = hp->next;  /* next header field */
     }