]> diplodocus.org Git - nmh/blob - config/config.c
Fix a segfault that happens when using the -file option.
[nmh] / 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 used to optionally format the bodies of messages by
199 * "mhl".
200 */
201
202 char *formatproc = NULL;
203
204 /*
205 * This program is called to incorporate messages into a folder.
206 */
207
208 char *incproc = nmhbindir (/inc);
209
210 /*
211 * When a user runs an nmh program for the first time, this program
212 * is called to create his nmh profile, and mail directory.
213 */
214
215 char *installproc = nmhlibdir (/install-mh);
216
217 /*
218 * This is the default program invoked by a "list" response
219 * at the "What now?" prompt. It is also used by the draft
220 * folder facility in comp/dist/forw/repl to display the
221 * draft message.
222 */
223
224 char *lproc = DEFAULT_PAGER;
225
226 /*
227 * This is the path for the Bell equivalent mail program.
228 */
229
230 char *mailproc = nmhbindir (/mhmail);
231
232 /*
233 * This is used by mhl as a front-end. It is also used
234 * by mhn as the default method of displaying message bodies
235 * or message parts of type text/plain.
236 */
237
238 char *moreproc = DEFAULT_PAGER;
239
240 /*
241 * This is the program (mhl) used to filter messages. It is
242 * used by mhn to filter and display the message headers of
243 * MIME messages. It is used by repl/forw (with -filter)
244 * to filter the message to which you are replying/forwarding.
245 * It is used by send/post (with -filter) to filter the message
246 * for "Bcc:" recipients.
247 */
248
249 char *mhlproc = nmhlibdir (/mhl);
250
251 /*
252 * This is the super handy BBoard reading program, which is
253 * really just the nmh shell program.
254 */
255
256 char *mshproc = nmhbindir (/msh);
257
258 /*
259 * This program is called to pack a folder.
260 */
261
262 char *packproc = nmhbindir (/packf);
263
264 /*
265 * This is the delivery program called by send to actually
266 * deliver mail to users. This is the interface to the MTS.
267 */
268
269 char *postproc = nmhlibdir (/post);
270
271 /*
272 * This is program is called by slocal to handle
273 * the action `folder' or `+'.
274 */
275
276 char *rcvstoreproc = nmhlibdir (/rcvstore);
277
278 /*
279 * This program is called to remove a folder.
280 */
281
282 char *rmfproc = nmhbindir (/rmf);
283
284 /*
285 * This program is called to remove a message by rmm or refile -nolink.
286 * It's usually empty, which means to rename the file to a backup name.
287 */
288
289 char *rmmproc = NULL;
290
291 /*
292 * This program is usually called by the user's whatnowproc, but it
293 * may also be called directly to send a message previously composed.
294 */
295
296 char *sendproc = nmhbindir (/send);
297
298 /*
299 * This is the path to the program used by "show"
300 * to display non-text (MIME) messages.
301 */
302
303 char *showmimeproc = nmhbindir (/mhshow);
304
305 /*
306 * This is the default program called by "show" to filter
307 * and display standard text (non-MIME) messages. It can be
308 * changed to a pager (such as "more" or "less") if you prefer
309 * that such message not be filtered in any way.
310 */
311
312 char *showproc = nmhlibdir (/mhl);
313
314 /*
315 * This program is called by vmh as the back-end to the window management
316 * protocol
317 */
318
319 char *vmhproc = nmhbindir (/msh);
320
321 /*
322 * This program is called after comp, et. al., have built a draft
323 */
324
325 char *whatnowproc = nmhbindir (/whatnow);
326
327 /*
328 * This program is called to list/validate the addresses in a message.
329 */
330
331 char *whomproc = nmhbindir (/whom);
332
333 /*
334 * This is the editor invoked by the various message
335 * composition programs. It SHOULD be a full screen
336 * editor, such as vi or emacs, but any editor will work.
337 */
338
339 char *defaulteditor = DEFAULT_EDITOR;
340
341 /*
342 * This is the global nmh alias file. It is somewhat obsolete, since
343 * global aliases should be handled by the Mail Transport Agent (MTA).
344 */
345
346 char *AliasFile = nmhetcdir (/MailAliases);
347
348 /*
349 * File protections
350 */
351
352 /*
353 * Folders (directories) are created with this protection (mode)
354 */
355
356 char *foldprot = "700";
357
358 /*
359 * Every NEW message will be created with this protection. When a
360 * message is filed it retains its protection, so this only applies
361 * to messages coming in through inc.
362 */
363
364 char *msgprot = "600";
365