Browse Source

tolerate case changes in X-TUID header name

it is legal for an email system to simply change the case of rfc2822
headers, and at least one imap server apparently does just that.
this would lead to us not finding our own header, which is obviously not
helpful.

REFMAIL: CA+fD2U3hJEszmvwBsXEpTsaWgJ2Dh373mCESM3M0kg3ZwAYjaw@mail.gmail.com
1.2
Oswald Buddenhagen 10 years ago
parent
commit
8979ebbdf2
  1. 1
      src/common.h
  2. 2
      src/drv_imap.c
  3. 2
      src/sync.c
  4. 16
      src/util.c

1
src/common.h

@ -116,6 +116,7 @@ void *memrchr( const void *s, int c, size_t n );
#endif #endif
int starts_with( const char *str, int strl, const char *cmp, int cmpl ); int starts_with( const char *str, int strl, const char *cmp, int cmpl );
int starts_with_upper( const char *str, int strl, const char *cmp, int cmpl );
int equals( const char *str, int strl, const char *cmp, int cmpl ); int equals( const char *str, int strl, const char *cmp, int cmpl );
#ifndef HAVE_TIMEGM #ifndef HAVE_TIMEGM

2
src/drv_imap.c

@ -967,7 +967,7 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED )
tmp = tmp->next; tmp = tmp->next;
if (!is_atom( tmp )) if (!is_atom( tmp ))
goto bfail; goto bfail;
if (starts_with( tmp->val, tmp->len, "X-TUID: ", 8 )) if (starts_with_upper( tmp->val, tmp->len, "X-TUID: ", 8 ))
tuid = tmp->val + 8; tuid = tmp->val + 8;
} else { } else {
bfail: bfail:

2
src/sync.c

@ -338,7 +338,7 @@ msg_fetched( int sts, void *aux )
if (c == '\r') if (c == '\r')
lcrs++; lcrs++;
else if (c == '\n') { else if (c == '\n') {
if (starts_with( fmap + start, len - start, "X-TUID: ", 8 )) { if (starts_with_upper( fmap + start, len - start, "X-TUID: ", 8 )) {
extra = (sbreak = start) - (ebreak = i); extra = (sbreak = start) - (ebreak = i);
goto oke; goto oke;
} }

16
src/util.c

@ -27,6 +27,7 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include <pwd.h> #include <pwd.h>
static int need_nl; static int need_nl;
@ -241,6 +242,21 @@ starts_with( const char *str, int strl, const char *cmp, int cmpl )
return (strl >= cmpl) && !memcmp( str, cmp, cmpl ); return (strl >= cmpl) && !memcmp( str, cmp, cmpl );
} }
int
starts_with_upper( const char *str, int strl, const char *cmp, int cmpl )
{
int i;
if (strl < 0)
strl = strnlen( str, cmpl + 1 );
if (strl < cmpl)
return 0;
for (i = 0; i < cmpl; i++)
if (str[i] != cmp[i] && toupper( str[i] ) != cmp[i])
return 0;
return 1;
}
int int
equals( const char *str, int strl, const char *cmp, int cmpl ) equals( const char *str, int strl, const char *cmp, int cmpl )
{ {

Loading…
Cancel
Save