2 ** repl.c -- reply to a message
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.
13 static struct swit switches[] = {
23 { "cc all|to|cc|me", 0 },
27 { "editor editor", 0 },
33 { "filter filterfile", 0 },
35 { "form formfile", 0 },
49 { "whatnowproc program", 0 },
51 { "nowhatnowproc", 0 },
57 { "file file", 4 }, /* interface from msh */
61 { "build", 5 }, /* interface from mhe */
67 static struct swit ccswitches[] = {
79 short ccto = -1; /* global for replsbr */
84 short groupreply = 0; /* Is this a group reply? */
86 int mime = 0; /* include original as MIME part */
87 char *form = NULL; /* form (components) file */
88 char *filter = NULL; /* message filter file */
89 char *fcc = NULL; /* folders to add to Fcc: header */
95 void docc(char *, int);
99 main(int argc, char **argv)
102 int nedit = 0, nwhat = 0;
103 char *cp, *cwd, *dp, *maildir, *file = NULL;
104 char *folder = NULL, *msg = NULL;
105 char *ed = NULL, drft[BUFSIZ], buf[BUFSIZ];
106 char **argp, **arguments;
107 struct msgs *mp = NULL;
115 setlocale(LC_ALL, "");
117 invo_name = mhbasename(argv[0]);
119 /* read user profile/context */
122 arguments = getarguments(invo_name, argc, argv, 1);
125 while ((cp = *argp++)) {
127 switch (smatch(++cp, switches)) {
129 ambigsw(cp, switches);
132 adios(NULL, "-%s unknown", cp);
135 snprintf(buf, sizeof(buf), "%s: [+folder] [msg] [switches]", invo_name);
136 print_help(buf, switches, 1);
139 print_version(invo_name);
157 if (!(cp = *argp++) || *cp == '-')
158 adios(NULL, "missing argument to %s",
163 if (!(cp = *argp++) || *cp == '-')
164 adios(NULL, "missing argument to %s",
170 if (!(ed = *argp++) || *ed == '-')
171 adios(NULL, "missing argument to %s",
180 if (!(whatnowproc = *argp++) ||
182 adios(NULL, "missing argument to %s",
188 buildsw++; /* fall... */
195 if (!(cp = *argp++) || *cp == '-')
196 adios(NULL, "missing argument to %s",
200 cp = dp = getcpy(expandfol(cp));
202 fcc = add(", ", fcc);
210 adios(NULL, "only one file at a time!");
211 if (!(cp = *argp++) || *cp == '-')
212 adios(NULL, "missing argument to %s",
214 file = getcpy(expanddir(cp));
217 if (!(cp = *argp++) || *cp == '-')
218 adios(NULL, "missing argument to %s",
220 filter = getcpy(etcpath(cp));
224 if (!(form = *argp++) || *form == '-')
225 adios(NULL, "missing argument to %s",
230 filter = getcpy(etcpath(mhlreply));
254 if (*cp == '+' || *cp == '@') {
256 adios(NULL, "only one folder at a time!");
258 folder = getcpy(expandfol(cp));
261 adios(NULL, "only one message at a time!");
276 if (file && (msg || folder))
277 adios(NULL, "can't mix files and folders/msgs");
280 strncpy(drft, buildsw ? toabsdir("reply")
281 : m_draft(seq_beyond), sizeof(drft));
283 strncpy(drft, m_draft(seq_beyond), sizeof(drft));
288 ** We are replying to a file.
290 anot = 0; /* we don't want to annotate a file */
293 ** We are replying to a message.
298 folder = getcurfol();
299 maildir = toabsdir(folder);
301 if (chdir(maildir) == NOTOK)
302 adios(maildir, "unable to change directory to");
304 /* read folder and create message structure */
305 if (!(mp = folder_read(folder)))
306 adios(NULL, "unable to read folder %s", folder);
308 /* check for empty folder */
310 adios(NULL, "no messages in %s", folder);
312 /* parse the message range/sequence/name and set SELECTED */
313 if (!m_convert(mp, msg))
315 seq_setprev(mp); /* set the previous-sequence */
318 adios(NULL, "only one message at a time!");
320 context_replace(curfolder, folder); /* update current folder */
321 seq_setcur(mp, mp->lowsel); /* update current message */
322 seq_save(mp); /* synchronize sequences */
323 context_save(); /* save the context file */
326 msg = file ? file : getcpy(m_name(mp->lowsel));
328 if ((in = fopen(msg, "r")) == NULL)
329 adios(msg, "unable to open");
331 /* find form (components) file */
334 form = etcpath(replgroupcomps);
336 form = etcpath(replcomps);
339 replout(in, msg, drft, mp, mime, form, filter, fcc);
344 what_now(ed, nedit, NOUSE, drft, msg, 0, mp, anot ? "Replied" : NULL,
351 docc(char *cp, int ccflag)
353 switch (smatch(cp, ccswitches)) {
355 ambigsw(cp, ccswitches);
358 adios(NULL, "-%scc %s unknown", ccflag ? "" : "no", cp);
373 ccto = cccc = ccme = ccflag;