17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
237c478bdstevel@tonic-gate/*	  All Rights Reserved  	*/
247c478bdstevel@tonic-gate
257c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate#include "mail.h"
287c478bdstevel@tonic-gate/*
297c478bdstevel@tonic-gate * link new entry into list of headerlines encountered of this type.
307c478bdstevel@tonic-gate * If contflg == TRUE, link this line to the end of the continuation lines
317c478bdstevel@tonic-gate * for the headerline specified (head or tail of type hdrtype).
327c478bdstevel@tonic-gate */
337c478bdstevel@tonic-gatevoid pushlist(hdrtype, where, s, contflg)
347c478bdstevel@tonic-gateregister	int	hdrtype;
357c478bdstevel@tonic-gateregister	int	where;
367c478bdstevel@tonic-gateregister		char *s;
377c478bdstevel@tonic-gate{
387c478bdstevel@tonic-gate	static char pn[] = "pushlist";
397c478bdstevel@tonic-gate	char		*p;
407c478bdstevel@tonic-gate	struct	hdrs	*nhp, *ohp, *nextcont;
417c478bdstevel@tonic-gate
427c478bdstevel@tonic-gate	/* Keep track of total bytes added to message due to    */
437c478bdstevel@tonic-gate	/* certain lines in case non-delivery                   */
447c478bdstevel@tonic-gate	/* notification needs to be sent. (See also copylet())  */
457c478bdstevel@tonic-gate	if (hdrtype == H_AFWDFROM) {
467c478bdstevel@tonic-gate		affbytecnt += (strlen(s) + ((contflg == TRUE) ?
477c478bdstevel@tonic-gate			1 :
487c478bdstevel@tonic-gate			(strlen(header[H_AFWDFROM].tag) + 2)) );
497c478bdstevel@tonic-gate		if (contflg == FALSE) {
507c478bdstevel@tonic-gate			affcnt++;
517c478bdstevel@tonic-gate		}
527c478bdstevel@tonic-gate	}
537c478bdstevel@tonic-gate	if (hdrtype == H_RECEIVED) {
547c478bdstevel@tonic-gate		rcvbytecnt += (strlen(s) + ((contflg == TRUE) ?
557c478bdstevel@tonic-gate			1 :
567c478bdstevel@tonic-gate			(strlen(header[H_RECEIVED].tag) + 2)) );
577c478bdstevel@tonic-gate	}
587c478bdstevel@tonic-gate	if ((p = malloc(sizeof(struct hdrs))) == (char *)NULL) {
597c478bdstevel@tonic-gate		errmsg(E_MEM,"malloc failed in pushlist()");
607c478bdstevel@tonic-gate		done(1);
617c478bdstevel@tonic-gate	}
627c478bdstevel@tonic-gate	memset(p, 0, sizeof(struct hdrs));
637c478bdstevel@tonic-gate
647c478bdstevel@tonic-gate	ohp = (where == HEAD ? hdrlines[hdrtype].head : hdrlines[hdrtype].tail);
657c478bdstevel@tonic-gate	nhp = (struct hdrs *)p;
667c478bdstevel@tonic-gate
677c478bdstevel@tonic-gate	(void) strlcpy(nhp->value, s, sizeof (nhp->value));
687c478bdstevel@tonic-gate
697c478bdstevel@tonic-gate	Dout(pn, 0, "hdrtype = %d/%s, contflg = %d, saved value = '%s'\n",
707c478bdstevel@tonic-gate		hdrtype, header[hdrtype].tag, contflg, s);
717c478bdstevel@tonic-gate
727c478bdstevel@tonic-gate	if (contflg) {
737c478bdstevel@tonic-gate		if (ohp == (struct hdrs *)NULL) {
747c478bdstevel@tonic-gate			/* This shouldn't happen.....? */
757c478bdstevel@tonic-gate			/* No headline of this type found so far. How */
767c478bdstevel@tonic-gate			/* did we think this is a continuation of something? */
777c478bdstevel@tonic-gate			if (debug > 0) {
787c478bdstevel@tonic-gate				Dout(pn, 0, "H_CONT with no hdr yet\n");
797c478bdstevel@tonic-gate				abort();
807c478bdstevel@tonic-gate			}
817c478bdstevel@tonic-gate			/* Throw it on the floor... (!) */
827c478bdstevel@tonic-gate			/**/
837c478bdstevel@tonic-gate			/* Subtract anything that might have been added above */
847c478bdstevel@tonic-gate			if (hdrtype == H_AFWDFROM) {
857c478bdstevel@tonic-gate			    affbytecnt -= (strlen(s) + ((contflg == TRUE) ?
867c478bdstevel@tonic-gate				1 :
877c478bdstevel@tonic-gate				(strlen(header[H_AFWDFROM].tag) + 2)) );
887c478bdstevel@tonic-gate			}
897c478bdstevel@tonic-gate			if (hdrtype == H_RECEIVED) {
907c478bdstevel@tonic-gate			    rcvbytecnt -= (strlen(s) + ((contflg == TRUE) ?
917c478bdstevel@tonic-gate				1 :
927c478bdstevel@tonic-gate				(strlen(header[H_RECEIVED].tag) + 2)) );
937c478bdstevel@tonic-gate			}
947c478bdstevel@tonic-gate			free ((char *)nhp);
957c478bdstevel@tonic-gate			return;
967c478bdstevel@tonic-gate		}
977c478bdstevel@tonic-gate		/* Since we ONLY walk down 'cont' chains, */
987c478bdstevel@tonic-gate		/* we only need forward links */
997c478bdstevel@tonic-gate		nextcont = ohp;
1007c478bdstevel@tonic-gate		while (nextcont->cont != (struct hdrs *)NULL) {
1017c478bdstevel@tonic-gate			nextcont = nextcont->cont;
1027c478bdstevel@tonic-gate		}
1037c478bdstevel@tonic-gate		/* Add this one to end of list... */
1047c478bdstevel@tonic-gate		nextcont->cont = nhp;
1057c478bdstevel@tonic-gate		return;
1067c478bdstevel@tonic-gate	}
1077c478bdstevel@tonic-gate
1087c478bdstevel@tonic-gate	/* link value from this header line to end of list for */
1097c478bdstevel@tonic-gate	/* all header lines of the same type */
1107c478bdstevel@tonic-gate
1117c478bdstevel@tonic-gate	if (ohp == (struct hdrs *)NULL) {
1127c478bdstevel@tonic-gate		/* Empty list so far. New element goes first */
1137c478bdstevel@tonic-gate		hdrlines[hdrtype].head = hdrlines[hdrtype].tail = nhp;
1147c478bdstevel@tonic-gate	} else {
1157c478bdstevel@tonic-gate		if (where == HEAD) {
1167c478bdstevel@tonic-gate			/* Add new element to head of list */
1177c478bdstevel@tonic-gate			nhp->next = ohp;
1187c478bdstevel@tonic-gate			hdrlines[hdrtype].head = ohp->prev = nhp;
1197c478bdstevel@tonic-gate		} else {
1207c478bdstevel@tonic-gate			/* Add new element to tail of list */
1217c478bdstevel@tonic-gate			nhp->prev = ohp;
1227c478bdstevel@tonic-gate			hdrlines[hdrtype].tail = ohp->next = nhp;
1237c478bdstevel@tonic-gate		}
1247c478bdstevel@tonic-gate	}
1257c478bdstevel@tonic-gate}
126