@ -179,7 +179,7 @@ socket_read (Socket_t * sock, char *buf, size_t len)
if ( sock - > use_ssl )
return SSL_read ( sock - > ssl , buf , len ) ;
# endif
return read ( sock - > fd , buf , len ) ;
return read ( sock - > rd fd, buf , len ) ;
}
static int
@ -189,7 +189,7 @@ socket_write (Socket_t * sock, char *buf, size_t len)
if ( sock - > use_ssl )
return SSL_write ( sock - > ssl , buf , len ) ;
# endif
return write ( sock - > fd , buf , len ) ;
return write ( sock - > wr fd, buf , len ) ;
}
static void
@ -455,8 +455,8 @@ imap_exec (imap_t * imap, const char *fmt, ...)
imap - > ns_shared = parse_list ( cmd , 0 ) ;
}
else if ( ! strcmp ( " OK " , arg ) | | ! strcmp ( " BAD " , arg ) | |
! strcmp ( " NO " , arg ) | | ! strcmp ( " PREAUTH " , arg ) | |
! strcmp ( " BYE " , arg ) )
! strcmp ( " NO " , arg ) | | ! strcmp ( " BYE " , arg ) | |
! strcmp ( " PREAUTH " , arg ) )
{
parse_response_code ( imap , cmd ) ;
}
@ -554,13 +554,15 @@ imap_exec (imap_t * imap, const char *fmt, ...)
* mailbox .
*/
imap_t *
imap_open ( config_t * box , unsigned int minuid , imap_t * imap )
imap_open ( config_t * box , unsigned int minuid , imap_t * imap , int flags )
{
int ret ;
int s ;
struct sockaddr_in addr ;
struct hostent * he ;
char * arg , * rsp ;
int reuse = 0 ;
int preauth = 0 ;
# if HAVE_LIBSSL
int use_ssl = 0 ;
# endif
@ -611,6 +613,47 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap)
{
/* open connection to IMAP server */
if ( box - > tunnel )
{
int a [ 2 ] ;
int b [ 2 ] ;
printf ( " Executing: %s... " , box - > tunnel ) ;
fflush ( stdout ) ;
if ( pipe ( a ) )
{
}
if ( pipe ( b ) )
{
}
if ( fork ( ) = = 0 )
{
if ( dup2 ( a [ 0 ] , 0 ) )
{
_exit ( 127 ) ;
}
close ( a [ 1 ] ) ;
if ( dup2 ( b [ 1 ] , 1 ) )
{
_exit ( 127 ) ;
}
close ( b [ 0 ] ) ;
execl ( " /bin/sh " , " sh " , " -c " , box - > tunnel ) ;
_exit ( 127 ) ;
}
close ( a [ 0 ] ) ;
close ( b [ 1 ] ) ;
imap - > sock - > rdfd = b [ 0 ] ;
imap - > sock - > wrfd = a [ 1 ] ;
puts ( " ok " ) ;
}
else
{
memset ( & addr , 0 , sizeof ( addr ) ) ;
addr . sin_port = htons ( box - > port ) ;
addr . sin_family = AF_INET ;
@ -639,11 +682,38 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap)
}
puts ( " ok " ) ;
imap - > sock - > fd = s ;
imap - > sock - > rdfd = s ;
imap - > sock - > wrfd = s ;
}
}
do
{
/* read the greeting string */
if ( buffer_gets ( imap - > buf , & rsp ) )
{
puts ( " Error, no greeting response " ) ;
ret = - 1 ;
break ;
}
if ( Verbose )
puts ( rsp ) ;
arg = next_arg ( & rsp ) ;
if ( ! arg | | * arg ! = ' * ' | | ( arg = next_arg ( & rsp ) ) = = NULL )
{
puts ( " Error, invalid greeting response " ) ;
ret = - 1 ;
break ;
}
if ( ! strcmp ( " PREAUTH " , arg ) )
preauth = 1 ;
else if ( strcmp ( " OK " , arg ) ! = 0 )
{
puts ( " Error, unknown greeting response " ) ;
ret = - 1 ;
break ;
}
/* if we are reusing the existing connection, we can skip the
* authentication steps .
*/
@ -691,7 +761,7 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap)
}
imap - > sock - > ssl = SSL_new ( SSLContext ) ;
SSL_set_fd ( imap - > sock - > ssl , imap - > sock - > fd ) ;
SSL_set_fd ( imap - > sock - > ssl , imap - > sock - > rd fd) ;
ret = SSL_connect ( imap - > sock - > ssl ) ;
if ( ret < = 0 )
{
@ -721,6 +791,8 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap)
break ;
# endif
if ( ! preauth )
{
puts ( " Logging in... " ) ;
# if HAVE_LIBSSL
if ( imap - > have_cram )
@ -754,6 +826,7 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap)
break ;
}
}
}
/* get NAMESPACE info */
if ( box - > use_namespace & & imap - > have_namespace )
@ -773,9 +846,7 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap)
fputs ( " Selecting mailbox... " , stdout ) ;
fflush ( stdout ) ;
if (
( ret =
imap_exec ( imap , " SELECT \" %s%s \" " , imap - > prefix , box - > box ) ) )
if ( ( ret = imap_exec ( imap , " SELECT \" %s%s \" " , imap - > prefix , box - > box ) ) )
break ;
printf ( " %d messages, %d recent \n " , imap - > count , imap - > recent ) ;
@ -804,7 +875,9 @@ imap_close (imap_t * imap)
if ( imap )
{
imap_exec ( imap , " LOGOUT " ) ;
close ( imap - > sock - > fd ) ;
close ( imap - > sock - > rdfd ) ;
if ( imap - > sock - > rdfd ! = imap - > sock - > wrfd )
close ( imap - > sock - > wrfd ) ;
free ( imap - > sock ) ;
free ( imap - > buf ) ;
free_message ( imap - > msgs ) ;