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 },
53 { "whatnowproc program", 0 },
55 { "nowhatnowproc", 0 },
61 { "file file", 4 }, /* interface from msh */
65 { "build", 5 }, /* interface from mhe */
71 static struct swit ccswitches[] = {
83 short ccto = -1; /* global for replsbr */
88 short groupreply = 0; /* Is this a group reply? */
90 int mime = 0; /* include original as MIME part */
91 char *form = NULL; /* form (components) file */
92 char *filter = NULL; /* message filter file */
93 char *fcc = NULL; /* folders to add to Fcc: header */
99 void docc(char *, int);
103 main(int argc, char **argv)
105 int anot = 0, inplace = 1;
106 int nedit = 0, nwhat = 0;
107 char *cp, *cwd, *dp, *maildir, *file = NULL;
108 char *folder = NULL, *msg = NULL;
109 char *ed = NULL, drft[BUFSIZ], buf[BUFSIZ];
110 char **argp, **arguments;
111 struct msgs *mp = NULL;
119 setlocale(LC_ALL, "");
121 invo_name = mhbasename(argv[0]);
123 /* read user profile/context */
126 arguments = getarguments(invo_name, argc, argv, 1);
129 while ((cp = *argp++)) {
131 switch (smatch(++cp, switches)) {
133 ambigsw(cp, switches);
136 adios(NULL, "-%s unknown", cp);
139 snprintf(buf, sizeof(buf), "%s: [+folder] [msg] [switches]", invo_name);
140 print_help(buf, switches, 1);
143 print_version(invo_name);
161 if (!(cp = *argp++) || *cp == '-')
162 adios(NULL, "missing argument to %s",
167 if (!(cp = *argp++) || *cp == '-')
168 adios(NULL, "missing argument to %s",
174 if (!(ed = *argp++) || *ed == '-')
175 adios(NULL, "missing argument to %s",
184 if (!(whatnowproc = *argp++) ||
186 adios(NULL, "missing argument to %s",
192 buildsw++; /* fall... */
199 if (!(cp = *argp++) || *cp == '-')
200 adios(NULL, "missing argument to %s",
204 cp = dp = getcpy(expandfol(cp));
206 fcc = add(", ", fcc);
214 adios(NULL, "only one file at a time!");
215 if (!(cp = *argp++) || *cp == '-')
216 adios(NULL, "missing argument to %s",
218 file = getcpy(expanddir(cp));
221 if (!(cp = *argp++) || *cp == '-')
222 adios(NULL, "missing argument to %s",
224 filter = getcpy(etcpath(cp));
228 if (!(form = *argp++) || *form == '-')
229 adios(NULL, "missing argument to %s",
234 filter = getcpy(etcpath(mhlreply));
265 if (*cp == '+' || *cp == '@') {
267 adios(NULL, "only one folder at a time!");
269 folder = getcpy(expandfol(cp));
272 adios(NULL, "only one message at a time!");
287 if (file && (msg || folder))
288 adios(NULL, "can't mix files and folders/msgs");
291 strncpy(drft, buildsw ? toabsdir("reply")
292 : m_draft(seq_beyond), sizeof(drft));
294 strncpy(drft, m_draft(seq_beyond), sizeof(drft));
299 ** We are replying to a file.
301 anot = 0; /* we don't want to annotate a file */
304 ** We are replying to a message.
309 folder = getcurfol();
310 maildir = toabsdir(folder);
312 if (chdir(maildir) == NOTOK)
313 adios(maildir, "unable to change directory to");
315 /* read folder and create message structure */
316 if (!(mp = folder_read(folder)))
317 adios(NULL, "unable to read folder %s", folder);
319 /* check for empty folder */
321 adios(NULL, "no messages in %s", folder);
323 /* parse the message range/sequence/name and set SELECTED */
324 if (!m_convert(mp, msg))
326 seq_setprev(mp); /* set the previous-sequence */
329 adios(NULL, "only one message at a time!");
331 context_replace(curfolder, folder); /* update current folder */
332 seq_setcur(mp, mp->lowsel); /* update current message */
333 seq_save(mp); /* synchronize sequences */
334 context_save(); /* save the context file */
337 msg = file ? file : getcpy(m_name(mp->lowsel));
339 if ((in = fopen(msg, "r")) == NULL)
340 adios(msg, "unable to open");
342 /* find form (components) file */
345 form = etcpath(replgroupcomps);
347 form = etcpath(replcomps);
350 replout(in, msg, drft, mp, mime, form, filter, fcc);
355 what_now(ed, nedit, NOUSE, drft, msg, 0, mp, anot ? "Replied" : NULL,
362 docc(char *cp, int ccflag)
364 switch (smatch(cp, ccswitches)) {
366 ambigsw(cp, ccswitches);
369 adios(NULL, "-%scc %s unknown", ccflag ? "" : "no", cp);
384 ccto = cccc = ccme = ccflag;