⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 headers.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
		sbp += strlen(sbp);	}	p = macvalue('r', e);	if (p != NULL)	{		sprintf(sbp, " proto=%s,", p);		sbp += strlen(sbp);	}	syslog(LOG_INFO, "%s relay=%s", sbuf, name);#  endif# endif}/***  PRIENCODE -- encode external priority names into internal values.****	Parameters:**		p -- priority in ascii.****	Returns:**		priority as a numeric level.****	Side Effects:**		none.*/priencode(p)	char *p;{	register int i;	for (i = 0; i < NumPriorities; i++)	{		if (!strcasecmp(p, Priorities[i].pri_name))			return (Priorities[i].pri_val);	}	/* unknown priority */	return (0);}/***  CRACKADDR -- parse an address and turn it into a macro****	This doesn't actually parse the address -- it just extracts**	it and replaces it with "$g".  The parse is totally ad hoc**	and isn't even guaranteed to leave something syntactically**	identical to what it started with.  However, it does leave**	something semantically identical.****	This algorithm has been cleaned up to handle a wider range**	of cases -- notably quoted and backslash escaped strings.**	This modification makes it substantially better at preserving**	the original syntax.****	Parameters:**		addr -- the address to be cracked.****	Returns:**		a pointer to the new version.****	Side Effects:**		none.****	Warning:**		The return value is saved in local storage and should**		be copied if it is to be reused.*/char *crackaddr(addr)	register char *addr;{	register char *p;	register char c;	int cmtlev;	int realcmtlev;	int anglelev, realanglelev;	int copylev;	bool qmode;	bool realqmode;	bool skipping;	bool putgmac = FALSE;	bool quoteit = FALSE;	bool gotangle = FALSE;	register char *bp;	char *buflim;	static char buf[MAXNAME];	if (tTd(33, 1))		printf("crackaddr(%s)\n", addr);	/* strip leading spaces */	while (*addr != '\0' && isascii(*addr) && isspace(*addr))		addr++;	/*	**  Start by assuming we have no angle brackets.  This will be	**  adjusted later if we find them.	*/	bp = buf;	buflim = &buf[sizeof buf - 5];	p = addr;	copylev = anglelev = realanglelev = cmtlev = realcmtlev = 0;	qmode = realqmode = FALSE;	while ((c = *p++) != '\0')	{		/*		**  If the buffer is overful, go into a special "skipping"		**  mode that tries to keep legal syntax but doesn't actually		**  output things.		*/		skipping = bp >= buflim;		if (copylev > 0 && !skipping)			*bp++ = c;		/* check for backslash escapes */		if (c == '\\')		{			/* arrange to quote the address */			if (cmtlev <= 0 && !qmode)				quoteit = TRUE;			if ((c = *p++) == '\0')			{				/* too far */				p--;				goto putg;			}			if (copylev > 0 && !skipping)				*bp++ = c;			goto putg;		}		/* check for quoted strings */		if (c == '"' && cmtlev <= 0)		{			qmode = !qmode;			if (copylev > 0 && !skipping)				realqmode = !realqmode;			continue;		}		if (qmode)			goto putg;		/* check for comments */		if (c == '(')		{			cmtlev++;			/* allow space for closing paren */			if (!skipping)			{				buflim--;				realcmtlev++;				if (copylev++ <= 0)				{					*bp++ = ' ';					*bp++ = c;				}			}		}		if (cmtlev > 0)		{			if (c == ')')			{				cmtlev--;				copylev--;				if (!skipping)				{					realcmtlev--;					buflim++;				}			}			continue;		}		else if (c == ')')		{			/* syntax error: unmatched ) */			if (copylev > 0 && !skipping)				bp--;		}		/* check for characters that may have to be quoted */		if (strchr(".'@,;:\\()[]", c) != NULL)		{			/*			**  If these occur as the phrase part of a <>			**  construct, but are not inside of () or already			**  quoted, they will have to be quoted.  Note that			**  now (but don't actually do the quoting).			*/			if (cmtlev <= 0 && !qmode)				quoteit = TRUE;		}		/* check for angle brackets */		if (c == '<')		{			register char *q;			/* assume first of two angles is bogus */			if (gotangle)				quoteit = TRUE;			gotangle = TRUE;			/* oops -- have to change our mind */			anglelev = 1;			if (!skipping)				realanglelev = 1;			bp = buf;			if (quoteit)			{				*bp++ = '"';				/* back up over the '<' and any spaces */				--p;				while (isascii(*--p) && isspace(*p))					continue;				p++;			}			for (q = addr; q < p; )			{				c = *q++;				if (bp < buflim)				{					if (quoteit && c == '"')						*bp++ = '\\';					*bp++ = c;				}			}			if (quoteit)			{				if (bp == &buf[1])					bp--;				else					*bp++ = '"';				while ((c = *p++) != '<')				{					if (bp < buflim)						*bp++ = c;				}				*bp++ = c;			}			copylev = 0;			putgmac = quoteit = FALSE;			continue;		}		if (c == '>')		{			if (anglelev > 0)			{				anglelev--;				if (!skipping)				{					realanglelev--;					buflim++;				}			}			else if (!skipping)			{				/* syntax error: unmatched > */				if (copylev > 0)					bp--;				quoteit = TRUE;				continue;			}			if (copylev++ <= 0)				*bp++ = c;			continue;		}		/* must be a real address character */	putg:		if (copylev <= 0 && !putgmac)		{			*bp++ = MACROEXPAND;			*bp++ = 'g';			putgmac = TRUE;		}	}	/* repair any syntactic damage */	if (realqmode)		*bp++ = '"';	while (realcmtlev-- > 0)		*bp++ = ')';	while (realanglelev-- > 0)		*bp++ = '>';	*bp++ = '\0';	if (tTd(33, 1))		printf("crackaddr=>`%s'\n", buf);	return (buf);}/***  PUTHEADER -- put the header part of a message from the in-core copy****	Parameters:**		mci -- the connection information.**		e -- envelope to use.****	Returns:**		none.****	Side Effects:**		none.*//* * Macro for fast max (not available in e.g. DG/UX, 386/ix). */#ifndef MAX# define MAX(a,b) (((a)>(b))?(a):(b))#endifputheader(mci, e)	register MCI *mci;	register ENVELOPE *e;{	char buf[MAX(MAXLINE,BUFSIZ)];	register HDR *h;	char obuf[MAXLINE];	if (tTd(34, 1))		printf("--- putheader, mailer = %s ---\n",			mci->mci_mailer->m_name);	for (h = e->e_header; h != NULL; h = h->h_link)	{		register char *p;		extern bool bitintersect();		if (tTd(34, 11))		{			printf("  %s: ", h->h_field);			xputs(h->h_value);		}		if (bitset(H_CHECK|H_ACHECK, h->h_flags) &&		    !bitintersect(h->h_mflags, mci->mci_mailer->m_flags))		{			if (tTd(34, 11))				printf(" (skipped)\n");			continue;		}		/* handle Resent-... headers specially */		if (bitset(H_RESENT, h->h_flags) && !bitset(EF_RESENT, e->e_flags))		{			if (tTd(34, 11))				printf(" (skipped (resent))\n");			continue;		}		/* suppress return receipts if requested */		if (bitset(H_RECEIPTTO, h->h_flags) &&		    bitset(EF_NORECEIPT, e->e_flags))		{			if (tTd(34, 11))				printf(" (skipped (receipt))\n");			continue;		}		/* macro expand value if generated internally */		p = h->h_value;		if (bitset(H_DEFAULT, h->h_flags))		{			expand(p, buf, &buf[sizeof buf], e);			p = buf;			if (p == NULL || *p == '\0')			{				if (tTd(34, 11))					printf(" (skipped -- null value)\n");				continue;			}		}		if (tTd(34, 11))			printf("\n");		if (bitset(H_FROM|H_RCPT, h->h_flags))		{			/* address field */			bool oldstyle = bitset(EF_OLDSTYLE, e->e_flags);			if (bitset(H_FROM, h->h_flags))				oldstyle = FALSE;			commaize(h, p, oldstyle, mci, e);		}		else		{			/* vanilla header line */			register char *nlp;			(void) sprintf(obuf, "%s: ", h->h_field);			while ((nlp = strchr(p, '\n')) != NULL)			{				*nlp = '\0';				(void) strcat(obuf, p);				*nlp = '\n';				putline(obuf, mci);				p = ++nlp;				obuf[0] = '\0';			}			(void) strcat(obuf, p);			putline(obuf, mci);		}	}}/***  COMMAIZE -- output a header field, making a comma-translated list.****	Parameters:**		h -- the header field to output.**		p -- the value to put in it.**		oldstyle -- TRUE if this is an old style header.**		mci -- the connection information.**		e -- the envelope containing the message.****	Returns:**		none.****	Side Effects:**		outputs "p" to file "fp".*/voidcommaize(h, p, oldstyle, mci, e)	register HDR *h;	register char *p;	bool oldstyle;	register MCI *mci;	register ENVELOPE *e;{	register char *obp;	int opos;	int omax;	bool firstone = TRUE;	char obuf[MAXLINE + 3];	/*	**  Output the address list translated by the	**  mailer and with commas.	*/	if (tTd(14, 2))		printf("commaize(%s: %s)\n", h->h_field, p);	obp = obuf;	(void) sprintf(obp, "%s: ", h->h_field);	opos = strlen(h->h_field) + 2;	obp += opos;	omax = mci->mci_mailer->m_linelimit - 2;	if (omax < 0 || omax > 78)		omax = 78;	/*	**  Run through the list of values.	*/	while (*p != '\0')	{		register char *name;		register int c;		char savechar;		int flags;		auto int stat;		/*		**  Find the end of the name.  New style names		**  end with a comma, old style names end with		**  a space character.  However, spaces do not		**  necessarily delimit an old-style name -- at		**  signs mean keep going.		*/		/* find end of name */		while ((isascii(*p) && isspace(*p)) || *p == ',')			p++;		name = p;		for (;;)		{			auto char *oldp;			char pvpbuf[PSBUFSIZE];			(void) prescan(p, oldstyle ? ' ' : ',', pvpbuf,				       sizeof pvpbuf, &oldp);			p = oldp;			/* look to see if we have an at sign */			while (*p != '\0' && isascii(*p) && isspace(*p))				p++;			if (*p != '@')			{				p = oldp;				break;			}			p += *p == '@' ? 1 : 2;			while (*p != '\0' && isascii(*p) && isspace(*p))				p++;		}		/* at the end of one complete name */		/* strip off trailing white space */		while (p >= name &&		       ((isascii(*p) && isspace(*p)) || *p == ',' || *p == '\0'))			p--;		if (++p == name)			continue;		savechar = *p;		*p = '\0';		/* translate the name to be relative */		flags = RF_HEADERADDR|RF_ADDDOMAIN;		if (bitset(H_FROM, h->h_flags))			flags |= RF_SENDERADDR;		stat = EX_OK;		name = remotename(name, mci->mci_mailer, flags, &stat, e);		if (*name == '\0')		{			*p = savechar;			continue;		}		/* output the name with nice formatting */		opos += strlen(name);		if (!firstone)			opos += 2;		if (opos > omax && !firstone)		{			(void) strcpy(obp, ",\n");			putline(obuf, mci);			obp = obuf;			(void) strcpy(obp, "        ");			opos = strlen(obp);			obp += opos;			opos += strlen(name);		}		else if (!firstone)		{			(void) strcpy(obp, ", ");			obp += 2;		}		while ((c = *name++) != '\0' && obp < &obuf[MAXLINE])			*obp++ = c;		firstone = FALSE;		*p = savechar;	}	(void) strcpy(obp, "\n");	putline(obuf, mci);}/***  COPYHEADER -- copy header list****	This routine is the equivalent of newstr for header lists****	Parameters:**		header -- list of header structures to copy.****	Returns:**		a copy of 'header'.****	Side Effects:**		none.*/HDR *copyheader(header)	register HDR *header;{	register HDR *newhdr;	HDR *ret;	register HDR **tail = &ret;	while (header != NULL)	{		newhdr = (HDR *) xalloc(sizeof(HDR));		STRUCTCOPY(*header, *newhdr);		*tail = newhdr;		tail = &newhdr->h_link;		header = header->h_link;	}	*tail = NULL;		return ret;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -