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 },
31 { "filter filterfile", 0 },
33 { "form formfile", 0 },
47 { "whatnowproc program", 0 },
49 { "nowhatnowproc", 0 },
55 { "file file", 4 }, /* interface from msh */
59 { "build", 5 }, /* interface from mhe */
65 static struct swit ccswitches[] = {
77 short ccto = -1; /* global for replsbr */
82 short groupreply = 0; /* Is this a group reply? */
84 int mime = 0; /* include original as MIME part */
85 char *form = NULL; /* form (components) file */
86 char *filter = NULL; /* message filter file */
92 void docc(char *, int);
96 main(int argc, char **argv)
99 int nedit = 0, nwhat = 0;
100 char *cp, *cwd, *maildir, *file = NULL;
101 char *folder = NULL, *msg = NULL;
102 char *ed = NULL, drft[BUFSIZ], buf[BUFSIZ];
103 char **argp, **arguments;
104 struct msgs *mp = NULL;
112 setlocale(LC_ALL, "");
114 invo_name = mhbasename(argv[0]);
116 /* read user profile/context */
119 arguments = getarguments(invo_name, argc, argv, 1);
122 while ((cp = *argp++)) {
124 switch (smatch(++cp, switches)) {
126 ambigsw(cp, switches);
129 adios(NULL, "-%s unknown", cp);
132 snprintf(buf, sizeof(buf), "%s: [+folder] [msg] [switches]", invo_name);
133 print_help(buf, switches, 1);
136 print_version(invo_name);
154 if (!(cp = *argp++) || *cp == '-')
155 adios(NULL, "missing argument to %s",
160 if (!(cp = *argp++) || *cp == '-')
161 adios(NULL, "missing argument to %s",
167 if (!(ed = *argp++) || *ed == '-')
168 adios(NULL, "missing argument to %s",
177 if (!(whatnowproc = *argp++) ||
179 adios(NULL, "missing argument to %s",
185 buildsw++; /* fall... */
193 adios(NULL, "only one file at a time!");
194 if (!(cp = *argp++) || *cp == '-')
195 adios(NULL, "missing argument to %s",
197 file = getcpy(expanddir(cp));
200 if (!(cp = *argp++) || *cp == '-')
201 adios(NULL, "missing argument to %s",
203 filter = getcpy(etcpath(cp));
207 if (!(form = *argp++) || *form == '-')
208 adios(NULL, "missing argument to %s",
213 filter = getcpy(etcpath(mhlreply));
237 if (*cp == '+' || *cp == '@') {
239 adios(NULL, "only one folder at a time!");
241 folder = getcpy(expandfol(cp));
244 adios(NULL, "only one message at a time!");
259 if (file && (msg || folder))
260 adios(NULL, "can't mix files and folders/msgs");
263 strncpy(drft, buildsw ? toabsdir("reply")
264 : m_draft(seq_beyond), sizeof(drft));
266 strncpy(drft, m_draft(seq_beyond), sizeof(drft));
271 ** We are replying to a file.
273 anot = 0; /* we don't want to annotate a file */
276 ** We are replying to a message.
281 folder = getcurfol();
282 maildir = toabsdir(folder);
284 if (chdir(maildir) == NOTOK)
285 adios(maildir, "unable to change directory to");
287 /* read folder and create message structure */
288 if (!(mp = folder_read(folder)))
289 adios(NULL, "unable to read folder %s", folder);
291 /* check for empty folder */
293 adios(NULL, "no messages in %s", folder);
295 /* parse the message range/sequence/name and set SELECTED */
296 if (!m_convert(mp, msg))
298 seq_setprev(mp); /* set the previous-sequence */
301 adios(NULL, "only one message at a time!");
303 context_replace(curfolder, folder); /* update current folder */
304 seq_setcur(mp, mp->lowsel); /* update current message */
305 seq_save(mp); /* synchronize sequences */
306 context_save(); /* save the context file */
309 msg = file ? file : getcpy(m_name(mp->lowsel));
311 if ((in = fopen(msg, "r")) == NULL)
312 adios(msg, "unable to open");
314 /* find form (components) file */
317 form = etcpath(replgroupcomps);
319 form = etcpath(replcomps);
322 replout(in, msg, drft, mp, mime, form, filter);
327 what_now(ed, nedit, NOUSE, drft, msg, 0, mp, anot ? "Replied" : NULL,
334 docc(char *cp, int ccflag)
336 switch (smatch(cp, ccswitches)) {
338 ambigsw(cp, ccswitches);
341 adios(NULL, "-%scc %s unknown", ccflag ? "" : "no", cp);
356 ccto = cccc = ccme = ccflag;