2 ** viamail.c -- send multiple files in a MIME 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.
11 #include <h/signals.h>
18 #include <h/mhparse.h>
20 #ifdef HAVE_SYS_WAIT_H
21 # include <sys/wait.h>
24 static struct swit switches[] = {
28 { "from mailpath", 0 },
30 { "subject subject", 0 },
32 { "parameters arguments", 0 },
34 { "description text", 0 },
36 { "comment text", 0 },
53 int ebcdicsw = 0; /* hack for linking purposes */
56 void set_endian (void);
59 int writeBase64aux (FILE *, FILE *);
64 static int via_mail (char *, char *, char *, char *, char *, char *);
68 main (int argc, char **argv)
70 char *f1 = NULL, *f2 = NULL, *f3 = NULL;
71 char *f4 = NULL, *f5 = NULL, *f7 = NULL;
72 char *cp, buf[BUFSIZ];
73 char **argp, **arguments;
76 setlocale(LC_ALL, "");
78 invo_name = r1bindex (argv[0], '/');
80 /* foil search of user profile/context */
81 if (context_foil (NULL) == -1)
84 arguments = getarguments (invo_name, argc, argv, 0);
87 while ((cp = *argp++)) {
89 switch (smatch (++cp, switches)) {
91 ambigsw (cp, switches);
94 adios (NULL, "-%s unknown", cp);
97 snprintf (buf, sizeof(buf), "%s [switches]",
99 print_help (buf, switches, 1);
102 print_version(invo_name);
107 adios (NULL, "missing argument to %s",
112 adios (NULL, "missing argument to %s",
117 adios (NULL, "missing argument to %s",
122 adios (NULL, "missing argument to %s",
127 adios (NULL, "missing argument to %s",
132 adios (NULL, "missing argument to %s",
153 adios (NULL, "missing -viamail \"mailpath\" switch");
155 via_mail (f1, f2, f3, f4, f5, f7);
156 return 0; /* dead code to satisfy the compiler */
165 via_mail (char *mailsw, char *subjsw, char *parmsw, char *descsw,
166 char *cmntsw, char *fromsw)
168 int status, vecp = 1;
175 umask (~m_gmprot ());
177 tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
178 if (tfile == NULL) adios("viamail", "unable to create temporary file");
180 strncpy (tmpfil, tfile, sizeof(tmpfil));
182 if (!strchr(mailsw, '@'))
183 mailsw = concat (mailsw, "@", LocalName (), NULL);
184 fprintf (fp, "To: %s\n", mailsw);
187 fprintf (fp, "Subject: %s\n", subjsw);
190 if (!strchr(fromsw, '@'))
191 fromsw = concat (fromsw, "@", LocalName (), NULL);
192 fprintf (fp, "From: %s\n", fromsw);
195 fprintf (fp, "%s: %s\n", VRSN_FIELD, VRSN_VALUE);
196 fprintf (fp, "%s: application/octet-stream", TYPE_FIELD);
199 fprintf (fp, "; %s", parmsw);
202 fprintf (fp, "\n\t(%s)", cmntsw);
205 fprintf (fp, "\n%s: %s", DESCR_FIELD, descsw);
207 fprintf (fp, "\n%s: %s\n\n", ENCODING_FIELD, "base64");
210 adios (tmpfil, "error writing to");
212 writeBase64aux (stdin, fp);
214 adios (tmpfil, "error writing to");
216 if (fstat (fileno (fp), &st) == NOTOK)
217 adios ("failed", "fstat of %s", tmpfil);
220 vec[0] = r1bindex (postproc, '/');
222 vec[vecp++] = "-verbose";
224 switch (sendsbr (vec, vecp, tmpfil, &st, 0, (char *)0, 0)) {
234 if (unlink (tmpfil) == -1)
235 advise (NULL, "unable to remove temp file %s", tmpfil);