dovecot-2.2: imap: Added %{deleted}, %{expunged} and %{trashed} ...
dovecot at dovecot.org
dovecot at dovecot.org
Fri May 15 11:57:22 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/e0a17714f0c9
changeset: 18707:e0a17714f0c9
user: Timo Sirainen <tss at iki.fi>
date: Fri May 15 14:55:21 2015 +0300
description:
imap: Added %{deleted}, %{expunged} and %{trashed} to imap_logout_format
diffstat:
doc/example-config/conf.d/20-imap.conf | 4 ++++
src/imap/cmd-close.c | 2 +-
src/imap/cmd-copy.c | 15 +++++++++++++++
src/imap/cmd-expunge.c | 2 +-
src/imap/cmd-store.c | 10 ++++++++++
src/imap/imap-client.c | 6 ++++++
src/imap/imap-client.h | 1 +
src/imap/imap-expunge.c | 4 +++-
src/imap/imap-expunge.h | 3 ++-
9 files changed, 43 insertions(+), 4 deletions(-)
diffs (186 lines):
diff -r 93bba97afb2a -r e0a17714f0c9 doc/example-config/conf.d/20-imap.conf
--- a/doc/example-config/conf.d/20-imap.conf Fri May 15 14:35:01 2015 +0300
+++ b/doc/example-config/conf.d/20-imap.conf Fri May 15 14:55:21 2015 +0300
@@ -14,6 +14,10 @@
# %{fetch_hdr_bytes} - Number of bytes with mail header data sent to client
# %{fetch_body_count} - Number of mails with mail body data sent to client
# %{fetch_body_bytes} - Number of bytes with mail body data sent to client
+# %{deleted} - Number of mails where client added \Deleted flag
+# %{expunged} - Number of mails that client expunged
+# %{trashed} - Number of mails that client copied/moved to the
+# special_use=\Trash mailbox.
#imap_logout_format = in=%i out=%o
# Override the IMAP CAPABILITY response. If the value begins with '+',
diff -r 93bba97afb2a -r e0a17714f0c9 src/imap/cmd-close.c
--- a/src/imap/cmd-close.c Fri May 15 14:35:01 2015 +0300
+++ b/src/imap/cmd-close.c Fri May 15 14:55:21 2015 +0300
@@ -19,7 +19,7 @@
client->mailbox = NULL;
storage = mailbox_get_storage(mailbox);
- if (imap_expunge(mailbox, NULL) < 0) {
+ if (imap_expunge(mailbox, NULL, &client->expunged_count) < 0) {
errstr = mailbox_get_last_error(mailbox, &error);
if (error != MAIL_ERROR_PERM)
client_send_untagged_storage_error(client, storage);
diff -r 93bba97afb2a -r e0a17714f0c9 src/imap/cmd-copy.c
--- a/src/imap/cmd-copy.c Fri May 15 14:35:01 2015 +0300
+++ b/src/imap/cmd-copy.c Fri May 15 14:55:21 2015 +0300
@@ -86,6 +86,19 @@
return ret;
}
+static void copy_update_trashed(struct client *client, struct mailbox *box,
+ unsigned int count)
+{
+ const struct mailbox_settings *set;
+
+ set = mailbox_settings_find(mailbox_get_namespace(box),
+ mailbox_get_vname(box));
+ if (set != NULL && set->special_use[0] != '\0' &&
+ str_array_icase_find(t_strsplit_spaces(set->special_use, " "),
+ "\\Trash"))
+ client->trashed_count += count;
+}
+
static bool cmd_copy_full(struct client_command_context *cmd, bool move)
{
struct client *client = cmd->client;
@@ -147,6 +160,7 @@
pool_unref(&changes.pool);
} else if (move) {
i_assert(copy_count == seq_range_count(&changes.saved_uids));
+ copy_update_trashed(client, destbox, copy_count);
str_printfa(msg, "* OK [COPYUID %u %s ",
changes.uid_validity, src_uidset);
@@ -159,6 +173,7 @@
pool_unref(&changes.pool);
} else {
i_assert(copy_count == seq_range_count(&changes.saved_uids));
+ copy_update_trashed(client, destbox, copy_count);
str_printfa(msg, "OK [COPYUID %u %s ", changes.uid_validity,
src_uidset);
diff -r 93bba97afb2a -r e0a17714f0c9 src/imap/cmd-expunge.c
--- a/src/imap/cmd-expunge.c Fri May 15 14:35:01 2015 +0300
+++ b/src/imap/cmd-expunge.c Fri May 15 14:55:21 2015 +0300
@@ -29,7 +29,7 @@
int ret;
ret = imap_expunge(client->mailbox, search_args == NULL ? NULL :
- search_args->args);
+ search_args->args, &client->expunged_count);
if (search_args != NULL)
mail_search_args_unref(&search_args);
if (ret < 0) {
diff -r 93bba97afb2a -r e0a17714f0c9 src/imap/cmd-store.c
--- a/src/imap/cmd-store.c Fri May 15 14:35:01 2015 +0300
+++ b/src/imap/cmd-store.c Fri May 15 14:55:21 2015 +0300
@@ -136,6 +136,8 @@
const char *set, *reply, *tagged_reply;
string_t *str;
int ret;
+ bool update_deletes;
+ unsigned int deleted_count;
if (!client_read_args(cmd, 0, 0, &args))
return FALSE;
@@ -188,6 +190,9 @@
&modified_set);
}
+ update_deletes = (ctx.flags & MAIL_DELETED) != 0 &&
+ ctx.modify_type != MODIFY_REMOVE;
+ deleted_count = 0;
while (mailbox_search_next(search_ctx, &mail)) {
if (ctx.max_modseq < (uint64_t)-1) {
/* check early so there's less work for transaction
@@ -197,6 +202,10 @@
continue;
}
}
+ if (update_deletes) {
+ if ((mail_get_flags(mail) & MAIL_DELETED) == 0)
+ deleted_count++;
+ }
if (ctx.modify_type == MODIFY_REPLACE || ctx.flags != 0)
mail_update_flags(mail, ctx.modify_type, ctx.flags);
if (ctx.modify_type == MODIFY_REPLACE || ctx.keywords != NULL) {
@@ -218,6 +227,7 @@
client_send_box_error(cmd, client->mailbox);
return TRUE;
}
+ client->deleted_count += deleted_count;
if (array_count(&modified_set) == 0)
tagged_reply = "OK Store completed.";
diff -r 93bba97afb2a -r e0a17714f0c9 src/imap/imap-client.c
--- a/src/imap/imap-client.c Fri May 15 14:35:01 2015 +0300
+++ b/src/imap/imap-client.c Fri May 15 14:55:21 2015 +0300
@@ -221,6 +221,9 @@
{ '\0', NULL, "fetch_hdr_bytes" },
{ '\0', NULL, "fetch_body_count" },
{ '\0', NULL, "fetch_body_bytes" },
+ { '\0', NULL, "deleted" },
+ { '\0', NULL, "expunged" },
+ { '\0', NULL, "trashed" },
{ '\0', NULL, NULL }
};
struct var_expand_table *tab;
@@ -236,6 +239,9 @@
tab[4].value = dec2str(client->fetch_hdr_bytes);
tab[5].value = dec2str(client->fetch_body_count);
tab[6].value = dec2str(client->fetch_body_bytes);
+ tab[7].value = dec2str(client->deleted_count);
+ tab[8].value = dec2str(client->expunged_count);
+ tab[9].value = dec2str(client->trashed_count);
str = t_str_new(128);
var_expand(str, client->set->imap_logout_format, tab);
diff -r 93bba97afb2a -r e0a17714f0c9 src/imap/imap-client.h
--- a/src/imap/imap-client.h Fri May 15 14:35:01 2015 +0300
+++ b/src/imap/imap-client.h Fri May 15 14:55:21 2015 +0300
@@ -139,6 +139,7 @@
/* For imap_logout_format statistics: */
unsigned int fetch_hdr_count, fetch_body_count;
uint64_t fetch_hdr_bytes, fetch_body_bytes;
+ unsigned int deleted_count, expunged_count, trashed_count;
/* SEARCHRES extension: Last saved SEARCH result */
ARRAY_TYPE(seq_range) search_saved_uidset;
diff -r 93bba97afb2a -r e0a17714f0c9 src/imap/imap-expunge.c
--- a/src/imap/imap-expunge.c Fri May 15 14:35:01 2015 +0300
+++ b/src/imap/imap-expunge.c Fri May 15 14:55:21 2015 +0300
@@ -5,7 +5,8 @@
#include "mail-search-build.h"
#include "imap-expunge.h"
-int imap_expunge(struct mailbox *box, struct mail_search_arg *next_search_arg)
+int imap_expunge(struct mailbox *box, struct mail_search_arg *next_search_arg,
+ unsigned int *expunged_count)
{
struct mail_search_context *ctx;
struct mailbox_transaction_context *t;
@@ -31,6 +32,7 @@
mail_search_args_unref(&search_args);
while (mailbox_search_next(ctx, &mail)) {
+ *expunged_count += 1;
mail_expunge(mail);
expunges = TRUE;
}
diff -r 93bba97afb2a -r e0a17714f0c9 src/imap/imap-expunge.h
--- a/src/imap/imap-expunge.h Fri May 15 14:35:01 2015 +0300
+++ b/src/imap/imap-expunge.h Fri May 15 14:55:21 2015 +0300
@@ -3,7 +3,8 @@
struct mail_search_arg;
-int imap_expunge(struct mailbox *box, struct mail_search_arg *next_search_arg)
+int imap_expunge(struct mailbox *box, struct mail_search_arg *next_search_arg,
+ unsigned int *expunged_count)
ATTR_NULL(2);
#endif
More information about the dovecot-cvs
mailing list