82d20b18a88d63632980070a1eeadee0c9ea2827
[mmh] / config / config.c
1
2 /*
3  * config.c -- master nmh configuration file
4  *
5  * This code is Copyright (c) 2002, by the authors of nmh.  See the
6  * COPYRIGHT file in the root directory of the nmh distribution for
7  * complete copyright information.
8  */
9
10 #include <h/mh.h>
11 #include <stdio.h>
12 #include <pwd.h>
13
14 #define nmhbindir(file) NMHBINDIR#file
15 #define nmhetcdir(file) NMHETCDIR#file
16 #define nmhlibdir(file) NMHLIBDIR#file
17
18
19 /*
20  * Find the location of a format or configuration
21  * file, and return its absolute pathname.
22  *
23  * 1) If already absolute pathname, then leave unchanged.
24  * 2) Next, if it begins with ~user, then expand it.
25  * 3) Next, check in nmh Mail directory.
26  * 4) Next, check in nmh `etc' directory.
27  *
28  */
29
30 char *
31 etcpath (char *file)
32 {
33     static char epath[PATH_MAX];
34     char *cp;
35     char *pp;
36     struct passwd *pw;
37
38     context_read();
39
40     switch (*file) {
41         case '/': 
42             /* If already absolute pathname, return it */
43             return file;
44
45         case '~': 
46             /* Expand ~username */
47             if ((cp = strchr(pp = file + 1, '/')))
48                 *cp++ = '\0';
49             if (*pp == '\0') {
50                 pp = mypath;
51             } else {
52                 if ((pw = getpwnam (pp)))
53                     pp = pw->pw_dir;
54                 else {
55                     if (cp)
56                         *--cp = '/';
57                     goto try_it;
58                 }
59             }
60
61             snprintf (epath, sizeof(epath), "%s/%s", pp, cp ? cp : "");
62             if (cp)
63                 *--cp = '/';
64
65             if (access (epath, R_OK) != NOTOK)
66                 return epath;   /* else fall */
67 try_it:
68
69         default: 
70             /* Check nmh Mail directory */
71             if (access ((cp = m_mailpath (file)), R_OK) != NOTOK)
72                 return cp;
73     }
74
75     /* Check nmh `etc' directory */
76     snprintf (epath, sizeof(epath), nmhetcdir(/%s), file);
77     return (access (epath, R_OK) != NOTOK ? epath : file);
78 }
79
80
81 /* 
82  * Standard yes/no switches structure
83  */
84
85 struct swit anoyes[] = {
86     { "no", 0 },
87     { "yes", 0 },
88     { NULL, 0 }
89 };
90
91 /* 
92  * nmh constants
93  */
94
95 /* initial profile for new users */
96 char *mh_defaults = nmhetcdir (/mh.profile);
97
98 /* default name of user profile */
99 char *mh_profile = ".mh_profile";
100
101 /* name of current message "sequence" */
102 char *current = "cur";
103
104 /* standard component files */
105 char *components = "components";                /* comp         */
106 char *replcomps = "replcomps";                  /* repl         */
107 char *replgroupcomps = "replgroupcomps";        /* repl -group  */
108 char *forwcomps = "forwcomps";                  /* forw         */
109 char *distcomps = "distcomps";                  /* dist         */
110 char *rcvdistcomps = "rcvdistcomps";            /* rcvdist      */
111 char *digestcomps = "digestcomps";              /* forw -digest */
112
113 /* standard format (filter) files */
114 char *mhlformat = "mhl.format";                 /* show         */
115 char *mhlreply = "mhl.reply";                   /* repl -filter */
116 char *mhlforward = "mhl.forward";               /* forw -filter */
117
118 char *draft = "draft";
119
120 char *inbox = "Inbox";
121 char *defaultfolder = "inbox";
122
123 char *pfolder = "Current-Folder";
124 char *usequence = "Unseen-Sequence";
125 char *psequence = "Previous-Sequence";
126 char *nsequence = "Sequence-Negation";
127
128 /* profile entries for storage locations */
129 char *nmhstorage = "nmh-storage";
130 char *nmhcache = "nmh-cache";
131 char *nmhprivcache = "nmh-private-cache";
132
133 /* profile entry for external ftp access command */
134 char *nmhaccessftp = "nmh-access-ftp";
135
136 char *mhlibdir = NMHLIBDIR;
137 char *mhetcdir = NMHETCDIR;
138
139 /* 
140  * nmh not-so constants
141  */
142
143 /*
144  * Default name for the nmh context file.
145  */
146 char *context = "context";
147
148 /*
149  * Default name of file for public sequences.  If NULL,
150  * then nmh will use private sequences by default, unless the
151  * user defines a value using the "mh-sequences" profile entry.
152  */
153 #ifdef NOPUBLICSEQ
154 char *mh_seq = NULL;
155 #else
156 char *mh_seq = ".mh_sequences";
157 #endif
158
159 /* 
160  * nmh globals
161  */
162
163 char ctxflags;          /* status of user's context   */
164 char *invo_name;        /* command invocation name    */
165 char *mypath;           /* user's $HOME               */
166 char *defpath;          /* pathname of user's profile */
167 char *ctxpath;          /* pathname of user's context */
168 struct node *m_defs;    /* profile/context structure  */
169
170 /* 
171  * nmh processes
172  */
173
174 /*
175  * This is the program to process MIME composition files
176  */
177 char *buildmimeproc = nmhbindir (/mhbuild);
178 /*
179  * This is the program to `cat' a file.
180  */
181 char *catproc = "/bin/cat";
182
183 /*
184  * mhl runs this program as a visual-end.
185  */
186
187 char *faceproc = NULL;
188
189 /*
190  * This program is usually called directly by users, but it is
191  * also invoked by the post program to process an "Fcc", or by
192  * comp/repl/forw/dist to refile a draft message.
193  */
194
195 char *fileproc = nmhbindir (/refile);
196
197 /* 
198  * This program is called to incorporate messages into a folder.
199  */
200
201 char *incproc = nmhbindir (/inc);
202
203 /*
204  * When a user runs an nmh program for the first time, this program
205  * is called to create his nmh profile, and mail directory.
206  */
207
208 char *installproc = nmhlibdir (/install-mh);
209
210 /*
211  * This is the default program invoked by a "list" response
212  * at the "What now?" prompt.  It is also used by the draft
213  * folder facility in comp/dist/forw/repl to display the
214  * draft message.
215  */
216
217 char *lproc = DEFAULT_PAGER;
218
219 /*
220  * This is the path for the Bell equivalent mail program.
221  */
222
223 char *mailproc = nmhbindir (/mhmail);
224
225 /*
226  * This is used by mhl as a front-end.  It is also used
227  * by mhn as the default method of displaying message bodies
228  * or message parts of type text/plain.
229  */
230
231 char *moreproc = DEFAULT_PAGER;
232
233 /* 
234  * This is the program (mhl) used to filter messages.  It is
235  * used by mhn to filter and display the message headers of
236  * MIME messages.  It is used by repl/forw (with -filter)
237  * to filter the message to which you are replying/forwarding.
238  * It is used by send/post (with -filter) to filter the message
239  * for "Bcc:" recipients.
240  */
241
242 char *mhlproc = nmhlibdir (/mhl);
243
244 /* 
245  * This is the super handy BBoard reading program, which is
246  * really just the nmh shell program.
247  */
248
249 char *mshproc = nmhbindir (/msh);
250
251 /* 
252  * This program is called to pack a folder.  
253  */
254
255 char *packproc = nmhbindir (/packf);
256
257 /*
258  * This is the delivery program called by send to actually
259  * deliver mail to users.  This is the interface to the MTS.
260  */
261
262 char *postproc = nmhlibdir (/post);
263
264 /*
265  * This is program is called by slocal to handle
266  * the action `folder' or `+'.
267  */
268
269 char *rcvstoreproc = nmhlibdir (/rcvstore);
270
271 /* 
272  * This program is called to remove a folder.  
273  */
274
275 char *rmfproc = nmhbindir (/rmf);
276
277 /* 
278  * This program is called to remove a message by rmm or refile -nolink.
279  * It's usually empty, which means to rename the file to a backup name.
280  */
281
282 char *rmmproc = NULL;
283
284 /*
285  * This program is usually called by the user's whatnowproc, but it
286  * may also be called directly to send a message previously composed.
287  */
288
289 char *sendproc = nmhbindir (/send);
290
291 /*
292  * This is the path to the program used by "show"
293  * to display non-text (MIME) messages.
294  */
295
296 char *showmimeproc = nmhbindir (/mhshow);
297
298 /*
299  * This is the default program called by "show" to filter
300  * and display standard text (non-MIME) messages.  It can be
301  * changed to a pager (such as "more" or "less") if you prefer
302  * that such message not be filtered in any way.
303  */
304
305 char *showproc = nmhlibdir (/mhl);
306
307 /* 
308  * This program is called by vmh as the back-end to the window management
309  * protocol
310  */
311
312 char *vmhproc = nmhbindir (/msh);
313
314 /* 
315  * This program is called after comp, et. al., have built a draft
316  */
317
318 char *whatnowproc = nmhbindir (/whatnow);
319
320 /* 
321  * This program is called to list/validate the addresses in a message.
322  */
323
324 char *whomproc = nmhbindir (/whom);
325
326 /*
327  * This is the editor invoked by the various message
328  * composition programs.  It SHOULD be a full screen
329  * editor, such as vi or emacs, but any editor will work.
330  */
331
332 char *defaulteditor = DEFAULT_EDITOR;
333
334 /* 
335  * This is the global nmh alias file.  It is somewhat obsolete, since
336  * global aliases should be handled by the Mail Transport Agent (MTA).
337  */
338
339 char *AliasFile = nmhetcdir (/MailAliases);
340
341 /* 
342  * File protections
343  */
344
345 /*
346  * Folders (directories) are created with this protection (mode)
347  */
348
349 char *foldprot = "700";
350
351 /*
352  * Every NEW message will be created with this protection.  When a
353  * message is filed it retains its protection, so this only applies
354  * to messages coming in through inc.
355  */
356
357 char *msgprot = "600";
358