annotate src/plugins/mail-log/mail-log-plugin.c @ 9575:0a00dcc4f0ea HEAD

lib-storage: Allow shared namespace prefix to use %variable modifiers.
author Timo Sirainen <tss@iki.fi>
date Wed, 26 May 2010 17:07:51 +0100
parents 00cd9aacd03c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9532
00cd9aacd03c Updated copyright notices to include year 2010.
Timo Sirainen <tss@iki.fi>
parents: 8726
diff changeset
1 /* Copyright (c) 2007-2010 Dovecot authors, see the included COPYING file */
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "array.h"
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
5 #include "str.h"
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "str-sanitize.h"
8550
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
7 #include "imap-util.h"
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "mail-storage-private.h"
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
9 #include "mailbox-list-private.h"
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "mail-log-plugin.h"
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
12 #include <stdlib.h>
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
13
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #define MAILBOX_NAME_LOG_LEN 64
8551
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
15 #define HEADER_LOG_LEN 80
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #define MAIL_LOG_CONTEXT(obj) \
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
18 MODULE_CONTEXT(obj, mail_log_storage_module)
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
19 #define MAIL_LOG_MAIL_CONTEXT(obj) \
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
20 MODULE_CONTEXT(obj, mail_log_mail_module)
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
21 #define MAIL_LOG_LIST_CONTEXT(obj) \
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
22 MODULE_CONTEXT(obj, mail_log_mailbox_list_module)
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
24 enum mail_log_field {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
25 MAIL_LOG_FIELD_UID = 0x01,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
26 MAIL_LOG_FIELD_BOX = 0x02,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
27 MAIL_LOG_FIELD_MSGID = 0x04,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
28 MAIL_LOG_FIELD_PSIZE = 0x08,
8550
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
29 MAIL_LOG_FIELD_VSIZE = 0x10,
8551
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
30 MAIL_LOG_FIELD_FLAGS = 0x20,
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
31 MAIL_LOG_FIELD_FROM = 0x40,
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
32 MAIL_LOG_FIELD_SUBJECT = 0x80
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
33 };
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
34 #define MAIL_LOG_DEFAULT_FIELDS \
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
35 (MAIL_LOG_FIELD_UID | MAIL_LOG_FIELD_BOX | \
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
36 MAIL_LOG_FIELD_MSGID | MAIL_LOG_FIELD_PSIZE)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
37
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
38 enum mail_log_event {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
39 MAIL_LOG_EVENT_DELETE = 0x01,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
40 MAIL_LOG_EVENT_UNDELETE = 0x02,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
41 MAIL_LOG_EVENT_EXPUNGE = 0x04,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
42 MAIL_LOG_EVENT_COPY = 0x08,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
43 MAIL_LOG_EVENT_MAILBOX_DELETE = 0x10,
6536
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
44 MAIL_LOG_EVENT_MAILBOX_RENAME = 0x20,
8550
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
45 MAIL_LOG_EVENT_FLAG_CHANGE = 0x40,
8552
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
46 MAIL_LOG_EVENT_APPEND = 0x80
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
47 };
8550
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
48 #define MAIL_LOG_DEFAULT_EVENTS \
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
49 (MAIL_LOG_EVENT_DELETE | MAIL_LOG_EVENT_UNDELETE | \
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
50 MAIL_LOG_EVENT_EXPUNGE | MAIL_LOG_EVENT_COPY | \
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
51 MAIL_LOG_EVENT_MAILBOX_DELETE | MAIL_LOG_EVENT_MAILBOX_RENAME)
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
52
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
53 static const char *field_names[] = {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
54 "uid",
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
55 "box",
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
56 "msgid",
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
57 "size",
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
58 "vsize",
8550
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
59 "flags",
8551
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
60 "from",
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
61 "subject",
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
62 NULL
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
63 };
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
64
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
65 static const char *event_names[] = {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
66 "delete",
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
67 "undelete",
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
68 "expunge",
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
69 "copy",
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
70 "mailbox_delete",
8550
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
71 "mailbox_rename",
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
72 "flag_change",
8552
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
73 "append",
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
74 NULL
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
75 };
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
76
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
77 struct mail_log_settings {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
78 enum mail_log_field fields;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
79 enum mail_log_event events;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
80
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
81 unsigned int group_events:1;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
82 };
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
83
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
84 struct mail_log_group_changes {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
85 enum mail_log_event event;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
86 const char *data;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
87
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
88 ARRAY_TYPE(seq_range) uids;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
89 uoff_t psize_total, vsize_total;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
90 };
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
91
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
92 struct mail_log_transaction_context {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
93 union mailbox_transaction_module_context module_ctx;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
94 pool_t pool;
8552
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
95 struct mail *tmp_mail;
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
96
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
97 ARRAY_DEFINE(group_changes, struct mail_log_group_changes);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
98
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
99 unsigned int changes;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
100 };
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
101
5185
24f4a959a24c Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents: 5117
diff changeset
102 const char *mail_log_plugin_version = PACKAGE_VERSION;
24f4a959a24c Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents: 5117
diff changeset
103
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
104 static struct mail_log_settings mail_log_set;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
105
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 static void (*mail_log_next_hook_mail_storage_created)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 (struct mail_storage *storage);
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
108 static void (*mail_log_next_hook_mailbox_list_created)
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
109 (struct mailbox_list *list);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
111 static MODULE_CONTEXT_DEFINE_INIT(mail_log_storage_module,
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
112 &mail_storage_module_register);
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
113 static MODULE_CONTEXT_DEFINE_INIT(mail_log_mail_module, &mail_module_register);
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
114 static MODULE_CONTEXT_DEFINE_INIT(mail_log_mailbox_list_module,
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
115 &mailbox_list_module_register);
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
116
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
117 static enum mail_log_field mail_log_field_find(const char *name)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
118 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
119 unsigned int i;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
120
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
121 for (i = 0; field_names[i] != NULL; i++) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
122 if (strcmp(name, field_names[i]) == 0)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
123 return 1 << i;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
124 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
125 return 0;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
126 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
127
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
128 static enum mail_log_event mail_log_event_find(const char *name)
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129 {
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
130 unsigned int i;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
131
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
132 for (i = 0; event_names[i] != NULL; i++) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
133 if (strcmp(name, event_names[i]) == 0)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
134 return 1 << i;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
135 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
136 return 0;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
137 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
138
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
139 static const char *mail_log_event_get_name(enum mail_log_event event)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
140 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
141 unsigned int i;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
142
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
143 for (i = 0; event_names[i] != NULL; i++) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
144 if ((unsigned)event == (unsigned)(1 << i))
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
145 return event_names[i];
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
146 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
147 i_unreached();
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
148 return NULL;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
149 }
5258
1fffd36401eb Log the mailbox name, unless it's INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5205
diff changeset
150
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
151 static struct mail_log_group_changes *
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
152 mail_log_action_get_group(struct mail_log_transaction_context *lt,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
153 enum mail_log_event event, const char *data)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
154 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
155 struct mail_log_group_changes *group;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
156 unsigned int i, count;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
157
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
158 if (!array_is_created(&lt->group_changes))
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
159 p_array_init(&lt->group_changes, lt->pool, 8);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
160
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
161 group = array_get_modifiable(&lt->group_changes, &count);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
162 for (i = 0; i < count; i++) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
163 if (group[i].event == event &&
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
164 null_strcmp(data, group[i].data) == 0)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
165 return &group[i];
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
166 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
167
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
168 group = array_append_space(&lt->group_changes);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
169 group->event = event;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
170 group->data = p_strdup(lt->pool, data);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
171 return group;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
172 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
173
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
174 static void
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
175 mail_log_action_add_group(struct mail_log_transaction_context *lt,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
176 struct mail *mail, enum mail_log_event event,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
177 const char *data)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
178 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
179 struct mail_log_group_changes *group;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
180 uoff_t size;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
181
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
182 group = mail_log_action_get_group(lt, event, data);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
183
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
184 if ((mail_log_set.fields & MAIL_LOG_FIELD_UID) != 0) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
185 if (!array_is_created(&group->uids))
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
186 p_array_init(&group->uids, lt->pool, 32);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
187 seq_range_array_add(&group->uids, 0, mail->uid);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
188 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
189
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
190 if ((mail_log_set.fields & MAIL_LOG_FIELD_PSIZE) != 0 &&
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
191 (event & (MAIL_LOG_EVENT_EXPUNGE | MAIL_LOG_EVENT_COPY)) != 0) {
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
192 if (mail_get_physical_size(mail, &size) == 0)
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
193 group->psize_total += size;
5258
1fffd36401eb Log the mailbox name, unless it's INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5205
diff changeset
194 }
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
196 if ((mail_log_set.fields & MAIL_LOG_FIELD_VSIZE) != 0 &&
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
197 (event & (MAIL_LOG_EVENT_EXPUNGE | MAIL_LOG_EVENT_COPY)) != 0) {
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
198 if (mail_get_virtual_size(mail, &size) == 0)
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
199 group->vsize_total += size;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
200 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
201 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
202
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
203 static void mail_log_append_mailbox_name(string_t *str, struct mailbox *box)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
204 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
205 const char *mailbox_str;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
206
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
207 /* most operations are for INBOX, and POP3 has only INBOX,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
208 so don't add it. */
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
209 mailbox_str = mailbox_get_name(box);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
210 if (strcmp(mailbox_str, "INBOX") != 0) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
211 str_printfa(str, "box=%s, ",
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
212 str_sanitize(mailbox_str, MAILBOX_NAME_LOG_LEN));
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
213 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
214 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
215
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
216 static void
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
217 mail_log_group(struct mailbox *box, const struct mail_log_group_changes *group)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
218 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
219 const struct seq_range *range;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
220 unsigned int i, count;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
221 string_t *str;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
222
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
223 str = t_str_new(128);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
224 str_printfa(str, "%s: ", mail_log_event_get_name(group->event));
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
225
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
226 if ((mail_log_set.fields & MAIL_LOG_FIELD_UID) != 0 &&
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
227 array_is_created(&group->uids)) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
228 str_append(str, "uids=");
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
229
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
230 range = array_get(&group->uids, &count);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
231 for (i = 0; i < count; i++) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
232 if (i != 0)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
233 str_append_c(str, ',');
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
234
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
235 str_printfa(str, "%u", range[i].seq1);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
236 if (range[i].seq1 != range[i].seq2)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
237 str_printfa(str, "-%u", range[i].seq2);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
238 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
239 str_append(str, ", ");
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
240 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
241
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
242 if ((mail_log_set.fields & MAIL_LOG_FIELD_BOX) != 0)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
243 mail_log_append_mailbox_name(str, box);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
244
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
245 if (group->event == MAIL_LOG_EVENT_COPY)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
246 str_printfa(str, "dest=%s, ", group->data);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
247
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
248 if (group->psize_total != 0)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
249 str_printfa(str, "size=%"PRIuUOFF_T", ", group->psize_total);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
250 if (group->vsize_total != 0)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
251 str_printfa(str, "size=%"PRIuUOFF_T", ", group->vsize_total);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
252 str_truncate(str, str_len(str)-2);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
253
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
254 i_info("%s", str_c(str));
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
255 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
256
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
257 static void
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
258 mail_log_group_changes(struct mailbox *box,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
259 struct mail_log_transaction_context *lt)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
260 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
261 const struct mail_log_group_changes *group;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
262 unsigned int i, count;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
263
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
264 group = array_get(&lt->group_changes, &count);
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6536
diff changeset
265 for (i = 0; i < count; i++) {
7226
e6693a0ec8e1 Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
266 T_BEGIN {
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6536
diff changeset
267 mail_log_group(box, &group[i]);
7226
e6693a0ec8e1 Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
268 } T_END;
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6536
diff changeset
269 }
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
270 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
271
8551
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
272 static void mail_log_add_hdr(struct mail *mail, string_t *str,
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
273 const char *name, const char *header)
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
274 {
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
275 const char *value;
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
276
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
277 if (mail_get_first_header(mail, header, &value) <= 0)
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
278 value = "";
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
279 str_printfa(str, "%s=%s, ", name, str_sanitize(value, HEADER_LOG_LEN));
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
280 }
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
281
7315
3f53f528d338 Copies were tracked using the source transaction instead of destination
Timo Sirainen <tss@iki.fi>
parents: 7226
diff changeset
282 static void mail_log_action(struct mailbox_transaction_context *dest_trans,
3f53f528d338 Copies were tracked using the source transaction instead of destination
Timo Sirainen <tss@iki.fi>
parents: 7226
diff changeset
283 struct mail *mail, enum mail_log_event event,
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
284 const char *data)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
285 {
7315
3f53f528d338 Copies were tracked using the source transaction instead of destination
Timo Sirainen <tss@iki.fi>
parents: 7226
diff changeset
286 struct mail_log_transaction_context *lt = MAIL_LOG_CONTEXT(dest_trans);
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
287 uoff_t size;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
288 string_t *str;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
289
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
290 if ((mail_log_set.events & event) == 0)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
291 return;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
292
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
293 lt->changes++;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
294
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
295 if (mail_log_set.group_events) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
296 mail_log_action_add_group(lt, mail, event, data);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
297 return;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
298 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
299
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
300 str = t_str_new(128);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
301 str_printfa(str, "%s: ", mail_log_event_get_name(event));
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
302
8552
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
303 if ((mail_log_set.fields & MAIL_LOG_FIELD_UID) != 0 && mail->uid != 0)
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
304 str_printfa(str, "uid=%u, ", mail->uid);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
305
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
306 if ((mail_log_set.fields & MAIL_LOG_FIELD_BOX) != 0)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
307 mail_log_append_mailbox_name(str, mail->box);
8550
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
308 if ((mail_log_set.fields & MAIL_LOG_FIELD_FLAGS) != 0) {
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
309 str_printfa(str, "flags=(");
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
310 imap_write_flags(str, mail_get_flags(mail),
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
311 mail_get_keywords(mail));
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
312 str_append(str, "), ");
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
313 }
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
314 if (event == MAIL_LOG_EVENT_COPY)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
315 str_printfa(str, "dest=%s, ", data);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
316
8551
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
317 if ((mail_log_set.fields & MAIL_LOG_FIELD_MSGID) != 0)
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
318 mail_log_add_hdr(mail, str, "msgid", "Message-ID");
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
319 if ((mail_log_set.fields & MAIL_LOG_FIELD_FROM) != 0)
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
320 mail_log_add_hdr(mail, str, "from", "From");
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
321 if ((mail_log_set.fields & MAIL_LOG_FIELD_SUBJECT) != 0)
2dcfd12f70f2 mail-log plugin: Added from and subject fields.
Timo Sirainen <tss@iki.fi>
parents: 8550
diff changeset
322 mail_log_add_hdr(mail, str, "subject", "Subject");
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
323
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
324 if ((mail_log_set.fields & MAIL_LOG_FIELD_PSIZE) != 0 &&
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
325 (event & (MAIL_LOG_EVENT_EXPUNGE | MAIL_LOG_EVENT_COPY)) != 0) {
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
326 if (mail_get_physical_size(mail, &size) == 0)
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
327 str_printfa(str, "size=%"PRIuUOFF_T", ", size);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
328 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
329 if ((mail_log_set.fields & MAIL_LOG_FIELD_VSIZE) != 0 &&
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
330 (event & (MAIL_LOG_EVENT_EXPUNGE | MAIL_LOG_EVENT_COPY)) != 0) {
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
331 if (mail_get_virtual_size(mail, &size) == 0)
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
332 str_printfa(str, "vsize=%"PRIuUOFF_T", ", size);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
333 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
334 str_truncate(str, str_len(str)-2);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
335
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
336 i_info("%s", str_c(str));
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
337 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
338
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6274
diff changeset
339 static void mail_log_mail_expunge(struct mail *_mail)
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
340 {
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
341 struct mail_private *mail = (struct mail_private *)_mail;
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
342 union mail_module_context *lmail = MAIL_LOG_MAIL_CONTEXT(mail);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
343
7226
e6693a0ec8e1 Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
344 T_BEGIN {
7315
3f53f528d338 Copies were tracked using the source transaction instead of destination
Timo Sirainen <tss@iki.fi>
parents: 7226
diff changeset
345 mail_log_action(_mail->transaction, _mail,
3f53f528d338 Copies were tracked using the source transaction instead of destination
Timo Sirainen <tss@iki.fi>
parents: 7226
diff changeset
346 MAIL_LOG_EVENT_EXPUNGE, NULL);
7226
e6693a0ec8e1 Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
347 } T_END;
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6274
diff changeset
348 lmail->super.expunge(_mail);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
349 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
350
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6274
diff changeset
351 static void
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
352 mail_log_mail_update_flags(struct mail *_mail, enum modify_type modify_type,
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
353 enum mail_flags flags)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
354 {
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
355 struct mail_private *mail = (struct mail_private *)_mail;
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
356 union mail_module_context *lmail = MAIL_LOG_MAIL_CONTEXT(mail);
5205
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
357 enum mail_flags old_flags, new_flags;
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
358
5205
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
359 old_flags = mail_get_flags(_mail);
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6274
diff changeset
360 lmail->super.update_flags(_mail, modify_type, flags);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
361
5205
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
362 new_flags = old_flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
363 switch (modify_type) {
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
364 case MODIFY_ADD:
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
365 new_flags |= flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
366 break;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
367 case MODIFY_REMOVE:
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
368 new_flags &= ~flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
369 break;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
370 case MODIFY_REPLACE:
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
371 new_flags = flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
372 break;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
373 }
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
374
8550
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
375 if (((old_flags ^ new_flags) & MAIL_DELETED) != 0) T_BEGIN {
7315
3f53f528d338 Copies were tracked using the source transaction instead of destination
Timo Sirainen <tss@iki.fi>
parents: 7226
diff changeset
376 mail_log_action(_mail->transaction, _mail,
3f53f528d338 Copies were tracked using the source transaction instead of destination
Timo Sirainen <tss@iki.fi>
parents: 7226
diff changeset
377 (new_flags & MAIL_DELETED) != 0 ?
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6536
diff changeset
378 MAIL_LOG_EVENT_DELETE :
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6536
diff changeset
379 MAIL_LOG_EVENT_UNDELETE, NULL);
7226
e6693a0ec8e1 Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
380 } T_END;
8550
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
381
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
382 if ((old_flags & ~MAIL_DELETED) != (new_flags & ~MAIL_DELETED)) {
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
383 mail_log_action(_mail->transaction, _mail,
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
384 MAIL_LOG_EVENT_FLAG_CHANGE, NULL);
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
385 }
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
386 }
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
387
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
388 static void
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
389 mail_log_mail_update_keywords(struct mail *_mail, enum modify_type modify_type,
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
390 struct mail_keywords *keywords)
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
391 {
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
392 struct mail_private *mail = (struct mail_private *)_mail;
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
393 union mail_module_context *lmail = MAIL_LOG_MAIL_CONTEXT(mail);
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
394 const char *const *old_keywords, *const *new_keywords;
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
395 unsigned int i;
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
396
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
397 old_keywords = mail_get_keywords(_mail);
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
398 lmail->super.update_keywords(_mail, modify_type, keywords);
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
399 new_keywords = mail_get_keywords(_mail);
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
400
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
401 for (i = 0; old_keywords[i] != NULL && new_keywords[i] != NULL; i++) {
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
402 if (strcmp(old_keywords[i], new_keywords[i]) != 0)
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
403 break;
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
404 }
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
405
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
406 if (old_keywords[i] != NULL || new_keywords[i] != NULL) {
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
407 mail_log_action(_mail->transaction, _mail,
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
408 MAIL_LOG_EVENT_FLAG_CHANGE, NULL);
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
409 }
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
410 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
411
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
412 static struct mail *
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
413 mail_log_mail_alloc(struct mailbox_transaction_context *t,
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
414 enum mail_fetch_field wanted_fields,
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
415 struct mailbox_header_lookup_ctx *wanted_headers)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
416 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
417 union mailbox_module_context *lbox = MAIL_LOG_CONTEXT(t->box);
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
418 union mail_module_context *lmail;
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
419 struct mail *_mail;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
420 struct mail_private *mail;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
421
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
422 _mail = lbox->super.mail_alloc(t, wanted_fields, wanted_headers);
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
423 mail = (struct mail_private *)_mail;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
424
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
425 lmail = p_new(mail->pool, union mail_module_context, 1);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
426 lmail->super = mail->v;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
427
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
428 mail->v.update_flags = mail_log_mail_update_flags;
8550
613151990b79 mail-log plugin: Added flag_change event and flags field.
Timo Sirainen <tss@iki.fi>
parents: 7462
diff changeset
429 mail->v.update_keywords = mail_log_mail_update_keywords;
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
430 mail->v.expunge = mail_log_mail_expunge;
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
431 MODULE_CONTEXT_SET_SELF(mail, mail_log_mail_module, lmail);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
432 return _mail;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
434
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
435 static int
8726
68db63cc32b3 Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
436 mail_log_copy(struct mail_save_context *ctx, struct mail *mail)
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437 {
8726
68db63cc32b3 Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
438 union mailbox_module_context *lbox =
68db63cc32b3 Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
439 MAIL_LOG_CONTEXT(ctx->transaction->box);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
440 const char *name;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
441
8726
68db63cc32b3 Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
442 if (lbox->super.copy(ctx, mail) < 0)
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
443 return -1;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
444
7226
e6693a0ec8e1 Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
445 T_BEGIN {
8726
68db63cc32b3 Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
446 name = str_sanitize(mailbox_get_name(ctx->transaction->box),
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6536
diff changeset
447 MAILBOX_NAME_LOG_LEN);
8726
68db63cc32b3 Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
448 mail_log_action(ctx->transaction, mail,
68db63cc32b3 Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
449 MAIL_LOG_EVENT_COPY, name);
7226
e6693a0ec8e1 Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
450 } T_END;
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451 return 0;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
452 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
453
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
454 static int
8552
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
455 mail_log_save_begin(struct mail_save_context *ctx, struct istream *input)
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
456 {
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
457 struct mail_log_transaction_context *lt =
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
458 MAIL_LOG_CONTEXT(ctx->transaction);
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
459 union mailbox_module_context *lbox =
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
460 MAIL_LOG_CONTEXT(ctx->transaction->box);
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
461
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
462 if (ctx->dest_mail == NULL) {
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
463 if (lt->tmp_mail == NULL)
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
464 lt->tmp_mail = mail_alloc(ctx->transaction, 0, NULL);
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
465 ctx->dest_mail = lt->tmp_mail;
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
466 }
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
467
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
468 return lbox->super.save_begin(ctx, input);
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
469 }
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
470
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
471 static int mail_log_save_finish(struct mail_save_context *ctx)
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
472 {
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
473 union mailbox_module_context *lbox =
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
474 MAIL_LOG_CONTEXT(ctx->transaction->box);
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
475
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
476 if (lbox->super.save_finish(ctx) < 0)
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
477 return -1;
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
478
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
479 T_BEGIN {
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
480 mail_log_action(ctx->transaction, ctx->dest_mail,
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
481 MAIL_LOG_EVENT_APPEND, NULL);
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
482 } T_END;
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
483 return 0;
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
484 }
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
485
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
486 static struct mailbox_transaction_context *
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
487 mail_log_transaction_begin(struct mailbox *box,
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
488 enum mailbox_transaction_flags flags)
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
489 {
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
490 union mailbox_module_context *lbox = MAIL_LOG_CONTEXT(box);
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
491 struct mailbox_transaction_context *t;
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
492 struct mail_log_transaction_context *lt;
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
493 pool_t pool;
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
494
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
495 t = lbox->super.transaction_begin(box, flags);
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
496
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
497 pool = pool_alloconly_create("mail log transaction", 1024);
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
498 lt = p_new(pool, struct mail_log_transaction_context, 1);
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
499 lt->pool = pool;
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
500 MODULE_CONTEXT_SET(t, mail_log_storage_module, lt);
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
501 return t;
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
502 }
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
503
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
504 static int
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
505 mail_log_transaction_commit(struct mailbox_transaction_context *t,
6274
bd67afb92ee5 More transaction_commit() compile fixes.
Timo Sirainen <tss@iki.fi>
parents: 5794
diff changeset
506 uint32_t *uid_validity_r,
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
507 uint32_t *first_saved_uid_r,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
508 uint32_t *last_saved_uid_r)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
509 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
510 struct mail_log_transaction_context *lt = MAIL_LOG_CONTEXT(t);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
511 union mailbox_module_context *lbox = MAIL_LOG_CONTEXT(t->box);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
512
8552
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
513 if (lt->changes > 0 && mail_log_set.group_events)
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
514 mail_log_group_changes(t->box, lt);
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
515 if (lt->tmp_mail != NULL)
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
516 mail_free(&lt->tmp_mail);
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
517 pool_unref(&lt->pool);
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
518
6512
1a3604c8ee05 mailbox_transaction_commit*() doesn't sync the mailbox anymore, so it
Timo Sirainen <tss@iki.fi>
parents: 6430
diff changeset
519 return lbox->super.transaction_commit(t, uid_validity_r,
6274
bd67afb92ee5 More transaction_commit() compile fixes.
Timo Sirainen <tss@iki.fi>
parents: 5794
diff changeset
520 first_saved_uid_r,
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
521 last_saved_uid_r);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
522 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
523
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
524 static void
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
525 mail_log_transaction_rollback(struct mailbox_transaction_context *t)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
526 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
527 struct mail_log_transaction_context *lt = MAIL_LOG_CONTEXT(t);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
528 union mailbox_module_context *lbox = MAIL_LOG_CONTEXT(t->box);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
529
8552
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
530 if (lt->changes > 0 && !mail_log_set.group_events) {
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
531 i_info("Transaction rolled back: "
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
532 "Ignore last %u changes", lt->changes);
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
533 }
8552
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
534 if (lt->tmp_mail != NULL)
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
535 mail_free(&lt->tmp_mail);
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
536 pool_unref(&lt->pool);
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
537
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
538 lbox->super.transaction_rollback(t);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
539 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
540
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
541 static struct mailbox *
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
542 mail_log_mailbox_open(struct mail_storage *storage, const char *name,
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
543 struct istream *input, enum mailbox_open_flags flags)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
544 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
545 union mail_storage_module_context *lstorage = MAIL_LOG_CONTEXT(storage);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
546 struct mailbox *box;
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
547 union mailbox_module_context *lbox;
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
548
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
549 box = lstorage->super.mailbox_open(storage, name, input, flags);
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
550 if (box == NULL)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
551 return NULL;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
552
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
553 lbox = p_new(box->pool, union mailbox_module_context, 1);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
554 lbox->super = box->v;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
555
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
556 box->v.mail_alloc = mail_log_mail_alloc;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
557 box->v.copy = mail_log_copy;
8552
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
558 box->v.save_begin = mail_log_save_begin;
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
559 box->v.save_finish = mail_log_save_finish;
adfe0b077dc7 mail-log plugin: Added initial support for append event. uids aren't logged though.
Timo Sirainen <tss@iki.fi>
parents: 8551
diff changeset
560 box->v.transaction_begin = mail_log_transaction_begin;
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
561 box->v.transaction_commit = mail_log_transaction_commit;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
562 box->v.transaction_rollback = mail_log_transaction_rollback;
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
563 MODULE_CONTEXT_SET_SELF(box, mail_log_storage_module, lbox);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
564 return box;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
565 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
566
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
567 static int
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
568 mail_log_mailbox_list_delete(struct mailbox_list *list, const char *name)
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
569 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
570 union mailbox_list_module_context *llist = MAIL_LOG_LIST_CONTEXT(list);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
571
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
572 if (llist->super.delete_mailbox(list, name) < 0)
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
573 return -1;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
574
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
575 if ((mail_log_set.events & MAIL_LOG_EVENT_MAILBOX_DELETE) == 0)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
576 return 0;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
577
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
578 i_info("Mailbox deleted: %s", str_sanitize(name, MAILBOX_NAME_LOG_LEN));
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
579 return 0;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
580 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
581
6536
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
582 static int
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
583 mail_log_mailbox_list_rename(struct mailbox_list *list, const char *oldname,
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
584 const char *newname)
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
585 {
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
586 union mailbox_list_module_context *llist = MAIL_LOG_LIST_CONTEXT(list);
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
587
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
588 if (llist->super.rename_mailbox(list, oldname, newname) < 0)
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
589 return -1;
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
590
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
591 if ((mail_log_set.events & MAIL_LOG_EVENT_MAILBOX_RENAME) == 0)
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
592 return 0;
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
593
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
594 i_info("Mailbox renamed: %s -> %s",
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
595 str_sanitize(oldname, MAILBOX_NAME_LOG_LEN),
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
596 str_sanitize(newname, MAILBOX_NAME_LOG_LEN));
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
597 return 0;
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
598 }
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
599
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
600 static void mail_log_mail_storage_created(struct mail_storage *storage)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
601 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
602 union mail_storage_module_context *lstorage;
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
603
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
604 lstorage = p_new(storage->pool, union mail_storage_module_context, 1);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
605 lstorage->super = storage->v;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
606 storage->v.mailbox_open = mail_log_mailbox_open;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
607
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
608 MODULE_CONTEXT_SET_SELF(storage, mail_log_storage_module, lstorage);
7462
068f6eefc62b next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents: 7315
diff changeset
609
068f6eefc62b next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents: 7315
diff changeset
610 if (mail_log_next_hook_mail_storage_created != NULL)
068f6eefc62b next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents: 7315
diff changeset
611 mail_log_next_hook_mail_storage_created(storage);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
612 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
613
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
614 static void mail_log_mailbox_list_created(struct mailbox_list *list)
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
615 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
616 union mailbox_list_module_context *llist;
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
617
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
618 llist = p_new(list->pool, union mailbox_list_module_context, 1);
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
619 llist->super = list->v;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
620 list->v.delete_mailbox = mail_log_mailbox_list_delete;
6536
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
621 list->v.rename_mailbox = mail_log_mailbox_list_rename;
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
622
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
623 MODULE_CONTEXT_SET_SELF(list, mail_log_mailbox_list_module, llist);
7462
068f6eefc62b next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents: 7315
diff changeset
624
068f6eefc62b next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents: 7315
diff changeset
625 if (mail_log_next_hook_mailbox_list_created != NULL)
068f6eefc62b next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents: 7315
diff changeset
626 mail_log_next_hook_mailbox_list_created(list);
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
627 }
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
628
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
629 static enum mail_log_field mail_log_parse_fields(const char *str)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
630 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
631 const char *const *tmp;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
632 static enum mail_log_field field, fields = 0;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
633
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
634 for (tmp = t_strsplit_spaces(str, ", "); *tmp != NULL; tmp++) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
635 field = mail_log_field_find(*tmp);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
636 if (field == 0)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
637 i_fatal("Unknown field in mail_log_fields: '%s'", *tmp);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
638 fields |= field;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
639 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
640 return fields;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
641 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
642
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
643 static enum mail_log_event mail_log_parse_events(const char *str)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
644 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
645 const char *const *tmp;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
646 static enum mail_log_event event, events = 0;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
647
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
648 for (tmp = t_strsplit_spaces(str, ", "); *tmp != NULL; tmp++) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
649 event = mail_log_event_find(*tmp);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
650 if (event == 0)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
651 i_fatal("Unknown event in mail_log_events: '%s'", *tmp);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
652 events |= event;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
653 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
654 return events;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
655 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
656
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
657 static void mail_log_read_settings(struct mail_log_settings *set)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
658 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
659 const char *str;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
660
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
661 memset(set, 0, sizeof(*set));
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
662
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
663 str = getenv("MAIL_LOG_FIELDS");
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
664 set->fields = str == NULL ? MAIL_LOG_DEFAULT_FIELDS :
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
665 mail_log_parse_fields(str);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
666
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
667 str = getenv("MAIL_LOG_EVENTS");
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
668 set->events = str == NULL ? MAIL_LOG_DEFAULT_EVENTS :
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
669 mail_log_parse_events(str);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
670
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
671 set->group_events = getenv("MAIL_LOG_GROUP_EVENTS") != NULL;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
672 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
673
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
674 void mail_log_plugin_init(void)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
675 {
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
676 mail_log_read_settings(&mail_log_set);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
677
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
678 mail_log_next_hook_mail_storage_created = hook_mail_storage_created;
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
679 hook_mail_storage_created = mail_log_mail_storage_created;
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
680
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
681 mail_log_next_hook_mailbox_list_created = hook_mailbox_list_created;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
682 hook_mailbox_list_created = mail_log_mailbox_list_created;
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
683 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
684
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
685 void mail_log_plugin_deinit(void)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
686 {
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
687 hook_mail_storage_created = mail_log_next_hook_mail_storage_created;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
688 hook_mailbox_list_created = mail_log_next_hook_mailbox_list_created;
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
689 }