3 * repl.c -- reply to a message
11 static struct swit switches[] = {
21 { "cc all|to|cc|me", 0 },
25 { "draftfolder +folder", 0 },
27 { "draftmessage msg", 0 },
29 { "nodraftfolder", 0 },
31 { "editor editor", 0 },
37 { "filter filterfile", 0 },
39 { "form formfile", 0 },
57 { "whatnowproc program", 0 },
59 { "nowhatnowproc", 0 },
61 { "width columns", 0 },
67 { "file file", -4 }, /* interface from msh */
71 { "build", -5 }, /* interface from mhe */
77 static struct swit ccswitches[] = {
89 static struct swit aqrnl[] = {
97 { "refile +folder", 0 },
103 static struct swit aqrl[] = {
107 { "refile +folder", 0 },
111 short ccto = 0; /* global for replsbr */
116 short outputlinelen = OUTPUTLINELEN;
117 short groupreply = 0; /* Is this a group reply? */
119 int mime = 0; /* include original as MIME part */
120 char *form = NULL; /* form (components) file */
121 char *filter = NULL; /* message filter file */
122 char *fcc = NULL; /* folders to add to Fcc: header */
128 void docc (char *, int);
132 main (int argc, char **argv)
135 int anot = 0, inplace = 1;
136 int nedit = 0, nwhat = 0;
137 char *cp, *cwd, *dp, *maildir, *file = NULL;
138 char *folder = NULL, *msg = NULL, *dfolder = NULL;
139 char *dmsg = NULL, *ed = NULL, drft[BUFSIZ], buf[BUFSIZ];
140 char **argp, **arguments;
141 struct msgs *mp = NULL;
150 setlocale(LC_ALL, "");
152 invo_name = r1bindex (argv[0], '/');
154 /* read user profile/context */
157 arguments = getarguments (invo_name, argc, argv, 1);
160 while ((cp = *argp++)) {
162 switch (smatch (++cp, switches)) {
164 ambigsw (cp, switches);
167 adios (NULL, "-%s unknown", cp);
170 snprintf (buf, sizeof(buf), "%s: [+folder] [msg] [switches]",
172 print_help (buf, switches, 1);
175 print_version(invo_name);
180 ccto = cccc = ccme = 1;
184 ccto = cccc = ccme = 0;
195 if (!(cp = *argp++) || *cp == '-')
196 adios (NULL, "missing argument to %s", argp[-2]);
200 if (!(cp = *argp++) || *cp == '-')
201 adios (NULL, "missing argument to %s", argp[-2]);
206 if (!(ed = *argp++) || *ed == '-')
207 adios (NULL, "missing argument to %s", argp[-2]);
215 if (!(whatnowproc = *argp++) || *whatnowproc == '-')
216 adios (NULL, "missing argument to %s", argp[-2]);
221 buildsw++; /* fall... */
228 if (!(cp = *argp++) || *cp == '-')
229 adios (NULL, "missing argument to %s", argp[-2]);
232 cp = dp = path (cp + 1, TSUBCWF);
234 fcc = add (", ", fcc);
242 adios (NULL, "only one file at a time!");
243 if (!(cp = *argp++) || *cp == '-')
244 adios (NULL, "missing argument to %s", argp[-2]);
245 file = path (cp, TFILE);
248 if (!(cp = *argp++) || *cp == '-')
249 adios (NULL, "missing argument to %s", argp[-2]);
250 filter = getcpy (etcpath (cp));
254 if (!(form = *argp++) || *form == '-')
255 adios (NULL, "missing argument to %s", argp[-2]);
259 filter = getcpy (etcpath (mhlreply));
289 if (!(cp = *argp++) || *cp == '-')
290 adios (NULL, "missing argument to %s", argp[-2]);
291 if ((outputlinelen = atoi (cp)) < 10)
292 adios (NULL, "impossible width %d", outputlinelen);
297 adios (NULL, "only one draft folder at a time!");
298 if (!(cp = *argp++) || *cp == '-')
299 adios (NULL, "missing argument to %s", argp[-2]);
300 dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
301 *cp != '@' ? TFOLDER : TSUBCWF);
305 adios (NULL, "only one draft message at a time!");
306 if (!(dmsg = *argp++) || *dmsg == '-')
307 adios (NULL, "missing argument to %s", argp[-2]);
315 if (*cp == '+' || *cp == '@') {
317 adios (NULL, "only one folder at a time!");
319 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
322 adios (NULL, "only one message at a time!");
328 cwd = getcpy (pwd ());
330 if (!context_find ("path"))
331 free (path ("./", TFOLDER));
332 if (file && (msg || folder))
333 adios (NULL, "can't mix files and folders/msgs");
338 strncpy (drft, buildsw ? m_maildir ("reply")
339 : m_draft (dfolder, NULL, NOUSE, &isdf), sizeof(drft));
341 /* Check if a draft exists */
342 if (!buildsw && stat (drft, &st) != NOTOK) {
344 strncpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf), sizeof(drft));
346 /* Check if a draft exists */
347 if (stat (drft, &st) != NOTOK) {
349 printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size);
350 for (i = LISTDSW; i != YESW;) {
351 if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl)))
353 switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) {
362 showfile (++argp, drft);
365 if (refile (++argp, drft) == 0)
369 advise (NULL, "say what?");
377 * We are replying to a file.
379 anot = 0; /* we don't want to annotate a file */
382 * We are replying to a message.
387 folder = getfolder (1);
388 maildir = m_maildir (folder);
390 if (chdir (maildir) == NOTOK)
391 adios (maildir, "unable to change directory to");
393 /* read folder and create message structure */
394 if (!(mp = folder_read (folder)))
395 adios (NULL, "unable to read folder %s", folder);
397 /* check for empty folder */
399 adios (NULL, "no messages in %s", folder);
401 /* parse the message range/sequence/name and set SELECTED */
402 if (!m_convert (mp, msg))
404 seq_setprev (mp); /* set the previous-sequence */
407 adios (NULL, "only one message at a time!");
409 context_replace (pfolder, folder); /* update current folder */
410 seq_setcur (mp, mp->lowsel); /* update current message */
411 seq_save (mp); /* synchronize sequences */
412 context_save (); /* save the context file */
415 msg = file ? file : getcpy (m_name (mp->lowsel));
417 if ((in = fopen (msg, "r")) == NULL)
418 adios (msg, "unable to open");
420 /* find form (components) file */
423 form = etcpath (replgroupcomps);
425 form = etcpath (replcomps);
428 replout (in, msg, drft, mp, outputlinelen, mime, form, filter, fcc);
433 what_now (ed, nedit, NOUSE, drft, msg, 0, mp,
434 anot ? "Replied" : NULL, inplace, cwd);
439 docc (char *cp, int ccflag)
441 switch (smatch (cp, ccswitches)) {
443 ambigsw (cp, ccswitches);
446 adios (NULL, "-%scc %s unknown", ccflag ? "" : "no", cp);
461 ccto = cccc = ccme = ccflag;