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 },
57 { "width columns", 0 },
63 { "file file", 4 }, /* interface from msh */
67 { "build", 5 }, /* interface from mhe */
73 static struct swit ccswitches[] = {
85 short ccto = -1; /* global for replsbr */
90 short outputlinelen = OUTPUTLINELEN;
91 short groupreply = 0; /* Is this a group reply? */
93 int mime = 0; /* include original as MIME part */
94 char *form = NULL; /* form (components) file */
95 char *filter = NULL; /* message filter file */
96 char *fcc = NULL; /* folders to add to Fcc: header */
102 void docc(char *, int);
106 main(int argc, char **argv)
108 int anot = 0, inplace = 1;
109 int nedit = 0, nwhat = 0;
110 char *cp, *cwd, *dp, *maildir, *file = NULL;
111 char *folder = NULL, *msg = NULL;
112 char *ed = NULL, drft[BUFSIZ], buf[BUFSIZ];
113 char **argp, **arguments;
114 struct msgs *mp = NULL;
122 setlocale(LC_ALL, "");
124 invo_name = mhbasename(argv[0]);
126 /* read user profile/context */
129 arguments = getarguments(invo_name, argc, argv, 1);
132 while ((cp = *argp++)) {
134 switch (smatch(++cp, switches)) {
136 ambigsw(cp, switches);
139 adios(NULL, "-%s unknown", cp);
142 snprintf(buf, sizeof(buf), "%s: [+folder] [msg] [switches]", invo_name);
143 print_help(buf, switches, 1);
146 print_version(invo_name);
164 if (!(cp = *argp++) || *cp == '-')
165 adios(NULL, "missing argument to %s",
170 if (!(cp = *argp++) || *cp == '-')
171 adios(NULL, "missing argument to %s",
177 if (!(ed = *argp++) || *ed == '-')
178 adios(NULL, "missing argument to %s",
187 if (!(whatnowproc = *argp++) ||
189 adios(NULL, "missing argument to %s",
195 buildsw++; /* fall... */
202 if (!(cp = *argp++) || *cp == '-')
203 adios(NULL, "missing argument to %s",
207 cp = dp = getcpy(expandfol(cp));
209 fcc = add(", ", fcc);
217 adios(NULL, "only one file at a time!");
218 if (!(cp = *argp++) || *cp == '-')
219 adios(NULL, "missing argument to %s",
221 file = getcpy(expanddir(cp));
224 if (!(cp = *argp++) || *cp == '-')
225 adios(NULL, "missing argument to %s",
227 filter = getcpy(etcpath(cp));
231 if (!(form = *argp++) || *form == '-')
232 adios(NULL, "missing argument to %s",
237 filter = getcpy(etcpath(mhlreply));
267 if (!(cp = *argp++) || *cp == '-')
268 adios(NULL, "missing argument to %s",
270 if ((outputlinelen = atoi(cp)) < 10)
271 adios(NULL, "impossible width %d",
276 if (*cp == '+' || *cp == '@') {
278 adios(NULL, "only one folder at a time!");
280 folder = getcpy(expandfol(cp));
283 adios(NULL, "only one message at a time!");
298 if (file && (msg || folder))
299 adios(NULL, "can't mix files and folders/msgs");
302 strncpy(drft, buildsw ? toabsdir("reply")
303 : m_draft(seq_beyond), sizeof(drft));
305 strncpy(drft, m_draft(seq_beyond), sizeof(drft));
310 ** We are replying to a file.
312 anot = 0; /* we don't want to annotate a file */
315 ** We are replying to a message.
320 folder = getcurfol();
321 maildir = toabsdir(folder);
323 if (chdir(maildir) == NOTOK)
324 adios(maildir, "unable to change directory to");
326 /* read folder and create message structure */
327 if (!(mp = folder_read(folder)))
328 adios(NULL, "unable to read folder %s", folder);
330 /* check for empty folder */
332 adios(NULL, "no messages in %s", folder);
334 /* parse the message range/sequence/name and set SELECTED */
335 if (!m_convert(mp, msg))
337 seq_setprev(mp); /* set the previous-sequence */
340 adios(NULL, "only one message at a time!");
342 context_replace(curfolder, folder); /* update current folder */
343 seq_setcur(mp, mp->lowsel); /* update current message */
344 seq_save(mp); /* synchronize sequences */
345 context_save(); /* save the context file */
348 msg = file ? file : getcpy(m_name(mp->lowsel));
350 if ((in = fopen(msg, "r")) == NULL)
351 adios(msg, "unable to open");
353 /* find form (components) file */
356 form = etcpath(replgroupcomps);
358 form = etcpath(replcomps);
361 replout(in, msg, drft, mp, outputlinelen, mime, form, filter, fcc);
366 what_now(ed, nedit, NOUSE, drft, msg, 0, mp, anot ? "Replied" : NULL,
373 docc(char *cp, int ccflag)
375 switch (smatch(cp, ccswitches)) {
377 ambigsw(cp, ccswitches);
380 adios(NULL, "-%scc %s unknown", ccflag ? "" : "no", cp);
395 ccto = cccc = ccme = ccflag;