summaryrefslogtreecommitdiff
path: root/src/mime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mime.c')
-rw-r--r--src/mime.c91
1 files changed, 47 insertions, 44 deletions
diff --git a/src/mime.c b/src/mime.c
index 3e5a610..7156891 100644
--- a/src/mime.c
+++ b/src/mime.c
@@ -1,42 +1,20 @@
/*
- * Copyright (c) 1994, 1996-1997 Eric P. Allman
+ * Copyright (c) 1998 Sendmail, Inc. All rights reserved.
+ * Copyright (c) 1994, 1996-1997 Eric P. Allman. All rights reserved.
* Copyright (c) 1994
* The Regents of the University of California. All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
+ * By using this file, you agree to the terms and conditions set
+ * forth in the LICENSE file which can be found at the top level of
+ * the sendmail distribution.
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
*/
# include "sendmail.h"
# include <string.h>
#ifndef lint
-static char sccsid[] = "@(#)mime.c 8.59 (Berkeley) 5/6/97";
+static char sccsid[] = "@(#)mime.c 8.71 (Berkeley) 1/18/1999";
#endif /* not lint */
/*
@@ -247,7 +225,8 @@ mime8to7(mci, header, e, boundaries, flags)
** Do a recursive descent into the message.
*/
- if (strcasecmp(type, "multipart") == 0 && !bitset(M87F_NO8BIT, flags))
+ if (strcasecmp(type, "multipart") == 0 &&
+ (!bitset(M87F_NO8BIT, flags) || bitset(M87F_NO8TO7, flags)))
{
int blen;
@@ -306,6 +285,7 @@ mime8to7(mci, header, e, boundaries, flags)
/* skip the early "comment" prologue */
putline("", mci);
+ mci->mci_flags &= ~MCIF_INHEADER;
while (fgets(buf, sizeof buf, e->e_dfp) != NULL)
{
bt = mimeboundary(buf, boundaries);
@@ -328,7 +308,7 @@ mime8to7(mci, header, e, boundaries, flags)
collect(e->e_dfp, FALSE, &hdr, e);
if (tTd(43, 101))
putline("+++after collect", mci);
- putheader(mci, hdr, e);
+ putheader(mci, hdr, e, flags);
if (tTd(43, 101))
putline("+++after putheader", mci);
bt = mime8to7(mci, hdr, e, boundaries, flags);
@@ -380,7 +360,7 @@ mime8to7(mci, header, e, boundaries, flags)
collect(e->e_dfp, FALSE, &hdr, e);
if (tTd(43, 101))
putline("+++after collect", mci);
- putheader(mci, hdr, e);
+ putheader(mci, hdr, e, flags);
if (tTd(43, 101))
putline("+++after putheader", mci);
if (hvalue("MIME-Version", hdr) == NULL)
@@ -400,7 +380,7 @@ mime8to7(mci, header, e, boundaries, flags)
*/
sectionsize = sectionhighbits = 0;
- if (!bitset(M87F_NO8BIT, flags))
+ if (!bitset(M87F_NO8BIT|M87F_NO8TO7, flags))
{
/* remember where we were */
offset = ftell(e->e_dfp);
@@ -462,8 +442,18 @@ mime8to7(mci, header, e, boundaries, flags)
if (sectionhighbits == 0)
{
/* no encoding necessary */
- if (cte != NULL)
+ if (cte != NULL &&
+ bitset(MCIF_INMIME, mci->mci_flags) &&
+ !bitset(M87F_NO8TO7, flags))
{
+ /*
+ ** Skip _unless_ in MIME mode and potentially
+ ** converting from 8 bit to 7 bit MIME. See
+ ** putheader() for the counterpart where the
+ ** CTE header is skipped in the opposite
+ ** situation.
+ */
+
snprintf(buf, sizeof buf,
"Content-Transfer-Encoding: %.200s", cte);
putline(buf, mci);
@@ -683,15 +673,22 @@ mime_getchar(fp, boundaries, btp)
static bool atbol = TRUE; /* at beginning of line */
static int bt = MBT_SYNTAX; /* boundary type of next EOF */
static u_char buf[128]; /* need not be a full line */
+ int start = 0; /* indicates position of - in buffer */
- if (buflen > 0)
+ if (buflen == 1 && *bp == '\n')
+ {
+ /* last \n in buffer may be part of next MIME boundary */
+ c = *bp;
+ }
+ else if (buflen > 0)
{
buflen--;
return *bp++;
}
+ else
+ c = getc(fp);
bp = buf;
buflen = 0;
- c = getc(fp);
if (c == '\n')
{
/* might be part of a MIME boundary */
@@ -703,6 +700,7 @@ mime_getchar(fp, boundaries, btp)
ungetc(c, fp);
return c;
}
+ start = 1;
}
if (c != EOF)
*bp++ = c;
@@ -731,7 +729,7 @@ mime_getchar(fp, boundaries, btp)
*bp++ = c;
}
*bp = '\0';
- bt = mimeboundary((char *) &buf[1], boundaries);
+ bt = mimeboundary((char *) &buf[start], boundaries);
switch (bt)
{
case MBT_FINAL:
@@ -992,6 +990,7 @@ mime7to8(mci, header, e)
cataddr(pvp, NULL, buf, sizeof buf, '\0');
cte = newstr(buf);
+ mci->mci_flags |= MCIF_INHEADER;
putline("Content-Transfer-Encoding: 8bit", mci);
snprintf(buf, sizeof buf,
"X-MIME-Autoconverted: from %.200s to 8bit by %s id %s",
@@ -1146,20 +1145,24 @@ mime_fromqp(infile, outfile, state, maxlen)
if ((c1 = *infile++) == 0)
break;
- if (c1 == '\n') /* ignore it */
+ if (c1 == '\n' || (c1 = HEXCHAR(c1)) == -1)
{
+ /* ignore it */
if (state == 0)
return 0;
}
else
{
- if ((c2 = *infile++) == '\0')
- break;
-
- c1 = HEXCHAR(c1);
- c2 = HEXCHAR(c2);
-
- if (++nchar > maxlen)
+ do
+ {
+ if ((c2 = *infile++) == '\0')
+ {
+ c2 = -1;
+ break;
+ }
+ } while ((c2 = HEXCHAR(c2)) == -1);
+
+ if (c2 == -1 || ++nchar > maxlen)
break;
*(*outfile)++ = c1 << 4 | c2;