From 718b54c985aa2fe7146df39176796ce4d6580504 Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 18 Aug 2004 23:37:46 +0000 Subject: Fixed bug where an '@' in the quoted name in the From address would break parsing. --- src/pop3.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'src/pop3.c') diff --git a/src/pop3.c b/src/pop3.c index 5d87e9a..0123b5f 100644 --- a/src/pop3.c +++ b/src/pop3.c @@ -93,6 +93,21 @@ static void Chomp(char *p) */ +static char *ChompChar(char *p, char c) +{ + size_t l; + + l=strlen(p); + + while (l && p[l-1]==c) + { + p[--l]=0; + } + + return p; +} + + static char *ChompQuotesWS(char *p) { size_t l; @@ -350,6 +365,7 @@ static void ParseHeader(POP3Message *msg, char *line) }; const char *name; + char *p; int f; int type=HDR_UNKNOWN; @@ -368,16 +384,31 @@ static void ParseHeader(POP3Message *msg, char *line) break; case HDR_FROM: - if (strchr(line,'<')) + if ((p=strchr(line,'<'))) { char *t[3]; - for(f=0;f<3 && t[f-1];f++) - t[f]=strtok(f==0 ? line:NULL,"<>@"); + /* Store up to the opening '<' + */ + t[0]=line; + *p=0; + + /* The uname must start here... + */ + t[1]=++p; + + /* Search for the @ + */ + t[2]=strchr(t[1],'@'); + + if (t[2]) + { + *t[2]++=0; + } msg->from=CopyStr(t[0] ? ChompQuotesWS(t[0]) : "UNKNOWN"); msg->from_uname=CopyStr(t[1] ? t[1] : "UNKNOWN"); - msg->from_domain=CopyStr(t[2] ? t[2] : "UNKNOWN"); + msg->from_domain=CopyStr(t[2] ? ChompChar(t[2],'>'):"UNKNOWN"); } else { -- cgit v1.2.3