/*
* Copyright (C) 1996-2000 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*/
#include "mutt.h"
#include "mutt_regex.h"
#include "mailbox.h"
#include "mime.h"
#include "rfc2047.h"
#include "rfc2231.h"
#ifdef HAVE_PGP
#include "pgp.h"
#endif /* HAVE_PGP */
#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 */