aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1996-09-22 15:31:58 +0000
committerEric S. Raymond <esr@thyrsus.com>1996-09-22 15:31:58 +0000
commite3886da199b060383ce1cc2a5e4b4da28ad10421 (patch)
treeb1186295d52734a135de0e4f43911964a0cc3f35
parent49e46d92e5a5c7adeb5aebdf923aa78639b4ca61 (diff)
downloadfetchmail-e3886da199b060383ce1cc2a5e4b4da28ad10421.tar.gz
fetchmail-e3886da199b060383ce1cc2a5e4b4da28ad10421.tar.bz2
fetchmail-e3886da199b060383ce1cc2a5e4b4da28ad10421.zip
Rob Funk's improved header parsing.
svn path=/trunk/; revision=102
-rw-r--r--driver.c65
1 files changed, 44 insertions, 21 deletions
diff --git a/driver.c b/driver.c
index a2bb8239..a707d1da 100644
--- a/driver.c
+++ b/driver.c
@@ -446,37 +446,52 @@ char *hdr;
if (*hp == '\n')
return(NULL);
else if (*hp == ':')
+ {
state = 1;
+ tp = address;
+ }
break;
- case 1: /* we've seen the colon, we're looking for addresses */
- if (*hp == '\n')
- return(NULL);
- else if (*hp == '"')
- state = 2;
- else if (*hp == '(')
+ case 1: /* we've seen the colon, now grab the address */
+ if ((*hp == '\n') || (*hp == ',')) /* end of address list */
+ {
+ *tp++ = '\0';
+ return(address);
+ }
+ else if (*hp == '"') /* quoted string */
+ {
+ state = 2;
+ *tp++ = *hp;
+ }
+ else if (*hp == '(') /* address comment -- ignore */
state = 3;
- else if (*hp == '<')
+ else if (*hp == '<') /* begin <address> */
{
state = 4;
tp = address;
}
- else if (isalnum(*hp))
+ else if (isspace(*hp)) /* ignore space */
+ state = 1;
+ else /* just take it */
{
- state = 5;
- tp = address;
+ state = 1;
*tp++ = *hp;
}
break;
- case 2: /* we're in a quoted human name, copy and ignore */
+ case 2: /* we're in a quoted string, copy verbatim */
if (*hp == '\n')
return(NULL);
+ if (*hp != '"')
+ *tp++ = *hp;
else if (*hp == '"')
+ {
+ *tp++ = *hp;
state = 1;
+ }
break;
- case 3: /* we're in a parenthesized human name, copy and ignore */
+ case 3: /* we're in a parenthesized comment, ignore */
if (*hp == '\n')
return(NULL);
else if (*hp == ')')
@@ -484,25 +499,33 @@ char *hdr;
break;
case 4: /* possible <>-enclosed address */
- if (*hp == '>')
+ if (*hp == '>') /* end of address */
{
*tp++ = '\0';
state = 1;
return(address);
}
- else
+ else if (*hp == '<') /* nested <> */
+ tp = address;
+ else if (*hp == '"') /* quoted address */
+ {
+ *tp++ = *hp;
+ state = 5;
+ }
+ else /* just copy address */
*tp++ = *hp;
break;
- case 5: /* address not <>-enclosed, terminate on any whitespace */
- if (isspace(*hp))
+ case 5: /* we're in a quoted address, copy verbatim */
+ if (*hp == '\n') /* mismatched quotes */
+ return(NULL);
+ if (*hp != '"') /* just copy it if it isn't a quote */
+ *tp++ = *hp;
+ else if (*hp == '"') /* end of quoted string */
{
- *tp++ = '\0';
- state = 1;
- return(address); /* prevents normal hp++ */
+ *tp++ = *hp;
+ state = 4;
}
- else
- *tp++ = *hp;
break;
}
}