4
4
#include "commands.h"
5
#include "imap-search.h"
5
#include "imap-search-args.h"
6
6
#include "imap-expunge.h"
8
static bool cmd_expunge_callback(struct client_command_context *cmd)
10
if (cmd->client->sync_seen_deletes && !cmd->uid) {
11
/* Outlook workaround: session 1 set \Deleted flag and
12
session 2 tried to expunge without having seen it yet.
13
expunge again. MAILBOX_TRANSACTION_FLAG_REFRESH should
14
have caught this already if index files are used. */
15
return cmd_expunge(cmd);
18
client_send_tagline(cmd, "OK Expunge completed.");
22
static bool cmd_expunge_finish(struct client_command_context *cmd,
23
struct mail_search_args *search_args)
25
struct client *client = cmd->client;
27
if (imap_expunge(client->mailbox, search_args == NULL ? NULL :
28
search_args->args) < 0) {
29
client_send_storage_error(cmd,
30
mailbox_get_storage(client->mailbox));
33
if (search_args != NULL)
34
mail_search_args_unref(&search_args);
36
client->sync_seen_deletes = FALSE;
37
client->sync_seen_expunges = FALSE;
38
if ((client->enabled_features & MAILBOX_FEATURE_QRESYNC) != 0) {
39
return cmd_sync(cmd, MAILBOX_SYNC_FLAG_EXPUNGE,
40
IMAP_SYNC_FLAG_SAFE, "OK Expunge completed.");
42
return cmd_sync_callback(cmd, MAILBOX_SYNC_FLAG_EXPUNGE,
44
cmd_expunge_callback);
8
48
bool cmd_uid_expunge(struct client_command_context *cmd)
10
struct client *client = cmd->client;
11
50
const struct imap_arg *args;
12
struct mail_search_arg *search_arg;
51
struct mail_search_args *search_args;
13
52
const char *uidset;
15
55
if (!client_read_args(cmd, 1, 0, &args))
27
search_arg = imap_search_get_arg(cmd, uidset, TRUE);
28
if (search_arg == NULL)
31
if (imap_expunge(client->mailbox, search_arg)) {
32
return cmd_sync(cmd, 0, IMAP_SYNC_FLAG_SAFE,
33
"OK Expunge completed.");
35
client_send_storage_error(cmd,
36
mailbox_get_storage(client->mailbox));
41
static bool cmd_expunge_callback(struct client_command_context *cmd)
43
if (cmd->client->sync_seen_deletes) {
44
/* Outlook workaround: session 1 set \Deleted flag and
45
session 2 tried to expunge without having seen it yet.
47
return cmd_expunge(cmd);
50
client_send_tagline(cmd, "OK Expunge completed.");
67
ret = imap_search_get_seqset(cmd, uidset, TRUE, &search_args);
70
return cmd_expunge_finish(cmd, search_args);
54
73
bool cmd_expunge(struct client_command_context *cmd)
56
struct client *client = cmd->client;
58
75
if (!client_verify_open_mailbox(cmd))
61
cmd->client->sync_seen_deletes = FALSE;
62
if (imap_expunge(client->mailbox, NULL)) {
63
return cmd_sync_callback(cmd, 0, IMAP_SYNC_FLAG_SAFE,
64
cmd_expunge_callback);
66
client_send_storage_error(cmd,
67
mailbox_get_storage(client->mailbox));
78
return cmd_expunge_finish(cmd, NULL);