|
@@ -266,7 +266,7 @@ done_imap_cmd( imap_store_t *ctx, struct imap_cmd *cmd, int response )
|
|
free( cmd );
|
|
free( cmd );
|
|
}
|
|
}
|
|
|
|
|
|
-static int
|
|
|
|
|
|
+static void
|
|
send_imap_cmd( imap_store_t *ctx, struct imap_cmd *cmd )
|
|
send_imap_cmd( imap_store_t *ctx, struct imap_cmd *cmd )
|
|
{
|
|
{
|
|
int bufl, litplus, iovcnt = 1;
|
|
int bufl, litplus, iovcnt = 1;
|
|
@@ -312,19 +312,13 @@ send_imap_cmd( imap_store_t *ctx, struct imap_cmd *cmd )
|
|
iov[2].takeOwn = KeepOwn;
|
|
iov[2].takeOwn = KeepOwn;
|
|
iovcnt = 3;
|
|
iovcnt = 3;
|
|
}
|
|
}
|
|
- if (socket_write( &ctx->conn, iov, iovcnt ) < 0)
|
|
|
|
- goto bail;
|
|
|
|
|
|
+ socket_write( &ctx->conn, iov, iovcnt );
|
|
if (cmd->param.to_trash && ctx->trashnc == TrashUnknown)
|
|
if (cmd->param.to_trash && ctx->trashnc == TrashUnknown)
|
|
ctx->trashnc = TrashChecking;
|
|
ctx->trashnc = TrashChecking;
|
|
cmd->next = 0;
|
|
cmd->next = 0;
|
|
*ctx->in_progress_append = cmd;
|
|
*ctx->in_progress_append = cmd;
|
|
ctx->in_progress_append = &cmd->next;
|
|
ctx->in_progress_append = &cmd->next;
|
|
ctx->num_in_progress++;
|
|
ctx->num_in_progress++;
|
|
- return 0;
|
|
|
|
-
|
|
|
|
- bail:
|
|
|
|
- done_imap_cmd( ctx, cmd, RESP_CANCEL );
|
|
|
|
- return -1;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
static int
|
|
static int
|
|
@@ -346,11 +340,10 @@ flush_imap_cmds( imap_store_t *ctx )
|
|
{
|
|
{
|
|
struct imap_cmd *cmd;
|
|
struct imap_cmd *cmd;
|
|
|
|
|
|
- while ((cmd = ctx->pending) && cmd_submittable( ctx, cmd )) {
|
|
|
|
|
|
+ if ((cmd = ctx->pending) && cmd_submittable( ctx, cmd )) {
|
|
if (!(ctx->pending = cmd->next))
|
|
if (!(ctx->pending = cmd->next))
|
|
ctx->pending_append = &ctx->pending;
|
|
ctx->pending_append = &ctx->pending;
|
|
- if (send_imap_cmd( ctx, cmd ) < 0)
|
|
|
|
- return -1;
|
|
|
|
|
|
+ send_imap_cmd( ctx, cmd );
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -379,7 +372,7 @@ cancel_submitted_imap_cmds( imap_store_t *ctx )
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static int
|
|
|
|
|
|
+static void
|
|
submit_imap_cmd( imap_store_t *ctx, struct imap_cmd *cmd )
|
|
submit_imap_cmd( imap_store_t *ctx, struct imap_cmd *cmd )
|
|
{
|
|
{
|
|
assert( ctx );
|
|
assert( ctx );
|
|
@@ -396,10 +389,9 @@ submit_imap_cmd( imap_store_t *ctx, struct imap_cmd *cmd )
|
|
*ctx->pending_append = cmd;
|
|
*ctx->pending_append = cmd;
|
|
ctx->pending_append = &cmd->next;
|
|
ctx->pending_append = &cmd->next;
|
|
}
|
|
}
|
|
- return 0;
|
|
|
|
|
|
+ } else {
|
|
|
|
+ send_imap_cmd( ctx, cmd );
|
|
}
|
|
}
|
|
-
|
|
|
|
- return send_imap_cmd( ctx, cmd );
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/* Minimal printf() replacement that supports an %\s format sequence to print backslash-escaped
|
|
/* Minimal printf() replacement that supports an %\s format sequence to print backslash-escaped
|
|
@@ -484,7 +476,7 @@ imap_vprintf( const char *fmt, va_list ap )
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static int
|
|
|
|
|
|
+static void
|
|
imap_exec( imap_store_t *ctx, struct imap_cmd *cmdp,
|
|
imap_exec( imap_store_t *ctx, struct imap_cmd *cmdp,
|
|
void (*done)( imap_store_t *ctx, struct imap_cmd *cmd, int response ),
|
|
void (*done)( imap_store_t *ctx, struct imap_cmd *cmd, int response ),
|
|
const char *fmt, ... )
|
|
const char *fmt, ... )
|
|
@@ -497,7 +489,7 @@ imap_exec( imap_store_t *ctx, struct imap_cmd *cmdp,
|
|
va_start( ap, fmt );
|
|
va_start( ap, fmt );
|
|
cmdp->cmd = imap_vprintf( fmt, ap );
|
|
cmdp->cmd = imap_vprintf( fmt, ap );
|
|
va_end( ap );
|
|
va_end( ap );
|
|
- return submit_imap_cmd( ctx, cmdp );
|
|
|
|
|
|
+ submit_imap_cmd( ctx, cmdp );
|
|
}
|
|
}
|
|
|
|
|
|
static void
|
|
static void
|
|
@@ -1332,8 +1324,7 @@ imap_socket_read( void *aux )
|
|
iov[1].buf = "\r\n";
|
|
iov[1].buf = "\r\n";
|
|
iov[1].len = 2;
|
|
iov[1].len = 2;
|
|
iov[1].takeOwn = KeepOwn;
|
|
iov[1].takeOwn = KeepOwn;
|
|
- if (socket_write( &ctx->conn, iov, 2 ) < 0)
|
|
|
|
- return;
|
|
|
|
|
|
+ socket_write( &ctx->conn, iov, 2 );
|
|
} else if (cmdp->param.cont) {
|
|
} else if (cmdp->param.cont) {
|
|
if (cmdp->param.cont( ctx, cmdp, cmd ))
|
|
if (cmdp->param.cont( ctx, cmdp, cmd ))
|
|
return;
|
|
return;
|
|
@@ -1369,9 +1360,8 @@ imap_socket_read( void *aux )
|
|
cmd2->orig_cmd = cmdp;
|
|
cmd2->orig_cmd = cmdp;
|
|
cmd2->gen.param.high_prio = 1;
|
|
cmd2->gen.param.high_prio = 1;
|
|
p = strchr( cmdp->cmd, '"' );
|
|
p = strchr( cmdp->cmd, '"' );
|
|
- if (imap_exec( ctx, &cmd2->gen, get_cmd_result_p2,
|
|
|
|
- "CREATE %.*s", imap_strchr( p + 1, '"' ) - p + 1, p ) < 0)
|
|
|
|
- return;
|
|
|
|
|
|
+ imap_exec( ctx, &cmd2->gen, get_cmd_result_p2,
|
|
|
|
+ "CREATE %.*s", imap_strchr( p + 1, '"' ) - p + 1, p );
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
resp = RESP_NO;
|
|
resp = RESP_NO;
|
|
@@ -1402,8 +1392,7 @@ imap_socket_read( void *aux )
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (flush_imap_cmds( ctx ) < 0)
|
|
|
|
- return;
|
|
|
|
|
|
+ flush_imap_cmds( ctx );
|
|
}
|
|
}
|
|
imap_invoke_bad_callback( ctx );
|
|
imap_invoke_bad_callback( ctx );
|
|
}
|
|
}
|
|
@@ -1921,7 +1910,8 @@ do_sasl_auth( imap_store_t *ctx, struct imap_cmd *cmdp ATTR_UNUSED, const char *
|
|
iov[iovcnt].len = 2;
|
|
iov[iovcnt].len = 2;
|
|
iov[iovcnt].takeOwn = KeepOwn;
|
|
iov[iovcnt].takeOwn = KeepOwn;
|
|
iovcnt++;
|
|
iovcnt++;
|
|
- return socket_write( &ctx->conn, iov, iovcnt );
|
|
|
|
|
|
+ socket_write( &ctx->conn, iov, iovcnt );
|
|
|
|
+ return 0;
|
|
|
|
|
|
bail:
|
|
bail:
|
|
imap_open_store_bail( ctx, FAIL_FINAL );
|
|
imap_open_store_bail( ctx, FAIL_FINAL );
|
|
@@ -2281,7 +2271,7 @@ imap_prepare_load_box( store_t *gctx, int opts )
|
|
gctx->opts = opts;
|
|
gctx->opts = opts;
|
|
}
|
|
}
|
|
|
|
|
|
-static int imap_submit_load( imap_store_t *, const char *, int, struct imap_cmd_refcounted_state * );
|
|
|
|
|
|
+static void imap_submit_load( imap_store_t *, const char *, int, struct imap_cmd_refcounted_state * );
|
|
|
|
|
|
static void
|
|
static void
|
|
imap_load_box( store_t *gctx, int minuid, int maxuid, int newuid, int *excs, int nexcs,
|
|
imap_load_box( store_t *gctx, int minuid, int maxuid, int newuid, int *excs, int nexcs,
|
|
@@ -2308,16 +2298,14 @@ imap_load_box( store_t *gctx, int minuid, int maxuid, int newuid, int *excs, int
|
|
if (i != j)
|
|
if (i != j)
|
|
bl += sprintf( buf + bl, ":%d", excs[i] );
|
|
bl += sprintf( buf + bl, ":%d", excs[i] );
|
|
}
|
|
}
|
|
- if (imap_submit_load( ctx, buf, 0, sts ) < 0)
|
|
|
|
- goto done;
|
|
|
|
|
|
+ imap_submit_load( ctx, buf, 0, sts );
|
|
}
|
|
}
|
|
if (maxuid == INT_MAX)
|
|
if (maxuid == INT_MAX)
|
|
maxuid = ctx->gen.uidnext ? ctx->gen.uidnext - 1 : 1000000000;
|
|
maxuid = ctx->gen.uidnext ? ctx->gen.uidnext - 1 : 1000000000;
|
|
if (maxuid >= minuid) {
|
|
if (maxuid >= minuid) {
|
|
if ((ctx->gen.opts & OPEN_FIND) && minuid < newuid) {
|
|
if ((ctx->gen.opts & OPEN_FIND) && minuid < newuid) {
|
|
sprintf( buf, "%d:%d", minuid, newuid - 1 );
|
|
sprintf( buf, "%d:%d", minuid, newuid - 1 );
|
|
- if (imap_submit_load( ctx, buf, 0, sts ) < 0)
|
|
|
|
- goto done;
|
|
|
|
|
|
+ imap_submit_load( ctx, buf, 0, sts );
|
|
if (newuid > maxuid)
|
|
if (newuid > maxuid)
|
|
goto done;
|
|
goto done;
|
|
sprintf( buf, "%d:%d", newuid, maxuid );
|
|
sprintf( buf, "%d:%d", newuid, maxuid );
|
|
@@ -2332,14 +2320,14 @@ imap_load_box( store_t *gctx, int minuid, int maxuid, int newuid, int *excs, int
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static int
|
|
|
|
|
|
+static void
|
|
imap_submit_load( imap_store_t *ctx, const char *buf, int tuids, struct imap_cmd_refcounted_state *sts )
|
|
imap_submit_load( imap_store_t *ctx, const char *buf, int tuids, struct imap_cmd_refcounted_state *sts )
|
|
{
|
|
{
|
|
- return imap_exec( ctx, imap_refcounted_new_cmd( sts ), imap_refcounted_done_box,
|
|
|
|
- "UID FETCH %s (UID%s%s%s)", buf,
|
|
|
|
- (ctx->gen.opts & OPEN_FLAGS) ? " FLAGS" : "",
|
|
|
|
- (ctx->gen.opts & OPEN_SIZE) ? " RFC822.SIZE" : "",
|
|
|
|
- tuids ? " BODY.PEEK[HEADER.FIELDS (X-TUID)]" : "");
|
|
|
|
|
|
+ imap_exec( ctx, imap_refcounted_new_cmd( sts ), imap_refcounted_done_box,
|
|
|
|
+ "UID FETCH %s (UID%s%s%s)", buf,
|
|
|
|
+ (ctx->gen.opts & OPEN_FLAGS) ? " FLAGS" : "",
|
|
|
|
+ (ctx->gen.opts & OPEN_SIZE) ? " RFC822.SIZE" : "",
|
|
|
|
+ tuids ? " BODY.PEEK[HEADER.FIELDS (X-TUID)]" : "");
|
|
}
|
|
}
|
|
|
|
|
|
/******************* imap_fetch_msg *******************/
|
|
/******************* imap_fetch_msg *******************/
|
|
@@ -2396,15 +2384,15 @@ imap_make_flags( int flags, char *buf )
|
|
return d;
|
|
return d;
|
|
}
|
|
}
|
|
|
|
|
|
-static int
|
|
|
|
|
|
+static void
|
|
imap_flags_helper( imap_store_t *ctx, int uid, char what, int flags,
|
|
imap_flags_helper( imap_store_t *ctx, int uid, char what, int flags,
|
|
struct imap_cmd_refcounted_state *sts )
|
|
struct imap_cmd_refcounted_state *sts )
|
|
{
|
|
{
|
|
char buf[256];
|
|
char buf[256];
|
|
|
|
|
|
buf[imap_make_flags( flags, buf )] = 0;
|
|
buf[imap_make_flags( flags, buf )] = 0;
|
|
- return imap_exec( ctx, imap_refcounted_new_cmd( sts ), imap_set_flags_p2,
|
|
|
|
- "UID STORE %d %cFLAGS.SILENT %s", uid, what, buf );
|
|
|
|
|
|
+ imap_exec( ctx, imap_refcounted_new_cmd( sts ), imap_set_flags_p2,
|
|
|
|
+ "UID STORE %d %cFLAGS.SILENT %s", uid, what, buf );
|
|
}
|
|
}
|
|
|
|
|
|
static void
|
|
static void
|
|
@@ -2422,8 +2410,10 @@ imap_set_msg_flags( store_t *gctx, message_t *msg, int uid, int add, int del,
|
|
}
|
|
}
|
|
if (add || del) {
|
|
if (add || del) {
|
|
struct imap_cmd_refcounted_state *sts = imap_refcounted_new_state( cb, aux );
|
|
struct imap_cmd_refcounted_state *sts = imap_refcounted_new_state( cb, aux );
|
|
- if ((add && imap_flags_helper( ctx, uid, '+', add, sts ) < 0) ||
|
|
|
|
- (del && imap_flags_helper( ctx, uid, '-', del, sts ) < 0)) {}
|
|
|
|
|
|
+ if (add)
|
|
|
|
+ imap_flags_helper( ctx, uid, '+', add, sts );
|
|
|
|
+ if (del)
|
|
|
|
+ imap_flags_helper( ctx, uid, '-', del, sts );
|
|
imap_refcounted_done( sts );
|
|
imap_refcounted_done( sts );
|
|
} else {
|
|
} else {
|
|
cb( DRV_OK, aux );
|
|
cb( DRV_OK, aux );
|
|
@@ -2474,9 +2464,8 @@ imap_close_box( store_t *gctx,
|
|
}
|
|
}
|
|
if (!bl)
|
|
if (!bl)
|
|
break;
|
|
break;
|
|
- if (imap_exec( ctx, imap_refcounted_new_cmd( sts ), imap_refcounted_done_box,
|
|
|
|
- "UID EXPUNGE %s", buf ) < 0)
|
|
|
|
- break;
|
|
|
|
|
|
+ imap_exec( ctx, imap_refcounted_new_cmd( sts ), imap_refcounted_done_box,
|
|
|
|
+ "UID EXPUNGE %s", buf );
|
|
}
|
|
}
|
|
imap_refcounted_done( sts );
|
|
imap_refcounted_done( sts );
|
|
} else {
|
|
} else {
|
|
@@ -2617,13 +2606,12 @@ imap_list_store( store_t *gctx, int flags,
|
|
imap_store_t *ctx = (imap_store_t *)gctx;
|
|
imap_store_t *ctx = (imap_store_t *)gctx;
|
|
struct imap_cmd_refcounted_state *sts = imap_refcounted_new_state( cb, aux );
|
|
struct imap_cmd_refcounted_state *sts = imap_refcounted_new_state( cb, aux );
|
|
|
|
|
|
- if (((flags & LIST_PATH) && (!(flags & LIST_INBOX) || !is_inbox( ctx, ctx->prefix, -1 )) &&
|
|
|
|
- imap_exec( ctx, imap_refcounted_new_cmd( sts ), imap_refcounted_done_box,
|
|
|
|
- "LIST \"\" \"%\\s*\"", ctx->prefix ) < 0) ||
|
|
|
|
- ((flags & LIST_INBOX) && (!(flags & LIST_PATH) || *ctx->prefix) &&
|
|
|
|
- imap_exec( ctx, imap_refcounted_new_cmd( sts ), imap_refcounted_done_box,
|
|
|
|
- "LIST \"\" INBOX*" ) < 0))
|
|
|
|
- {}
|
|
|
|
|
|
+ if ((flags & LIST_PATH) && (!(flags & LIST_INBOX) || !is_inbox( ctx, ctx->prefix, -1 )))
|
|
|
|
+ imap_exec( ctx, imap_refcounted_new_cmd( sts ), imap_refcounted_done_box,
|
|
|
|
+ "LIST \"\" \"%\\s*\"", ctx->prefix );
|
|
|
|
+ if ((flags & LIST_INBOX) && (!(flags & LIST_PATH) || *ctx->prefix))
|
|
|
|
+ imap_exec( ctx, imap_refcounted_new_cmd( sts ), imap_refcounted_done_box,
|
|
|
|
+ "LIST \"\" INBOX*" );
|
|
imap_refcounted_done( sts );
|
|
imap_refcounted_done( sts );
|
|
}
|
|
}
|
|
|
|
|