]>
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.
16 #include <h/mhparse.h>
18 #define VIAMAIL_SWITCHES \
19 X("to mailpath", 0, TOSW) \
20 X("from mailpath", 0, FROMSW) \
21 X("subject subject", 0, SUBJECTSW) \
22 X("parameters arguments", 0, PARAMSW) \
23 X("description text", 0, DESCRIPTSW) \
24 X("comment text", 0, COMMENTSW) \
25 X("delay seconds", 0, DELAYSW) \
26 X("verbose", 0, VERBSW) \
27 X("noverbose", 0, NVERBSW) \
28 X("version", 0, VERSIONSW) \
29 X("help", 0, HELPSW) \
30 X("debug", -5, DEBUGSW) \
32 #define X(sw, minchars, id) id,
33 DEFINE_SWITCH_ENUM(VIAMAIL
);
36 #define X(sw, minchars, id) { sw, minchars, id },
37 DEFINE_SWITCH_ARRAY(VIAMAIL
, switches
);
47 static int via_mail (char *, char *, char *, char *, char *, int, char *);
51 main (int argc
, char **argv
)
54 char *f1
= NULL
, *f2
= NULL
, *f3
= NULL
;
55 char *f4
= NULL
, *f5
= NULL
, *f7
= NULL
;
56 char *cp
, buf
[BUFSIZ
];
57 char **argp
, **arguments
;
59 if (nmh_init(argv
[0], 1)) { return 1; }
61 arguments
= getarguments (invo_name
, argc
, argv
, 0);
64 while ((cp
= *argp
++)) {
66 switch (smatch (++cp
, switches
)) {
68 ambigsw (cp
, switches
);
71 adios (NULL
, "-%s unknown", cp
);
74 snprintf (buf
, sizeof(buf
), "%s [switches]", invo_name
);
75 print_help (buf
, switches
, 1);
78 print_version(invo_name
);
83 adios (NULL
, "missing argument to %s", argp
[-2]);
87 adios (NULL
, "missing argument to %s", argp
[-2]);
91 adios (NULL
, "missing argument to %s", argp
[-2]);
95 adios (NULL
, "missing argument to %s", argp
[-2]);
99 adios (NULL
, "missing argument to %s", argp
[-2]);
102 if (!(cp
= *argp
++) || *cp
== '-')
103 adios (NULL
, "missing argument to %s", argp
[-2]);
106 * If there is an error, just reset the delay parameter
107 * to -1. We will set a default delay later.
109 if (sscanf (cp
, "%d", &delay
) != 1)
114 adios (NULL
, "missing argument to %s", argp
[-2]);
132 adios (NULL
, "missing -viamail \"mailpath\" switch");
134 via_mail (f1
, f2
, f3
, f4
, f5
, delay
, f7
);
135 return 0; /* dead code to satisfy the compiler */
144 via_mail (char *mailsw
, char *subjsw
, char *parmsw
, char *descsw
,
145 char *cmntsw
, int delay
, char *fromsw
)
148 char tmpfil
[BUFSIZ
], *program
;
155 umask (~m_gmprot ());
157 if ((tfile
= m_mktemp2(NULL
, invo_name
, NULL
, &fp
)) == NULL
) {
158 adios(NULL
, "unable to create temporary file in %s", get_temp_dir());
160 strncpy (tmpfil
, tfile
, sizeof(tmpfil
));
162 if (!strchr(mailsw
, '@'))
163 mailsw
= concat (mailsw
, "@", LocalName (0), NULL
);
164 fprintf (fp
, "To: %s\n", mailsw
);
167 fprintf (fp
, "Subject: %s\n", subjsw
);
170 if (!strchr(fromsw
, '@'))
171 fromsw
= concat (fromsw
, "@", LocalName (0), NULL
);
172 fprintf (fp
, "From: %s\n", fromsw
);
175 fprintf (fp
, "%s: %s\n", VRSN_FIELD
, VRSN_VALUE
);
176 fprintf (fp
, "%s: application/octet-stream", TYPE_FIELD
);
179 fprintf (fp
, "; %s", parmsw
);
182 fprintf (fp
, "\n\t(%s)", cmntsw
);
185 fprintf (fp
, "\n%s: %s", DESCR_FIELD
, descsw
);
187 fprintf (fp
, "\n%s: %s\n\n", ENCODING_FIELD
, "base64");
190 adios (tmpfil
, "error writing to");
192 writeBase64aux (stdin
, fp
, 0);
194 adios (tmpfil
, "error writing to");
196 if (fstat (fileno (fp
), &st
) == NOTOK
)
197 adios ("failed", "fstat of %s", tmpfil
);
206 vec
= argsplit(postproc
, &program
, &vecp
);
208 vec
[vecp
++] = "-verbose";
210 if ((cp
= context_find ("credentials"))) {
211 /* post doesn't read context so need to pass credentials. */
212 vec
[vecp
++] = "-credentials";
216 switch (sendsbr (vec
, vecp
, program
, tmpfil
, &st
, 0)) {
226 if (m_unlink (tmpfil
) == -1)
227 advise (tmpfil
, "unable to remove temp file %s", tmpfil
);