/*
* Copyright (C) 1996-8 Michael R. Elkins <me@cs.hmc.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "mutt.h"
#include "mutt_regex.h"
#include "mailbox.h"
#include "mime.h"
#include "rfc2047.h"
#ifdef _PGPPATH
#include "pgp.h"
#endif /* _PGPPATH */
#include <string.h>
#include <ctype.h>
#include <sys/stat.h>
#include <stdlib.h>
/* Reads an arbitrarily long header field, and looks ahead for continuation
* lines. ``line'' must point to a dynamically allocated string; it is
* increased if more space is required to fit the whole line.
*/
static char *read_rfc822_line (FILE *f, char *line, size_t *linelen)
{
char *buf = line;
char ch;
size_t offset = 0;
FOREVER
{
if (fgets (buf, *linelen - offset, f) == NULL || /* end of file or */
(ISSPACE (*line) && !offset)) /* end of headers */
{
*line = 0;
return (line);
}
buf += strlen (buf) - 1;
if (*buf == '\n')
{
/* we did get a full line. remove trailing space */
while (ISSPACE (*buf))
*buf-- = 0; /* we cannot come beyond line's beginning because
* it begins with a non-space */
/* check to see if the next line is a continuation line */
if ((ch = fgetc (f)) != ' ' && ch != '\t')
{
ungetc (ch, f);
return (line); /* next line is a separate header field or EOH */
}
/* eat tabs and spaces from the beginning of the continuation line */
while ((ch = fgetc (f)) == ' ' || ch == '\t')
;
ungetc (ch, f);
*++buf = ' '; /* string is still terminated because we removed
at least one whitespace char above */
}
buf++;
offset = buf - line;
if (*linelen < offset + STRING)
{
/* grow the buffer */
*linelen += STRING;
safe_realloc ((void **) &line, *linelen);
buf = line + offset;
}
}
/* not reached */
}
static LIST *mutt_parse_references (char *s)
{
LIST *t, *lst = NULL;
while ((s = strtok (s, " \t")) != NULL)
{
/*
* some mail clients add other garbage be