2 * Copyright (c) 1998 Sendmail, Inc. All rights reserved.
3 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * By using this file, you agree to the terms and conditions set
8 * forth in the LICENSE file which can be found at the top level of
9 * the sendmail distribution.
14 static char sccsid[] = "@(#)headers.c 8.136 (Berkeley) 1/26/1999";
18 # include "sendmail.h"
21 ** SETUPHEADERS -- initialize headers in symbol table
36 for (hi = HdrInfo; hi->hi_field != NULL; hi++)
38 s = stab(hi->hi_field, ST_HEADER, ST_ENTER);
39 s->s_header.hi_flags = hi->hi_flags;
40 s->s_header.hi_ruleset = NULL;
44 ** CHOMPHEADER -- process and save a header line.
46 ** Called by collect and by readcf to deal with header lines.
49 ** line -- header as a text line.
50 ** def -- if set, this is a default value.
51 ** hdrp -- a pointer to the place to save the header.
52 ** e -- the envelope including this header.
55 ** flags for this header.
58 ** The header is saved on the header list.
59 ** Contents of 'line' are destroyed.
62 struct hdrinfo NormalHeader = { NULL, 0, NULL };
65 chompheader(line, def, hdrp, e)
80 bool nullheader = FALSE;
85 printf("chompheader: ");
90 headeronly = hdrp != NULL;
94 /* strip off options */
100 register char *q = strchr(p + 1, *p);
110 syserr("553 header syntax error, line \"%s\"", line);
114 /* find canonical name */
116 while (isascii(*p) && isgraph(*p) && *p != ':')
119 while (isascii(*p) && isspace(*p))
121 if (*p++ != ':' || fname == fvalue)
123 syserr("553 header syntax error, line \"%s\"", line);
128 /* strip field value on front */
133 /* if the field is null, go ahead and use the default */
134 while (isascii(*p) && isspace(*p))
139 /* security scan: long field names are end-of-header */
140 if (strlen(fname) > 100)
143 /* check to see if it represents a ruleset call */
148 (void) expand(fvalue, hbuf, sizeof hbuf, e);
149 for (p = hbuf; isascii(*p) && isspace(*p); )
151 if ((*p++ & 0377) == CALLSUBR)
155 if (strtorwset(p, &endp, ST_ENTER) > 0)
158 s = stab(fname, ST_HEADER, ST_ENTER);
159 s->s_header.hi_ruleset = newstr(p);
165 /* see if it is a known type */
166 s = stab(fname, ST_HEADER, ST_FIND);
175 printf("no header flags match\n");
177 printf("header match, flags=%x, ruleset=%s\n",
179 hi->hi_ruleset == NULL ? "<NULL>" : hi->hi_ruleset);
182 /* see if this is a resent message */
183 if (!def && !headeronly && bitset(H_RESENT, hi->hi_flags))
184 e->e_flags |= EF_RESENT;
186 /* if this is an Errors-To: header keep track of it now */
187 if (UseErrorsTo && !def && !headeronly &&
188 bitset(H_ERRORSTO, hi->hi_flags))
189 (void) sendtolist(fvalue, NULLADDR, &e->e_errorqueue, 0, e);
191 /* if this means "end of header" quit now */
192 if (!headeronly && bitset(H_EOH, hi->hi_flags))
196 ** Horrible hack to work around problem with Lotus Notes SMTP
197 ** mail gateway, which generates From: headers with newlines in
198 ** them and the <address> on the second line. Although this is
199 ** legal RFC 822, many MUAs don't handle this properly and thus
200 ** never find the actual address.
203 if (bitset(H_FROM, hi->hi_flags) && SingleLineFromHeader)
205 while ((p = strchr(fvalue, '\n')) != NULL)
210 ** If there is a check ruleset, verify it against the header.
213 if (!def && hi->hi_ruleset != NULL)
214 (void) rscheck(hi->hi_ruleset, fvalue, NULL, e);
217 ** Drop explicit From: if same as what we would generate.
218 ** This is to make MH (which doesn't always give a full name)
219 ** insert the full name information in all circumstances.
223 if (!bitset(EF_RESENT, e->e_flags))
225 if (!def && !headeronly && !bitset(EF_QUEUERUN, e->e_flags) &&
226 strcasecmp(fname, p) == 0)
230 printf("comparing header from (%s) against default (%s or %s)\n",
231 fvalue, e->e_from.q_paddr, e->e_from.q_user);
233 if (e->e_from.q_paddr != NULL &&
234 (strcmp(fvalue, e->e_from.q_paddr) == 0 ||
235 strcmp(fvalue, e->e_from.q_user) == 0))
239 /* delete default value for this header */
240 for (hp = hdrp; (h = *hp) != NULL; hp = &h->h_link)
242 if (strcasecmp(fname, h->h_field) == 0 &&
243 bitset(H_DEFAULT, h->h_flags) &&
244 !bitset(H_FORCE, h->h_flags))
248 /* user-supplied value was null */
254 /* copy conditions from default case */
255 bcopy((char *)h->h_mflags, (char *)mopts,
261 /* create a new node */
262 h = (HDR *) xalloc(sizeof *h);
263 h->h_field = newstr(fname);
264 h->h_value = newstr(fvalue);
266 bcopy((char *) mopts, (char *) h->h_mflags, sizeof mopts);
268 h->h_flags = hi->hi_flags;
270 /* strip EOH flag if parsing MIME headers */
272 h->h_flags &= ~H_EOH;
274 h->h_flags |= H_DEFAULT;
276 h->h_flags |= H_CHECK;
278 /* hack to see if this is a new format message */
279 if (!def && !headeronly && bitset(H_RCPT|H_FROM, h->h_flags) &&
280 (strchr(fvalue, ',') != NULL || strchr(fvalue, '(') != NULL ||
281 strchr(fvalue, '<') != NULL || strchr(fvalue, ';') != NULL))
283 e->e_flags &= ~EF_OLDSTYLE;
289 ** ADDHEADER -- add a header entry to the end of the queue.
291 ** This bypasses the special checking of chompheader.
294 ** field -- the name of the header field.
295 ** value -- the value of the field.
296 ** hp -- an indirect pointer to the header structure list.
302 ** adds the field on the list of headers for this envelope.
306 addheader(field, value, hdrlist)
315 /* find info struct */
316 s = stab(field, ST_HEADER, ST_FIND);
318 /* find current place in list -- keep back pointer? */
319 for (hp = hdrlist; (h = *hp) != NULL; hp = &h->h_link)
321 if (strcasecmp(field, h->h_field) == 0)
325 /* allocate space for new header */
326 h = (HDR *) xalloc(sizeof *h);
328 h->h_value = newstr(value);
330 h->h_flags = H_DEFAULT;
332 h->h_flags |= s->s_header.hi_flags;
333 clrbitmap(h->h_mflags);
337 ** HVALUE -- return value of a header.
339 ** Only "real" fields (i.e., ones that have not been supplied
340 ** as a default) are used.
343 ** field -- the field name.
344 ** header -- the header list.
347 ** pointer to the value part.
348 ** NULL if not found.
355 hvalue(field, header)
361 for (h = header; h != NULL; h = h->h_link)
363 if (!bitset(H_DEFAULT, h->h_flags) &&
364 strcasecmp(h->h_field, field) == 0)
370 ** ISHEADER -- predicate telling if argument is a header.
372 ** A line is a header if it has a single word followed by
373 ** optional white space followed by a colon.
375 ** Header fields beginning with two dashes, although technically
376 ** permitted by RFC822, are automatically rejected in order
377 ** to make MIME work out. Without this we could have a technically
378 ** legal header such as ``--"foo:bar"'' that would also be a legal
382 ** h -- string to check for possible headerness.
385 ** TRUE if h is a header.
396 register char *s = h;
398 if (s[0] == '-' && s[1] == '-')
401 while (*s > ' ' && *s != ':' && *s != '\0')
407 /* following technically violates RFC822 */
408 while (isascii(*s) && isspace(*s))
414 ** EATHEADER -- run through the stored header and extract info.
417 ** e -- the envelope to process.
418 ** full -- if set, do full processing (e.g., compute
419 ** message priority). This should not be set
420 ** when reading a queue file because some info
421 ** needed to compute the priority is wrong.
427 ** Sets a bunch of global variables from information
428 ** in the collected header.
429 ** Aborts the message if the hop count is exceeded.
434 register ENVELOPE *e;
442 extern int priencode __P((char *));
445 ** Set up macros for possible expansion in headers.
448 define('f', e->e_sender, e);
449 define('g', e->e_sender, e);
450 if (e->e_origrcpt != NULL && *e->e_origrcpt != '\0')
451 define('u', e->e_origrcpt, e);
453 define('u', NULL, e);
455 /* full name of from person */
456 p = hvalue("full-name", e->e_header);
459 extern bool rfc822_string __P((char *));
461 if (!rfc822_string(p))
463 extern char *addquotes __P((char *));
466 ** Quote a full name with special characters
467 ** as a comment so crackaddr() doesn't destroy
468 ** the name portion of the address.
476 printf("----- collected header -----\n");
478 for (h = e->e_header; h != NULL; h = h->h_link)
481 printf("%s: ", h->h_field);
482 if (h->h_value == NULL)
489 /* do early binding */
490 if (bitset(H_DEFAULT, h->h_flags))
498 expand(h->h_value, buf, sizeof buf, e);
501 if (bitset(H_FROM, h->h_flags))
503 extern char *crackaddr __P((char *));
505 expand(crackaddr(buf), buf, sizeof buf, e);
507 h->h_value = newstr(buf);
508 h->h_flags &= ~H_DEFAULT;
518 /* count the number of times it has been processed */
519 if (bitset(H_TRACE, h->h_flags))
522 /* send to this person if we so desire */
523 if (GrabTo && bitset(H_RCPT, h->h_flags) &&
524 !bitset(H_DEFAULT, h->h_flags) &&
525 (!bitset(EF_RESENT, e->e_flags) || bitset(H_RESENT, h->h_flags)))
528 int saveflags = e->e_flags;
531 (void) sendtolist(h->h_value, NULLADDR,
532 &e->e_sendqueue, 0, e);
536 ** Change functionality so a fatal error on an
537 ** address doesn't affect the entire envelope.
540 /* delete fatal errors generated by this address */
541 if (!bitset(EF_FATALERRS, saveflags))
542 e->e_flags &= ~EF_FATALERRS;
546 /* save the message-id for logging */
547 p = "resent-message-id";
548 if (!bitset(EF_RESENT, e->e_flags))
550 if (strcasecmp(h->h_field, p) == 0)
553 while (isascii(*msgid) && isspace(*msgid))
558 printf("----------------------------\n");
560 /* if we are just verifying (that is, sendmail -t -bv), drop out now */
561 if (OpMode == MD_VERIFY)
564 /* store hop count */
565 if (hopcnt > e->e_hopcount)
566 e->e_hopcount = hopcnt;
568 /* message priority */
569 p = hvalue("precedence", e->e_header);
571 e->e_class = priencode(p);
573 e->e_timeoutclass = TOC_NONURGENT;
574 else if (e->e_class > 0)
575 e->e_timeoutclass = TOC_URGENT;
578 e->e_msgpriority = e->e_msgsize
579 - e->e_class * WkClassFact
580 + e->e_nrcpts * WkRecipFact;
583 /* message timeout priority */
584 p = hvalue("priority", e->e_header);
587 /* (this should be in the configuration file) */
588 if (strcasecmp(p, "urgent") == 0)
589 e->e_timeoutclass = TOC_URGENT;
590 else if (strcasecmp(p, "normal") == 0)
591 e->e_timeoutclass = TOC_NORMAL;
592 else if (strcasecmp(p, "non-urgent") == 0)
593 e->e_timeoutclass = TOC_NONURGENT;
596 /* date message originated */
597 p = hvalue("posted-date", e->e_header);
599 p = hvalue("date", e->e_header);
603 /* check to see if this is a MIME message */
604 if ((e->e_bodytype != NULL &&
605 strcasecmp(e->e_bodytype, "8BITMIME") == 0) ||
606 hvalue("MIME-Version", e->e_header) != NULL)
608 e->e_flags |= EF_IS_MIME;
610 e->e_bodytype = "8BITMIME";
612 else if ((p = hvalue("Content-Type", e->e_header)) != NULL)
614 /* this may be an RFC 1049 message */
615 p = strpbrk(p, ";/");
616 if (p == NULL || *p == ';')
619 e->e_flags |= EF_DONT_MIME;
624 ** From person in antiquated ARPANET mode
625 ** required by UK Grey Book e-mail gateways (sigh)
628 if (OpMode == MD_ARPAFTP)
630 register struct hdrinfo *hi;
632 for (hi = HdrInfo; hi->hi_field != NULL; hi++)
634 if (bitset(H_FROM, hi->hi_flags) &&
635 (!bitset(H_RESENT, hi->hi_flags) ||
636 bitset(EF_RESENT, e->e_flags)) &&
637 (p = hvalue(hi->hi_field, e->e_header)) != NULL)
640 if (hi->hi_field != NULL)
643 printf("eatheader: setsender(*%s == %s)\n",
645 setsender(p, e, NULL, '\0', TRUE);
650 ** Log collection information.
653 if (bitset(EF_LOGSENDER, e->e_flags) && LogLevel > 4)
655 e->e_flags &= ~EF_LOGSENDER;
658 ** LOGSENDER -- log sender information
661 ** e -- the envelope to log
662 ** msgid -- the message id
670 register ENVELOPE *e;
677 char hbuf[MAXNAME + 1];
678 char sbuf[MAXLINE + 1];
679 char mbuf[MAXNAME + 1];
681 /* don't allow newlines in the message-id */
685 if (l > sizeof mbuf - 1)
687 bcopy(msgid, mbuf, l);
690 while ((p = strchr(p, '\n')) != NULL)
694 if (bitset(EF_RESPONSE, e->e_flags))
696 else if ((name = macvalue('_', e)) != NULL)
698 else if (RealHostName == NULL)
700 else if (RealHostName[0] == '[')
705 (void) snprintf(hbuf, sizeof hbuf, "%.80s", RealHostName);
706 if (RealHostAddr.sa.sa_family != 0)
708 p = &hbuf[strlen(hbuf)];
709 (void) snprintf(p, SPACELEFT(hbuf, p), " (%.100s)",
710 anynet_ntoa(&RealHostAddr));
714 /* some versions of syslog only take 5 printf args */
715 # if (SYSLOG_BUFSIZE) >= 256
717 snprintf(sbp, SPACELEFT(sbuf, sbp),
718 "from=%.200s, size=%ld, class=%d, pri=%ld, nrcpts=%d",
719 e->e_from.q_paddr == NULL ? "<NONE>" : e->e_from.q_paddr,
720 e->e_msgsize, e->e_class, e->e_msgpriority, e->e_nrcpts);
724 snprintf(sbp, SPACELEFT(sbuf, sbp), ", msgid=%.100s", mbuf);
727 if (e->e_bodytype != NULL)
729 (void) snprintf(sbp, SPACELEFT(sbuf, sbp), ", bodytype=%.20s",
733 p = macvalue('r', e);
735 (void) snprintf(sbp, SPACELEFT(sbuf, sbp), ", proto=%.20s", p);
736 sm_syslog(LOG_INFO, e->e_id,
737 "%.850s, relay=%.100s",
740 # else /* short syslog buffer */
742 sm_syslog(LOG_INFO, e->e_id,
744 e->e_from.q_paddr == NULL ? "<NONE>"
745 : shortenstring(e->e_from.q_paddr, 83));
746 sm_syslog(LOG_INFO, e->e_id,
747 "size=%ld, class=%ld, pri=%ld, nrcpts=%d",
748 e->e_msgsize, e->e_class, e->e_msgpriority, e->e_nrcpts);
750 sm_syslog(LOG_INFO, e->e_id,
752 shortenstring(mbuf, 83));
755 if (e->e_bodytype != NULL)
757 snprintf(sbp, SPACELEFT(sbuf, sbp), "bodytype=%.20s, ", e->e_bodytype);
760 p = macvalue('r', e);
763 snprintf(sbp, SPACELEFT(sbuf, sbp), "proto=%.20s, ", p);
766 sm_syslog(LOG_INFO, e->e_id,
767 "%.400srelay=%.100s", sbuf, name);
771 ** PRIENCODE -- encode external priority names into internal values.
774 ** p -- priority in ascii.
777 ** priority as a numeric level.
789 for (i = 0; i < NumPriorities; i++)
791 if (!strcasecmp(p, Priorities[i].pri_name))
792 return (Priorities[i].pri_val);
795 /* unknown priority */
799 ** CRACKADDR -- parse an address and turn it into a macro
801 ** This doesn't actually parse the address -- it just extracts
802 ** it and replaces it with "$g". The parse is totally ad hoc
803 ** and isn't even guaranteed to leave something syntactically
804 ** identical to what it started with. However, it does leave
805 ** something semantically identical.
807 ** This algorithm has been cleaned up to handle a wider range
808 ** of cases -- notably quoted and backslash escaped strings.
809 ** This modification makes it substantially better at preserving
810 ** the original syntax.
813 ** addr -- the address to be cracked.
816 ** a pointer to the new version.
822 ** The return value is saved in local storage and should
823 ** be copied if it is to be reused.
834 int anglelev, realanglelev;
840 bool putgmac = FALSE;
841 bool quoteit = FALSE;
842 bool gotangle = FALSE;
843 bool gotcolon = FALSE;
848 static char buf[MAXNAME + 1];
851 printf("crackaddr(%s)\n", addr);
853 /* strip leading spaces */
854 while (*addr != '\0' && isascii(*addr) && isspace(*addr))
858 ** Start by assuming we have no angle brackets. This will be
859 ** adjusted later if we find them.
863 buflim = &buf[sizeof buf - 7];
865 copylev = anglelev = realanglelev = cmtlev = realcmtlev = 0;
867 qmode = realqmode = FALSE;
869 while ((c = *p++) != '\0')
872 ** If the buffer is overful, go into a special "skipping"
873 ** mode that tries to keep legal syntax but doesn't actually
877 skipping = bp >= buflim;
879 if (copylev > 0 && !skipping)
882 /* check for backslash escapes */
885 /* arrange to quote the address */
886 if (cmtlev <= 0 && !qmode)
889 if ((c = *p++) == '\0')
895 if (copylev > 0 && !skipping)
900 /* check for quoted strings */
901 if (c == '"' && cmtlev <= 0)
904 if (copylev > 0 && !skipping)
905 realqmode = !realqmode;
911 /* check for comments */
916 /* allow space for closing paren */
945 /* syntax error: unmatched ) */
946 if (copylev > 0 && !skipping)
950 /* count nesting on [ ... ] (for IPv6 domain literals) */
956 /* check for group: list; syntax */
957 if (c == ':' && anglelev <= 0 && bracklev <= 0 &&
958 !gotcolon && !ColonOkInAddr)
963 ** Check for DECnet phase IV ``::'' (host::user)
964 ** or ** DECnet phase V ``:.'' syntaxes. The latter
965 ** covers ``user@DEC:.tay.myhost'' and
966 ** ``DEC:.tay.myhost::user'' syntaxes (bletch).
969 if (*p == ':' || *p == '.')
971 if (cmtlev <= 0 && !qmode)
973 if (copylev > 0 && !skipping)
989 /* back up over the ':' and any spaces */
991 while (isascii(*--p) && isspace(*p))
995 for (q = addrhead; q < p; )
1000 if (quoteit && c == '"')
1007 if (bp == &bufhead[1])
1011 while ((c = *p++) != ':')
1019 /* any trailing white space is part of group: */
1020 while (isascii(*p) && isspace(*p) && bp < buflim)
1023 putgmac = quoteit = FALSE;
1029 if (c == ';' && copylev <= 0 && !ColonOkInAddr)
1035 /* check for characters that may have to be quoted */
1036 if (strchr(MustQuoteChars, c) != NULL)
1039 ** If these occur as the phrase part of a <>
1040 ** construct, but are not inside of () or already
1041 ** quoted, they will have to be quoted. Note that
1042 ** now (but don't actually do the quoting).
1045 if (cmtlev <= 0 && !qmode)
1049 /* check for angle brackets */
1054 /* assume first of two angles is bogus */
1059 /* oops -- have to change our mind */
1069 /* back up over the '<' and any spaces */
1071 while (isascii(*--p) && isspace(*p))
1075 for (q = addrhead; q < p; )
1080 if (quoteit && c == '"')
1091 while ((c = *p++) != '<')
1099 putgmac = quoteit = FALSE;
1116 /* syntax error: unmatched > */
1127 /* must be a real address character */
1129 if (copylev <= 0 && !putgmac)
1131 if (bp > bufhead && bp[-1] == ')')
1133 *bp++ = MACROEXPAND;
1139 /* repair any syntactic damage */
1142 while (realcmtlev-- > 0)
1144 while (realanglelev-- > 0)
1150 printf("crackaddr=>`");
1158 ** PUTHEADER -- put the header part of a message from the in-core copy
1161 ** mci -- the connection information.
1162 ** h -- the header to put.
1163 ** e -- envelope to use.
1164 ** flags -- MIME conversion flags.
1174 * Macro for fast max (not available in e.g. DG/UX, 386/ix).
1177 # define MAX(a,b) (((a)>(b))?(a):(b))
1181 putheader(mci, hdr, e, flags)
1184 register ENVELOPE *e;
1188 char buf[MAX(MAXLINE,BUFSIZ)];
1192 printf("--- putheader, mailer = %s ---\n",
1193 mci->mci_mailer->m_name);
1196 ** If we're in MIME mode, we're not really in the header of the
1197 ** message, just the header of one of the parts of the body of
1198 ** the message. Therefore MCIF_INHEADER should not be turned on.
1201 if (!bitset(MCIF_INMIME, mci->mci_flags))
1202 mci->mci_flags |= MCIF_INHEADER;
1204 for (h = hdr; h != NULL; h = h->h_link)
1206 register char *p = h->h_value;
1207 extern bool bitintersect __P((BITMAP, BITMAP));
1211 printf(" %s: ", h->h_field);
1215 #if _FFR_MAX_MIME_HEADER_LENGTH
1216 /* heuristic shortening of MIME fields to avoid MUA overflows */
1217 if (MaxMimeFieldLength > 0 &&
1218 wordinclass(h->h_field,
1219 macid("{checkMIMEFieldHeaders}", NULL)))
1221 extern bool fix_mime_header __P((char *));
1223 if (fix_mime_header(h->h_value))
1225 sm_syslog(LOG_ALERT, e->e_id,
1226 "Truncated MIME %s header due to field size (possible attack)",
1229 printf(" truncated MIME %s header due to field size (possible attack)\n",
1234 if (MaxMimeHeaderLength > 0 &&
1235 wordinclass(h->h_field,
1236 macid("{checkMIMETextHeaders}", NULL)))
1238 if (strlen(h->h_value) > MaxMimeHeaderLength)
1240 h->h_value[MaxMimeHeaderLength - 1] = '\0';
1241 sm_syslog(LOG_ALERT, e->e_id,
1242 "Truncated long MIME %s header (possible attack)",
1245 printf(" truncated long MIME %s header (possible attack)\n",
1250 if (MaxMimeHeaderLength > 0 &&
1251 wordinclass(h->h_field,
1252 macid("{checkMIMEHeaders}", NULL)))
1254 extern bool shorten_rfc822_string __P((char *, int));
1256 if (shorten_rfc822_string(h->h_value, MaxMimeHeaderLength))
1258 sm_syslog(LOG_ALERT, e->e_id,
1259 "Truncated long MIME %s header (possible attack)",
1262 printf(" truncated long MIME %s header (possible attack)\n",
1269 ** Suppress Content-Transfer-Encoding: if we are MIMEing
1270 ** and we are potentially converting from 8 bit to 7 bit
1271 ** MIME. If converting, add a new CTE header in
1274 if (bitset(H_CTE, h->h_flags) &&
1275 bitset(MCIF_CVT8TO7|MCIF_CVT7TO8|MCIF_INMIME,
1277 !bitset(M87F_NO8TO7, flags))
1280 printf(" (skipped (content-transfer-encoding))\n");
1284 if (bitset(MCIF_INMIME, mci->mci_flags))
1288 put_vanilla_header(h, p, mci);
1292 if (bitset(H_CHECK|H_ACHECK, h->h_flags) &&
1293 !bitintersect(h->h_mflags, mci->mci_mailer->m_flags))
1296 printf(" (skipped)\n");
1300 /* handle Resent-... headers specially */
1301 if (bitset(H_RESENT, h->h_flags) && !bitset(EF_RESENT, e->e_flags))
1304 printf(" (skipped (resent))\n");
1308 /* suppress return receipts if requested */
1309 if (bitset(H_RECEIPTTO, h->h_flags) &&
1310 #if _FFR_DSN_RRT_OPTION
1311 (RrtImpliesDsn || bitset(EF_NORECEIPT, e->e_flags)))
1313 bitset(EF_NORECEIPT, e->e_flags))
1317 printf(" (skipped (receipt))\n");
1321 /* macro expand value if generated internally */
1322 if (bitset(H_DEFAULT, h->h_flags))
1324 expand(p, buf, sizeof buf, e);
1329 printf(" (skipped -- null value)\n");
1334 if (bitset(H_BCC, h->h_flags))
1336 /* Bcc: field -- either truncate or delete */
1337 if (bitset(EF_DELETE_BCC, e->e_flags))
1340 printf(" (skipped -- bcc)\n");
1344 /* no other recipient headers: truncate value */
1345 (void) snprintf(obuf, sizeof obuf, "%s:",
1355 if (bitset(H_FROM|H_RCPT, h->h_flags))
1358 bool oldstyle = bitset(EF_OLDSTYLE, e->e_flags);
1360 if (bitset(H_FROM, h->h_flags))
1362 commaize(h, p, oldstyle, mci, e);
1366 put_vanilla_header(h, p, mci);
1371 ** If we are converting this to a MIME message, add the
1376 if (bitset(MM_MIME8BIT, MimeMode) &&
1377 bitset(EF_HAS8BIT, e->e_flags) &&
1378 !bitset(EF_DONT_MIME, e->e_flags) &&
1379 !bitnset(M_8BITS, mci->mci_mailer->m_flags) &&
1380 !bitset(MCIF_CVT8TO7|MCIF_CVT7TO8, mci->mci_flags))
1382 if (hvalue("MIME-Version", e->e_header) == NULL)
1383 putline("MIME-Version: 1.0", mci);
1384 if (hvalue("Content-Type", e->e_header) == NULL)
1386 snprintf(obuf, sizeof obuf,
1387 "Content-Type: text/plain; charset=%s",
1391 if (hvalue("Content-Transfer-Encoding", e->e_header) == NULL)
1392 putline("Content-Transfer-Encoding: 8bit", mci);
1397 ** PUT_VANILLA_HEADER -- output a fairly ordinary header
1400 ** h -- the structure describing this header
1401 ** v -- the value of this header
1402 ** mci -- the connection info for output
1409 put_vanilla_header(h, v, mci)
1419 putflags = PXLF_HEADER;
1421 if (bitnset(M_7BITHDRS, mci->mci_mailer->m_flags))
1422 putflags |= PXLF_STRIP8BIT;
1424 (void) snprintf(obuf, sizeof obuf, "%.200s: ", h->h_field);
1425 obp = obuf + strlen(obuf);
1426 while ((nlp = strchr(v, '\n')) != NULL)
1431 if (SPACELEFT(obuf, obp) - 1 < l)
1432 l = SPACELEFT(obuf, obp) - 1;
1434 snprintf(obp, SPACELEFT(obuf, obp), "%.*s", l, v);
1435 putxline(obuf, strlen(obuf), mci, putflags);
1438 if (*v != ' ' && *v != '\t')
1441 snprintf(obp, SPACELEFT(obuf, obp), "%.*s",
1442 (int)(sizeof obuf - (obp - obuf) - 1), v);
1443 putxline(obuf, strlen(obuf), mci, putflags);
1446 ** COMMAIZE -- output a header field, making a comma-translated list.
1449 ** h -- the header field to output.
1450 ** p -- the value to put in it.
1451 ** oldstyle -- TRUE if this is an old style header.
1452 ** mci -- the connection information.
1453 ** e -- the envelope containing the message.
1459 ** outputs "p" to file "fp".
1463 commaize(h, p, oldstyle, mci, e)
1468 register ENVELOPE *e;
1473 bool firstone = TRUE;
1474 int putflags = PXLF_HEADER;
1475 char obuf[MAXLINE + 3];
1478 ** Output the address list translated by the
1479 ** mailer and with commas.
1483 printf("commaize(%s: %s)\n", h->h_field, p);
1486 if (bitnset(M_7BITHDRS, mci->mci_mailer->m_flags))
1487 putflags |= PXLF_STRIP8BIT;
1491 (void) snprintf(obp, SPACELEFT(obuf, obp), "%.200s: ", h->h_field);
1492 opos = strlen(h->h_field) + 2;
1496 omax = mci->mci_mailer->m_linelimit - 2;
1497 if (omax < 0 || omax > 78)
1501 ** Run through the list of values.
1506 register char *name;
1513 ** Find the end of the name. New style names
1514 ** end with a comma, old style names end with
1515 ** a space character. However, spaces do not
1516 ** necessarily delimit an old-style name -- at
1517 ** signs mean keep going.
1520 /* find end of name */
1521 while ((isascii(*p) && isspace(*p)) || *p == ',')
1527 char pvpbuf[PSBUFSIZE];
1529 (void) prescan(p, oldstyle ? ' ' : ',', pvpbuf,
1530 sizeof pvpbuf, &oldp, NULL);
1533 /* look to see if we have an at sign */
1534 while (*p != '\0' && isascii(*p) && isspace(*p))
1542 p += *p == '@' ? 1 : 2;
1543 while (*p != '\0' && isascii(*p) && isspace(*p))
1546 /* at the end of one complete name */
1548 /* strip off trailing white space */
1550 ((isascii(*p) && isspace(*p)) || *p == ',' || *p == '\0'))
1557 /* translate the name to be relative */
1558 flags = RF_HEADERADDR|RF_ADDDOMAIN;
1559 if (bitset(H_FROM, h->h_flags))
1560 flags |= RF_SENDERADDR;
1562 else if (e->e_from.q_mailer != NULL &&
1563 bitnset(M_UDBRECIPIENT, e->e_from.q_mailer->m_flags))
1565 extern char *udbsender __P((char *));
1568 q = udbsender(name);
1574 name = remotename(name, mci->mci_mailer, flags, &stat, e);
1580 name = denlstring(name, FALSE, TRUE);
1582 /* output the name with nice formatting */
1583 opos += strlen(name);
1586 if (opos > omax && !firstone)
1588 snprintf(obp, SPACELEFT(obuf, obp), ",\n");
1589 putxline(obuf, strlen(obuf), mci, putflags);
1591 (void) strcpy(obp, " ");
1594 opos += strlen(name);
1598 snprintf(obp, SPACELEFT(obuf, obp), ", ");
1602 while ((c = *name++) != '\0' && obp < &obuf[MAXLINE])
1608 putxline(obuf, strlen(obuf), mci, putflags);
1611 ** COPYHEADER -- copy header list
1613 ** This routine is the equivalent of newstr for header lists
1616 ** header -- list of header structures to copy.
1619 ** a copy of 'header'.
1627 register HDR *header;
1629 register HDR *newhdr;
1631 register HDR **tail = &ret;
1633 while (header != NULL)
1635 newhdr = (HDR *) xalloc(sizeof(HDR));
1636 STRUCTCOPY(*header, *newhdr);
1638 tail = &newhdr->h_link;
1639 header = header->h_link;
1646 ** FIX_MIME_HEADER -- possibly truncate/rebalance parameters in a MIME header
1648 ** Run through all of the parameters of a MIME header and
1649 ** possibly truncate and rebalance the parameter according
1650 ** to MaxMimeFieldLength.
1653 ** string -- the full header
1656 ** TRUE if the header was modified, FALSE otherwise
1659 ** string modified in place
1663 fix_mime_header(string)
1666 bool modified = FALSE;
1667 char *begin = string;
1669 extern char *find_character __P((char *, char));
1670 extern bool shorten_rfc822_string __P((char *, int));
1672 if (string == NULL || *string == '\0')
1675 /* Split on each ';' */
1676 while ((end = find_character(begin, ';')) != NULL)
1683 /* Shorten individual parameter */
1684 if (shorten_rfc822_string(begin, MaxMimeFieldLength))
1687 /* Collapse the possibly shortened string with rest */
1688 bp = begin + strlen(begin);
1696 /* copy character by character due to overlap */