@ -1628,13 +1628,13 @@ imap_socket_read( void *aux )
resp = parse_list ( ctx , cmd , parse_namespace_rsp ) ;
resp = parse_list ( ctx , cmd , parse_namespace_rsp ) ;
goto listret ;
goto listret ;
} else if ( ( arg1 = next_arg ( & cmd ) ) ) {
} else if ( ( arg1 = next_arg ( & cmd ) ) ) {
if ( ! strcmp ( " EXISTS " , arg1 ) )
if ( ! strcmp ( " EXISTS " , arg1 ) ) {
ctx - > total_msgs = atoi ( arg ) ;
ctx - > total_msgs = atoi ( arg ) ;
else if ( ! strcmp ( " EXPUNGE " , arg1 ) )
} else if ( ! strcmp ( " EXPUNGE " , arg1 ) ) {
ctx - > total_msgs - - ;
ctx - > total_msgs - - ;
else if ( ! strcmp ( " RECENT " , arg1 ) )
} else if ( ! strcmp ( " RECENT " , arg1 ) ) {
ctx - > recent_msgs = atoi ( arg ) ;
ctx - > recent_msgs = atoi ( arg ) ;
else if ( ! strcmp ( " FETCH " , arg1 ) ) {
} else if ( ! strcmp ( " FETCH " , arg1 ) ) {
resp = parse_list ( ctx , cmd , parse_fetch_rsp ) ;
resp = parse_list ( ctx , cmd , parse_fetch_rsp ) ;
goto listret ;
goto listret ;
}
}
@ -1714,8 +1714,9 @@ imap_socket_read( void *aux )
resp = RESP_NO ;
resp = RESP_NO ;
if ( cmdp - > param . failok ) // SELECT
if ( cmdp - > param . failok ) // SELECT
goto doresp ;
goto doresp ;
} else /*if (!strcmp( "BAD", arg ))*/
} else /*if (!strcmp( "BAD", arg ))*/ {
resp = RESP_CANCEL ;
resp = RESP_CANCEL ;
}
error ( " IMAP command '%s' returned an error: %s %s \n " ,
error ( " IMAP command '%s' returned an error: %s %s \n " ,
starts_with ( cmdp - > cmd , - 1 , " LOGIN " , 5 ) ?
starts_with ( cmdp - > cmd , - 1 , " LOGIN " , 5 ) ?
" LOGIN <user> <pass> " :
" LOGIN <user> <pass> " :
@ -1824,11 +1825,12 @@ imap_cancel_unowned( void *gctx )
{
{
imap_store_t * store , * * storep ;
imap_store_t * store , * * storep ;
for ( storep = & unowned ; ( store = * storep ) ; storep = & store - > next )
for ( storep = & unowned ; ( store = * storep ) ; storep = & store - > next ) {
if ( store = = gctx ) {
if ( store = = gctx ) {
* storep = store - > next ;
* storep = store - > next ;
break ;
break ;
}
}
}
imap_cancel_store ( gctx ) ;
imap_cancel_store ( gctx ) ;
}
}
@ -1917,14 +1919,15 @@ imap_alloc_store( store_conf_t *conf, const char *label )
imap_store_t * ctx , * * ctxp ;
imap_store_t * ctx , * * ctxp ;
/* First try to recycle a whole store. */
/* First try to recycle a whole store. */
for ( ctxp = & unowned ; ( ctx = * ctxp ) ; ctxp = & ctx - > next )
for ( ctxp = & unowned ; ( ctx = * ctxp ) ; ctxp = & ctx - > next ) {
if ( ctx - > state = = SST_GOOD & & ctx - > conf = = cfg ) {
if ( ctx - > state = = SST_GOOD & & ctx - > conf = = cfg ) {
* ctxp = ctx - > next ;
* ctxp = ctx - > next ;
goto gotstore ;
goto gotstore ;
}
}
}
/* Then try to recycle a server connection. */
/* Then try to recycle a server connection. */
for ( ctxp = & unowned ; ( ctx = * ctxp ) ; ctxp = & ctx - > next )
for ( ctxp = & unowned ; ( ctx = * ctxp ) ; ctxp = & ctx - > next ) {
if ( ctx - > conf - > server = = srvc ) {
if ( ctx - > conf - > server = = srvc ) {
* ctxp = ctx - > next ;
* ctxp = ctx - > next ;
free_string_list ( ctx - > boxes ) ;
free_string_list ( ctx - > boxes ) ;
@ -1935,6 +1938,7 @@ imap_alloc_store( store_conf_t *conf, const char *label )
ctx - > state = SST_HALF ;
ctx - > state = SST_HALF ;
goto gotsrv ;
goto gotsrv ;
}
}
}
/* Finally, schedule opening a new server connection. */
/* Finally, schedule opening a new server connection. */
ctx = nfcalloc ( sizeof ( * ctx ) ) ;
ctx = nfcalloc ( sizeof ( * ctx ) ) ;
@ -3039,12 +3043,13 @@ imap_make_flags( int flags, char *buf )
const char * s ;
const char * s ;
uint i , d ;
uint i , d ;
for ( i = d = 0 ; i < as ( Flags ) ; i + + )
for ( i = d = 0 ; i < as ( Flags ) ; i + + ) {
if ( flags & ( 1 < < i ) ) {
if ( flags & ( 1 < < i ) ) {
buf [ d + + ] = ' ' ;
buf [ d + + ] = ' ' ;
for ( s = Flags [ i ] ; * s ; s + + )
for ( s = Flags [ i ] ; * s ; s + + )
buf [ d + + ] = * s ;
buf [ d + + ] = * s ;
}
}
}
buf [ 0 ] = ' ( ' ;
buf [ 0 ] = ' ( ' ;
buf [ d + + ] = ' ) ' ;
buf [ d + + ] = ' ) ' ;
return d ;
return d ;
@ -3521,8 +3526,9 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
memset ( & sserver , 0 , sizeof ( sserver ) ) ;
memset ( & sserver , 0 , sizeof ( sserver ) ) ;
server = & sserver ;
server = & sserver ;
type = " IMAP store " ;
type = " IMAP store " ;
} else
} else {
return 0 ;
return 0 ;
}
server - > sconf . timeout = 20 ;
server - > sconf . timeout = 20 ;
# ifdef HAVE_LIBSSL
# ifdef HAVE_LIBSSL
@ -3536,35 +3542,34 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
if ( ! strcasecmp ( " Host " , cfg - > cmd ) ) {
if ( ! strcasecmp ( " Host " , cfg - > cmd ) ) {
/* The imap[s]: syntax is just a backwards compat hack. */
/* The imap[s]: syntax is just a backwards compat hack. */
arg = cfg - > val ;
arg = cfg - > val ;
if ( starts_with ( arg , - 1 , " imap: " , 5 ) )
arg + = 5 ;
# ifdef HAVE_LIBSSL
# ifdef HAVE_LIBSSL
if ( starts_with ( arg , - 1 , " imaps: " , 6 ) ) {
else if ( starts_with ( arg , - 1 , " imaps: " , 6 ) ) {
arg + = 6 ;
arg + = 6 ;
server - > ssl_type = SSL_IMAPS ;
server - > ssl_type = SSL_IMAPS ;
if ( server - > sconf . ssl_versions = = - 1 )
if ( server - > sconf . ssl_versions = = - 1 )
server - > sconf . ssl_versions = TLSv1 | TLSv1_1 | TLSv1_2 | TLSv1_3 ;
server - > sconf . ssl_versions = TLSv1 | TLSv1_1 | TLSv1_2 | TLSv1_3 ;
} else
}
# endif
# endif
if ( starts_with ( arg , - 1 , " imap: " , 5 ) )
arg + = 5 ;
if ( starts_with ( arg , - 1 , " // " , 2 ) )
if ( starts_with ( arg , - 1 , " // " , 2 ) )
arg + = 2 ;
arg + = 2 ;
if ( arg ! = cfg - > val )
if ( arg ! = cfg - > val )
warn ( " %s:%d: Notice: URL notation is deprecated; use a plain host name and possibly 'SSLType IMAPS' instead \n " , cfg - > file , cfg - > line ) ;
warn ( " %s:%d: Notice: URL notation is deprecated; use a plain host name and possibly 'SSLType IMAPS' instead \n " , cfg - > file , cfg - > line ) ;
server - > sconf . host = nfstrdup ( arg ) ;
server - > sconf . host = nfstrdup ( arg ) ;
}
} else if ( ! strcasecmp ( " User " , cfg - > cmd ) ) {
else if ( ! strcasecmp ( " User " , cfg - > cmd ) )
server - > user = nfstrdup ( cfg - > val ) ;
server - > user = nfstrdup ( cfg - > val ) ;
else if ( ! strcasecmp ( " UserCmd " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " UserCmd " , cfg - > cmd ) ) {
server - > user_cmd = nfstrdup ( cfg - > val ) ;
server - > user_cmd = nfstrdup ( cfg - > val ) ;
else if ( ! strcasecmp ( " Pass " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " Pass " , cfg - > cmd ) ) {
server - > pass = nfstrdup ( cfg - > val ) ;
server - > pass = nfstrdup ( cfg - > val ) ;
else if ( ! strcasecmp ( " PassCmd " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " PassCmd " , cfg - > cmd ) ) {
server - > pass_cmd = nfstrdup ( cfg - > val ) ;
server - > pass_cmd = nfstrdup ( cfg - > val ) ;
# ifdef HAVE_MACOS_KEYCHAIN
# ifdef HAVE_MACOS_KEYCHAIN
else if ( ! strcasecmp ( " UseKeychain " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " UseKeychain " , cfg - > cmd ) ) {
server - > use_keychain = parse_bool ( cfg ) ;
server - > use_keychain = parse_bool ( cfg ) ;
# endif
# endif
else if ( ! strcasecmp ( " Port " , cfg - > cmd ) ) {
} else if ( ! strcasecmp ( " Port " , cfg - > cmd ) ) {
int port = parse_int ( cfg ) ;
int port = parse_int ( cfg ) ;
if ( ( unsigned ) port > 0xffff ) {
if ( ( unsigned ) port > 0xffff ) {
error ( " %s:%d: Invalid port number \n " , cfg - > file , cfg - > line ) ;
error ( " %s:%d: Invalid port number \n " , cfg - > file , cfg - > line ) ;
@ -3572,9 +3577,9 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
} else {
} else {
server - > sconf . port = ( ushort ) port ;
server - > sconf . port = ( ushort ) port ;
}
}
} else if ( ! strcasecmp ( " Timeout " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " Timeout " , cfg - > cmd ) ) {
server - > sconf . timeout = parse_int ( cfg ) ;
server - > sconf . timeout = parse_int ( cfg ) ;
else if ( ! strcasecmp ( " PipelineDepth " , cfg - > cmd ) ) {
} else if ( ! strcasecmp ( " PipelineDepth " , cfg - > cmd ) ) {
if ( ( server - > max_in_progress = parse_int ( cfg ) ) < 1 ) {
if ( ( server - > max_in_progress = parse_int ( cfg ) ) < 1 ) {
error ( " %s:%d: PipelineDepth must be at least 1 \n " , cfg - > file , cfg - > line ) ;
error ( " %s:%d: PipelineDepth must be at least 1 \n " , cfg - > file , cfg - > line ) ;
cfg - > err = 1 ;
cfg - > err = 1 ;
@ -3593,9 +3598,8 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
cfg - > err = 1 ;
cfg - > err = 1 ;
gotcap : ;
gotcap : ;
} while ( ( arg = get_arg ( cfg , ARG_OPTIONAL , NULL ) ) ) ;
} while ( ( arg = get_arg ( cfg , ARG_OPTIONAL , NULL ) ) ) ;
}
# ifdef HAVE_LIBSSL
# ifdef HAVE_LIBSSL
else if ( ! strcasecmp ( " CertificateFile " , cfg - > cmd ) ) {
} else if ( ! strcasecmp ( " CertificateFile " , cfg - > cmd ) ) {
server - > sconf . cert_file = expand_strdup ( cfg - > val ) ;
server - > sconf . cert_file = expand_strdup ( cfg - > val ) ;
if ( access ( server - > sconf . cert_file , R_OK ) ) {
if ( access ( server - > sconf . cert_file , R_OK ) ) {
sys_error ( " %s:%d: CertificateFile '%s' " ,
sys_error ( " %s:%d: CertificateFile '%s' " ,
@ -3653,34 +3657,34 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
cfg - > err = 1 ;
cfg - > err = 1 ;
}
}
} while ( ( arg = get_arg ( cfg , ARG_OPTIONAL , NULL ) ) ) ;
} while ( ( arg = get_arg ( cfg , ARG_OPTIONAL , NULL ) ) ) ;
} else if ( ! strcasecmp ( " RequireSSL " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " RequireSSL " , cfg - > cmd ) ) {
require_ssl = parse_bool ( cfg ) ;
require_ssl = parse_bool ( cfg ) ;
else if ( ! strcasecmp ( " UseIMAPS " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " UseIMAPS " , cfg - > cmd ) ) {
use_imaps = parse_bool ( cfg ) ;
use_imaps = parse_bool ( cfg ) ;
else if ( ! strcasecmp ( " UseSSLv2 " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " UseSSLv2 " , cfg - > cmd ) ) {
warn ( " Warning: UseSSLv2 is no longer supported \n " ) ;
warn ( " Warning: UseSSLv2 is no longer supported \n " ) ;
else if ( ! strcasecmp ( " UseSSLv3 " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " UseSSLv3 " , cfg - > cmd ) ) {
warn ( " Warning: UseSSLv3 is no longer supported \n " ) ;
warn ( " Warning: UseSSLv3 is no longer supported \n " ) ;
else if ( ! strcasecmp ( " UseTLSv1 " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " UseTLSv1 " , cfg - > cmd ) ) {
use_tlsv1 = parse_bool ( cfg ) ;
use_tlsv1 = parse_bool ( cfg ) ;
else if ( ! strcasecmp ( " UseTLSv1.1 " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " UseTLSv1.1 " , cfg - > cmd ) ) {
use_tlsv11 = parse_bool ( cfg ) ;
use_tlsv11 = parse_bool ( cfg ) ;
else if ( ! strcasecmp ( " UseTLSv1.2 " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " UseTLSv1.2 " , cfg - > cmd ) ) {
use_tlsv12 = parse_bool ( cfg ) ;
use_tlsv12 = parse_bool ( cfg ) ;
else if ( ! strcasecmp ( " UseTLSv1.3 " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " UseTLSv1.3 " , cfg - > cmd ) ) {
use_tlsv13 = parse_bool ( cfg ) ;
use_tlsv13 = parse_bool ( cfg ) ;
# endif
# endif
else if ( ! strcasecmp ( " AuthMech " , cfg - > cmd ) | |
} else if ( ! strcasecmp ( " AuthMech " , cfg - > cmd ) | |
! strcasecmp ( " AuthMechs " , cfg - > cmd ) ) {
! strcasecmp ( " AuthMechs " , cfg - > cmd ) ) {
arg = cfg - > val ;
arg = cfg - > val ;
do
do {
add_string_list ( & server - > auth_mechs , arg ) ;
add_string_list ( & server - > auth_mechs , arg ) ;
while ( ( arg = get_arg ( cfg , ARG_OPTIONAL , NULL ) ) ) ;
} while ( ( arg = get_arg ( cfg , ARG_OPTIONAL , NULL ) ) ) ;
} else if ( ! strcasecmp ( " RequireCRAM " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " RequireCRAM " , cfg - > cmd ) ) {
require_cram = parse_bool ( cfg ) ;
require_cram = parse_bool ( cfg ) ;
else if ( ! strcasecmp ( " Tunnel " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " Tunnel " , cfg - > cmd ) ) {
server - > sconf . tunnel = nfstrdup ( cfg - > val ) ;
server - > sconf . tunnel = nfstrdup ( cfg - > val ) ;
else if ( store ) {
} else if ( store ) {
if ( ! strcasecmp ( " Account " , cfg - > cmd ) ) {
if ( ! strcasecmp ( " Account " , cfg - > cmd ) ) {
for ( srv = servers ; srv ; srv = srv - > next )
for ( srv = servers ; srv ; srv = srv - > next )
if ( srv - > name & & ! strcmp ( srv - > name , cfg - > val ) )
if ( srv - > name & & ! strcmp ( srv - > name , cfg - > val ) )
@ -3690,21 +3694,22 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
continue ;
continue ;
gotsrv :
gotsrv :
store - > server = srv ;
store - > server = srv ;
} else if ( ! strcasecmp ( " UseNamespace " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " UseNamespace " , cfg - > cmd ) ) {
store - > use_namespace = parse_bool ( cfg ) ;
store - > use_namespace = parse_bool ( cfg ) ;
else if ( ! strcasecmp ( " SubscribedOnly " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " SubscribedOnly " , cfg - > cmd ) ) {
store - > use_lsub = parse_bool ( cfg ) ;
store - > use_lsub = parse_bool ( cfg ) ;
else if ( ! strcasecmp ( " Path " , cfg - > cmd ) )
} else if ( ! strcasecmp ( " Path " , cfg - > cmd ) ) {
store - > path = nfstrdup ( cfg - > val ) ;
store - > path = nfstrdup ( cfg - > val ) ;
else if ( ! strcasecmp ( " PathDelimiter " , cfg - > cmd ) ) {
} else if ( ! strcasecmp ( " PathDelimiter " , cfg - > cmd ) ) {
if ( strlen ( cfg - > val ) ! = 1 ) {
if ( strlen ( cfg - > val ) ! = 1 ) {
error ( " %s:%d: Path delimiter must be exactly one character long \n " , cfg - > file , cfg - > line ) ;
error ( " %s:%d: Path delimiter must be exactly one character long \n " , cfg - > file , cfg - > line ) ;
cfg - > err = 1 ;
cfg - > err = 1 ;
continue ;
continue ;
}
}
store - > delimiter = cfg - > val [ 0 ] ;
store - > delimiter = cfg - > val [ 0 ] ;
} else
} else {
parse_generic_store ( & store - > gen , cfg , " IMAPStore " ) ;
parse_generic_store ( & store - > gen , cfg , " IMAPStore " ) ;
}
continue ;
continue ;
} else {
} else {
error ( " %s:%d: keyword '%s' is not recognized in IMAPAccount sections \n " ,
error ( " %s:%d: keyword '%s' is not recognized in IMAPAccount sections \n " ,
@ -3784,13 +3789,14 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
}
}
if ( ! server - > auth_mechs )
if ( ! server - > auth_mechs )
add_string_list ( & server - > auth_mechs , " * " ) ;
add_string_list ( & server - > auth_mechs , " * " ) ;
if ( ! server - > sconf . port )
if ( ! server - > sconf . port ) {
server - > sconf . port =
server - > sconf . port =
# ifdef HAVE_LIBSSL
# ifdef HAVE_LIBSSL
server - > ssl_type = = SSL_IMAPS ? 993 :
server - > ssl_type = = SSL_IMAPS ? 993 :
# endif
# endif
143 ;
143 ;
}
}
}
if ( store ) {
if ( store ) {
if ( ! store - > server ) {
if ( ! store - > server ) {
store - > server = nfmalloc ( sizeof ( sserver ) ) ;
store - > server = nfmalloc ( sizeof ( sserver ) ) ;