]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/mhmail.c
1 /* mhmail.c - simple mail program */
3 static char ident
[] = "@(#)$Id: mhmail.c,v 1.9 1993/08/20 15:51:29 jromine Exp $";
15 static struct swit switches
[] = {
41 static TYPESIG
intrser ();
44 static char tmpfil
[BUFSIZ
];
74 setlocale(LC_ALL
, "");
76 invo_name
= r1bindex (argv
[0], '/');
80 execlp (incproc
, r1bindex (incproc
, '/'), NULLCP
);
81 adios (incproc
, "unable to exec");
86 while (cp
= *argp
++) {
88 switch (smatch (++cp
, switches
)) {
90 ambigsw (cp
, switches
);
94 adios (NULLCP
, "-%s unknown", cp
);
97 (void) sprintf (buf
, "%s [addrs ... [switches]]",
103 if (!(from
= *argp
++) || *from
== '-')
104 adios (NULLCP
, "missing argument to %s", argp
[-2]);
108 if (!(body
= *argp
++) || *body
== '-')
109 adios (NULLCP
, "missing argument to %s", argp
[-2]);
117 if (!(subject
= *argp
++) || *subject
== '-')
118 adios (NULLCP
, "missing argument to %s", argp
[-2]);
130 cclist
= cclist
? add (cp
, add (", ", cclist
)) : getcpy (cp
);
132 tolist
= tolist
? add (cp
, add (", ", tolist
)) : getcpy (cp
);
138 adios (NULLCP
, "usage: %s addrs ... [switches]", invo_name
);
139 (void) strcpy (tmpfil
, m_tmpfil (invo_name
));
140 if ((out
= fopen (tmpfil
, "w")) == NULL
)
141 adios (tmpfil
, "unable to write");
142 (void) chmod (tmpfil
, 0600);
144 setsig (SIGINT
, intrser
);
146 fprintf (out
, "%sTo: %s\n", resent
? "Resent-" : "", tolist
);
148 fprintf (out
, "%scc: %s\n", resent
? "Resent-" : "", cclist
);
150 fprintf (out
, "%sSubject: %s\n", resent
? "Resent-" : "", subject
);
152 fprintf (out
, "%sFrom: %s\n", resent
? "Resent-" : "", from
);
154 (void) fputs ("\n", out
);
157 fprintf (out
, "%s", body
);
158 if (*body
&& *(body
+ strlen (body
) - 1) != '\n')
163 (i
= fread (buf
, sizeof *buf
, sizeof buf
, stdin
)) > 0;
165 if (fwrite (buf
, sizeof *buf
, i
, out
) != i
)
166 adios (tmpfil
, "error writing");
168 (void) unlink (tmpfil
);
177 vec
[nvec
++] = r1bindex (postproc
, '/');
178 vec
[nvec
++] = tmpfil
;
180 vec
[nvec
++] = "-dist";
182 vec
[nvec
++] = "-queued";
185 for (i
= 0; (child_id
= fork ()) == NOTOK
&& i
< 5; i
++)
188 case NOTOK
: /* report failure and then send it */
189 admonish (NULLCP
, "unable to fork");
192 execvp (postproc
, vec
);
193 fprintf (stderr
, "unable to exec ");
198 if (status
= pidXwait (child_id
, postproc
)) {
199 fprintf (stderr
, "Letter saved in dead.letter\n");
200 execl ("/bin/mv", "mv", tmpfil
, "dead.letter", NULLCP
);
201 execl ("/usr/bin/mv", "mv", tmpfil
, "dead.letter", NULLCP
);
206 (void) unlink (tmpfil
);
207 done (status
? 1 : 0);
215 static TYPESIG
intrser (i
)
220 (void) signal (i
, SIG_IGN
);
223 (void) unlink (tmpfil
);
224 done (i
!= 0 ? 1 : 0);