summaryrefslogtreecommitdiff
path: root/imap/src/c-client
diff options
context:
space:
mode:
authorEduardo Chappa <chappa@washington.edu>2013-11-02 02:51:18 -0600
committerEduardo Chappa <chappa@washington.edu>2013-11-02 02:51:18 -0600
commit7fe712882b909931088a318c08041b0e7974a000 (patch)
tree2770f9b084e2efc7fc55e96e9bf4352cf2ff33a3 /imap/src/c-client
parentbdfc834badee92ceeb2befe02f1d065ced5b9ddf (diff)
downloadalpine-7fe712882b909931088a318c08041b0e7974a000.tar.xz
* Update to version 2.19.1
* Upgrade UW-IMAP to Panda IMAP from https://github.com/jonabbey/panda-imap. * Replace tabs by spaces in From and Subject fields to control for size in screen of these fields. Change only in index screen display.
Diffstat (limited to 'imap/src/c-client')
-rw-r--r--imap/src/c-client/auth_md5.c48
-rw-r--r--imap/src/c-client/imap4r1.c153
-rw-r--r--imap/src/c-client/mail.c98
-rw-r--r--imap/src/c-client/mail.h33
-rw-r--r--imap/src/c-client/misc.c53
-rw-r--r--imap/src/c-client/misc.h29
-rw-r--r--imap/src/c-client/nntp.c41
-rw-r--r--imap/src/c-client/pop3.c38
-rw-r--r--imap/src/c-client/rfc822.c69
-rw-r--r--imap/src/c-client/smanager.c37
-rw-r--r--imap/src/c-client/smtp.c57
-rw-r--r--imap/src/c-client/utf8.c77
12 files changed, 414 insertions, 319 deletions
diff --git a/imap/src/c-client/auth_md5.c b/imap/src/c-client/auth_md5.c
index 29ab947d..f32ebc88 100644
--- a/imap/src/c-client/auth_md5.c
+++ b/imap/src/c-client/auth_md5.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2007 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2011 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: CRAM-MD5 authenticator
*
* Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 21 October 1998
- * Last Edited: 30 January 2007
+ * Last Edited: 8 April 2011
+ *
+ * Previous versions of this file were
+ *
+ * Copyright 1988-2007 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
*/
/* MD5 context */
@@ -49,7 +46,8 @@ long auth_md5_client (authchallenge_t challenger,authrespond_t responder,
char *auth_md5_server (authresponse_t responder,int argc,char *argv[]);
char *auth_md5_pwd (char *user);
char *apop_login (char *chal,char *user,char *md5,int argc,char *argv[]);
-char *hmac_md5 (char *text,unsigned long tl,char *key,unsigned long kl);
+char *hmac_md5 (char *hshbuf, char *text,unsigned long tl,char *key,
+ unsigned long kl);
void md5_init (MD5CONTEXT *ctx);
void md5_update (MD5CONTEXT *ctx,unsigned char *data,unsigned long len);
void md5_final (unsigned char *digest,MD5CONTEXT *ctx);
@@ -97,7 +95,7 @@ long auth_md5_client (authchallenge_t challenger,authrespond_t responder,
char *service,NETMBX *mb,void *stream,
unsigned long *trial,char *user)
{
- char pwd[MAILTMPLEN];
+ char pwd[MAILTMPLEN],hshbuf[2*MD5DIGLEN + 1];
void *challenge;
unsigned long clen;
long ret = NIL;
@@ -112,7 +110,7 @@ long auth_md5_client (authchallenge_t challenger,authrespond_t responder,
ret = LONGT; /* will get a BAD response back */
}
else { /* got password, build response */
- sprintf (pwd,"%.65s %.33s",user,hmac_md5 (challenge,clen,
+ sprintf (pwd,"%.65s %.33s",user,hmac_md5 (hshbuf,challenge,clen,
pwd,strlen (pwd)));
fs_give ((void **) &challenge);
/* send credentials, allow retry if OK */
@@ -146,7 +144,7 @@ static int md5try = MAXLOGINTRIALS;
char *auth_md5_server (authresponse_t responder,int argc,char *argv[])
{
char *ret = NIL;
- char *p,*u,*user,*authuser,*hash,chal[MAILTMPLEN];
+ char *p,*u,*user,*authuser,*hash,chal[MAILTMPLEN],hshbuf[2*MD5DIGLEN + 1];
unsigned long cl,pl;
/* generate challenge */
sprintf (chal,"<%lu.%lu@%s>",(unsigned long) getpid (),
@@ -161,7 +159,8 @@ char *auth_md5_server (authresponse_t responder,int argc,char *argv[])
/* get password */
if (p = auth_md5_pwd ((authuser && *authuser) ? authuser : user)) {
pl = strlen (p);
- u = (md5try && !strcmp (hash,hmac_md5 (chal,cl,p,pl))) ? user : NIL;
+ u = (md5try && !strcmp (hash,hmac_md5 (hshbuf,chal,cl,p,pl))) ?
+ user : NIL;
memset (p,0,pl); /* erase sensitive information */
fs_give ((void **) &p); /* flush erased password */
/* now log in for real */
@@ -265,17 +264,18 @@ char *apop_login (char *chal,char *user,char *md5,int argc,char *argv[])
/*
* RFC 2104 HMAC hashing
- * Accepts: text to hash
+ * Accepts: destination buffer of size 2*MD5DIGLEN + 1
+ * text to hash
* text length
* key
* key length
* Returns: hash as text, always
*/
-char *hmac_md5 (char *text,unsigned long tl,char *key,unsigned long kl)
+char *hmac_md5 (char *hshbuf, char *text,unsigned long tl,char *key,
+ unsigned long kl)
{
int i,j;
- static char hshbuf[2*MD5DIGLEN + 1];
char *s;
MD5CONTEXT ctx;
char *hex = "0123456789abcdef";
diff --git a/imap/src/c-client/imap4r1.c b/imap/src/c-client/imap4r1.c
index 48017cab..9c72e642 100644
--- a/imap/src/c-client/imap4r1.c
+++ b/imap/src/c-client/imap4r1.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2008 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2011 Mark Crispin
* ========================================================================
*/
@@ -15,13 +7,19 @@
* Program: Interactive Message Access Protocol 4rev1 (IMAP4R1) routines
*
* Author: Mark Crispin
- * UW Technology
- * University of Washington
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 15 June 1988
- * Last Edited: 8 May 2008
+ * Last Edited: 3 October 2011
+ *
+ * Previous versions of this file were
+ *
+ * Copyright 1988-2008 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* This original version of this file is
* Copyright 1988 Stanford University
@@ -362,7 +360,7 @@ void *imap_parameters (long function,void *value)
if (((IMAPLOCAL *) ((MAILSTREAM *) value)->local)->cap.namespace &&
!((IMAPLOCAL *) ((MAILSTREAM *) value)->local)->namespace)
imap_send (((MAILSTREAM *) value),"NAMESPACE",NIL);
- value = (void *) &((IMAPLOCAL *) ((MAILSTREAM *) value)->local)->namespace;
+ value = (void *) ((IMAPLOCAL *) ((MAILSTREAM *) value)->local)->namespace;
break;
case GET_THREADERS:
value = (void *)
@@ -493,7 +491,7 @@ void imap_list (MAILSTREAM *stream,char *ref,char *pat)
void imap_lsub (MAILSTREAM *stream,char *ref,char *pat)
{
void *sdb = NIL;
- char *s,mbx[MAILTMPLEN];
+ char *s,mbx[MAILTMPLEN],tmp[MAILTMPLEN];
/* do it on the server */
imap_list_work (stream,"LSUB",ref,pat,NIL);
if (*pat == '{') { /* if remote pattern, must be IMAP */
@@ -506,9 +504,10 @@ void imap_lsub (MAILSTREAM *stream,char *ref,char *pat)
if (ref && *ref) sprintf (mbx,"%s%s",ref,pat);
else strcpy (mbx,pat);
- if (s = sm_read (&sdb)) do if (imap_valid (s) && pmatch (s,mbx))
+ if (s = sm_read (tmp,&sdb)) do if (imap_valid (s) && pmatch (s,mbx))
mm_lsub (stream,NIL,s,NIL);
- while (s = sm_read (&sdb)); /* until no more subscriptions */
+ /* until no more subscriptions */
+ while (s = sm_read (tmp,&sdb));
}
/* IMAP find list of mailboxes
@@ -965,7 +964,7 @@ MAILSTREAM *imap_open (MAILSTREAM *stream)
if (LOCAL->tls1) strcat (tmp,"/tls1");
if (LOCAL->tls1_1) strcat (tmp,"/tls1_1");
if (LOCAL->tls1_2) strcat (tmp,"/tls1_2");
- if (LOCAL->dtls1) strcat (tmp,"/dtls");
+ if (LOCAL->dtls1) strcat (tmp,"/dtls1");
if (LOCAL->tlssslv23) strcat (tmp,"/tls-sslv23");
if (LOCAL->notlsflag) strcat (tmp,"/notls");
if (LOCAL->sslflag) strcat (tmp,"/ssl");
@@ -3715,8 +3714,7 @@ void imap_parse_unsolicited (MAILSTREAM *stream,IMAPPARSEDREPLY *reply)
}
/* get message data type, canonicalize upper */
s = ucase (strtok_r (reply->text," ",&r));
- /* and locate the text after it */
- t = strtok_r (NIL,"\n",&r);
+ t = strtok_r (NIL,"\n",&r); /* and locate the text after it */
/* now take the action */
/* change in size of mailbox */
if (!strcmp (s,"EXISTS") && (msgno >= stream->nmsgs))
@@ -3731,7 +3729,7 @@ void imap_parse_unsolicited (MAILSTREAM *stream,IMAPPARSEDREPLY *reply)
mail_expunged (stream,msgno);
}
- else if ((!strcmp (s,"FETCH") || !strcmp (s,"STORE")) &&
+ else if (t && (!strcmp (s,"FETCH") || !strcmp (s,"STORE")) &&
msgno && (msgno <= stream->nmsgs)) {
char *prop;
GETS_DATA md;
@@ -3742,8 +3740,7 @@ void imap_parse_unsolicited (MAILSTREAM *stream,IMAPPARSEDREPLY *reply)
(imapenvelope_t) mail_parameters (stream,GET_IMAPENVELOPE,NIL);
++t; /* skip past open parenthesis */
/* parse Lisp-form property list */
- while (prop = (strtok_r (t," )",&r))) {
- t = strtok_r (NIL,"\n",&r);
+ while ((prop = (strtok_r (t," )",&r))) && (t = strtok_r (NIL,"\n",&r))) {
INIT_GETS (md,stream,elt->msgno,NIL,0,0);
e = NIL; /* not pointing at any envelope yet */
/* canonicalize property, parse it */
@@ -3892,6 +3889,11 @@ void imap_parse_unsolicited (MAILSTREAM *stream,IMAPPARSEDREPLY *reply)
}
if (e && *e) env = *e; /* note envelope if we got one */
}
+ if (prop) {
+ sprintf (LOCAL->tmp,"Missing data for property: %.80s",prop);
+ mm_notify (stream,LOCAL->tmp,WARN);
+ stream->unhealthy = T;
+ }
/* do callback if requested */
if (ie && env) (*ie) (stream,msgno,env);
}
@@ -4278,17 +4280,7 @@ void imap_parse_response (MAILSTREAM *stream,char *text,long errflg,long ntfy)
if (s = strchr (strncpy (t = LOCAL->tmp,s,i),' ')) *s++ = '\0';
if (s) { /* have argument? */
ntfy = NIL; /* suppress mm_notify if normal SELECT data */
- if (!compare_cstring (t,"UIDVALIDITY") &&
- ((j = strtoul (s,NIL,10)) != stream->uid_validity)) {
- mailcache_t mc = (mailcache_t) mail_parameters (NIL,GET_CACHE,NIL);
- stream->uid_validity = j;
- /* purge any UIDs in cache */
- for (j = 1; j <= stream->nmsgs; j++)
- if (elt = (MESSAGECACHE *) (*mc) (stream,j,CH_ELT))
- elt->private.uid = 0;
- }
- else if (!compare_cstring (t,"UIDNEXT"))
- stream->uid_last = strtoul (s,NIL,10) - 1;
+ if (!compare_cstring (t,"CAPABILITY")) imap_parse_capabilities(stream,s);
else if (!compare_cstring (t,"PERMANENTFLAGS") && (*s == '(') &&
(t[i-1] == ')')) {
t[i-1] = '\0'; /* tie off flags */
@@ -4312,8 +4304,19 @@ void imap_parse_response (MAILSTREAM *stream,char *text,long errflg,long ntfy)
while (s = strtok_r (NIL," ",&r));
}
- else if (!compare_cstring (t,"CAPABILITY"))
- imap_parse_capabilities (stream,s);
+ else if (!compare_cstring (t,"UIDVALIDITY") && (j = strtoul (s,NIL,10))){
+ /* do this in separate if because of ntfy */
+ if (j != stream->uid_validity) {
+ mailcache_t mc = (mailcache_t) mail_parameters (NIL,GET_CACHE,NIL);
+ stream->uid_validity = j;
+ /* purge any UIDs in cache */
+ for (j = 1; j <= stream->nmsgs; j++)
+ if (elt = (MESSAGECACHE *) (*mc) (stream,j,CH_ELT))
+ elt->private.uid = 0;
+ }
+ }
+ else if (!compare_cstring (t,"UIDNEXT"))
+ stream->uid_last = strtoul (s,NIL,10) - 1;
else if ((j = LEVELUIDPLUS (stream) && LOCAL->appendmailbox) &&
!compare_cstring (t,"COPYUID") &&
(cu = (copyuid_t) mail_parameters (NIL,GET_COPYUID,NIL)) &&
@@ -4574,9 +4577,10 @@ void imap_parse_envelope (MAILSTREAM *stream,ENVELOPE **env,
unsigned char **txtptr,IMAPPARSEDREPLY *reply)
{
ENVELOPE *oenv = *env;
- char c = *((*txtptr)++); /* grab first character */
+ char c = **txtptr; /* grab first character */
/* ignore leading spaces */
- while (c == ' ') c = *((*txtptr)++);
+ while (c == ' ') c = *++*txtptr;
+ if (c) ++*txtptr; /* skip past first character */
switch (c) { /* dispatch on first character */
case '(': /* if envelope S-expression */
*env = mail_newenvelope (); /* parse the new envelope */
@@ -4639,7 +4643,7 @@ ADDRESS *imap_parse_adrlist (MAILSTREAM *stream,unsigned char **txtptr,
char c = **txtptr; /* sniff at first character */
/* ignore leading spaces */
while (c == ' ') c = *++*txtptr;
- ++*txtptr; /* skip past open paren */
+ if (c) ++*txtptr; /* skip past open paren */
switch (c) {
case '(': /* if envelope S-expression */
adr = imap_parse_address (stream,txtptr,reply);
@@ -4786,11 +4790,11 @@ void imap_parse_flags (MAILSTREAM *stream,MESSAGECACHE *elt,
elt->user_flags = NIL; /* zap old flag values */
elt->seen = elt->deleted = elt->flagged = elt->answered = elt->draft =
elt->recent = NIL;
- while (c != ')') { /* parse list of flags */
+ do { /* parse list of flags */
/* point at a flag */
while (*(flag = ++*txtptr) == ' ');
/* scan for end of flag */
- while (**txtptr != ' ' && **txtptr != ')') ++*txtptr;
+ while (**txtptr && (**txtptr != ' ') && (**txtptr != ')')) ++*txtptr;
c = **txtptr; /* save delimiter */
**txtptr = '\0'; /* tie off flag */
if (!*flag) break; /* null flag */
@@ -4805,8 +4809,12 @@ void imap_parse_flags (MAILSTREAM *stream,MESSAGECACHE *elt,
}
/* otherwise user flag */
else elt->user_flags |= imap_parse_user_flag (stream,flag);
+ } while (c && (c != ')'));
+ if (c) ++*txtptr; /* bump past delimiter */
+ else {
+ mm_notify (stream,"Unterminated flags list",WARN);
+ stream->unhealthy = T;
}
- ++*txtptr; /* bump past delimiter */
if (!old.valid || (old.seen != elt->seen) ||
(old.deleted != elt->deleted) || (old.flagged != elt->flagged) ||
(old.answered != elt->answered) || (old.draft != elt->draft) ||
@@ -4899,7 +4907,7 @@ unsigned char *imap_parse_string (MAILSTREAM *stream,unsigned char **txtptr,
(readprogress_t) mail_parameters (NIL,GET_READPROGRESS,NIL);
/* ignore leading spaces */
while (c == ' ') c = *++*txtptr;
- st = ++*txtptr; /* remember start of string */
+ if (c) st = ++*txtptr; /* remember start of string */
switch (c) {
case '"': /* if quoted string */
i = 0; /* initial byte count */
@@ -4947,14 +4955,21 @@ unsigned char *imap_parse_string (MAILSTREAM *stream,unsigned char **txtptr,
if (len) *len = 0;
break;
case '{': /* if literal string */
+ if (!isdigit (**txtptr)) {
+ sprintf (LOCAL->tmp,"Invalid server literal length %.80s",*txtptr);
+ mm_notify (stream,LOCAL->tmp,WARN);
+ stream->unhealthy = T; /* read and discard */
+ i = 0;
+ }
/* get size of string */
- if ((i = strtoul (*txtptr,(char **) txtptr,10)) > MAXSERVERLIT) {
+ else if ((i = strtoul (*txtptr,(char **) txtptr,10)) > MAXSERVERLIT) {
sprintf (LOCAL->tmp,"Absurd server literal length %lu",i);
mm_notify (stream,LOCAL->tmp,WARN);
stream->unhealthy = T; /* read and discard */
- do net_getbuffer (LOCAL->netstream,j = min (i,(long) IMAPTMPLEN - 1),
- LOCAL->tmp);
- while (i -= j);
+ for (j = IMAPTMPLEN - 1; i; i -= j) {
+ if (j > i) j = i;
+ net_getbuffer (LOCAL->netstream,j,LOCAL->tmp);
+ }
}
if (len) *len = i; /* set return value */
if (md && mg) { /* have special routine to slurp string? */
@@ -5113,9 +5128,10 @@ void imap_parse_body_structure (MAILSTREAM *stream,BODY *body,
int i;
char *s;
PART *part = NIL;
- char c = *((*txtptr)++); /* grab first character */
+ char c = **txtptr; /* grab first character */
/* ignore leading spaces */
- while (c == ' ') c = *((*txtptr)++);
+ while (c == ' ') c = *++*txtptr;
+ if (c) ++*txtptr; /* skip past first character */
switch (c) { /* dispatch on first character */
case '(': /* body structure list */
if (**txtptr == '(') { /* multipart body? */
@@ -5172,9 +5188,12 @@ void imap_parse_body_structure (MAILSTREAM *stream,BODY *body,
(i <= TYPEMAX) && body_types[i] && strcmp (s,body_types[i]); i++);
if (i <= TYPEMAX) { /* only if found a slot */
body->type = i; /* set body type */
- if (body_types[i]) fs_give ((void **) &s);
- else body_types[i]=s; /* assign empty slot */
+ if (!body_types[i]) { /* assign empty slot */
+ body_types[i] = s;
+ s = NIL; /* don't free this string */
+ }
}
+ if (s) fs_give ((void **) &s);
}
if (body->subtype = imap_parse_string(stream,txtptr,reply,NIL,NIL,LONGT))
ucase (body->subtype); /* parse subtype */
@@ -5195,10 +5214,13 @@ void imap_parse_body_structure (MAILSTREAM *stream,BODY *body,
if (i > ENCMAX) body->encoding = ENCOTHER;
else { /* only if found a slot */
body->encoding = i; /* set body encoding */
- if (body_encodings[i]) fs_give ((void **) &s);
/* assign empty slot */
- else body_encodings[i] = s;
+ if (!body_encodings[i]) {
+ body_encodings[i] = s;
+ s = NIL; /* don't free this string */
+ }
}
+ if (s) fs_give ((void **) &s);
}
/* parse size of contents in bytes */
body->size.bytes = strtoul (*txtptr,(char **) txtptr,10);
@@ -5212,6 +5234,7 @@ void imap_parse_body_structure (MAILSTREAM *stream,BODY *body,
if (!env) {
mm_notify (stream,"Missing body message envelope",WARN);
stream->unhealthy = T;
+ fs_give ((void **) &body->subtype);
body->subtype = cpystr ("RFC822_MISSING_ENVELOPE");
break;
}
@@ -5284,8 +5307,7 @@ PARAMETER *imap_parse_body_parameter (MAILSTREAM *stream,
char c,*s;
/* ignore leading spaces */
while ((c = *(*txtptr)++) == ' ');
- /* parse parameter list */
- if (c == '(') while (c != ')') {
+ if (c == '(') do { /* parse parameter list */
/* append new parameter to tail */
if (ret) par = par->next = mail_newbody_parameter ();
else ret = par = mail_newbody_parameter ();
@@ -5308,13 +5330,17 @@ PARAMETER *imap_parse_body_parameter (MAILSTREAM *stream,
case ')': /* end of attribute/value pairs */
++*txtptr; /* skip past closing paren */
break;
+ case '\0':
+ mm_notify (stream,"Unterminated parameter list", WARN);
+ stream->unhealthy = T;
+ break;
default:
sprintf (LOCAL->tmp,"Junk at end of parameter: %.80s",(char *) *txtptr);
mm_notify (stream,LOCAL->tmp,WARN);
stream->unhealthy = T;
break;
}
- }
+ } while (c && (c != ')'));
/* empty parameter, must be NIL */
else if (((c == 'N') || (c == 'n')) &&
((*(s = *txtptr) == 'I') || (*s == 'i')) &&
@@ -5364,7 +5390,7 @@ void imap_parse_disposition (MAILSTREAM *stream,BODY *body,
mm_notify (stream,LOCAL->tmp,WARN);
stream->unhealthy = T;
/* try to skip to next space */
- while ((*++*txtptr != ' ') && (**txtptr != ')') && **txtptr);
+ while (**txtptr && (*++*txtptr != ' ') && (**txtptr != ')'));
break;
}
}
@@ -5437,12 +5463,13 @@ void imap_parse_extension (MAILSTREAM *stream,unsigned char **txtptr,
unsigned long i,j;
switch (*++*txtptr) { /* action depends upon first character */
case '(':
- while (**txtptr != ')') imap_parse_extension (stream,txtptr,reply);
- ++*txtptr; /* bump past closing parenthesis */
+ while (**txtptr && (**txtptr != ')'))
+ imap_parse_extension (stream,txtptr,reply);
+ if (**txtptr) ++*txtptr; /* bump past closing parenthesis */
break;
case '"': /* if quoted string */
- while (*++*txtptr != '"') if (**txtptr == '\\') ++*txtptr;
- ++*txtptr; /* bump past closing quote */
+ while ((*++*txtptr != '"') && **txtptr) if (**txtptr == '\\') ++*txtptr;
+ if (**txtptr) ++*txtptr; /* bump past closing quote */
break;
case 'N': /* if NIL */
case 'n':
@@ -5471,7 +5498,7 @@ void imap_parse_extension (MAILSTREAM *stream,unsigned char **txtptr,
mm_notify (stream,LOCAL->tmp,WARN);
stream->unhealthy = T;
/* try to skip to next space */
- while ((*++*txtptr != ' ') && (**txtptr != ')') && **txtptr);
+ while (**txtptr && (*++*txtptr != ' ') && (**txtptr != ')'));
break;
}
}
diff --git a/imap/src/c-client/mail.c b/imap/src/c-client/mail.c
index 0b479a1c..871d07eb 100644
--- a/imap/src/c-client/mail.c
+++ b/imap/src/c-client/mail.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2008 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2010 Mark Crispin
* ========================================================================
*/
@@ -15,13 +7,20 @@
* Program: Mailbox Access routines
*
* Author: Mark Crispin
- * UW Technology
- * University of Washington
- * Seattle, WA 98195
- * Internet: MRC@Washington.EDU
*
* Date: 22 November 1989
- * Last Edited: 15 April 2008
+ * Last Edited: 15 November 2010
+ *
+ * Previous versions of this file were
+*
+ * Copyright 1988-2008 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
*/
@@ -30,7 +29,9 @@
#include <time.h>
#include "c-client.h"
-char *UW_copyright = "Copyright 1988-2007 University of Washington\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n";
+char *Panda_copyright = "Copyright 2008-2010 Mark Crispin\n";
+
+char *UW_copyright = "Copyright 1988-2008 University of Washington\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n";
/* c-client global data */
@@ -349,6 +350,11 @@ void *mail_parameters (MAILSTREAM *stream,long function,void *value)
else ret = env_parameters (function,value);
break;
case GET_NAMESPACE:
+ ret = (stream && stream->dtb && !(stream->dtb->flags & DR_LOCAL)) ?
+ /* KLUDGE ALERT: note stream passed as value */
+ (*stream->dtb->parameters) (function,stream) :
+ env_parameters (function,value);
+ break;
case GET_NEWSRC: /* use stream dtb instead of environment */
ret = (stream && stream->dtb) ?
/* KLUDGE ALERT: note stream passed as value */
@@ -3395,12 +3401,14 @@ unsigned long mail_filter (char *text,unsigned long len,STRINGLIST *lines,
while (((*src++ != '\012') && (*src++ != '\012') && (*src++ != '\012') &&
(*src++ != '\012') && (*src++ != '\012') && (*src++ != '\012') &&
(*src++ != '\012') && (*src++ != '\012') && (*src++ != '\012') &&
- (*src++ != '\012')) || ((*src == ' ') || (*src == '\t')));
+ (*src++ != '\012')) ||
+ ((src < end) && ((*src == ' ') || (*src == '\t'))));
else if (src == dst) { /* copy to self */
while (((*src++ != '\012') && (*src++ != '\012') && (*src++ != '\012') &&
(*src++ != '\012') && (*src++ != '\012') && (*src++ != '\012') &&
(*src++ != '\012') && (*src++ != '\012') && (*src++ != '\012') &&
- (*src++ != '\012')) || ((*src == ' ') || (*src == '\t')));
+ (*src++ != '\012')) ||
+ ((src < end) && ((*src == ' ') || (*src == '\t'))));
dst = src; /* update destination */
}
else { /* copy line and any continuation line */
@@ -3409,7 +3417,7 @@ unsigned long mail_filter (char *text,unsigned long len,STRINGLIST *lines,
((*dst++ = *src++) != '\012') && ((*dst++ = *src++) != '\012') &&
((*dst++ = *src++) != '\012') && ((*dst++ = *src++) != '\012') &&
((*dst++ = *src++) != '\012') && ((*dst++ = *src++) != '\012'))||
- ((*src == ' ') || (*src == '\t')));
+ ((src < end) && ((*src == ' ') || (*src == '\t'))));
/* in case hit the guard LF */
if (src > end) dst -= (src - end);
}
@@ -4402,7 +4410,8 @@ SORTCACHE **mail_sort_loadcache (MAILSTREAM *stream,SORTPGM *pgm)
default: /* tie off extraneous text */
*x = x[1] = '\0';
}
- if (adr = rfc822_parse_address (&adr,adr,&t,BADHOST,0)) {
+ rfc822_parse_adrlist (&adr,t,BADHOST);
+ if (adr) {
s->from = adr->mailbox;
adr->mailbox = NIL;
mail_free_address (&adr);
@@ -4435,7 +4444,8 @@ SORTCACHE **mail_sort_loadcache (MAILSTREAM *stream,SORTPGM *pgm)
default: /* tie off extraneous text */
*x = x[1] = '\0';
}
- if (adr = rfc822_parse_address (&adr,adr,&t,BADHOST,0)) {
+ rfc822_parse_adrlist (&adr,t,BADHOST);
+ if (adr) {
s->to = adr->mailbox;
adr->mailbox = NIL;
mail_free_address (&adr);
@@ -4459,8 +4469,8 @@ SORTCACHE **mail_sort_loadcache (MAILSTREAM *stream,SORTPGM *pgm)
case '\t':
memmove (x,v,strlen (v));
break;
- case 't': /* continuation but with extra "To:" */
- case 'T':
+ case 'c': /* continuation but with extra "cc:" */
+ case 'C':
if (v = strchr (v,':')) {
memmove (x,v+1,strlen (v+1));
break;
@@ -4468,7 +4478,8 @@ SORTCACHE **mail_sort_loadcache (MAILSTREAM *stream,SORTPGM *pgm)
default: /* tie off extraneous text */
*x = x[1] = '\0';
}
- if (adr = rfc822_parse_address (&adr,adr,&t,BADHOST,0)) {
+ rfc822_parse_adrlist (&adr,t,BADHOST);
+ if (adr) {
s->cc = adr->mailbox;
adr->mailbox = NIL;
mail_free_address (&adr);
@@ -4663,16 +4674,16 @@ int mail_sort_compare (const void *a1,const void *a2)
i = compare_ulong (s1->size,s2->size);
break;
case SORTFROM: /* sort by first from */
- i = compare_cstring (s1->from,s2->from);
+ i = compare_string (s1->from,s2->from);
break;
case SORTTO: /* sort by first to */
- i = compare_cstring (s1->to,s2->to);
+ i = compare_string (s1->to,s2->to);
break;
case SORTCC: /* sort by first cc */
- i = compare_cstring (s1->cc,s2->cc);
+ i = compare_string (s1->cc,s2->cc);
break;
case SORTSUBJECT: /* sort by subject */
- i = compare_cstring (s1->subject,s2->subject);
+ i = compare_string (s1->subject,s2->subject);
break;
}
if (pgm->reverse) i = -i; /* flip results if necessary */
@@ -5522,21 +5533,24 @@ long mail_parse_flags (MAILSTREAM *stream,char *flag,unsigned long *uf)
long mail_usable_network_stream (MAILSTREAM *stream,char *name)
{
NETMBX smb,nmb,omb;
- return (stream && stream->dtb && !(stream->dtb->flags & DR_LOCAL) &&
- mail_valid_net_parse (name,&nmb) &&
- mail_valid_net_parse (stream->mailbox,&smb) &&
- mail_valid_net_parse (stream->original_mailbox,&omb) &&
- ((!compare_cstring (smb.host,
- trustdns ? tcp_canonical (nmb.host) : nmb.host)&&
- !strcmp (smb.service,nmb.service) &&
- (!nmb.port || (smb.port == nmb.port)) &&
- (nmb.anoflag == stream->anonymous) &&
- (!nmb.user[0] || !strcmp (smb.user,nmb.user))) ||
- (!compare_cstring (omb.host,nmb.host) &&
- !strcmp (omb.service,nmb.service) &&
- (!nmb.port || (omb.port == nmb.port)) &&
- (nmb.anoflag == stream->anonymous) &&
- (!nmb.user[0] || !strcmp (omb.user,nmb.user))))) ? LONGT : NIL;
+ char *s = NIL;
+ long ret= (stream && stream->dtb && !(stream->dtb->flags & DR_LOCAL) &&
+ mail_valid_net_parse (name,&nmb) &&
+ mail_valid_net_parse (stream->mailbox,&smb) &&
+ mail_valid_net_parse (stream->original_mailbox,&omb) &&
+ ((!compare_cstring (smb.host,trustdns ?
+ (s = tcp_canonical (nmb.host)) : nmb.host) &&
+ !strcmp (smb.service,nmb.service) &&
+ (!nmb.port || (smb.port == nmb.port)) &&
+ (nmb.anoflag == stream->anonymous) &&
+ (!nmb.user[0] || !strcmp (smb.user,nmb.user))) ||
+ (!compare_cstring (omb.host,nmb.host) &&
+ !strcmp (omb.service,nmb.service) &&
+ (!nmb.port || (omb.port == nmb.port)) &&
+ (nmb.anoflag == stream->anonymous) &&
+ (!nmb.user[0] || !strcmp (omb.user,nmb.user))))) ? LONGT : NIL;
+ if(s) fs_give((void **) &s);
+ return ret;
}
/* Mail data structure instantiation routines */
diff --git a/imap/src/c-client/mail.h b/imap/src/c-client/mail.h
index ad63fa2d..fe7eaa77 100644
--- a/imap/src/c-client/mail.h
+++ b/imap/src/c-client/mail.h
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2008 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2011 Mark Crispin
* ========================================================================
*/
@@ -15,18 +7,25 @@
* Program: Mailbox Access routines
*
* Author: Mark Crispin
- * UW Technology
- * University of Washington
- * Seattle, WA 98195
- * Internet: MRC@Washington.EDU
*
* Date: 22 November 1989
- * Last Edited: 16 December 2008
+ * Last Edited: 8 April 2011
+ *
+ * Previous versions of this file were
+ *
+ * Copyright 1988-2008 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
*/
/* The Version */
-#define CCLIENTVERSION "2007e"
+#define CCLIENTVERSION "2010"
/* Build parameters */
@@ -177,6 +176,8 @@
#define SET_EXTERNALAUTHID (long) 230
#define GET_SSLCAPATH (long) 231
#define SET_SSLCAPATH (long) 232
+#define GET_RESTRICTIONS (long) 233
+#define SET_RESTRICTIONS (long) 234
/* 3xx: TCP/IP */
#define GET_OPENTIMEOUT (long) 300
@@ -1839,7 +1840,7 @@ char *net_localhost (NETSTREAM *stream);
long sm_subscribe (char *mailbox);
long sm_unsubscribe (char *mailbox);
-char *sm_read (void **sdb);
+char *sm_read (char *sbname,void **sdb);
void ssl_onceonlyinit (void);
char *ssl_start_tls (char *s);
diff --git a/imap/src/c-client/misc.c b/imap/src/c-client/misc.c
index 4b789af8..bcbc49e2 100644
--- a/imap/src/c-client/misc.c
+++ b/imap/src/c-client/misc.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2006 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,19 @@
* Program: Miscellaneous utility routines
*
* Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 5 July 1988
- * Last Edited: 6 December 2006
+ * Last Edited: 19 November 2008
+ *
+ * Previous versions of this file were
+ *
+ * Copyright 1988-2006 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* This original version of this file is
* Copyright 1988 Stanford University
@@ -434,14 +430,35 @@ int compare_ulong (unsigned long l1,unsigned long l2)
int compare_uchar (unsigned char c1,unsigned char c2)
{
- return compare_ulong (((c1 >= 'A') && (c1 <= 'Z')) ? c1 + ('a' - 'A') : c1,
- ((c2 >= 'A') && (c2 <= 'Z')) ? c2 + ('a' - 'A') : c2);
+ return compare_ulong (((c1 >= 'a') && (c1 <= 'z')) ? c1 - ('a' - 'A') : c1,
+ ((c2 >= 'a') && (c2 <= 'z')) ? c2 - ('a' - 'A') : c2);
}
+/* Compare two strings by octet
+ * Accepts: first string
+ * second string
+ * Returns: -1 if s1 < s2, 0 if s1 == s2, 1 if s1 > s2
+ *
+ * Effectively strcmp() but without locales
+ */
+
+int compare_string (unsigned char *s1,unsigned char *s2)
+{
+ int i;
+ if (!s1) return s2 ? -1 : 0; /* empty string cases */
+ else if (!s2) return 1;
+ for (; *s1 && *s2; s1++,s2++) if (i = (compare_ulong (*s1,*s2))) return i;
+ if (*s1) return 1; /* first string is longer */
+ return *s2 ? -1 : 0; /* second string longer : strings identical */
+}
+
+
/* Compare two case-independent ASCII strings
* Accepts: first string
* second string
* Returns: -1 if s1 < s2, 0 if s1 == s2, 1 if s1 > s2
+ *
+ * Effectively strcasecmp() but without locales
*/
int compare_cstring (unsigned char *s1,unsigned char *s2)
diff --git a/imap/src/c-client/misc.h b/imap/src/c-client/misc.h
index 1ac79485..4e7afc23 100644
--- a/imap/src/c-client/misc.h
+++ b/imap/src/c-client/misc.h
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2006 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,19 @@
* Program: Miscellaneous utility routines
*
* Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 5 July 1988
- * Last Edited: 30 August 2006
+ * Last Edited: 19 November 2008
+ *
+ * Previous versions of this file were
+ *
+ * Copyright 1988-2006 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* This original version of this file is
* Copyright 1988 Stanford University
@@ -106,5 +102,6 @@ void **hash_lookup_and_add (HASHTAB *hashtab,char *key,void *data,long extra);
unsigned char hex2byte (unsigned char c1,unsigned char c2);
int compare_ulong (unsigned long l1,unsigned long l2);
int compare_uchar (unsigned char c1,unsigned char c2);
+int compare_string (unsigned char *s1,unsigned char *s2);
int compare_cstring (unsigned char *s1,unsigned char *s2);
int compare_csizedtext (unsigned char *s1,SIZEDTEXT *s2);
diff --git a/imap/src/c-client/nntp.c b/imap/src/c-client/nntp.c
index 5a805e86..cee546d1 100644
--- a/imap/src/c-client/nntp.c
+++ b/imap/src/c-client/nntp.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2007 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2011 Mark Crispin
* ========================================================================
*/
@@ -15,18 +7,24 @@
* Program: Network News Transfer Protocol (NNTP) routines
*
* Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 10 February 1992
- * Last Edited: 6 September 2007
+ * Last Edited: 8 April 2011
+ *
+ * Previous versions of this file were:
+ *
+ * Copyright 1988-2007 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
*/
+
#include <ctype.h>
#include <stdio.h>
#include "c-client.h"
@@ -385,7 +383,7 @@ void nntp_list (MAILSTREAM *stream,char *ref,char *pat)
void nntp_lsub (MAILSTREAM *stream,char *ref,char *pat)
{
void *sdb = NIL;
- char *s,mbx[MAILTMPLEN];
+ char *s,mbx[MAILTMPLEN],tmp[MAILTMPLEN];
/* return data from newsrc */
if (nntp_canonicalize (ref,pat,mbx,NIL)) newsrc_lsub (stream,mbx);
if (*pat == '{') { /* if remote pattern, must be NNTP */
@@ -398,9 +396,10 @@ void nntp_lsub (MAILSTREAM *stream,char *ref,char *pat)
if (ref && *ref) sprintf (mbx,"%s%s",ref,pat);
else strcpy (mbx,pat);
- if (s = sm_read (&sdb)) do if (nntp_valid (s) && pmatch (s,mbx))
+ if (s = sm_read (tmp,&sdb)) do if (nntp_valid (s) && pmatch (s,mbx))
mm_lsub (stream,NIL,s,NIL);
- while (s = sm_read (&sdb)); /* until no more subscriptions */
+ /* until no more subscriptions */
+ while (s = sm_read (tmp,&sdb));
}
/* NNTP canonicalize newsgroup name
@@ -760,6 +759,10 @@ MAILSTREAM *nntp_mopen (MAILSTREAM *stream)
if (LOCAL->tlssslv23) strcat (tmp,"/tls-sslv23");
if (LOCAL->notlsflag) strcat (tmp,"/notls");
if (LOCAL->sslflag) strcat (tmp,"/ssl");
+ if (LOCAL->tls1) strcat (tmp,"/tls1");
+ if (LOCAL->dtls1) strcat (tmp,"/dtls1");
+ if (LOCAL->tls1_1) strcat (tmp,"/tls1_1");
+ if (LOCAL->tls1_2) strcat (tmp,"/tls1_2");
if (LOCAL->novalidate) strcat (tmp,"/novalidate-cert");
if (LOCAL->nntpstream->loser) strcat (tmp,"/loser");
if (stream->secure) strcat (tmp,"/secure");
diff --git a/imap/src/c-client/pop3.c b/imap/src/c-client/pop3.c
index 123abd9d..52573f52 100644
--- a/imap/src/c-client/pop3.c
+++ b/imap/src/c-client/pop3.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2007 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2011 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Post Office Protocol 3 (POP3) client routines
*
* Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 6 June 1994
- * Last Edited: 4 April 2007
+ * Last Edited: 8 April 2011
+ *
+ * Previous versions of this file were:
+ *
+ * Copyright 1988-2007 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
*/
@@ -265,7 +262,7 @@ void pop3_list (MAILSTREAM *stream,char *ref,char *pat)
void pop3_lsub (MAILSTREAM *stream,char *ref,char *pat)
{
void *sdb = NIL;
- char *s,mbx[MAILTMPLEN];
+ char *s,mbx[MAILTMPLEN],tmp[MAILTMPLEN];
if (*pat == '{') { /* if remote pattern, must be POP3 */
if (!pop3_valid (pat)) return;
ref = NIL; /* good POP3 pattern, punt reference */
@@ -276,9 +273,10 @@ void pop3_lsub (MAILSTREAM *stream,char *ref,char *pat)
if (ref && *ref) sprintf (mbx,"%s%s",ref,pat);
else strcpy (mbx,pat);
- if (s = sm_read (&sdb)) do if (pop3_valid (s) && pmatch (s,mbx))
+ if (s = sm_read (tmp,&sdb)) do if (pop3_valid (s) && pmatch (s,mbx))
mm_lsub (stream,NIL,s,NIL);
- while (s = sm_read (&sdb)); /* until no more subscriptions */
+ /* until no more subscriptions */
+ while (s = sm_read (tmp,&sdb));
}
@@ -425,7 +423,7 @@ MAILSTREAM *pop3_open (MAILSTREAM *stream)
if (mb.tlssslv23) strcat (tmp,"/tls-sslv23");
if (mb.tls1) strcat (tmp,"/tls1");
if (mb.tls1_1) strcat (tmp,"/tls1_1");
- if (mb.tls1_2) strcat (tmp,"/tls1_1");
+ if (mb.tls1_2) strcat (tmp,"/tls1_2");
if (mb.dtls1) strcat (tmp,"/dtls1");
if (mb.notlsflag) strcat (tmp,"/notls");
if (mb.sslflag) strcat (tmp,"/ssl");
diff --git a/imap/src/c-client/rfc822.c b/imap/src/c-client/rfc822.c
index d9239646..03e92ca3 100644
--- a/imap/src/c-client/rfc822.c
+++ b/imap/src/c-client/rfc822.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2008 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2010 Mark Crispin
* ========================================================================
*/
@@ -15,13 +7,19 @@
* Program: RFC 2822 and MIME routines
*
* Author: Mark Crispin
- * UW Technology
- * University of Washington
- * Seattle, WA 98195
- * Internet: MRC@Washington.EDU
*
* Date: 27 July 1988
- * Last Edited: 14 May 2008
+ * Last Edited: 30 September 2010
+ *
+ * Previous versions of this file were:
+ *
+ * Copyright 1988-2008 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* This original version of this file is
* Copyright 1988 Stanford University
@@ -284,17 +282,26 @@ void rfc822_parse_content (BODY *body,STRING *bs,char *h,unsigned long depth,
}
if (!body->subtype) /* default subtype if still unknown */
body->subtype = cpystr (rfc822_default_subtype (body->type));
- /* note offset and sizes */
- body->contents.offset = GETPOS (bs);
- /* note internal body size in all cases */
- body->size.bytes = body->contents.text.size = i = SIZE (bs);
- if (!(flags & DR_CRLF)) body->size.bytes = strcrlflen (bs);
+ /* calculate offset */
+ if (bs->size >= (body->contents.offset = GETPOS (bs))) {
+ body->contents.text.size = i = SIZE (bs);
+ body->size.bytes = (flags & DR_CRLF) ? i : strcrlflen (bs);
+ }
+ else { /* paranoia code */
+#if 0
+ fatal("rfc822_parse_content botch");
+#endif
+ body->size.bytes = body->contents.text.size = i = 0;
+ body->contents.offset = bs->size;
+ SETPOS(bs,bs->size);
+ }
+
switch (body->type) { /* see if anything else special to do */
case TYPETEXT: /* text content */
if (!body->parameter) { /* no parameters set */
body->parameter = mail_newbody_parameter ();
body->parameter->attribute = cpystr ("CHARSET");
- while (i--) { /* count lines and guess charset */
+ while (i && i--) { /* count lines and guess charset */
c = SNX (bs); /* get current character */
/* charset still unknown? */
if (!body->parameter->value) {
@@ -319,7 +326,7 @@ void rfc822_parse_content (BODY *body,STRING *bs,char *h,unsigned long depth,
}
}
/* just count lines */
- else while (i--) if ((SNX (bs)) == '\n') body->size.lines++;
+ else while (i && i--) if ((SNX (bs)) == '\n') body->size.lines++;
break;
case TYPEMESSAGE: /* encapsulated message */
@@ -363,6 +370,7 @@ void rfc822_parse_content (BODY *body,STRING *bs,char *h,unsigned long depth,
/* count number of lines */
while (i--) if (SNX (bs) == '\n') body->size.lines++;
break;
+
case TYPEMULTIPART: /* multiple parts */
switch (body->encoding) { /* make sure valid encoding */
case ENC7BIT: /* these are valid nested encodings */
@@ -380,7 +388,6 @@ void rfc822_parse_content (BODY *body,STRING *bs,char *h,unsigned long depth,
if (!s1) s1 = "-"; /* yucky default */
j = strlen (s1) + 2; /* length of cookie and header */
c = '\012'; /* initially at beginning of line */
-
while (i > j) { /* examine data */
if (m = GETPOS (bs)) m--; /* get position in front of character */
switch (c) { /* examine each line */
@@ -405,6 +412,7 @@ void rfc822_parse_content (BODY *body,STRING *bs,char *h,unsigned long depth,
}
break;
}
+
/* swallow trailing whitespace */
while ((c == ' ') || (c == '\t'))
c = ((i && i--) ? (SNX (bs)) : '\012');
@@ -478,7 +486,6 @@ void rfc822_parse_content (BODY *body,STRING *bs,char *h,unsigned long depth,
/* end of data ties off the header */
if (!i || !--i) s1[j++] = c = '\0';
}
-
/* find header item type */
if (((s1[0] == 'C') || (s1[0] == 'c')) &&
((s1[1] == 'O') || (s1[1] == 'o')) &&
@@ -494,6 +501,7 @@ void rfc822_parse_content (BODY *body,STRING *bs,char *h,unsigned long depth,
rfc822_parse_content_header (&part->body,ucase (s1+8),s);
}
}
+
/* skip header trailing (CR)LF */
if (i && (CHR (bs) =='\015')) {i--; c1 = SNX (bs);}
if (i && (CHR (bs) =='\012')) {i--; c1 = SNX (bs);}
@@ -1061,7 +1069,7 @@ ADDRESS *rfc822_parse_addrspec (char *string,char **ret,char *defaulthost)
else if (!(adr->host = rfc822_parse_domain (++end,&end)))
adr->host = cpystr (errhst);
/* default host if missing */
- if (!adr->host) adr->host = cpystr (defaulthost);
+ if (!adr->host) adr->host = cpystr (defaulthost ? defaulthost : "@");
/* try person name in comments if missing */
if (end && !(adr->personal && *adr->personal)) {
while (*end == ' ') ++end; /* see if we can find a person name here */
@@ -1380,7 +1388,7 @@ static long rfc822_output_data (RFC822BUFFER *buf,char *string,long len)
}
/* soutr buffer now if full */
if ((len || (buf->cur == buf->end)) && !rfc822_output_flush (buf))
- return NIL;
+ return NIL;
}
return LONGT;
}
@@ -2064,8 +2072,12 @@ unsigned char *rfc822_qprint (unsigned char *src,unsigned long srcl,
t = d; /* accept any leading spaces */
break;
default: /* two hex digits then */
- if (!(isxdigit (c) && (((unsigned long) (s - src)) < srcl) &&
- (e = *s++) && isxdigit (e))) {
+ if (isxdigit (c) && (((unsigned long) (s - src)) < srcl) &&
+ isxdigit(*s)) {
+ e = *s++; /* eat second hex digit now */
+ *d++ = hex2byte (c,e);/* merge the two hex digits */
+ }
+ else {
/* This indicates bad MIME. One way that it can be caused is if
a single-section message was QUOTED-PRINTABLE encoded and then
something (e.g. a mailing list processor) appended text. The
@@ -2081,10 +2093,7 @@ unsigned char *rfc822_qprint (unsigned char *src,unsigned long srcl,
}
*d++ = '='; /* treat = as ordinary character */
*d++ = c; /* and the character following */
- t = d; /* note point of non-space */
- break;
}
- *d++ = hex2byte (c,e); /* merge the two hex digits */
t = d; /* note point of non-space */
break;
}
diff --git a/imap/src/c-client/smanager.c b/imap/src/c-client/smanager.c
index cee659ff..1f9b508c 100644
--- a/imap/src/c-client/smanager.c
+++ b/imap/src/c-client/smanager.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2006 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2011 Mark Crispin
* ========================================================================
*/
@@ -15,18 +7,24 @@
* Program: Subscription Manager
*
* Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 3 December 1992
- * Last Edited: 6 December 2006
+ * Last Edited: 8 April 2011
+ *
+ * Previous versions of this file were
+ *
+ * Copyright 1988-2006 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
*/
+
#include <stdio.h>
#include <ctype.h>
#include "c-client.h"
@@ -103,13 +101,12 @@ long sm_unsubscribe (char *mailbox)
}
/* Read subscription database
- * Accepts: pointer to subscription database handle (handle NIL if first time)
+ * Accepts: pointer to destination buffer of size MAILTMPLEN
+ * pointer to subscription database handle (handle NIL if first time)
* Returns: character string for subscription database or NIL if done
*/
-static char sbname[MAILTMPLEN];
-
-char *sm_read (void **sdb)
+char *sm_read (char *sbname,void **sdb)
{
FILE *f = (FILE *) *sdb;
char *s;
diff --git a/imap/src/c-client/smtp.c b/imap/src/c-client/smtp.c
index fe38cad0..47c7e5a6 100644
--- a/imap/src/c-client/smtp.c
+++ b/imap/src/c-client/smtp.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2008 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,19 @@
* Program: Simple Mail Transfer Protocol (SMTP) routines
*
* Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 27 July 1988
- * Last Edited: 28 January 2008
+ * Last Edited: 19 November 2008
+ *
+ * Previous versions of this file were
+ *
+ * Copyright 1988-2008 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* This original version of this file is
* Copyright 1988 Stanford University
@@ -395,8 +391,7 @@ SENDSTREAM *smtp_close (SENDSTREAM *stream)
if (stream) { /* send "QUIT" */
if (stream->netstream) { /* do close actions if have netstream */
smtp_send (stream,"QUIT",NIL);
- if (stream->netstream) /* could have been closed during "QUIT" */
- net_close (stream->netstream);
+ if (stream->netstream) net_close (stream->netstream);
}
/* clean up */
if (stream->host) fs_give ((void **) &stream->host);
@@ -436,13 +431,13 @@ long smtp_mail (SENDSTREAM *stream,char *type,ENVELOPE *env,BODY *body)
sprintf (smtpserver,"{%.200s/smtp%s}<none>",
(long) mail_parameters (NIL,GET_TRUSTDNS,NIL) ?
((long) mail_parameters (NIL,GET_SASLUSESPTRNAME,NIL) ?
- net_remotehost (stream->netstream) :
- net_host (stream->netstream)) :
- stream->host,
- (stream->netstream->dtb ==
- (NETDRIVER *) mail_parameters (NIL,GET_SSLDRIVER,NIL)) ?
- "/ssl" : "");
- do {
+ net_remotehost (stream->netstream) :
+ net_host (stream->netstream)) :
+ stream->host,
+ (stream->netstream->dtb ==
+ (NETDRIVER *) mail_parameters (NIL,GET_SSLDRIVER,NIL)) ?
+ "/ssl" : "");
+ do { /* make sure stream is in good shape */
smtp_send (stream,"RSET",NIL);
if (retry) { /* need to retry with authentication? */
NETMBX mb;
@@ -487,6 +482,7 @@ long smtp_mail (SENDSTREAM *stream,char *type,ENVELOPE *env,BODY *body)
case SMTPOK: /* looks good */
break;
default: /* other failure */
+ smtp_send (stream,"RSET",NIL);
return NIL;
}
/* negotiate the recipients */
@@ -500,7 +496,10 @@ long smtp_mail (SENDSTREAM *stream,char *type,ENVELOPE *env,BODY *body)
}
} while (retry);
/* negotiate data command */
- if (!(smtp_send (stream,"DATA",NIL) == SMTPREADY)) return NIL;
+ if (!(smtp_send (stream,"DATA",NIL) == SMTPREADY)) {
+ smtp_send (stream,"RSET",NIL);
+ return NIL;
+ }
/* send message data */
if (!rfc822_output_full (&buf,env,body,
ESMTP.eightbit.ok && ESMTP.eightbit.want)) {
@@ -508,7 +507,11 @@ long smtp_mail (SENDSTREAM *stream,char *type,ENVELOPE *env,BODY *body)
return NIL; /* can't do much else here */
}
/* send trailing dot */
- return (smtp_send (stream,".",NIL) == SMTPOK) ? LONGT : NIL;
+ if (smtp_send (stream,".",NIL) != SMTPOK) {
+ smtp_send (stream,"RSET",NIL);
+ return NIL;
+ }
+ return LONGT;
}
/* Simple Mail Transfer Protocol send VERBose
diff --git a/imap/src/c-client/utf8.c b/imap/src/c-client/utf8.c
index 8fda7ffd..c752d7a2 100644
--- a/imap/src/c-client/utf8.c
+++ b/imap/src/c-client/utf8.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2008 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2010 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: UTF-8 routines
*
* Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 11 June 1997
- * Last Edited: 17 January 2008
+ * Last Edited: 28 May 2010
+ *
+ * Previous versions of this file were
+ *
+ * Copyright 1988-2008 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
*/
@@ -1023,20 +1020,52 @@ unsigned long utf8_get_raw (unsigned char **s,unsigned long *i)
if (c < 0x80) ret = c; /* U+0000 - U+007f */
else if (c < 0xc2); /* c0 and c1 never valid */
else if (c < 0xe0) { /* U+0080 - U+07ff */
- if (c &= 0x1f) more = 1;
+ c &= 0x1f;
+ if (c1 >= 0x80) more = 1;
+ }
+ else if (c == 0xe0) { /* U+0800 - U+0fff */
+ c &= 0x0f;
+ if (c1 >= 0xa0) more = 2;
+ }
+ else if (c < 0xed) { /* U+1000 - U+cfff */
+ c &= 0x0f;
+ if (c1 >= 0x80) more = 2;
}
- else if (c < 0xf0) { /* U+0800 - U+ffff */
- if ((c &= 0x0f) || (c1 >= 0xa0)) more = 2;
+ else if (c == 0xed) { /* U+d000 - U+d7ff */
+ c &= 0x0f;
+ if ((c1 >= 0x80) && (c1 <= 0x9f)) more = 2;
}
- else if (c < 0xf8) { /* U+10000 - U+10ffff (and 110000 - 1fffff) */
- if ((c &= 0x07) || (c1 >= 0x90)) more = 3;
+ else if (c < 0xf0) { /* U+e000 - U+ffff */
+ c &= 0x0f;
+ if (c1 >= 0x80) more = 2;
+ }
+ else if (c == 0xf0) { /* U+10000 - U+3ffff */
+ c &= 0x07;
+ if (c1 >= 0x90) more = 3;
+ }
+ else if (c < 0xf3) { /* U+40000 - U+fffff */
+ c &= 0x07;
+ if (c1 >= 0x80) more = 3;
+ }
+#if 0
+ else if (c == 0xf4) { /* U+100000 - U+10ffff */
+ c &= 0x07;
+ if (((c1 >= 0x80) && (c1 <= 0x8f))) more = 3;
+ }
+#else
+ else if (c < 0xf8) { /* U+100000 - U+10ffff (and 110000 - 1fffff) */
+ c &= 0x07;
+ if ((c1 >= 0x80)) more = 3;
}
else if (c < 0xfc) { /* ISO 10646 200000 - 3ffffff */
- if ((c &= 0x03) || (c1 >= 0x88)) more = 4;
+ c &= 0x03;
+ if ((c1 >= 0x80)) more = 4;
}
else if (c < 0xfe) { /* ISO 10646 4000000 - 7fffffff */
- if ((c &= 0x01) || (c1 >= 0x84)) more = 5;
+ c &= 0x01;
+ if ((c1 >= 0x80)) more = 5;
}
+#endif
/* fe and ff never valid */
if (more) { /* multi-octet, make sure more to come */
if (!j) return U8G_ENDSTRI;
@@ -1186,7 +1215,7 @@ unsigned long ucs4_cs_get (CHARSET *cs,unsigned char **s,unsigned long *i)
if (j--) c1 = *t++; /* get second octet */
else return U8G_ENDSTRI;
SJISTOJIS (c,c1);
- c = JISTOUNICODE (c,c1,ku,ten);
+ ret = JISTOUNICODE (c,c1,ku,ten);
}
break;