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", argp[-2]);
169 if (!(cp = *argp++) || *cp == '-')
170 adios(NULL, "missing argument to %s", argp[-2]);
175 if (!(ed = *argp++) || *ed == '-')
176 adios(NULL, "missing argument to %s", argp[-2]);
184 if (!(whatnowproc = *argp++) ||
186 adios(NULL, "missing argument to %s", argp[-2]);
191 buildsw++; /* fall... */
198 if (!(cp = *argp++) || *cp == '-')
199 adios(NULL, "missing argument to %s", argp[-2]);
202 cp = dp = getcpy(expandfol(cp));
204 fcc = add(", ", fcc);
212 adios(NULL, "only one file at a time!");
213 if (!(cp = *argp++) || *cp == '-')
214 adios(NULL, "missing argument to %s", argp[-2]);
215 file = getcpy(expanddir(cp));
218 if (!(cp = *argp++) || *cp == '-')
219 adios(NULL, "missing argument to %s", argp[-2]);
220 filter = getcpy(etcpath(cp));
224 if (!(form = *argp++) || *form == '-')
225 adios(NULL, "missing argument to %s", argp[-2]);
229 filter = getcpy(etcpath(mhlreply));
259 if (!(cp = *argp++) || *cp == '-')
260 adios(NULL, "missing argument to %s", argp[-2]);
261 if ((outputlinelen = atoi(cp)) < 10)
262 adios(NULL, "impossible width %d", outputlinelen);
266 if (*cp == '+' || *cp == '@') {
268 adios(NULL, "only one folder at a time!");
270 folder = getcpy(expandfol(cp));
273 adios(NULL, "only one message at a time!");
288 if (file && (msg || folder))
289 adios(NULL, "can't mix files and folders/msgs");
292 strncpy(drft, buildsw ? toabsdir("reply")
293 : m_draft("new"), sizeof(drft));
295 strncpy(drft, m_draft("new"), sizeof(drft));
300 ** We are replying to a file.
302 anot = 0; /* we don't want to annotate a file */
305 ** We are replying to a message.
310 folder = getcurfol();
311 maildir = toabsdir(folder);
313 if (chdir(maildir) == NOTOK)
314 adios(maildir, "unable to change directory to");
316 /* read folder and create message structure */
317 if (!(mp = folder_read(folder)))
318 adios(NULL, "unable to read folder %s", folder);
320 /* check for empty folder */
322 adios(NULL, "no messages in %s", folder);
324 /* parse the message range/sequence/name and set SELECTED */
325 if (!m_convert(mp, msg))
327 seq_setprev(mp); /* set the previous-sequence */
330 adios(NULL, "only one message at a time!");
332 context_replace(curfolder, folder); /* update current folder */
333 seq_setcur(mp, mp->lowsel); /* update current message */
334 seq_save(mp); /* synchronize sequences */
335 context_save(); /* save the context file */
338 msg = file ? file : getcpy(m_name(mp->lowsel));
340 if ((in = fopen(msg, "r")) == NULL)
341 adios(msg, "unable to open");
343 /* find form (components) file */
346 form = etcpath(replgroupcomps);
348 form = etcpath(replcomps);
351 replout(in, msg, drft, mp, outputlinelen, mime, form, filter, fcc);
356 what_now(ed, nedit, NOUSE, drft, msg, 0, mp, anot ? "Replied" : NULL,
363 docc(char *cp, int ccflag)
365 switch (smatch(cp, ccswitches)) {
367 ambigsw(cp, ccswitches);
370 adios(NULL, "-%scc %s unknown", ccflag ? "" : "no",
386 ccto = cccc = ccme = ccflag;