diff options
author | Ian C <ianc@noddybox.co.uk> | 2004-01-26 02:01:49 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2004-01-26 02:01:49 +0000 |
commit | c378e8f900d85d59a8a616bf0b8b14e426d898e1 (patch) | |
tree | 0dbf84eab213d73e58b8041c7d0b2057ba5bcb0f /src/pop3.c | |
parent | f3a485b283141787667ea98b8e0a8687f07d9062 (diff) |
Added allow_to in domain; Added include; Update docs; Fixed folding header lines
Diffstat (limited to 'src/pop3.c')
-rw-r--r-- | src/pop3.c | 94 |
1 files changed, 78 insertions, 16 deletions
@@ -57,6 +57,7 @@ static const char message_id[]=KBS_MSG_H; #define HDR_FROM 1 #define HDR_TO 2 #define HDR_CONTENT_TYPE 3 +#define HDR_DEBUG 4 /* ---------------------------------------- TYPES */ @@ -71,6 +72,7 @@ static int connected=FALSE; /* ---------------------------------------- PRIVATE FUNCTIONS */ +/* static void Chomp(char *p) { size_t l; @@ -87,6 +89,7 @@ static void Chomp(char *p) p[--l]=0; } } +*/ static char *ChompQuotesWS(char *p) @@ -182,13 +185,14 @@ static int Send(const char *cmd, ...) } +static char gc_buff[BLOCKSIZE]; +static ssize_t gc_len=0; +static int gc_ptr=0; + + static int GetChar(void) { - static char buff[BLOCKSIZE]; - static ssize_t len=0; - static int ptr=0; - - if (len==0 || ptr==len) + if (gc_len==0 || gc_ptr==gc_len) { struct timeval tv; fd_set set; @@ -205,13 +209,20 @@ static int GetChar(void) if (!FD_ISSET(sock,&set)) return -1; - if ((len=read(sock,buff,sizeof buff))<1) + if ((gc_len=read(sock,gc_buff,sizeof gc_buff))<1) return -1; - ptr=0; + gc_ptr=0; } - return buff[ptr++]; + return gc_buff[gc_ptr++]; +} + + +static void UnGetChar(int c) +{ + if (gc_ptr) + gc_buff[--gc_ptr]=c; } @@ -225,7 +236,8 @@ static int GetLine(DString t) while(!done && (ch=GetChar())!=-1) { - DSAddChar(t,ch); + if (ch!='\015' && ch!='\012') + DSAddChar(t,ch); if (last=='\015' && ch=='\012') done=TRUE; @@ -236,8 +248,6 @@ static int GetLine(DString t) if (ch==-1) return FALSE; - Chomp(t->text); - return TRUE; } @@ -263,14 +273,59 @@ static int GetResponse(DString ret) } +static int IsHeader(const DString line) +{ + const char *p; + + p=line->text; + + while(*p && !isspace(*p)) + { + if (*p==':') + return TRUE; + + p++; + } + + return FALSE; +} + + static int GetMultiLine(DString ret) { - int flag; + int done=FALSE; + int flag=TRUE; - if (GetLine(ret)) - flag=TRUE; - else - flag=FALSE; + while (!done) + { + if (GetLine(ret)) + { + if (IsHeader(ret)) + { + int ch; + + if ((ch=GetChar())!=-1) + { + if (ch!=' ' && ch!='\t') + done=TRUE; + + UnGetChar(ch); + } + else + { + flag=FALSE; + done=TRUE; + } + } + else + done=TRUE; + } + else + { + flag=FALSE; + done=TRUE; + } + } return flag; } @@ -289,15 +344,18 @@ static void ParseHeader(POP3Message *msg, char *line) {"To: ", HDR_TO}, {"Content-type: ", HDR_CONTENT_TYPE}, {"Content-Type: ", HDR_CONTENT_TYPE}, + /* {"Received: ", HDR_DEBUG}, */ {NULL, HDR_UNKNOWN} }; + const char *name; int f; int type=HDR_UNKNOWN; for(f=0;type==HDR_UNKNOWN && field[f].text;f++) if (strncmp(field[f].text,line,strlen(field[f].text))==0) { + name=field[f].text; type=field[f].type; line+=strlen(field[f].text); } @@ -341,6 +399,10 @@ static void ParseHeader(POP3Message *msg, char *line) msg->content_type=CopyStr(line); break; + case HDR_DEBUG: + printf("%s = '%s'\n",name,line); + break; + default: break; } |