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 = r1bindex (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]",
144 print_help (buf, switches, 1);
147 print_version(invo_name);
165 if (!(cp = *argp++) || *cp == '-')
166 adios (NULL, "missing argument to %s", argp[-2]);
170 if (!(cp = *argp++) || *cp == '-')
171 adios (NULL, "missing argument to %s", argp[-2]);
176 if (!(ed = *argp++) || *ed == '-')
177 adios (NULL, "missing argument to %s", argp[-2]);
185 if (!(whatnowproc = *argp++) || *whatnowproc == '-')
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 = path (cp + 1, TSUBCWF);
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 = path (cp, TFILE);
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 = pluspath (cp);
273 adios (NULL, "only one message at a time!");
286 cwd = getcpy (pwd ());
288 if (!context_find ("path"))
289 free (path ("./", TFOLDER));
290 if (file && (msg || folder))
291 adios (NULL, "can't mix files and folders/msgs");
294 strncpy (drft, buildsw ? m_maildir ("reply")
295 : m_draft("new"), sizeof(drft));
297 strncpy (drft, m_draft("new"), sizeof(drft));
302 * We are replying to a file.
304 anot = 0; /* we don't want to annotate a file */
307 * We are replying to a message.
312 folder = getfolder (1);
313 maildir = m_maildir (folder);
315 if (chdir (maildir) == NOTOK)
316 adios (maildir, "unable to change directory to");
318 /* read folder and create message structure */
319 if (!(mp = folder_read (folder)))
320 adios (NULL, "unable to read folder %s", folder);
322 /* check for empty folder */
324 adios (NULL, "no messages in %s", folder);
326 /* parse the message range/sequence/name and set SELECTED */
327 if (!m_convert (mp, msg))
329 seq_setprev (mp); /* set the previous-sequence */
332 adios (NULL, "only one message at a time!");
334 context_replace (pfolder, folder); /* update current folder */
335 seq_setcur (mp, mp->lowsel); /* update current message */
336 seq_save (mp); /* synchronize sequences */
337 context_save (); /* save the context file */
340 msg = file ? file : getcpy (m_name (mp->lowsel));
342 if ((in = fopen (msg, "r")) == NULL)
343 adios (msg, "unable to open");
345 /* find form (components) file */
348 form = etcpath (replgroupcomps);
350 form = etcpath (replcomps);
353 replout (in, msg, drft, mp, outputlinelen, mime, form, filter, fcc);
358 what_now (ed, nedit, NOUSE, drft, msg, 0, mp,
359 anot ? "Replied" : NULL, inplace, cwd);
365 docc (char *cp, int ccflag)
367 switch (smatch (cp, ccswitches)) {
369 ambigsw (cp, ccswitches);
372 adios (NULL, "-%scc %s unknown", ccflag ? "" : "no", cp);
387 ccto = cccc = ccme = ccflag;