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