Split nmh dir into mmh dir (~/.mmh) and mail storage (~/Mail).
authormarkus schnalke <meillo@marmaro.de>
Fri, 23 Dec 2011 07:00:58 +0000 (08:00 +0100)
committermarkus schnalke <meillo@marmaro.de>
Fri, 23 Dec 2011 07:00:58 +0000 (08:00 +0100)
The profile (~/.mh_profile) became (~/.mmh/profile).

The idea was to separate the configuration files and the data (= messages).

The environment variables changed accordingly:
MH -> MMHP (profile)
MHCONTEXT -> MMHC (context)
new: MMH (mmh dir)

mh-install is not adjusted, yet.

config/config.c
h/mh.h
sbr/context_read.c
sbr/path.c
uip/mhparam.c

index 2bcc435..3f9d106 100644 (file)
@@ -9,29 +9,57 @@
 #include <h/mh.h>
 
 
 #include <h/mh.h>
 
 
+
 /*
 /*
-** Standard yes/no switches structure
+** nmh globals
 */
 */
-struct swit anoyes[] = {
-       { "no", 0 },
-       { "yes", 0 },
-       { NULL, 0 }
-};
+
+char *mhlibdir = NMHLIBDIR;
+char *mhetcdir = NMHETCDIR;
+
+char *invo_name;        /* command invocation name    */
+char *mypath;           /* user's $HOME               */
+char *mmhpath;          /* pathname of user's mmh dir */
+char *defpath;          /* pathname of user's profile */
+char *ctxpath;          /* pathname of user's context */
+char ctxflags;          /* status of user's context   */
+struct node *m_defs;    /* profile/context structure  */
 
 
 /*
 ** nmh constants
 
 
 /*
 ** nmh constants
+**
+** Important: Adjust uip/mmh.sh if you make changes here!
 */
 
 */
 
-/* initial profile for new users */
-char *mh_defaults = NMHETCDIR"/mh.profile";
+/* default name of the mail storage */
+char *mailstore = "Mail";
+
+/* default name of user profile */
+char *mmhdir = ".mmh";
 
 /* default name of user profile */
 
 /* default name of user profile */
-char *mh_profile = ".mh_profile";
+char *profile = "profile";
+
+/* default name for the nmh context file */
+char *context = "context";
+
+/*
+** Default name of file for public sequences.  If NULL,
+** then nmh will use private sequences by default, unless the
+** user defines a value using the "mh-sequences" profile entry.
+*/
+#ifdef NOPUBLICSEQ
+       char *mh_seq = NULL;
+#else
+       char *mh_seq = ".mh_sequences";
+#endif
+
 
 /* name of current message "sequence" */
 char *current = "cur";
 
 
 /* name of current message "sequence" */
 char *current = "cur";
 
+
 /* standard component files */
 char *components     = "components";       /* comp         */
 char *replcomps      = "replcomps";        /* repl         */
 /* standard component files */
 char *components     = "components";       /* comp         */
 char *replcomps      = "replcomps";        /* repl         */
@@ -46,11 +74,11 @@ char *mhlformat      = "mhl.format";       /* show         */
 char *mhlreply       = "mhl.reply";        /* repl -filter */
 char *mhlforward     = "mhl.forward";      /* forw -filter */
 
 char *mhlreply       = "mhl.reply";        /* repl -filter */
 char *mhlforward     = "mhl.forward";      /* forw -filter */
 
-char *draftfolder = "+drafts";
-
 char *inbox = "Inbox";
 char *defaultfolder = "+inbox";
 
 char *inbox = "Inbox";
 char *defaultfolder = "+inbox";
 
+char *draftfolder = "+drafts";
+
 char *curfolder = "Current-Folder";
 char *usequence = "Unseen-Sequence";
 char *psequence = "Previous-Sequence";
 char *curfolder = "Current-Folder";
 char *usequence = "Unseen-Sequence";
 char *psequence = "Previous-Sequence";
@@ -64,42 +92,6 @@ char *nmhprivcache = "nmh-private-cache";
 /* profile entry for external ftp access command */
 char *nmhaccessftp = "nmh-access-ftp";
 
 /* profile entry for external ftp access command */
 char *nmhaccessftp = "nmh-access-ftp";
 
-char *mhlibdir = NMHLIBDIR;
-char *mhetcdir = NMHETCDIR;
-
-
-/*
-** nmh not-so constants
-*/
-
-/*
-** Default name for the nmh context file.
-*/
-char *context = "context";
-
-/*
-** Default name of file for public sequences.  If NULL,
-** then nmh will use private sequences by default, unless the
-** user defines a value using the "mh-sequences" profile entry.
-*/
-#ifdef NOPUBLICSEQ
-char *mh_seq = NULL;
-#else
-char *mh_seq = ".mh_sequences";
-#endif
-
-
-/*
-** nmh globals
-*/
-
-char ctxflags;          /* status of user's context   */
-char *invo_name;        /* command invocation name    */
-char *mypath;           /* user's $HOME               */
-char *defpath;          /* pathname of user's profile */
-char *ctxpath;          /* pathname of user's context */
-struct node *m_defs;    /* profile/context structure  */
-
 
 /*
 ** nmh processes
 
 /*
 ** nmh processes
@@ -256,3 +248,15 @@ char *foldprot = "700";
 ** to messages coming in through inc.
 */
 char *msgprot = "600";
 ** to messages coming in through inc.
 */
 char *msgprot = "600";
+
+
+
+/*
+** Standard yes/no switches structure
+*/
+struct swit anoyes[] = {
+       { "no", 0 },
+       { "yes", 0 },
+       { NULL, 0 }
+};
+
diff --git a/h/mh.h b/h/mh.h
index 8ca6c44..0c0d81f 100644 (file)
--- a/h/mh.h
+++ b/h/mh.h
@@ -282,9 +282,12 @@ extern char ctxflags;
 
 extern char *invo_name;      /* command invocation name         */
 extern char *mypath;         /* user's $HOME                    */
 
 extern char *invo_name;      /* command invocation name         */
 extern char *mypath;         /* user's $HOME                    */
+extern char *mmhdir;
+extern char *mmhpath;
 extern char *defpath;        /* pathname of user's profile      */
 extern char *ctxpath;        /* pathname of user's context      */
 extern struct node *m_defs;  /* list of profile/context entries */
 extern char *defpath;        /* pathname of user's profile      */
 extern char *ctxpath;        /* pathname of user's context      */
 extern struct node *m_defs;  /* list of profile/context entries */
+extern char *mailstore;      /* name of mail storage directory  */
 
 /*
 ** These standard strings are defined in config.c.  They are the
 
 /*
 ** These standard strings are defined in config.c.  They are the
@@ -298,6 +301,7 @@ extern char *altmsglink;
 extern char *catproc;
 extern char *components;
 extern char *context;
 extern char *catproc;
 extern char *components;
 extern char *context;
+extern char *curfolder;
 extern char *current;
 extern char *defaulteditor;
 extern char *defaultfolder;
 extern char *current;
 extern char *defaulteditor;
 extern char *defaultfolder;
@@ -312,9 +316,8 @@ extern char *inbox;
 extern char *incproc;
 extern char *installproc;
 extern char *lproc;
 extern char *incproc;
 extern char *installproc;
 extern char *lproc;
+extern char *mhetcdir;
 extern char *mailproc;
 extern char *mailproc;
-extern char *mh_defaults;
-extern char *mh_profile;
 extern char *mh_seq;
 extern char *mhlformat;
 extern char *mhlforward;
 extern char *mh_seq;
 extern char *mhlformat;
 extern char *mhlforward;
@@ -329,7 +332,7 @@ extern char *nmhprivcache;
 extern char *nsequence;
 extern char *packproc;
 extern char *postproc;
 extern char *nsequence;
 extern char *packproc;
 extern char *postproc;
-extern char *curfolder;
+extern char *profile;
 extern char *psequence;
 extern char *rcvdistcomps;
 extern char *rcvstoreproc;
 extern char *psequence;
 extern char *rcvdistcomps;
 extern char *rcvstoreproc;
index 6ca9a3d..1e795b0 100644 (file)
@@ -8,18 +8,20 @@
 ** This function must be called early on in any nmh utility, and
 ** may only be called once.  It does the following:
 **
 ** This function must be called early on in any nmh utility, and
 ** may only be called once.  It does the following:
 **
-**  o  Sets the global variable "mypath" to the home directory path.
-**
-**  o  Sets the global variable "defpath" to the absolute path of
-**     the profile file.
+**  o  Sets the global variables to absolute paths:
+**     - "mypath": home directory (HOME)
+**     - "mmhpath": mmh directory (MMH)
+**     - "defpath": profile file (MMHP)
+**     - "ctxpath": context file (MMHC)
 **
 **  o  Reads in the profile file.  Bails out if it can't.
 **
 **  o  Makes sure that the mail directory exists, prompting for
 **     creation if it doesn't.
 **
 **
 **  o  Reads in the profile file.  Bails out if it can't.
 **
 **  o  Makes sure that the mail directory exists, prompting for
 **     creation if it doesn't.
 **
-**  o  Reads the context file either as set by the MHCONTEXT
-**     environment variable or by the profile.
+**  o  Reads the context file.
+**
+** You might need to adjust uip/mmh.sh if you make changes here.
 */
 
 #include <h/mh.h>    /* mh internals */
 */
 
 #include <h/mh.h>    /* mh internals */
@@ -40,106 +42,135 @@ context_read(void)
        ** If this routine _is_ called again (despite the wanings in the
        ** comments above), return immediately.
        */
        ** If this routine _is_ called again (despite the wanings in the
        ** comments above), return immediately.
        */
-       if ( m_defs != 0 )
+       if (m_defs) {
                return;
                return;
+       }
 
        /*
        ** Find user's home directory. Try the HOME environment variable first,
        ** the home directory field in the password file if that's not found.
        */
 
        /*
        ** Find user's home directory. Try the HOME environment variable first,
        ** the home directory field in the password file if that's not found.
        */
-       if ((mypath = getenv("HOME")) == NULL) {
-               if ((pw = getpwuid(getuid())) == (struct passwd *)0 ||
-                                       *pw->pw_dir == '\0')
+       if (!(mypath = getenv("HOME"))) {
+               if (!(pw = getpwuid(getuid())) || !*pw->pw_dir) {
                        adios(NULL, "cannot determine your home directory");
                        adios(NULL, "cannot determine your home directory");
-               else
-                       mypath = pw->pw_dir;
+               }
+               mypath = pw->pw_dir;
        }
 
        /*
        }
 
        /*
-       ** Find and read user's profile.  Check for the existence of
-       ** an MH environment variable first with non-empty contents.
-       ** Convert any relative path name found there to an absolute one.
-       ** Look for the profile in the user's home directory if the MH
-       ** environment variable isn't set.
+       ** set mmhpath
        */
        */
-
-       if ((cp = getenv("MH")) && *cp != '\0') {
-               defpath = getcpy(expanddir(cp));
-
-               if (stat(defpath, &st) != -1 && (st.st_mode & S_IFREG) == 0)
-                       adios(NULL, "`%s' specified by your MH environment variable is not a normal file", cp);
-
-               if ((ib = fopen(defpath, "r")) == (FILE *)0)
-                       adios(NULL, "unable to read the `%s' profile specified by your MH environment variable", defpath);
+       if ((cp = getenv("MMH")) && *cp) {
+               mmhpath = getcpy(expanddir(cp));  /* rel to cwd */
+               if (stat(mmhpath, &st) != -1 && (st.st_mode & S_IFDIR) == 0) {
+                       adios(NULL, "`%s' specified by your MMH environment variable is not a directory", cp);
+               }
        } else {
        } else {
-               defpath = concat(mypath, "/", mh_profile, NULL);
-
-               if ((ib = fopen(defpath, "r")) == (FILE *)0)
-                       adios(NULL, "Doesn't look like nmh is installed.  Run install-mh to do so.");
-
-               cp = mh_profile;
+               mmhpath = concat(mypath, "/", mmhdir, NULL);
+               if (stat(mmhpath, &st) == -1 || (st.st_mode & S_IFDIR) == 0) {
+                       adios(NULL, "Doesn't look like mmh is set up for your account.  Run `install-mh' to do so.");
+               }
        }
 
        }
 
+       /*
+       ** Find and read user's profile.  Check for the existence of
+       ** a non-empty MMHP environment variable first.  Look for the
+       ** profile in the mmh directory otherwise.
+       */
+       if ((cp = getenv("MMHP")) && *cp) {
+               if (*cp == '/') {
+                       defpath = getcpy(cp);
+               } else {
+                       defpath = concat(mmhpath, "/", cp, NULL);
+               }
+               if (stat(defpath, &st) != -1 && (st.st_mode & S_IFREG) == 0) {
+                       adios(NULL, "Your profile `%s', specified by the MMHP environment variable, is not a normal file", cp);
+               }
+               if ((ib = fopen(defpath, "r")) == (FILE *)0) {
+                       adios(NULL, "Unable to read your profile `%s', specified by the MMHP environment variable", defpath);
+               }
+       } else {
+               defpath = concat(mmhpath, "/", profile, NULL);
+               if ((ib = fopen(defpath, "r")) == (FILE *)0) {
+                       adios(NULL, "No profile found. Please create `%s' first.", defpath);
+               }
+               cp = profile;
+       }
        readconfig(&m_defs, ib, cp, 0);
        fclose(ib);
 
        /*
        readconfig(&m_defs, ib, cp, 0);
        fclose(ib);
 
        /*
-       ** Find the user's nmh directory, which is specified by the "path"
-       ** profile component.  Convert a relative path name to an absolute
-       ** one rooted in the home directory.
+       ** Find the user's mail storage directory, which is specified by
+       ** the `Path' profile component.  Convert a relative path name
+       ** to an absolute one rooted in the home directory.
        */
        */
-
-       if ((cp = context_find("path")) == NULL)
-               adios(NULL, "Your %s file does not contain a path entry.",
-                               defpath);
-
-       if (*cp == '\0')
-               adios(NULL, "Your `%s' profile file does not contain a valid path entry.", defpath);
-
-       if (*cp != '/')
-               snprintf(nd = buf, sizeof(buf), "%s/%s", mypath, cp);
-       else
+       if ((cp = context_find("path")) == NULL) {
+               adios(NULL, "Your profile `%s' does not contain the required path entry.", defpath);
+       }
+       if (!*cp) {
+               adios(NULL, "The Path entry of your profile `%s' must be non-empty.", defpath);
+       }
+       if (*cp == '/') {
                nd = cp;
                nd = cp;
-
+       } else {
+               snprintf(nd = buf, sizeof buf, "%s/%s", mypath, cp);
+       }
        if (stat(nd, &st) == -1) {
        if (stat(nd, &st) == -1) {
-               if (errno != ENOENT)
+               if (errno != ENOENT) {
                        adios(nd, "error opening");
                        adios(nd, "error opening");
-               cp = concat("Your MH-directory \"", nd, "\" doesn't exist; Create it? ", NULL);
-               if (!getanswer(cp))
-                       adios(NULL, "unable to access MH-directory \"%s\"",
-                                       nd);
+               }
+               cp = concat("Your mail storage directory `", nd, "' doesn't exist; Create it? ", NULL);
+               if (!getanswer(cp)) {
+                       adios(NULL, "Unable to access the mail storage directory `%s'", nd);
+               }
                free(cp);
                free(cp);
-               if (!makedir(nd))
-                       adios(NULL, "unable to create %s", nd);
-       } else if ((st.st_mode & S_IFDIR) == 0)
-               adios(NULL, "`%s' is not a directory", nd);
+               if (!makedir(nd)) {
+                       adios(nd, "unable to create");
+               }
+       } else if ((st.st_mode & S_IFDIR) == 0) {
+               adios(NULL, "Your mail storage `%s' is not a directory", nd);
+       }
+       /*
+       ** Create the default folder (inbox)
+       */
+       cp = toabsdir(defaultfolder);
+       if (stat(cp, &st) == -1) {
+               if (!makedir(cp)) {
+                       adios(cp, "Unable to create the default folder");
+               }
+       } else if ((st.st_mode & S_IFDIR) == 0) {
+               adios(NULL, "The default folder `%s' is not a directory", cp);
+       }
 
        /*
        ** Open and read user's context file.  The name of the context
 
        /*
        ** Open and read user's context file.  The name of the context
-       ** file comes from the profile unless overridden by the MHCONTEXT
+       ** file comes from the profile unless overridden by the MMHC
        ** environment variable.
        */
        ** environment variable.
        */
-
-       if ((cp = getenv("MHCONTEXT")) == NULL || *cp == '\0')
-               cp = context;
+       if (!(cp = getenv("MMHC")) || !*cp) {
+               if (!(cp = context_find("context")) || !*cp) {
+                       cp = context;
+               }
+       }
 
        /*
        ** context is NULL if context_foil() was called to disable use
 
        /*
        ** context is NULL if context_foil() was called to disable use
-       ** of context We also support users setting explicitly setting
-       ** MHCONTEXT to /dev/null.  (if this wasn't specialcased then the
-       ** locking would be liable to fail)
+       ** of context. We also support users setting explicitly setting
+       ** MMHC to /dev/null.  (If this wasn't special-cased then the
+       ** locking would be liable to fail.)
        */
        */
-       if (!cp || (strcmp(cp,"/dev/null") == 0)) {
+       if (!context || (strcmp(cp, "/dev/null") == 0)) {
                ctxpath = NULL;
                return;
        }
 
                ctxpath = NULL;
                return;
        }
 
-       ctxpath = getcpy(toabsdir(cp));
-
+       if (*cp == '/') {
+               ctxpath = getcpy(cp);
+       } else {
+               ctxpath = concat(mmhpath, "/", cp, NULL);
+       }
        if ((ib = lkfopen(ctxpath, "r"))) {
                readconfig((struct node **) 0, ib, cp, 1);
                lkfclose(ib, ctxpath);
        }
        if ((ib = lkfopen(ctxpath, "r"))) {
                readconfig((struct node **) 0, ib, cp, 1);
                lkfclose(ib, ctxpath);
        }
-
-       return;
 }
 }
index fd05f34..e5576b8 100644 (file)
@@ -9,8 +9,6 @@
 #include <h/mh.h>
 #include <pwd.h>
 
 #include <h/mh.h>
 #include <pwd.h>
 
-extern char *mhetcdir;
-
 
 /*
 ** Find the location of a format or configuration
 
 /*
 ** Find the location of a format or configuration
@@ -18,8 +16,8 @@ extern char *mhetcdir;
 **
 ** 1) If it begins with ~user, then expand it.
 ** 2) Next, if already absolute pathname, then leave unchanged.
 **
 ** 1) If it begins with ~user, then expand it.
 ** 2) Next, if already absolute pathname, then leave unchanged.
-** 3) Next, check in nmh Mail directory.
-** 4) Next, check in nmh `etc' directory.
+** 3) Next, check in mmh directory.
+** 4) Next, check in mmh `etc' directory.
 */
 char *
 etcpath(char *file)
 */
 char *
 etcpath(char *file)
@@ -29,7 +27,7 @@ etcpath(char *file)
        char *pp;
        struct passwd *pw;
 
        char *pp;
        struct passwd *pw;
 
-       context_read();
+       /* XXX: here was: ``context_read();'' -- why? */
        if (*file == '~') {
                /* Expand `~user' */
                if ((cp = strchr(pp = file + 1, '/')))
        if (*file == '~') {
                /* Expand `~user' */
                if ((cp = strchr(pp = file + 1, '/')))
@@ -60,14 +58,16 @@ try_it:
                return file;
        }
 
                return file;
        }
 
-       /* Check nmh Mail directory */
-       strncpy(epath, toabsdir(file), sizeof epath);
+       /* Check mmh directory */
+       snprintf(epath, sizeof epath, "%s/%s", mmhpath, file);
        if (access(epath, R_OK) != NOTOK)
                return epath;
 
        /* Check nmh `etc' directory */
        snprintf(epath, sizeof epath, "%s/%s", mhetcdir, file);
        return (access(epath, R_OK) != NOTOK ? epath : file);
        if (access(epath, R_OK) != NOTOK)
                return epath;
 
        /* Check nmh `etc' directory */
        snprintf(epath, sizeof epath, "%s/%s", mhetcdir, file);
        return (access(epath, R_OK) != NOTOK ? epath : file);
+
+       /* TODO: What is the ultimate fallback? NULL or file? */
 }
 
 
 }
 
 
index 5bbd9fc..dc122ad 100644 (file)
@@ -12,7 +12,6 @@
 #include <h/mh.h>
 
 extern char *mhlibdir;
 #include <h/mh.h>
 
 extern char *mhlibdir;
-extern char *mhetcdir;
 
 static struct swit switches[] = {
 #define COMPSW  0
 
 static struct swit switches[] = {
 #define COMPSW  0