@ -80,15 +80,21 @@ parse_info (message_t * m, char *s)
}
}
}
}
static unsigned int
/*
read_uid ( const char * path , const char * file )
* There are three possible results of this function :
* > 1 uid was already seen
* 0 uid was not yet seen
* - 1 unable to read uid because of some other error
*/
static int
read_uid ( const char * path , const char * file , unsigned int * uid /* out */ )
{
{
char full [ _POSIX_PATH_MAX ] ;
char full [ _POSIX_PATH_MAX ] ;
int fd ;
int fd ;
int ret = 0 ;
int ret = - 1 ;
int len ;
int len ;
char buf [ 64 ] ;
char buf [ 64 ] , * ptr ;
unsigned int uid = 0 ;
snprintf ( full , sizeof ( full ) , " %s/%s " , path , file ) ;
snprintf ( full , sizeof ( full ) , " %s/%s " , path , file ) ;
fd = open ( full , O_RDONLY ) ;
fd = open ( full , O_RDONLY ) ;
@ -103,18 +109,20 @@ read_uid (const char *path, const char *file)
}
}
len = read ( fd , buf , sizeof ( buf ) - 1 ) ;
len = read ( fd , buf , sizeof ( buf ) - 1 ) ;
if ( len = = - 1 )
if ( len = = - 1 )
{
perror ( " read " ) ;
perror ( " read " ) ;
ret = - 1 ;
}
else
else
{
{
buf [ len ] = 0 ;
buf [ len ] = 0 ;
uid = atol ( buf ) ;
errno = 0 ;
* uid = strtoul ( buf , & ptr , 10 ) ;
if ( errno )
perror ( " strtoul " ) ;
else if ( ptr & & * ptr = = ' \n ' )
ret = 1 ;
/* else invalid value */
}
}
close ( fd ) ;
close ( fd ) ;
return ret ? ( unsigned int ) ret : uid ;
return ret ;
}
}
/* NOTE: this is NOT NFS safe */
/* NOTE: this is NOT NFS safe */
@ -233,12 +241,14 @@ maildir_open (const char *path, int flags)
goto err ;
goto err ;
/* check for the uidvalidity value */
/* check for the uidvalidity value */
m - > uidvalidity = read_uid ( m - > path , " isyncuidvalidity " ) ;
i = read_uid ( m - > path , " isyncuidvalidity " , & m - > uidvalidity ) ;
if ( m - > uidvalidity = = ( unsigned int ) - 1 )
if ( i = = - 1 )
goto err ;
goto err ;
else if ( i > 0 )
m - > uidseen = 1 ;
/* load the current maxuid */
/* load the current maxuid */
if ( ( m - > maxuid = read_uid ( m - > path , " isyncmaxuid " ) ) = = ( unsigned int ) - 1 )
if ( read_uid ( m - > path , " isyncmaxuid " , & m - > maxuid ) = = - 1 )
goto err ;
goto err ;
if ( flags & OPEN_FAST )
if ( flags & OPEN_FAST )