9 date 95.12.06.21.07.03; author jromine; state Exp;
14 date 93.08.25.17.25.18; author jromine; state Exp;
19 date 92.12.15.00.20.22; author jromine; state Exp;
24 date 92.11.04.00.43.17; author jromine; state Exp;
29 date 92.10.16.21.36.45; author jromine; state Exp;
34 date 92.05.19.21.07.06; author jromine; state Exp;
39 date 92.02.05.07.26.30; author jromine; state Exp;
44 date 92.02.04.17.46.56; author jromine; state Exp;
49 date 92.01.31.22.09.50; author jromine; state Exp;
54 date 90.04.05.14.59.50; author sources; state Exp;
59 date 90.03.23.15.02.44; author sources; state Exp;
64 date 90.03.20.10.35.58; author sources; state Exp;
69 date 90.02.06.13.19.09; author sources; state Exp;
74 date 90.02.01.14.15.54; author sources; state Exp;
79 date 90.02.01.14.15.39; author sources; state Exp;
93 @/* forw.c - forward messages */
95 static char ident[] = "@@(#)$Id: forw.c,v 1.14 1993/08/25 17:25:18 jromine Exp jromine $";
99 #include "../h/formatsbr.h"
100 #include "../zotnet/tws.h"
102 #include <sys/types.h>
103 #include <sys/stat.h>
109 #define MIMEminc(a) (a)
111 #define MIMEminc(a) 0
114 #define IFORMAT "digest-issue-%s"
115 #define VFORMAT "digest-volume-%s"
117 static mhl_draft(), copy_draft(), build_form();
120 static struct swit switches[] = {
127 "draftfolder +folder", 0,
129 "draftmessage msg", 0,
139 "filter filterfile", 0,
154 "mime", MIMEminc(-4),
156 "nomime", MIMEminc(-6),
166 "whatnowproc program", 0,
174 "file file", -4, /* interface from msh */
177 "dashmunging", -4, /* interface to mhl */
183 "build", -5, /* interface from mhe */
191 static struct swit aqrnl[] = {
207 static struct swit aqrl[] = {
218 static char drft[BUFSIZ];
220 static char delim3[] =
221 "\n------------------------------------------------------------\n\n";
222 static char delim4[] = "\n------------------------------\n\n";
225 static struct msgs *mp = NULL; /* used a lot */
276 setlocale(LC_ALL, "");
278 invo_name = r1bindex (argv[0], '/');
279 if ((cp = m_find (invo_name)) != NULL) {
280 ap = brkstring (cp = getcpy (cp), " ", "\n");
281 ap = copyip (ap, arguments);
285 (void) copyip (argv + 1, ap);
290 while (cp = *argp++) {
292 switch (smatch (++cp, switches)) {
294 ambigsw (cp, switches);
297 adios (NULLCP, "-%s unknown", cp);
299 (void) sprintf (buf, "%s [+folder] [msgs] [switches]",
301 help (buf, switches);
312 if (!(ed = *argp++) || *ed == '-')
313 adios (NULLCP, "missing argument to %s", argp[-2]);
321 if (!(whatnowproc = *argp++) || *whatnowproc == '-')
322 adios (NULLCP, "missing argument to %s", argp[-2]);
327 buildsw++; /* fall... */
335 adios (NULLCP, "only one file at a time!");
336 if (!(cp = *argp++) || *cp == '-')
337 adios (NULLCP, "missing argument to %s", argp[-2]);
338 file = path (cp, TFILE);
341 if (!(cp = *argp++) || *cp == '-')
342 adios (NULLCP, "missing argument to %s", argp[-2]);
343 filter = getcpy (libpath (cp));
347 if (!(form = *argp++) || *form == '-')
348 adios (NULLCP, "missing argument to %s", argp[-2]);
352 filter = getcpy (libpath (mhlforward));
376 if (!(digest = *argp++) || *digest == '-')
377 adios (NULLCP, "missing argument to %s", argp[-2]);
381 if (!(cp = *argp++) || *cp == '-')
382 adios (NULLCP, "missing argument to %s", argp[-2]);
383 if ((issue = atoi (cp)) < 1)
384 adios (NULLCP, "bad argument %s %s", argp[-2], cp);
387 if (!(cp = *argp++) || *cp == '-')
388 adios (NULLCP, "missing argument to %s", argp[-2]);
389 if ((volume = atoi (cp)) < 1)
390 adios (NULLCP, "bad argument %s %s", argp[-2], cp);
395 adios (NULLCP, "only one draft folder at a time!");
396 if (!(cp = *argp++) || *cp == '-')
397 adios (NULLCP, "missing argument to %s", argp[-2]);
398 dfolder = path (*cp == '+' || *cp == '@@' ? cp + 1 : cp,
399 *cp != '@@' ? TFOLDER : TSUBCWF);
403 adios (NULLCP, "only one draft message at a time!");
404 if (!(dmsg = *argp++) || *dmsg == '-')
405 adios (NULLCP, "missing argument to %s", argp[-2]);
419 if (*cp == '+' || *cp == '@@') {
421 adios (NULLCP, "only one folder at a time!");
423 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
431 cwd = getcpy (pwd ());
433 if (!m_find ("path"))
434 free (path ("./", TFOLDER));
435 if (file && (msgp || folder))
436 adios (NULLCP, "can't mix files and folders/msgs");
440 (void) strcpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf));
441 if (stat (drft, &st) != NOTOK) {
443 (void) strcpy (drft, buildsw ? m_maildir ("draft")
444 : m_draft (dfolder, NULLCP, NOUSE, &isdf));
445 if (!buildsw && stat (drft, &st) != NOTOK) {
447 printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size);
448 for (i = LISTDSW; i != YESW;) {
449 if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl)))
451 switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) {
460 (void) showfile (++argp, drft);
463 if (refile (++argp, drft) == 0)
467 advise (NULLCP, "say what?");
481 msgs[msgp++] = "cur";
483 folder = m_getfolder ();
484 maildir = m_maildir (folder);
486 if (chdir (maildir) == NOTOK)
487 adios (maildir, "unable to change directory to");
488 if (!(mp = m_gmsg (folder)))
489 adios (NULLCP, "unable to read folder %s", folder);
490 if (mp -> hghmsg == 0)
491 adios (NULLCP, "no messages in %s", folder);
493 for (msgnum = 0; msgnum < msgp; msgnum++)
494 if (!m_convert (mp, msgs[msgnum]))
501 if (filter && access (filter, 04) == NOTOK)
502 adios (filter, "unable to read");
506 (void) sprintf (buf, IFORMAT, digest);
508 && (cp = m_find (buf))
509 && ((issue = atoi (cp)) < 0))
514 (void) sprintf (buf, VFORMAT, digest);
515 if ((cp = m_find (buf)) == NULL || (volume = atoi (cp)) <= 0)
519 in = build_form (form, digest, volume, issue);
523 if ((in = open (libpath (form), 0)) == NOTOK)
524 adios (form, "unable to open form file");
527 if ((in = open (libpath (forwcomps), 0)) == NOTOK)
528 adios (forwcomps, "unable to open default components file");
532 if ((out = creat (drft, m_gmprot ())) == NOTOK)
533 adios (drft, "unable to create");
535 cpydata (in, out, form, drft);
541 if ((in = open (file, 0)) == NOTOK)
542 adios (file, "unable to open");
543 cpydata (in, out, file, drft);
550 mhl_draft (out, digest, volume, issue, drft, filter, dashflg);
552 copy_draft (out, digest, drft, volume, issue, mime);
556 (void) sprintf (buf, IFORMAT, digest);
557 (void) sprintf (value, "%d", issue);
558 m_replace (buf, getcpy (value));
559 (void) sprintf (buf, VFORMAT, digest);
560 (void) sprintf (value, "%d", volume);
561 m_replace (buf, getcpy (value));
564 m_replace (pfolder, folder);
565 if (mp -> lowsel != mp -> curmsg)
566 m_setcur (mp, mp -> lowsel);
573 (void) what_now (ed, nedit, NOUSE, drft, NULLCP, 0, mp,
574 anot ? "Forwarded" : NULLCP, inplace, cwd);
580 static mhl_draft (out, digest, volume, issue, file, filter, dashflg)
585 register char *digest,
597 if (pipe (pd) == NOTOK)
598 adios ("pipe", "unable to create");
600 vec[0] = r1bindex (mhlproc, '/');
602 for (i = 0; (child_id = fork ()) == NOTOK && i < 5; i++)
606 adios ("fork", "unable to");
609 (void) close (pd[0]);
610 (void) dup2 (pd[1], 1);
611 (void) close (pd[1]);
614 vec[i++] = "-forwall";
618 vec[i++] = "-digest";
621 sprintf(buf1, "%d", issue); vec[i++] = buf1;
622 vec[i++] = "-volume";
623 sprintf(buf2, "%d", volume); vec[i++] = buf2;
625 vec[i++] = dashflg ? "-dashmunging" : "-nodashmunging";
626 if (mp -> numsel >= MAXARGS - i)
627 adios (NULLCP, "more than %d messages for %s exec",
628 vec[0], MAXARGS - i);
629 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
630 if (mp -> msgstats[msgnum] & SELECTED)
631 vec[i++] = getcpy (m_name (msgnum));
634 execvp (mhlproc, vec);
635 fprintf (stderr, "unable to exec ");
640 (void) close (pd[1]);
641 cpydata (pd[0], out, vec[0], file);
642 (void) close (pd[0]);
643 (void) pidXwait (child_id, mhlproc);
650 static copy_draft (out, digest, file, volume, issue, mime)
655 register char *digest,
667 (void) sprintf (buffer, "#forw [forwarded message%s] +%s",
668 mp -> numsel == 1 ? "" : "s", mp -> foldpath);
669 (void) write (out, buffer, strlen (buffer));
670 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
671 if (mp -> msgstats[msgnum] & SELECTED) {
672 (void) sprintf (buffer, " %s", m_name (msgnum));
673 (void) write (out, buffer, strlen (buffer));
675 (void) write (out, "\n", 1);
682 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
683 if (mp -> msgstats[msgnum] & SELECTED) {
685 (void) strcpy (buffer,
686 msgnum == mp -> lowsel ? delim3 : delim4);
688 (void) strcpy (bp = buffer, "\n-------"), bp += strlen (bp);
689 if (msgnum == mp -> lowsel)
690 (void) sprintf (bp, " Forwarded Message%s",
691 mp -> numsel > 1 ? "s" : "");
693 (void) sprintf (bp, " Message %d", msgcnt);
695 (void) strcpy (bp, "\n\n");
697 (void) write (out, buffer, strlen (buffer));
699 if ((fd = open (msgnam = m_name (msgnum), 0)) == NOTOK) {
700 admonish (msgnam, "unable to read message");
703 cpydgst (fd, out, msgnam, file);
710 (void) strcpy (buffer, delim4);
712 (void) sprintf (buffer, "\n------- End of Forwarded Message%s\n\n",
713 mp -> numsel > 1 ? "s" : "");
714 (void) write (out, buffer, strlen (buffer));
717 (void) sprintf (buffer, "End of %s Digest [Volume %d Issue %d]\n", digest, volume, issue);
719 for (bp = buffer + i; i > 1; i--)
723 (void) write (out, buffer, strlen (buffer));
729 static int build_form (form, digest, volume, issue)
741 register struct comp *cptr;
745 nfs = new_fs (form, NULLCP, NULLCP);
746 fmtsize = strlen (nfs) + 256;
747 (void) fmt_compile (nfs, &fmt);
749 FINDCOMP (cptr, "digest");
751 cptr->c_text = digest;
752 FINDCOMP (cptr, "date");
754 cptr->c_text = getcpy(dtimenow ());
762 (void) strcpy (tmpfil, m_tmpfil (invo_name));
763 if ((tmp = fopen (tmpfil, "w+")) == NULL)
764 adios (tmpfil, "unable to create");
765 (void) unlink (tmpfil);
766 if ((in = dup (fileno (tmp))) == NOTOK)
767 adios ("dup", "unable to");
769 if ((line = malloc ((unsigned) fmtsize)) == NULLCP)
770 adios (NULLCP, "unable to allocate format line storage");
771 (void) fmtscan (fmt, line, fmtsize, dat);
772 (void) fputs (line, tmp);
775 adios (tmpfil, "error writing");
777 (void) lseek (in, (off_t)0, 0);
785 @off_t fixes for BSD44
790 static char ident[] = "@@(#)$Id: forw.c,v 1.13 1992/12/15 00:20:22 jromine Exp jromine $";
793 (void) sprintf (buffer, "#forw [] +%s", mp -> foldpath);
804 static char ident[] = "@@(#)$Id: forw.c,v 1.12 1992/11/04 00:43:17 jromine Exp jromine $";
807 long lseek (), time ();
810 printf ("Draft \"%s\" exists (%ld bytes).", drft, st.st_size);
813 (void) lseek (in, 0L, 0);
824 static char ident[] = "@@(#)$Id: forw.c,v 1.11 1992/10/16 21:36:45 jromine Exp jromine $";
857 static char ident[] = "@@(#)$Id: forw.c,v 1.10 1992/05/19 21:07:06 jromine Exp jromine $";
870 static char ident[] = "@@(#)$Id: forw.c,v 1.9 1992/02/05 07:26:30 jromine Exp jromine $";
908 copy_draft (out, digest, drft, volume, issue);
911 static copy_draft (out, digest, file, volume, issue)
921 @put unseen sequence in mh-format
926 static char ident[] = "@@(#)$Id: forw.c,v 1.8 1992/02/04 17:46:56 jromine Exp jromine $";
929 #define IFMT "digest-issue-%s"
930 #define VFMT "digest-volume-%s"
933 (void) sprintf (buf, IFMT, digest);
936 (void) sprintf (buf, VFMT, digest);
939 (void) sprintf (buf, IFMT, digest);
942 (void) sprintf (buf, VFMT, digest);
948 @rename m_whatnow() to what_now() since it's not a m_ routine
953 static char ident[] = "@@(#)$Id: forw.c,v 1.7 1992/01/31 22:09:50 jromine Exp jromine $";
968 static char ident[] = "@@(#)$Id: forw.c,v 1.6 1990/04/05 14:59:50 sources Exp jromine $";
971 (void) m_whatnow (ed, nedit, NOUSE, drft, NULLCP, 0, mp,
982 static char ident[] = "@@(#)$Id:$";
1000 @make -[no]dashmunging hidden
1009 @additions for digests
1028 mhl_draft (out, digest, drft, filter, dashflg);
1031 copy_draft (out, digest, drft);
1034 static mhl_draft (out, digest, file, filter, dashflg)
1042 static copy_draft (out, digest, file)
1046 (void) sprintf (buffer, "End of %s Digest\n", digest);
1052 @make -[no]dashmunging visible
1069 "nodashmunging", -6,