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 = mhbasename(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;
177 tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
179 adios("viamail", "unable to create temporary file");
181 strncpy(tmpfil, tfile, sizeof(tmpfil));
183 if (!strchr(mailsw, '@'))
184 mailsw = concat(mailsw, "@", LocalName(), NULL);
185 fprintf(fp, "To: %s\n", mailsw);
188 fprintf(fp, "Subject: %s\n", subjsw);
191 if (!strchr(fromsw, '@'))
192 fromsw = concat(fromsw, "@", LocalName(), NULL);
193 fprintf(fp, "From: %s\n", fromsw);
196 fprintf(fp, "%s: %s\n", VRSN_FIELD, VRSN_VALUE);
197 fprintf(fp, "%s: application/octet-stream", TYPE_FIELD);
200 fprintf(fp, "; %s", parmsw);
203 fprintf(fp, "\n\t(%s)", cmntsw);
206 fprintf(fp, "\n%s: %s", DESCR_FIELD, descsw);
208 fprintf(fp, "\n%s: %s\n\n", ENCODING_FIELD, "base64");
211 adios(tmpfil, "error writing to");
213 writeBase64aux(stdin, fp);
215 adios(tmpfil, "error writing to");
217 if (fstat(fileno(fp), &st) == NOTOK)
218 adios("failed", "fstat of %s", tmpfil);
221 vec[0] = mhbasename(postproc);
223 vec[vecp++] = "-verbose";
225 switch (sendsbr(vec, vecp, tmpfil, &st, 0)) {
235 if (unlink(tmpfil) == -1)
236 advise(NULL, "unable to remove temp file %s", tmpfil);