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]", 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 = path (cp + 1,
205 fcc = add (", ", fcc);
213 adios (NULL, "only one file at a time!");
214 if (!(cp = *argp++) || *cp == '-')
215 adios (NULL, "missing argument to %s", argp[-2]);
216 file = path (cp, TFILE);
219 if (!(cp = *argp++) || *cp == '-')
220 adios (NULL, "missing argument to %s", argp[-2]);
221 filter = getcpy (etcpath (cp));
225 if (!(form = *argp++) || *form == '-')
226 adios (NULL, "missing argument to %s", argp[-2]);
230 filter = getcpy (etcpath (mhlreply));
260 if (!(cp = *argp++) || *cp == '-')
261 adios (NULL, "missing argument to %s", argp[-2]);
262 if ((outputlinelen = atoi (cp)) < 10)
263 adios (NULL, "impossible width %d", outputlinelen);
267 if (*cp == '+' || *cp == '@') {
269 adios (NULL, "only one folder at a time!");
271 folder = pluspath (cp);
274 adios (NULL, "only one message at a time!");
287 cwd = getcpy (pwd ());
289 if (!context_find ("path"))
290 free (path ("./", TFOLDER));
291 if (file && (msg || folder))
292 adios (NULL, "can't mix files and folders/msgs");
295 strncpy (drft, buildsw ? m_maildir ("reply")
296 : m_draft("new"), sizeof(drft));
298 strncpy (drft, m_draft("new"), sizeof(drft));
303 ** We are replying to a file.
305 anot = 0; /* we don't want to annotate a file */
308 ** We are replying to a message.
313 folder = getfolder (1);
314 maildir = m_maildir (folder);
316 if (chdir (maildir) == NOTOK)
317 adios (maildir, "unable to change directory to");
319 /* read folder and create message structure */
320 if (!(mp = folder_read (folder)))
321 adios (NULL, "unable to read folder %s", folder);
323 /* check for empty folder */
325 adios (NULL, "no messages in %s", folder);
327 /* parse the message range/sequence/name and set SELECTED */
328 if (!m_convert (mp, msg))
330 seq_setprev (mp); /* set the previous-sequence */
333 adios (NULL, "only one message at a time!");
335 context_replace (pfolder, folder); /* update current folder */
336 seq_setcur (mp, mp->lowsel); /* update current message */
337 seq_save (mp); /* synchronize sequences */
338 context_save (); /* save the context file */
341 msg = file ? file : getcpy (m_name (mp->lowsel));
343 if ((in = fopen (msg, "r")) == NULL)
344 adios (msg, "unable to open");
346 /* find form (components) file */
349 form = etcpath (replgroupcomps);
351 form = etcpath (replcomps);
354 replout (in, msg, drft, mp, outputlinelen, mime, form, filter, fcc);
359 what_now (ed, nedit, NOUSE, drft, msg, 0, mp,
360 anot ? "Replied" : NULL, inplace, cwd);
366 docc (char *cp, int ccflag)
368 switch (smatch (cp, ccswitches)) {
370 ambigsw (cp, ccswitches);
373 adios (NULL, "-%scc %s unknown",
374 ccflag ? "" : "no", cp);
389 ccto = cccc = ccme = ccflag;