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