* mhoutsbr.c -- routines to output MIME messages
* -- given a Content structure
*
- * $Id$
+ * This code is Copyright (c) 2002, by the authors of nmh. See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
*/
#include <h/mh.h>
#include <h/md5.h>
#include <errno.h>
#include <signal.h>
-#include <zotnet/mts/mts.h>
+#include <h/mts.h>
#include <h/tws.h>
#include <h/mime.h>
#include <h/mhparse.h>
-#ifdef HAVE_SYS_WAIT_H
-# include <sys/wait.h>
-#endif
-
-extern int errno;
extern int ebcdicsw;
static char ebcdicsafe[0x100] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
-static char nib2b64[0x40+1] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
/*
* prototypes
*/
int output_message (CT, char *);
-int writeBase64aux (FILE *, FILE *);
+int output_message_fp (CT, FILE *, char *);
/*
* static prototypes
static int writeExternalBody (CT, FILE *);
static int write8Bit (CT, FILE *);
static int writeQuoted (CT, FILE *);
-static int writeBase64 (CT, FILE *);
+static int writeBase64ct (CT, FILE *);
/*
*/
int
-output_message (CT ct, char *file)
+output_message_fp (CT ct, FILE *fp, char *file)
{
- FILE *fp;
-
- if ((fp = fopen (file, "w")) == NULL) {
- advise (file, "unable to open for writing");
- return NOTOK;
- }
-
if (output_content (ct, fp) == NOTOK)
return NOTOK;
if (fflush (fp)) {
- advise (file, "error writing to");
+ advise ((file?file:"<FILE*>"), "error writing to");
return NOTOK;
}
- fclose (fp);
-
return OK;
}
+int
+output_message (CT ct, char *file)
+{
+ FILE *fp;
+ int status;
+
+ if ((fp = fopen (file, "w")) == NULL) {
+ advise (file, "unable to open for writing");
+ return NOTOK;
+ }
+ status = output_message_fp(ct, fp, file);
+ fclose(fp);
+ return status;
+}
+
/*
* Output a Content structure to a file.
case CE_BASE64:
putc ('\n', out);
- result = writeBase64 (ct, out);
+ result = writeBase64ct (ct, out);
break;
case CE_BINARY:
case 'N':
for (ap = ci2->ci_attrs, ep = ci2->ci_values; *ap; ap++, ep++)
- if (!strcasecmp (*ap, "name")) {
+ if (!mh_strcasecmp (*ap, "name")) {
fprintf (out, "%s", *ep);
break;
}
*/
static int
-writeBase64 (CT ct, FILE *out)
+writeBase64ct (CT ct, FILE *out)
{
int fd, result;
char *file;
(*ct->c_ceclosefnx) (ct);
return result;
}
-
-
-int
-writeBase64aux (FILE *in, FILE *out)
-{
- int cc, n;
- char inbuf[3];
-
- n = BPERLIN;
- while ((cc = fread (inbuf, sizeof(*inbuf), sizeof(inbuf), in)) > 0) {
- unsigned long bits;
- char *bp;
- char outbuf[4];
-
- if (cc < sizeof(inbuf)) {
- inbuf[2] = 0;
- if (cc < sizeof(inbuf) - 1)
- inbuf[1] = 0;
- }
- bits = (inbuf[0] & 0xff) << 16;
- bits |= (inbuf[1] & 0xff) << 8;
- bits |= inbuf[2] & 0xff;
-
- for (bp = outbuf + sizeof(outbuf); bp > outbuf; bits >>= 6)
- *--bp = nib2b64[bits & 0x3f];
- if (cc < sizeof(inbuf)) {
- outbuf[3] = '=';
- if (cc < sizeof inbuf - 1)
- outbuf[2] = '=';
- }
-
- fwrite (outbuf, sizeof(*outbuf), sizeof(outbuf), out);
-
- if (cc < sizeof(inbuf)) {
- putc ('\n', out);
- return OK;
- }
-
- if (--n <= 0) {
- n = BPERLIN;
- putc ('\n', out);
- }
- }
- if (n != BPERLIN)
- putc ('\n', out);
-
- return OK;
-}