From f1dd8ccc0442943325d67077175274356f7959f2 Mon Sep 17 00:00:00 2001 From: Alfons Hoogervorst Date: Tue, 16 Dec 2003 11:12:37 +0000 Subject: [PATCH] * src/procheader.c make sure we discard folding white space --- ChangeLog.claws | 5 +++++ configure.ac | 2 +- src/procheader.c | 43 +++++++++++++++++++++++++++++++++++-------- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/ChangeLog.claws b/ChangeLog.claws index 5377ced8c..2e6c6c589 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,3 +1,8 @@ +2003-12-15 [alfons] 0.9.7claws44 + + * src/procheader.c + make sure we discard folding white space + 2003-12-15 [luke] 0.9.7claws43 * src/textview.c * src/mimeview.c diff --git a/configure.ac b/configure.ac index 52a4c157d..c9ea8585a 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ MINOR_VERSION=9 MICRO_VERSION=7 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=43 +EXTRA_VERSION=44 if test $EXTRA_VERSION -eq 0; then VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws else diff --git a/src/procheader.c b/src/procheader.c index 1adc3ef07..7def36dfd 100644 --- a/src/procheader.c +++ b/src/procheader.c @@ -38,6 +38,7 @@ typedef char *(*getlinefunc)(char *, int, void *); typedef int (*peekcharfunc)(void *); +typedef int (*getcharfunc)(void *); typedef gint (*get_one_field_func)(gchar *, gint, void *, HeaderEntry[]); static gint string_get_one_field(gchar *buf, gint len, char **str, @@ -45,10 +46,14 @@ static gint string_get_one_field(gchar *buf, gint len, char **str, static char *string_getline(char *buf, int len, char **str); static int string_peekchar(char **str); -static int fpeekchar(FILE *fp); +static int string_getchar(char **str); +static int file_peekchar(FILE *fp); +static int file_getchar(FILE *fp); static gint generic_get_one_field(gchar *buf, gint len, void *data, HeaderEntry hentry[], - getlinefunc getline, peekcharfunc peekchar); + getlinefunc getline, + peekcharfunc peekchar, + getcharfunc getchar); static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags, gboolean full, gboolean decrypted); @@ -57,7 +62,8 @@ gint procheader_get_one_field(gchar *buf, gint len, FILE *fp, HeaderEntry hentry[]) { return generic_get_one_field(buf, len, fp, hentry, - (getlinefunc)fgets, (peekcharfunc)fpeekchar); + (getlinefunc)fgets, (peekcharfunc)file_peekchar, + (getcharfunc)file_getchar); } static gint string_get_one_field(gchar *buf, gint len, char **str, @@ -65,7 +71,8 @@ static gint string_get_one_field(gchar *buf, gint len, char **str, { return generic_get_one_field(buf, len, str, hentry, (getlinefunc)string_getline, - (peekcharfunc)string_peekchar); + (peekcharfunc)string_peekchar, + (getcharfunc)string_getchar); } static char *string_getline(char *buf, int len, char **str) @@ -86,14 +93,25 @@ static int string_peekchar(char **str) return **str; } -static int fpeekchar(FILE *fp) +static int string_getchar(char **str) +{ + return *(*str)++; +} + +static int file_peekchar(FILE *fp) { return ungetc(getc(fp), fp); } +static int file_getchar(FILE *fp) +{ + return getc(fp); +} + static gint generic_get_one_field(gchar *buf, gint len, void *data, HeaderEntry *hentry, - getlinefunc getline, peekcharfunc peekchar) + getlinefunc getline, peekcharfunc peekchar, + getcharfunc getchar_) { gint nexthead; gint hnum = 0; @@ -124,25 +142,34 @@ static gint generic_get_one_field(gchar *buf, gint len, void *data, /* remove trailing new line */ strretchomp(buf); +#define UNFOLD_LINE() \ + (!hentry || (hp && hp->unfold)) + /* unfold line */ while (1) { nexthead = peekchar(data); + /* ([*WSP CRLF] 1*WSP) */ if (nexthead == ' ' || nexthead == '\t') { size_t buflen = strlen(buf); - + + /* discard 1*WSP when one header or unfolding was requested */ + if (UNFOLD_LINE()) + getchar_(data); + /* concatenate next line */ if ((len - buflen) > 2) { if (getline(buf + buflen, len - buflen, data) == NULL) break; /* trim trailing \n if requesting one header or * unfolding was requested */ - if (!hentry || (hp && hp->unfold)) + if (UNFOLD_LINE()) strretchomp(buf); } else break; } else break; } +#undef UNFOLD_LINE return hnum; } -- 2.25.1