]>
diplodocus.org Git - nmh/blob - uip/viamail.c
3 * viamail.c -- send multiple files in a MIME message
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
12 #include <h/signals.h>
19 #include <h/mhparse.h>
21 static struct swit switches
[] = {
25 { "from mailpath", 0 },
27 { "subject subject", 0 },
29 { "parameters arguments", 0 },
31 { "description text", 0 },
33 { "comment text", 0 },
35 { "delay seconds", 0 },
53 int ebcdicsw
= 0; /* hack for linking purposes */
58 static int via_mail (char *, char *, char *, char *, char *, int, char *);
62 main (int argc
, char **argv
)
65 char *f1
= NULL
, *f2
= NULL
, *f3
= NULL
;
66 char *f4
= NULL
, *f5
= NULL
, *f7
= NULL
;
67 char *cp
, buf
[BUFSIZ
];
68 char **argp
, **arguments
;
71 setlocale(LC_ALL
, "");
73 invo_name
= r1bindex (argv
[0], '/');
75 /* foil search of user profile/context */
76 if (context_foil (NULL
) == -1)
79 arguments
= getarguments (invo_name
, argc
, argv
, 0);
82 while ((cp
= *argp
++)) {
84 switch (smatch (++cp
, switches
)) {
86 ambigsw (cp
, switches
);
89 adios (NULL
, "-%s unknown", cp
);
92 snprintf (buf
, sizeof(buf
), "%s [switches]", invo_name
);
93 print_help (buf
, switches
, 1);
96 print_version(invo_name
);
101 adios (NULL
, "missing argument to %s", argp
[-2]);
105 adios (NULL
, "missing argument to %s", argp
[-2]);
109 adios (NULL
, "missing argument to %s", argp
[-2]);
113 adios (NULL
, "missing argument to %s", argp
[-2]);
117 adios (NULL
, "missing argument to %s", argp
[-2]);
120 if (!(cp
= *argp
++) || *cp
== '-')
121 adios (NULL
, "missing argument to %s", argp
[-2]);
124 * If there is an error, just reset the delay parameter
125 * to -1. We will set a default delay later.
127 if (sscanf (cp
, "%d", &delay
) != 1)
132 adios (NULL
, "missing argument to %s", argp
[-2]);
152 adios (NULL
, "missing -viamail \"mailpath\" switch");
154 via_mail (f1
, f2
, f3
, f4
, f5
, delay
, f7
);
155 return 0; /* dead code to satisfy the compiler */
164 via_mail (char *mailsw
, char *subjsw
, char *parmsw
, char *descsw
,
165 char *cmntsw
, int delay
, char *fromsw
)
167 int status
, vecp
= 1;
174 umask (~m_gmprot ());
176 tfile
= m_mktemp2(NULL
, invo_name
, NULL
, &fp
);
177 if (tfile
== NULL
) adios("viamail", "unable to create temporary file");
179 strncpy (tmpfil
, tfile
, sizeof(tmpfil
));
181 if (!strchr(mailsw
, '@'))
182 mailsw
= concat (mailsw
, "@", LocalName (0), NULL
);
183 fprintf (fp
, "To: %s\n", mailsw
);
186 fprintf (fp
, "Subject: %s\n", subjsw
);
189 if (!strchr(fromsw
, '@'))
190 fromsw
= concat (fromsw
, "@", LocalName (0), NULL
);
191 fprintf (fp
, "From: %s\n", fromsw
);
194 fprintf (fp
, "%s: %s\n", VRSN_FIELD
, VRSN_VALUE
);
195 fprintf (fp
, "%s: application/octet-stream", TYPE_FIELD
);
198 fprintf (fp
, "; %s", parmsw
);
201 fprintf (fp
, "\n\t(%s)", cmntsw
);
204 fprintf (fp
, "\n%s: %s", DESCR_FIELD
, descsw
);
206 fprintf (fp
, "\n%s: %s\n\n", ENCODING_FIELD
, "base64");
209 adios (tmpfil
, "error writing to");
211 writeBase64aux (stdin
, fp
);
213 adios (tmpfil
, "error writing to");
215 if (fstat (fileno (fp
), &st
) == NOTOK
)
216 adios ("failed", "fstat of %s", tmpfil
);
224 vec
[0] = r1bindex (postproc
, '/');
226 vec
[vecp
++] = "-verbose";
228 switch (sendsbr (vec
, vecp
, tmpfil
, &st
, 0, (char *)0, 0)) {
238 if (unlink (tmpfil
) == -1)
239 advise (NULL
, "unable to remove temp file %s", tmpfil
);