imap-sync.c revision 47a5a7e8296f3b8f2fac9a0659d4de3f2723ba4a
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */
ccd83028a34cc6e2b6370eb7ecf1cf25e717c2d3Timo Sirainenstatic void uids_to_seqs(struct mailbox *box, ARRAY_TYPE(seq_range) *uids)
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen mailbox_get_seq_range(box, range->seq1, range->seq2,
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen /* since we have to notify about expunged messages,
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen we expect that all the referenced UIDs exist */
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen i_assert(seq2 - seq1 == range->seq2 - range->seq1);
923eb3dde28e4d8841c14fd6b4a69635b7070c3eTimo Sirainen /* replace uids with seqs */
150e64c376365becf1ec5c9d45912ecb840eea96Timo Sirainenstatic int search_update_fetch_more(const struct imap_search_update *update)
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen if ((ret = imap_fetch_more_no_lock_update(update->fetch_ctx)) <= 0)
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen /* finished the FETCH */
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainenimap_sync_send_fetch_to_search_update(struct imap_sync_context *ctx,
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen if (array_count(&ctx->search_adds) == 0 || !ctx->have_new_mails)
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen arg = mail_search_build_add(search_args, SEARCH_UIDSET);
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen p_array_init(&arg->value.seqset, search_args->pool, 1);
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen /* find the newly appended messages: ctx->messages_count is the message
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen count before new messages found by sync, client->messages_count is
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen the number of messages after. */
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen seq_range_array_add_range(&seqs, ctx->messages_count+1,
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen mailbox_get_uid_range(ctx->client->mailbox, &seqs, &arg->value.seqset);
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen /* remove messages not in the search_adds list */
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen seq_range_array_intersect(&arg->value.seqset, &ctx->search_adds);
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen imap_fetch_begin(update->fetch_ctx, ctx->client->mailbox, search_args);
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainenimap_sync_send_search_update(struct imap_sync_context *ctx,
303a87c31cb4aa198326694e231df53a043e63c7Timo Sirainen mailbox_search_result_sync(update->result, &ctx->search_removes,
f2bd9e507b8befdd95a983f86664febf5c19bd95Timo Sirainen i_assert(array_count(&ctx->search_adds) == 0 || !removes_only);
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen ret = imap_sync_send_fetch_to_search_update(ctx, update);
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen /* convert to sequences */
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen uids_to_seqs(ctx->client->mailbox, &ctx->search_removes);
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen uids_to_seqs(ctx->client->mailbox, &ctx->search_adds);
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen imap_write_seq_range(cmd, &ctx->search_removes);
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen o_stream_nsend(ctx->client->output, str_data(cmd), str_len(cmd));
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainenimap_sync_send_search_updates(struct imap_sync_context *ctx, bool removes_only)
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen unsigned int i, count;
06e72c658de3ce1252594b151313df90acf73271Timo Sirainen if (!array_is_created(&ctx->client->search_updates))
06e72c658de3ce1252594b151313df90acf73271Timo Sirainen if (!array_is_created(&ctx->search_removes)) {
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen updates = array_get(&ctx->client->search_updates, &count);
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen for (i = ctx->search_update_idx; i < count; i++) {
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen ret = imap_sync_send_search_update(ctx, &updates[i],
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainenimap_sync_init(struct client *client, struct mailbox *box,
2584e86cc2d8c31ba30a4109cf4ba09d1e37e28aTimo Sirainen enum imap_sync_flags imap_flags, enum mailbox_sync_flags flags)
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen /* NOTIFY enabled without SELECTED-DELAYED */
07974f50bd55b06fd6d465f2c0e491794786e2faTimo Sirainen /* make sure user can't DoS the system by causing Dovecot to create
07974f50bd55b06fd6d465f2c0e491794786e2faTimo Sirainen tons of useless namespaces. */
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen mail_user_drop_useless_namespaces(client->user);
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen ctx->sync_ctx = mailbox_sync_init(box, flags);
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen ctx->t = mailbox_transaction_begin(box, 0, "Mailbox sync");
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen ctx->mail = mail_alloc(ctx->t, MAIL_FETCH_FLAGS, NULL);
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen i_array_init(&ctx->tmp_keywords, client->keywords.announce_count + 8);
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen if ((client->enabled_features & MAILBOX_FEATURE_QRESYNC) != 0) {
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen /* always send UIDs in FETCH replies */
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen /* send search updates the first time after sync is initialized.
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen it now contains expunged messages that must be sent before
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen EXPUNGE replies. */
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen if (imap_sync_send_search_updates(ctx, TRUE) == 0)
2584e86cc2d8c31ba30a4109cf4ba09d1e37e28aTimo Sirainenimap_sync_send_highestmodseq(struct imap_sync_context *ctx,
2584e86cc2d8c31ba30a4109cf4ba09d1e37e28aTimo Sirainen client->highest_fetch_modseq > client->sync_last_full_modseq) {
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen /* if client updates highest-modseq using returned MODSEQs
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen it loses expunges. try to avoid this by sending it a lower
f5a24412980cb19b07cb0cd12dba75886f281875Timo Sirainen pre-expunge HIGHESTMODSEQ reply. */
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen } else if (!ctx->sync_status.sync_delayed_expunges &&
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen ctx->status.highest_modseq > client->sync_last_full_modseq &&
51327f2489a4e0e615eb9f7d921473cf8512bb79Timo Sirainen ctx->status.highest_modseq > client->highest_fetch_modseq) {
51327f2489a4e0e615eb9f7d921473cf8512bb79Timo Sirainen /* we've probably sent some VANISHED or EXISTS replies which
51327f2489a4e0e615eb9f7d921473cf8512bb79Timo Sirainen increased the highest-modseq. notify the client about
17da42c31202b1b3e7e308121ea17d922c24da1bTimo Sirainen /* no sending */
bd74402ca1a39ec303075fefb1212d7e18a71531Timo Sirainen } else if (sync_cmd->sync != NULL && /* IDLE doesn't have ->sync */
bd74402ca1a39ec303075fefb1212d7e18a71531Timo Sirainen sync_cmd->sync->tagline != NULL && /* NOTIFY doesn't have tagline */
ef11d3930c3602fc86349a4e3a53442df470b601Timo Sirainen strncmp(sync_cmd->sync->tagline, "OK ", 3) == 0 &&
c6ae908f6a2313573625d782bdd4e0ff3882c44aTimo Sirainen /* modify the tagged reply directly */
17da42c31202b1b3e7e308121ea17d922c24da1bTimo Sirainen sync_cmd->sync->tagline = p_strdup_printf(sync_cmd->pool,
ef11d3930c3602fc86349a4e3a53442df470b601Timo Sirainen /* send an untagged OK reply */
ef11d3930c3602fc86349a4e3a53442df470b601Timo Sirainen if (!ctx->sync_status.sync_delayed_expunges) {
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen /* no delayed expunges, remember this for future */
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen client->sync_last_full_modseq = ctx->status.highest_modseq;
2584e86cc2d8c31ba30a4109cf4ba09d1e37e28aTimo Sirainenstatic int imap_sync_finish(struct imap_sync_context *ctx, bool aborting)
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen /* the transaction is used only for fetching modseqs/flags.
ccb77e2f63626ec46e5745ef4f38baa8e8e504fcTimo Sirainen it can't really fail.. */
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen if (mailbox_sync_deinit(&ctx->sync_ctx, &ctx->sync_status) < 0 ||
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen mailbox_get_open_status(ctx->box, STATUS_UIDVALIDITY |
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen if (ctx->status.uidvalidity != client->uidvalidity) {
8039af9679af6fb56116b353fe44f7dd4c08f031Timo Sirainen /* most clients would get confused by this. disconnect them. */
a4bc2c3962b94f83c7bb7bebe7af364f4dee7883Timo Sirainen "Mailbox UIDVALIDITY changed");
a4bc2c3962b94f83c7bb7bebe7af364f4dee7883Timo Sirainen "IMAP session state is inconsistent, please relogin.");
ccd83028a34cc6e2b6370eb7ecf1cf25e717c2d3Timo Sirainen /* we can't trust status information anymore, so don't try to
ccd83028a34cc6e2b6370eb7ecf1cf25e717c2d3Timo Sirainen sync message counts. */
a4bc2c3962b94f83c7bb7bebe7af364f4dee7883Timo Sirainen if (ctx->status.messages < ctx->messages_count)
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen if (ctx->status.messages != ctx->messages_count &&
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen t_strdup_printf("* %u EXISTS", ctx->status.messages));
8039af9679af6fb56116b353fe44f7dd4c08f031Timo Sirainen if (ctx->status.recent != client->recent_count &&
a4bc2c3962b94f83c7bb7bebe7af364f4dee7883Timo Sirainen t_strdup_printf("* %u RECENT", ctx->status.recent));
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen client->messages_count = ctx->status.messages;
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainenstatic int imap_sync_notify_more(struct imap_sync_context *ctx)
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen if (ctx->have_new_mails && ctx->client->notify_ctx != NULL) {
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen /* send FETCH replies for the new mails */
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen if ((ret = imap_client_notify_newmails(ctx->client)) == 0)
923eb3dde28e4d8841c14fd6b4a69635b7070c3eTimo Sirainen /* send search updates the second time after syncing in done.
923eb3dde28e4d8841c14fd6b4a69635b7070c3eTimo Sirainen now it contains added/removed messages. */
923eb3dde28e4d8841c14fd6b4a69635b7070c3eTimo Sirainen if ((ret = imap_sync_send_search_updates(ctx, FALSE)) < 0)
923eb3dde28e4d8841c14fd6b4a69635b7070c3eTimo Sirainenint imap_sync_deinit(struct imap_sync_context *ctx,
923eb3dde28e4d8841c14fd6b4a69635b7070c3eTimo Sirainen if ((ctx->client->enabled_features & MAILBOX_FEATURE_QRESYNC) != 0 &&
923eb3dde28e4d8841c14fd6b4a69635b7070c3eTimo Sirainenstatic void imap_sync_add_modseq(struct imap_sync_context *ctx, string_t *str)
923eb3dde28e4d8841c14fd6b4a69635b7070c3eTimo Sirainen if (ctx->client->highest_fetch_modseq < modseq)
923eb3dde28e4d8841c14fd6b4a69635b7070c3eTimo Sirainen str_printfa(str, "MODSEQ (%"PRIu64")", modseq);
a4bc2c3962b94f83c7bb7bebe7af364f4dee7883Timo Sirainenstatic int imap_sync_send_flags(struct imap_sync_context *ctx, string_t *str)
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen const char *const *keywords;
0b7651dc6ad21cce8579b5957252ae0daf972668Timo Sirainen keywords = client_get_keyword_names(ctx->client, &ctx->tmp_keywords,
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen if ((ctx->imap_flags & IMAP_SYNC_FLAG_SEND_UID) != 0)
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen if ((ctx->client->enabled_features & MAILBOX_FEATURE_CONDSTORE) != 0 &&
10cfe8a2bdc5ccfc05380689c71c27209327538fTimo Sirainen return client_send_line_next(ctx->client, str_c(str));
a54be2bd26d6f0860d194d3aeedfa6b7fc14d24cTimo Sirainenstatic int imap_sync_send_modseq(struct imap_sync_context *ctx, string_t *str)
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen if ((ctx->imap_flags & IMAP_SYNC_FLAG_SEND_UID) != 0)
88286b0527bcc0711e312e9db65ca121a45213e3Timo Sirainen return client_send_line_next(ctx->client, str_c(str));
88286b0527bcc0711e312e9db65ca121a45213e3Timo Sirainenstatic void imap_sync_vanished(struct imap_sync_context *ctx)
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen unsigned int i, count;
923eb3dde28e4d8841c14fd6b4a69635b7070c3eTimo Sirainen /* Convert expunge sequences to UIDs and send them in VANISHED line. */
923eb3dde28e4d8841c14fd6b4a69635b7070c3eTimo Sirainen for (i = 0; i < count; i++) {
d42c9a8f362b76740418c4f9f9441eb7fc661e57Timo Sirainen for (seq = seqs[i].seq1; seq <= seqs[i].seq2; seq++) {
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen o_stream_nsend(ctx->client->output, str_data(line), str_len(line));
0b7651dc6ad21cce8579b5957252ae0daf972668Timo Sirainenstatic int imap_sync_send_expunges(struct imap_sync_context *ctx, string_t *str)
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen /* NOTIFY: MessageEvent not specified for selected mailbox */
88286b0527bcc0711e312e9db65ca121a45213e3Timo Sirainen /* Use a single VANISHED line */
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen for (; ctx->seq >= ctx->sync_rec.seq1; ctx->seq--) {
5735ada0f82788ee1b5228978d5bd8dad5a04219Timo Sirainen /* buffer full, continue later */
5735ada0f82788ee1b5228978d5bd8dad5a04219Timo Sirainen ret = client_send_line_next(ctx->client, str_c(str));
ccd83028a34cc6e2b6370eb7ecf1cf25e717c2d3Timo Sirainenint imap_sync_more(struct imap_sync_context *ctx)
ccd83028a34cc6e2b6370eb7ecf1cf25e717c2d3Timo Sirainen /* finish syncing even when client has disconnected. otherwise our
ccd83028a34cc6e2b6370eb7ecf1cf25e717c2d3Timo Sirainen internal state (ctx->messages_count) can get messed up and unless
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen we immediately stop handling all commands and syncs we could end up
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen assert-crashing. */
88286b0527bcc0711e312e9db65ca121a45213e3Timo Sirainen /* get next one */
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen if (!mailbox_sync_next(ctx->sync_ctx, &ctx->sync_rec)) {
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen /* finished */
88286b0527bcc0711e312e9db65ca121a45213e3Timo Sirainen if (ctx->sync_rec.seq2 > ctx->messages_count) {
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen /* don't send change notifications of messages we
28cd2599128e102198758cf6080588305feb6bcdTimo Sirainen haven't even announced to client yet */
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen if (ctx->sync_rec.seq1 > ctx->messages_count) {
1939d1843ee6c7ca5e5baa3967b0332341440005Timo Sirainen /* EXPUNGEs must come last */
1939d1843ee6c7ca5e5baa3967b0332341440005Timo Sirainen ctx->sync_rec.type == MAILBOX_SYNC_TYPE_EXPUNGE);
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen /* NOTIFY: FlagChange not specified for
ccd83028a34cc6e2b6370eb7ecf1cf25e717c2d3Timo Sirainen selected mailbox */
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen for (; ctx->seq <= ctx->sync_rec.seq2; ctx->seq++) {
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen /* update only after we're finished, so that
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen the seq2 > messages_count check above
ccd83028a34cc6e2b6370eb7ecf1cf25e717c2d3Timo Sirainen doesn't break */
279b22f320f6139da5c1b0e2a5ead6692e7db947Timo Sirainen /* NOTIFY: FlagChange not specified for
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen selected mailbox. The RFC doesn't explicitly
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen specify MODSEQ changes, but they're close
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen enough to flag changes. */
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen for (; ctx->seq <= ctx->sync_rec.seq2; ctx->seq++) {
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen /* buffer full */
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainenbool imap_sync_is_allowed(struct client *client)
2d340205d897e23fbecb40c8e63a4ca49bd6739bTimo Sirainen mailbox_transaction_get_count(client->mailbox) > 0)
ccd83028a34cc6e2b6370eb7ecf1cf25e717c2d3Timo Sirainenstatic bool cmd_finish_sync(struct client_command_context *cmd)
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainenstatic bool cmd_sync_continue(struct client_command_context *sync_cmd)
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen struct imap_sync_context *ctx = sync_cmd->context;
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen /* Finish all commands that waited for this sync. Go through the queue
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen backwards, so that tagged replies are sent in the same order as
42507d758b053bb483de58fba55c73a9eb5d3fbaTimo Sirainen they were received. This fixes problems with clients that rely on
42507d758b053bb483de58fba55c73a9eb5d3fbaTimo Sirainen this (Apple Mail 3.2) */
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen for (cmd = client->command_queue; cmd->next != NULL; cmd = cmd->next) ;
ccd83028a34cc6e2b6370eb7ecf1cf25e717c2d3Timo Sirainen if (cmd->state == CLIENT_COMMAND_STATE_WAIT_SYNC &&
ccd83028a34cc6e2b6370eb7ecf1cf25e717c2d3Timo Sirainen cmd->sync->counter+1 == client->sync_counter) {
ccd83028a34cc6e2b6370eb7ecf1cf25e717c2d3Timo Sirainenstatic void get_common_sync_flags(struct client *client,
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen unsigned int count = 0, fast_count = 0, noexpunges_count = 0;
1939d1843ee6c7ca5e5baa3967b0332341440005Timo Sirainen for (cmd = client->command_queue; cmd != NULL; cmd = cmd->next) {
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen if ((cmd->sync->flags & MAILBOX_SYNC_FLAG_FAST) != 0)
35283613d4c04ce18836e9fc431582c87b3710a0Timo Sirainen if ((cmd->sync->flags & MAILBOX_SYNC_FLAG_NO_EXPUNGES) != 0)
ccd83028a34cc6e2b6370eb7ecf1cf25e717c2d3Timo Sirainen i_assert(noexpunges_count == 0 || noexpunges_count == count);
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen i_assert((*flags_r & MAILBOX_SYNC_FLAG_FIX_INCONSISTENT) == 0);
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainenstatic bool cmd_sync_client(struct client_command_context *sync_cmd)
5735ada0f82788ee1b5228978d5bd8dad5a04219Timo Sirainen /* there may be multiple commands waiting. use their combined flags */
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen get_common_sync_flags(client, &flags, &imap_flags);
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen no_newmail = (client->set->parsed_workarounds & WORKAROUND_DELAY_NEWMAIL) != 0 &&
279b22f320f6139da5c1b0e2a5ead6692e7db947Timo Sirainen client->notify_ctx == NULL && /* always disabled with NOTIFY */
279b22f320f6139da5c1b0e2a5ead6692e7db947Timo Sirainen /* expunges might break the client just as badly as new mail
279b22f320f6139da5c1b0e2a5ead6692e7db947Timo Sirainen notifications. */
279b22f320f6139da5c1b0e2a5ead6692e7db947Timo Sirainen ctx = imap_sync_init(client, client->mailbox, imap_flags, flags);
279b22f320f6139da5c1b0e2a5ead6692e7db947Timo Sirainen /* handle the syncing using sync_cmd. it doesn't actually matter which
279b22f320f6139da5c1b0e2a5ead6692e7db947Timo Sirainen one of the pending commands it is. */
279b22f320f6139da5c1b0e2a5ead6692e7db947Timo Sirainen sync_cmd->state = CLIENT_COMMAND_STATE_WAIT_OUTPUT;
279b22f320f6139da5c1b0e2a5ead6692e7db947Timo Sirainen o_stream_set_flush_pending(client->output, TRUE);
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainenbool cmd_sync(struct client_command_context *cmd, enum mailbox_sync_flags flags,
c96eb61168670cfdd7596baba18856d3f086a093Timo Sirainen enum imap_sync_flags imap_flags, const char *tagline)
d2470b3dfe91ca07459185384ee25080b42a1636Timo Sirainen /* no mailbox selected, no point in delaying the sync */
return TRUE;
return FALSE;
return FALSE;
return ret;
return FALSE;
bool ret;
T_BEGIN {
} T_END;
return ret;