Deleted Added
full compact
headers.c (116542) headers.c (120259)
1/*
2 * Copyright (c) 1998-2003 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
11 *
1/*
2 * Copyright (c) 1998-2003 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
11 *
12 * $FreeBSD: head/contrib/sendmail/src/headers.c 120259 2003-09-19 23:14:57Z gshapiro $
12 */
13
14#include <sendmail.h>
15
13 */
14
15#include <sendmail.h>
16
16SM_RCSID("@(#)$Id: headers.c,v 8.266.4.5 2003/03/12 22:42:52 gshapiro Exp $")
17SM_RCSID("@(#)$Id: headers.c,v 8.266.4.7 2003/09/03 21:32:20 ca Exp $")
17
18static size_t fix_mime_header __P((HDR *, ENVELOPE *));
19static int priencode __P((char *));
20static void put_vanilla_header __P((HDR *, char *, MCI *));
21
22/*
23** SETUPHEADERS -- initialize headers in symbol table
24**

--- 110 unchanged lines hidden (view full) ---

135 if (*++p == '\0')
136 {
137 *q = '?';
138 goto hse;
139 }
140
141 mid = (unsigned char) macid(p);
142 if (bitset(0200, mid))
18
19static size_t fix_mime_header __P((HDR *, ENVELOPE *));
20static int priencode __P((char *));
21static void put_vanilla_header __P((HDR *, char *, MCI *));
22
23/*
24** SETUPHEADERS -- initialize headers in symbol table
25**

--- 110 unchanged lines hidden (view full) ---

136 if (*++p == '\0')
137 {
138 *q = '?';
139 goto hse;
140 }
141
142 mid = (unsigned char) macid(p);
143 if (bitset(0200, mid))
144 {
143 p += strlen(macname(mid)) + 2;
145 p += strlen(macname(mid)) + 2;
146 SM_ASSERT(p <= q);
147 }
144 else
145 p++;
146
147 /* catch ?$abc? */
148 if (*p != '\0')
149 {
150 *q = '?';
151 goto hse;

--- 158 unchanged lines hidden (view full) ---

310 {
311 int l, k;
312 char qval[MAXNAME];
313
314 l = 0;
315 qval[l++] = '"';
316
317 /* - 3 to avoid problems with " at the end */
148 else
149 p++;
150
151 /* catch ?$abc? */
152 if (*p != '\0')
153 {
154 *q = '?';
155 goto hse;

--- 158 unchanged lines hidden (view full) ---

314 {
315 int l, k;
316 char qval[MAXNAME];
317
318 l = 0;
319 qval[l++] = '"';
320
321 /* - 3 to avoid problems with " at the end */
322 /* should be sizeof(qval), not MAXNAME */
318 for (k = 0; fvalue[k] != '\0' && l < MAXNAME - 3; k++)
319 {
320 switch (fvalue[k])
321 {
322 /* XXX other control chars? */
323 case '\011': /* ht */
324 case '\012': /* nl */
325 case '\013': /* vt */

--- 844 unchanged lines hidden (view full) ---

1170 buflim++;
1171 }
1172 }
1173 continue;
1174 }
1175 else if (c == ')')
1176 {
1177 /* syntax error: unmatched ) */
323 for (k = 0; fvalue[k] != '\0' && l < MAXNAME - 3; k++)
324 {
325 switch (fvalue[k])
326 {
327 /* XXX other control chars? */
328 case '\011': /* ht */
329 case '\012': /* nl */
330 case '\013': /* vt */

--- 844 unchanged lines hidden (view full) ---

1175 buflim++;
1176 }
1177 }
1178 continue;
1179 }
1180 else if (c == ')')
1181 {
1182 /* syntax error: unmatched ) */
1178 if (copylev > 0 && SM_HAVE_ROOM)
1183 if (copylev > 0 && SM_HAVE_ROOM && bp > bufhead)
1179 bp--;
1180 }
1181
1182 /* count nesting on [ ... ] (for IPv6 domain literals) */
1183 if (c == '[')
1184 bracklev++;
1185 else if (c == ']')
1186 bracklev--;

--- 157 unchanged lines hidden (view full) ---

1344 if (addangle)
1345 buflim++;
1346 addangle = false;
1347 }
1348 }
1349 else if (SM_HAVE_ROOM)
1350 {
1351 /* syntax error: unmatched > */
1184 bp--;
1185 }
1186
1187 /* count nesting on [ ... ] (for IPv6 domain literals) */
1188 if (c == '[')
1189 bracklev++;
1190 else if (c == ']')
1191 bracklev--;

--- 157 unchanged lines hidden (view full) ---

1349 if (addangle)
1350 buflim++;
1351 addangle = false;
1352 }
1353 }
1354 else if (SM_HAVE_ROOM)
1355 {
1356 /* syntax error: unmatched > */
1352 if (copylev > 0)
1357 if (copylev > 0 && bp > bufhead)
1353 bp--;
1354 quoteit = true;
1355 continue;
1356 }
1357 if (copylev++ <= 0)
1358 SM_APPEND_CHAR(c);
1359 continue;
1360 }

--- 327 unchanged lines hidden (view full) ---

1688 putflags |= PXLF_STRIP8BIT;
1689 (void) sm_snprintf(obuf, sizeof obuf, "%.200s: ", h->h_field);
1690 obp = obuf + strlen(obuf);
1691 while ((nlp = strchr(v, '\n')) != NULL)
1692 {
1693 int l;
1694
1695 l = nlp - v;
1358 bp--;
1359 quoteit = true;
1360 continue;
1361 }
1362 if (copylev++ <= 0)
1363 SM_APPEND_CHAR(c);
1364 continue;
1365 }

--- 327 unchanged lines hidden (view full) ---

1693 putflags |= PXLF_STRIP8BIT;
1694 (void) sm_snprintf(obuf, sizeof obuf, "%.200s: ", h->h_field);
1695 obp = obuf + strlen(obuf);
1696 while ((nlp = strchr(v, '\n')) != NULL)
1697 {
1698 int l;
1699
1700 l = nlp - v;
1701
1702 /*
1703 ** XXX This is broken for SPACELEFT()==0
1704 ** However, SPACELEFT() is always > 0 unless MAXLINE==1.
1705 */
1706
1696 if (SPACELEFT(obuf, obp) - 1 < (size_t) l)
1697 l = SPACELEFT(obuf, obp) - 1;
1698
1699 (void) sm_snprintf(obp, SPACELEFT(obuf, obp), "%.*s", l, v);
1700 putxline(obuf, strlen(obuf), mci, putflags);
1701 v += l + 1;
1702 obp = obuf;
1703 if (*v != ' ' && *v != '\t')
1704 *obp++ = ' ';
1705 }
1707 if (SPACELEFT(obuf, obp) - 1 < (size_t) l)
1708 l = SPACELEFT(obuf, obp) - 1;
1709
1710 (void) sm_snprintf(obp, SPACELEFT(obuf, obp), "%.*s", l, v);
1711 putxline(obuf, strlen(obuf), mci, putflags);
1712 v += l + 1;
1713 obp = obuf;
1714 if (*v != ' ' && *v != '\t')
1715 *obp++ = ' ';
1716 }
1717
1718 /* XXX This is broken for SPACELEFT()==0 */
1706 (void) sm_snprintf(obp, SPACELEFT(obuf, obp), "%.*s",
1707 (int) (SPACELEFT(obuf, obp) - 1), v);
1708 putxline(obuf, strlen(obuf), mci, putflags);
1709}
1710/*
1711** COMMAIZE -- output a header field, making a comma-translated list.
1712**
1713** Parameters:

--- 18 unchanged lines hidden (view full) ---

1732 register MCI *mci;
1733 register ENVELOPE *e;
1734{
1735 register char *obp;
1736 int opos;
1737 int omax;
1738 bool firstone = true;
1739 int putflags = PXLF_HEADER;
1719 (void) sm_snprintf(obp, SPACELEFT(obuf, obp), "%.*s",
1720 (int) (SPACELEFT(obuf, obp) - 1), v);
1721 putxline(obuf, strlen(obuf), mci, putflags);
1722}
1723/*
1724** COMMAIZE -- output a header field, making a comma-translated list.
1725**
1726** Parameters:

--- 18 unchanged lines hidden (view full) ---

1745 register MCI *mci;
1746 register ENVELOPE *e;
1747{
1748 register char *obp;
1749 int opos;
1750 int omax;
1751 bool firstone = true;
1752 int putflags = PXLF_HEADER;
1753 char **res;
1740 char obuf[MAXLINE + 3];
1741
1742 /*
1743 ** Output the address list translated by the
1744 ** mailer and with commas.
1745 */
1746
1747 if (tTd(14, 2))
1748 sm_dprintf("commaize(%s: %s)\n", h->h_field, p);
1749
1750 if (bitnset(M_7BITHDRS, mci->mci_mailer->m_flags))
1751 putflags |= PXLF_STRIP8BIT;
1752
1753 obp = obuf;
1754 (void) sm_snprintf(obp, SPACELEFT(obuf, obp), "%.200s: ",
1755 h->h_field);
1754 char obuf[MAXLINE + 3];
1755
1756 /*
1757 ** Output the address list translated by the
1758 ** mailer and with commas.
1759 */
1760
1761 if (tTd(14, 2))
1762 sm_dprintf("commaize(%s: %s)\n", h->h_field, p);
1763
1764 if (bitnset(M_7BITHDRS, mci->mci_mailer->m_flags))
1765 putflags |= PXLF_STRIP8BIT;
1766
1767 obp = obuf;
1768 (void) sm_snprintf(obp, SPACELEFT(obuf, obp), "%.200s: ",
1769 h->h_field);
1770
1771 /* opos = strlen(obp); */
1756 opos = strlen(h->h_field) + 2;
1757 if (opos > 202)
1758 opos = 202;
1759 obp += opos;
1760 omax = mci->mci_mailer->m_linelimit - 2;
1761 if (omax < 0 || omax > 78)
1762 omax = 78;
1763

--- 16 unchanged lines hidden (view full) ---

1780 ** necessarily delimit an old-style name -- at
1781 ** signs mean keep going.
1782 */
1783
1784 /* find end of name */
1785 while ((isascii(*p) && isspace(*p)) || *p == ',')
1786 p++;
1787 name = p;
1772 opos = strlen(h->h_field) + 2;
1773 if (opos > 202)
1774 opos = 202;
1775 obp += opos;
1776 omax = mci->mci_mailer->m_linelimit - 2;
1777 if (omax < 0 || omax > 78)
1778 omax = 78;
1779

--- 16 unchanged lines hidden (view full) ---

1796 ** necessarily delimit an old-style name -- at
1797 ** signs mean keep going.
1798 */
1799
1800 /* find end of name */
1801 while ((isascii(*p) && isspace(*p)) || *p == ',')
1802 p++;
1803 name = p;
1804 res = NULL;
1788 for (;;)
1789 {
1790 auto char *oldp;
1791 char pvpbuf[PSBUFSIZE];
1792
1805 for (;;)
1806 {
1807 auto char *oldp;
1808 char pvpbuf[PSBUFSIZE];
1809
1793 (void) prescan(p, oldstyle ? ' ' : ',', pvpbuf,
1794 sizeof pvpbuf, &oldp, NULL);
1810 res = prescan(p, oldstyle ? ' ' : ',', pvpbuf,
1811 sizeof pvpbuf, &oldp, NULL);
1795 p = oldp;
1812 p = oldp;
1813#if _FFR_IGNORE_BOGUS_ADDR
1814 /* ignore addresses that can't be parsed */
1815 if (res == NULL)
1816 {
1817 name = p;
1818 continue;
1819 }
1820#endif /* _FFR_IGNORE_BOGUS_ADDR */
1796
1797 /* look to see if we have an at sign */
1798 while (*p != '\0' && isascii(*p) && isspace(*p))
1799 p++;
1800
1801 if (*p != '@')
1802 {
1803 p = oldp;

--- 6 unchanged lines hidden (view full) ---

1810 /* at the end of one complete name */
1811
1812 /* strip off trailing white space */
1813 while (p >= name &&
1814 ((isascii(*p) && isspace(*p)) || *p == ',' || *p == '\0'))
1815 p--;
1816 if (++p == name)
1817 continue;
1821
1822 /* look to see if we have an at sign */
1823 while (*p != '\0' && isascii(*p) && isspace(*p))
1824 p++;
1825
1826 if (*p != '@')
1827 {
1828 p = oldp;

--- 6 unchanged lines hidden (view full) ---

1835 /* at the end of one complete name */
1836
1837 /* strip off trailing white space */
1838 while (p >= name &&
1839 ((isascii(*p) && isspace(*p)) || *p == ',' || *p == '\0'))
1840 p--;
1841 if (++p == name)
1842 continue;
1843
1844 /*
1845 ** if prescan() failed go a bit backwards; this is a hack,
1846 ** there should be some better error recovery.
1847 */
1848
1849 if (res == NULL && p > name &&
1850 !((isascii(*p) && isspace(*p)) || *p == ',' || *p == '\0'))
1851 --p;
1818 savechar = *p;
1819 *p = '\0';
1820
1821 /* translate the name to be relative */
1822 flags = RF_HEADERADDR|RF_ADDDOMAIN;
1823 if (bitset(H_FROM, h->h_flags))
1824 flags |= RF_SENDERADDR;
1825#if USERDB

--- 27 unchanged lines hidden (view full) ---

1853 opos += strlen(name);
1854 if (!firstone)
1855 opos += 2;
1856 if (opos > omax && !firstone)
1857 {
1858 (void) sm_strlcpy(obp, ",\n", SPACELEFT(obuf, obp));
1859 putxline(obuf, strlen(obuf), mci, putflags);
1860 obp = obuf;
1852 savechar = *p;
1853 *p = '\0';
1854
1855 /* translate the name to be relative */
1856 flags = RF_HEADERADDR|RF_ADDDOMAIN;
1857 if (bitset(H_FROM, h->h_flags))
1858 flags |= RF_SENDERADDR;
1859#if USERDB

--- 27 unchanged lines hidden (view full) ---

1887 opos += strlen(name);
1888 if (!firstone)
1889 opos += 2;
1890 if (opos > omax && !firstone)
1891 {
1892 (void) sm_strlcpy(obp, ",\n", SPACELEFT(obuf, obp));
1893 putxline(obuf, strlen(obuf), mci, putflags);
1894 obp = obuf;
1861 (void) sm_strlcpy(obp, " ", sizeof obp);
1895 (void) sm_strlcpy(obp, " ", sizeof obuf);
1862 opos = strlen(obp);
1863 obp += opos;
1864 opos += strlen(name);
1865 }
1866 else if (!firstone)
1867 {
1868 (void) sm_strlcpy(obp, ", ", SPACELEFT(obuf, obp));
1869 obp += 2;
1870 }
1871
1872 while ((c = *name++) != '\0' && obp < &obuf[MAXLINE])
1873 *obp++ = c;
1874 firstone = false;
1875 *p = savechar;
1876 }
1896 opos = strlen(obp);
1897 obp += opos;
1898 opos += strlen(name);
1899 }
1900 else if (!firstone)
1901 {
1902 (void) sm_strlcpy(obp, ", ", SPACELEFT(obuf, obp));
1903 obp += 2;
1904 }
1905
1906 while ((c = *name++) != '\0' && obp < &obuf[MAXLINE])
1907 *obp++ = c;
1908 firstone = false;
1909 *p = savechar;
1910 }
1877 *obp = '\0';
1911 if (obp < &obuf[sizeof obuf])
1912 *obp = '\0';
1913 else
1914 obuf[sizeof obuf - 1] = '\0';
1878 putxline(obuf, strlen(obuf), mci, putflags);
1879}
1880/*
1881** COPYHEADER -- copy header list
1882**
1883** This routine is the equivalent of newstr for header lists
1884**
1885** Parameters:

--- 55 unchanged lines hidden (view full) ---

1941 char *end;
1942 size_t len = 0;
1943 size_t retlen = 0;
1944
1945 if (begin == NULL || *begin == '\0')
1946 return 0;
1947
1948 /* Split on each ';' */
1915 putxline(obuf, strlen(obuf), mci, putflags);
1916}
1917/*
1918** COPYHEADER -- copy header list
1919**
1920** This routine is the equivalent of newstr for header lists
1921**
1922** Parameters:

--- 55 unchanged lines hidden (view full) ---

1978 char *end;
1979 size_t len = 0;
1980 size_t retlen = 0;
1981
1982 if (begin == NULL || *begin == '\0')
1983 return 0;
1984
1985 /* Split on each ';' */
1986 /* find_character() never returns NULL */
1949 while ((end = find_character(begin, ';')) != NULL)
1950 {
1951 char save = *end;
1952 char *bp;
1953
1954 *end = '\0';
1955
1956 len = strlen(begin);

--- 45 unchanged lines hidden ---
1987 while ((end = find_character(begin, ';')) != NULL)
1988 {
1989 char save = *end;
1990 char *bp;
1991
1992 *end = '\0';
1993
1994 len = strlen(begin);

--- 45 unchanged lines hidden ---