imap-sync.c revision 5fb3bff645380804c9db2510940c41db6b8fdb01
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen/* Copyright (C) 2002-2004 Timo Sirainen */
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainenimap_sync_init(struct client *client, struct mailbox *box,
39e6fcc3e8b1ccb13087c232cb6bdea04d1a20a4Timo Sirainen enum imap_sync_flags imap_flags, enum mailbox_sync_flags flags)
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen ctx->sync_ctx = mailbox_sync_init(box, flags);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen ctx->mail = mail_alloc(ctx->t, MAIL_FETCH_FLAGS, 0);
bc3698b8892df8003b410daea6f5bbcd20433808Timo Sirainen /* if keyword list changed, send the new list before flag changes */
bc3698b8892df8003b410daea6f5bbcd20433808Timo Sirainen if (mailbox_get_status(ctx->box, STATUS_KEYWORDS, &status) == 0) {
bc3698b8892df8003b410daea6f5bbcd20433808Timo Sirainen if (client_save_keywords(&client->keywords, status.keywords))
bc3698b8892df8003b410daea6f5bbcd20433808Timo Sirainen client_send_mailbox_flags(client, box, status.keywords);
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainenint imap_sync_deinit(struct imap_sync_context *ctx)
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen STATUS_MESSAGES | STATUS_RECENT, &status) < 0 ||
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen ctx->client->messages_count = status.messages;
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen t_strdup_printf("* %u EXISTS", status.messages));
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen if (status.recent != ctx->client->recent_count) {
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen t_strdup_printf("* %u RECENT", status.recent));
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainenint imap_sync_more(struct imap_sync_context *ctx)
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen const char *const *keywords;
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen /* get next one */
68efcccb384f2d6871164b072457e87473502c51Timo Sirainen /* all finished ok */
a54be2bd26d6f0860d194d3aeedfa6b7fc14d24cTimo Sirainen if (ctx->sync_rec.seq2 > ctx->messages_count) {
a54be2bd26d6f0860d194d3aeedfa6b7fc14d24cTimo Sirainen /* don't send change notifications of messages we
a54be2bd26d6f0860d194d3aeedfa6b7fc14d24cTimo Sirainen haven't even announced to client yet */
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen for (; ctx->seq <= ctx->sync_rec.seq2; ctx->seq++) {
39e6fcc3e8b1ccb13087c232cb6bdea04d1a20a4Timo Sirainen if (ctx->imap_flags & IMAP_SYNC_FLAG_SEND_UID) {
68efcccb384f2d6871164b072457e87473502c51Timo Sirainen ret = client_send_line(ctx->client, str_c(str));
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen for (; ctx->seq >= ctx->sync_rec.seq1; ctx->seq--) {
68efcccb384f2d6871164b072457e87473502c51Timo Sirainen ret = client_send_line(ctx->client, str_c(str));
d42c9a8f362b76740418c4f9f9441eb7fc661e57Timo Sirainen /* update only after we're finished, so that
d42c9a8f362b76740418c4f9f9441eb7fc661e57Timo Sirainen the seq2 > messages_count check above
d42c9a8f362b76740418c4f9f9441eb7fc661e57Timo Sirainen doesn't break */
88286b0527bcc0711e312e9db65ca121a45213e3Timo Sirainen /* failure / buffer full */
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainenint imap_sync_nonselected(struct mailbox *box, enum mailbox_sync_flags flags)
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenstatic bool cmd_sync_continue(struct client_command_context *cmd)
88286b0527bcc0711e312e9db65ca121a45213e3Timo Sirainen if ((ret = imap_sync_more(ctx->sync_ctx)) == 0)
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen client_send_untagged_storage_error(cmd->client,
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenbool cmd_sync(struct client_command_context *cmd, enum mailbox_sync_flags flags,
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen enum imap_sync_flags imap_flags, const char *tagline)
294f1a51763015cda0e2d874c5027d6fe7a2cd54Timo Sirainen if ((client_workarounds & WORKAROUND_DELAY_NEWMAIL) != 0 &&
18634dae6e304bac982bb1e0ff1b6b88fc448dbcTimo Sirainen /* expunges might break just as badly as new mail
18634dae6e304bac982bb1e0ff1b6b88fc448dbcTimo Sirainen notifications. besides, currently indexing code doesn't
18634dae6e304bac982bb1e0ff1b6b88fc448dbcTimo Sirainen handle expunges + no-newmail so this is required, unless
18634dae6e304bac982bb1e0ff1b6b88fc448dbcTimo Sirainen we did this only for no-expunges case.. */
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen ctx = p_new(cmd->pool, struct cmd_sync_context, 1);