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