/***********************************************************************
* *
* This software is part of the BSD package *
*Copyright (c) 1978-2011 The Regents of the University of California an*
* *
* 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 *
* materials provided with the distribution. *
* *
* 3. Neither the name of The Regents of the University of California*
* names of its contributors may be used to endorse or *
* promote products derived from this software without *
* specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. *
* *
* 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 *
* distribution. *
* 3. 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. *
* *
* 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. *
* *
* Kurt Shoens (UCB) *
* gsf *
* *
***********************************************************************/
#pragma prototyped
/*
* Mail -- a mail program
*
* Routines for processing and detecting headlines.
*/
#include "mailx.h"
"newsgroups", GNEWS,
"article-id", GNEWS,
"sender", GNEWS,
"apparently-to", GTO,
"original-to", GTO,
"to", GTO,
"cc", GCC,
"bcc", GBCC,
"subject", GSUB,
"subj", GSUB,
"status", GSTATUS,
"references", GREFERENCES,
"message-id", GMESSAGEID,
"received", 0,
"return-path", 0,
"importance", 0,
"in-reply-to", 0,
"priority", 0,
"x-", 0,
};
/*
* Data setup for mimehead().
*/
struct content {
const char* name;
int index;
};
"boundary", CONTENT_boundary,
"disposition", CONTENT_disposition,
"filename", CONTENT_filename,
"name", CONTENT_name,
"transfer-encoding", CONTENT_encoding,
"type", CONTENT_type,
};
/*
* Called by mimehead() to set content data values.
*/
static int
{
char* s;
char* e;
case CONTENT_boundary:
break;
}
}
break;
case CONTENT_disposition:
/*FALLTHROUGH*/
case CONTENT_type:
else if (!*ap->type || !strchr(ap->type, '/') || cp->index == CONTENT_type && (ap->flags & PART_disposition)) {
if (!(e = strchr(s, '\n')))
e = s + strlen(s);
{
}
else
}
break;
case CONTENT_encoding:
break;
case CONTENT_name:
break;
/*FALLTHROUGH*/
case CONTENT_filename:
break;
}
return 0;
}
/*
* Open a mime handle and return non-0 if ok to mime.
* op==0 for header parsing, op==1 for viewing.
*/
int
{
return 0;
return 0;
}
}
}
return 1;
}
/*
* Set up a message for header parsing.
*/
int
headset(register struct parse* pp, struct msg* mp, FILE* fp, struct header* hp, Dt_t** ignore, unsigned long flags)
{
int r;
}
else
}
r = 1;
register char* s;
register char* t;
int c;
/*
* Pun on GMETOO -- if from me then don't ignore To:
*/
c = *t;
*t = 0;
if (streq(s, state.var.user) || (np = dictsearch(&state.aliases, s, LOOKUP)) && streq(np->name, state.var.user))
*t = c;
}
do {
}
return r;
}
/*
* Generate the message status field.
*/
static void
{
register char* s;
*s++ = ' ';
*s++ = 'X';
*s++ = 'R';
*s++ = 'O';
if (*(s - 1) == ' ')
s--;
*s++ = '\n';
*s = 0;
}
/*
* Attach part ap to the current message.
*/
static void
{
register int c;
register int p;
register char* s;
register char* t;
else {
for (p = 0; c = *s++; p = c) {
if (c == '/' || c == '\\') {
c = 0;
}
else {
if (isspace(c) || iscntrl(c) || !isprint(c) || c == '#' || c == '$' || c == '&' || c == '*' || c == '(' || c == ')' || c == '"' || c == '\'' || c == '`' || c == '<' || c == '>' || c == '?' || c == '[' || c == ']' || c == '{' || c == '}')
c = '_';
if (c != '_' && c != '-' || p != '_' && p != '-')
*t++ = c;
}
}
*t = 0;
}
note(DEBUG, "part %d offset=%ld size=%ld lines=%ld flags=0x%08x type=%s name=%s", ap->count, (long)ap->offset, (long)ap->size, (long)ap->lines, ap->flags, ap->type, ap->name);
else
}
/*
* Read the next header line.
*/
static char*
{
register char* s;
register char* e;
register char* t;
register int c;
register int n;
return 0;
}
break;
}
t = s;
if (s < e) {
*(s - 1) = ' ';
*s++ = ' ';
}
n = 1;
n++;
if (s < e)
*s++ = c;
if (c == '\n')
break;
}
}
}
*s = 0;
}
/*
* Get mime multipart content.
*/
static void
{
register char* s;
unsigned long count;
int n;
int header;
return;
ap = 0;
header = 0;
if (state.part.in.boundary && (pp->length == (state.part.in.boundary->size + 3) || pp->length == (state.part.in.boundary->size + 5)) && s[0] == '-' && s[1] == '-' && !strncmp(s + 2, state.part.in.boundary->data, state.part.in.boundary->size)) {
if (ap) {
}
break;
}
header = 1;
header = 0;
if (n != EOF)
}
}
}
else if (header) {
header = 1;
}
else
}
}
else if (ap) {
}
}
if (ap) {
if (header)
else
}
}
/*
* Get the next message header.
*/
int
{
register char* s;
register char* t;
register int n;
int i;
int separator;
/*
* A blank line separates the headers from the body.
*/
if ((n = *s) == '\n' || n == '\r' && (n = *(s + 1)) == '\n') {
/*
* If the next batch of lines up to
* a blank line look like headers then
* treat them as such rather than
* message body. This compensates
* for those mailers that botch the
* message manual of style.
*/
separator = 1;
i = 0;
for (;;) {
goto done;
if ((n = *s) == '\n' || n == '\r' && (n = *(s + 1)) == '\n') {
if (!separator)
break;
}
else if (isspace(n)) {
if (!i)
goto done;
separator = 0;
}
else if (isalpha(n) || n == '>') {
t = s;
do {
if (!*s || isspace(*s))
goto done;
} while (*s++ != ':');
if (!i) {
n = s - t - 1;
if (n > 2 && (t[0] == 'X' || t[0] == 'x') && t[1] == '-')
i = 1;
else {
i = -1;
do {
if (++i >= elementsof(fields))
goto done;
}
}
}
separator = 0;
}
else if (isprint(n)) {
while (*++s == n);
if (*s != '\n' && (*s != '\r' || *(s + 1) != '\n'))
goto done;
if (separator)
}
else
goto done;
}
continue;
done:
*s++ = '\n';
*s = 0;
}
break;
}
if (isspace(n))
continue;
t = s;
while (*++t == n);
if (*t == '\n' || *t == '\r' && *(t + 1) == '\n') {
if (n == '-' && (t - s) > 2) {
/*
* Edit rule treated like a blank line.
*/
break;
}
/*
* Treat rules as ignored header lines.
*/
continue;
}
}
if ((pp->flags & GMIME) && mimehead(state.part.mime, (void*)contents, elementsof(contents), sizeof(*contents), s))
else {
i = 0;
while (*s == '>') {
s++;
i = 1;
}
for (n = 0; *s && !isspace(*s) && *s != ':'; n = *s++) {
if (isupper(*s)) {
if (isalnum(n))
*s = tolower(*s);
}
else if (islower(*s)) {
if (!isalnum(n))
*s = toupper(*s);
}
}
continue;
*s = 0;
if (!pp->ignore || !ignored(pp->ignore, pp->name) || (pp->flags & GMETOO) && streq(pp->name, "To") && ((pp->flags &= ~GMETOO), 1)) {
while (isspace(*++s));
if (upper(*s) == *t) {
while (lower(*++s) == *++t);
if (!*s && *t == ':') {
}
break;
}
}
}
}
}
return 1;
}
}
}
return 1;
}
}
return 0;
}
/*
* Fetch the field info by name from the passed message.
*/
static char*
{
register char* r = 0;
register int n = 0;
register int i;
register int u;
u = -u;
else if (u < 0) {
continue;
}
if (i > n) {
n = i;
}
else
}
}
}
return r;
}
/*
* Fetch the field info by type from the passed message.
*/
static char*
{
register char* s;
register char* e;
register char* t;
int i;
break;
}
return 0;
}
for (i = 0; i < elementsof(fields); i++)
*t = 0;
for (e = s, i = 0; *e; e++)
if (isspace(*e))
{
if (i || *e != ' ')
{
t = e;
while (i = *e++)
{
if (isspace(i))
for (i = ' '; isspace(*e); e++);
*t++ = i;
}
*t = 0;
break;
}
i = 1;
}
else
i = 0;
return s;
}
#if 0
#else
#endif
return 0;
namebuf[0] = 0;
for (;;) {
for (; *s == ' ' || *s == '\t'; s++) ;
for (t = &namebuf[strlen(namebuf)]; *s && *s != ' ' && *s != '\t' && t < namebuf + sizeof(namebuf) - 1;)
*t++ = *s++;
*t = 0;
break;
break;
break;
while (s = strchr(s, 'r')) {
if (!(s = strchr(s, 'f')))
break;
break;
if (!(s = strchr(s, ' ')))
break;
s++;
if (first) {
first = 0;
}
t++;
s = strncopy(t, s, e - t);
strncopy(s, "!", e - s);
}
goto again;
}
s++;
}
}
}
}
/*
* If name!=0 then it contains the header name,
* otherwise grab by type.
*/
char*
{
register char* s;
if (!name)
return s;
}
/*
* Collect a liberal (space, tab delimited) word into b.
* Update p to point to the next word.
*/
char*
wordnext(char** p, char* b)
{
register char* s;
register char* t;
register int c;
if (!(s = *p) || !*s)
return 0;
while (isspace(*s))
s++;
t = b;
while ((c = *s++) && !isspace(c)) {
*t++ = c;
if (c == '"') {
do {
if (!(c = *s++)) {
s--;
break;
}
} while ((*t++ = c) != '"');
}
}
if (!c)
s--;
else
while (isspace(*s))
s++;
*p = s;
*t = 0;
return *b ? b : (char*)0;
}
/*
* Split a headline into its useful components.
* Copy the line into dynamic string space, then set
* pointers into the copied line in the passed headline
* structure. Actually, it scans.
*/
void
{
register char* s;
register char* t;
register char* e;
t = pbuf;
e = t + psize;
}
if (mp) {
}
}
else {
if (*(s = line)) {
if (s[0] == 't' && s[1] == 't' && s[2] == 'y') {
}
if (*(s = line))
}
}
}
}
/*
* See if the passed line buffer is a mail header.
* Return true if yes. Note the extreme pains to
* accomodate all funny formats.
*/
int
{
register char* cp;
return 1;
}
*cp++ != ' ')
return 0;
return 0;
}
return 1;
}