-self_delimiting:
- fseek (ct->c_fp, 0L, SEEK_SET);
-
- if (fflush (ce->ce_fp)) {
- content_error (ce->ce_file, ct, "error writing to");
- goto clean_up;
- }
-
- if (digested) {
- unsigned char digest[16];
-
- MD5Final (digest, &mdContext);
- if (memcmp((char *) digest, (char *) ct->c_digest,
- sizeof(digest) / sizeof(digest[0])))
- content_error (NULL, ct,
- "content integrity suspect (digest mismatch) -- continuing");
- else
- if (debugsw)
- fprintf (stderr, "content integrity confirmed\n");
- }
-
- fseek (ce->ce_fp, 0L, SEEK_SET);
-
-ready_to_go:
- *file = ce->ce_file;
- return fileno (ce->ce_fp);
-
-clean_up:
- free_encoding (ct, 0);
- return NOTOK;
-}
-
-
-/*
- * QUOTED PRINTABLE
- */
-
-static char hex2nib[0x80] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-
-static int
-InitQuoted (CT ct)
-{
- return init_encoding (ct, openQuoted);
-}
-
-
-static int
-openQuoted (CT ct, char **file)
-{
- int cc, digested, len, quoted;
- char *cp, *ep;
- char buffer[BUFSIZ];
- unsigned char mask;
- CE ce;
- MD5_CTX mdContext;
-
- ce = ct->c_cefile;
- if (ce->ce_fp) {
- fseek (ce->ce_fp, 0L, SEEK_SET);
- goto ready_to_go;
- }
-
- if (ce->ce_file) {
- if ((ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) {
- content_error (ce->ce_file, ct, "unable to fopen for reading");
- return NOTOK;
- }
- goto ready_to_go;
- }
-
- if (*file == NULL) {
- ce->ce_file = add (m_scratch ("", tmp), NULL);
- ce->ce_unlink = 1;
- } else {
- ce->ce_file = add (*file, NULL);
- ce->ce_unlink = 0;
- }
-
- if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
- content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
- return NOTOK;
- }
-
- if ((len = ct->c_end - ct->c_begin) < 0)
- adios (NULL, "internal error(2)");
-
- if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) {
- content_error (ct->c_file, ct, "unable to open for reading");
- return NOTOK;
- }
-
- if ((digested = ct->c_digested))
- MD5Init (&mdContext);
-
- quoted = 0;
-#ifdef lint
- mask = 0;
-#endif
-
- fseek (ct->c_fp, ct->c_begin, SEEK_SET);
- while (len > 0) {
- char *dp;
-
- if (fgets (buffer, sizeof(buffer) - 1, ct->c_fp) == NULL) {
- content_error (NULL, ct, "premature eof");
- goto clean_up;
- }
-
- if ((cc = strlen (buffer)) > len)
- cc = len;
- len -= cc;
-
- for (ep = (cp = buffer) + cc - 1; cp <= ep; ep--)
- if (!isspace (*ep))
- break;
- *++ep = '\n', ep++;
-
- for (; cp < ep; cp++) {
- if (quoted) {
- if (quoted > 1) {
- if (!isxdigit (*cp)) {
-invalid_hex:
- dp = "expecting hexidecimal-digit";
- goto invalid_encoding;
- }
- mask <<= 4;
- mask |= hex2nib[*cp & 0x7f];
- putc (mask, ce->ce_fp);
- if (digested)
- MD5Update (&mdContext, &mask, 1);
- } else {
- switch (*cp) {
- case ':':
- putc (*cp, ce->ce_fp);
- if (digested)
- MD5Update (&mdContext, (unsigned char *) ":", 1);
- break;
-
- default:
- if (!isxdigit (*cp))
- goto invalid_hex;
- mask = hex2nib[*cp & 0x7f];
- quoted = 2;
- continue;
- }
- }
-
- if (ferror (ce->ce_fp)) {
- content_error (ce->ce_file, ct, "error writing to");
- goto clean_up;
- }
- quoted = 0;
- continue;
- }
-
- switch (*cp) {
- default:
- if (*cp < '!' || *cp > '~') {
- int i;
- dp = "expecting character in range [!..~]";
-
-invalid_encoding:
- i = strlen (invo_name) + 2;
- content_error (NULL, ct,
- "invalid QUOTED-PRINTABLE encoding -- %s,\n%*.*sbut got char 0x%x",
- dp, i, i, "", *cp);
- goto clean_up;
- }
- /* and fall...*/
- case ' ':
- case '\t':
- case '\n':
- putc (*cp, ce->ce_fp);
- if (digested) {
- if (*cp == '\n')
- MD5Update (&mdContext, (unsigned char *) "\r\n",2);
- else
- MD5Update (&mdContext, (unsigned char *) cp, 1);
- }
- if (ferror (ce->ce_fp)) {
- content_error (ce->ce_file, ct, "error writing to");
- goto clean_up;
- }
- break;
-
- case '=':
- if (*++cp != '\n') {
- quoted = 1;
- cp--;