annotate src/plugins/mail-log/mail-log-plugin.c @ 6536:2a2fd5c3b42e HEAD

Log mailbox renames also.
author Timo Sirainen <tss@iki.fi>
date Sat, 06 Oct 2007 03:08:48 +0300
parents 1a3604c8ee05
children 414c9d631a81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6430
47c3c4d41b26 Copyright cleanup: 2007-2007 -> 2007
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
1 /* Copyright (c) 2007 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"
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #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
8 #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
9 #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
10
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
11 #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
12
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #define MAILBOX_NAME_LOG_LEN 64
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #define MSGID_LOG_LEN 80
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 #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
17 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
18 #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
19 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
20 #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
21 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
22
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
23 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
24 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
25 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
26 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
27 MAIL_LOG_FIELD_PSIZE = 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
28 MAIL_LOG_FIELD_VSIZE = 0x10
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
29 };
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
30 #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
31 (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
32 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
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 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
35 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
36 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
37 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
38 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
39 MAIL_LOG_EVENT_MAILBOX_DELETE = 0x10,
6536
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
40 MAIL_LOG_EVENT_MAILBOX_RENAME = 0x20,
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
41
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_MASK_ALL = 0x1f
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 };
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
44 #define MAIL_LOG_DEFAULT_EVENTS MAIL_LOG_EVENT_MASK_ALL
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
45
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
46 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
47 "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
48 "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
49 "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
50 "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
51 "vsize",
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 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
53 };
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
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 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
56 "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
57 "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
58 "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
59 "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
60 "mailbox_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
61 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
62 };
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 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
65 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
66 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
67
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 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
69 };
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
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
71 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
72 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
73 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
74
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 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
76 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
77 };
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
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 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
80 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
81 pool_t pool;
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 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
84
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 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
86 };
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
5185
24f4a959a24c Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents: 5117
diff changeset
88 const char *mail_log_plugin_version = PACKAGE_VERSION;
24f4a959a24c Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents: 5117
diff changeset
89
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
90 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
91
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 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
93 (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
94 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
95 (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
96
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
97 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
98 &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
99 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
100 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
101 &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
102
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
103 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
104 {
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 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
106
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
107 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
108 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
109 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
110 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
111 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
112 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
113
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
114 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
115 {
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
116 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
117
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 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
119 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
120 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
121 }
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 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
123 }
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 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
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 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
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
129 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
130 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
131 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
132 }
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 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
134 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
135 }
5258
1fffd36401eb Log the mailbox name, unless it's INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5205
diff changeset
136
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
137 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
138 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
139 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
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 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
142 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
143
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 (!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
145 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
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 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
148 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
149 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
150 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
151 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
152 }
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
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 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
155 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
156 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
157 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
158 }
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
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 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
161 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
162 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
163 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
164 {
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 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
166 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
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 = 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
169
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 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
171 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
172 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
173 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
174 }
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
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 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
177 (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
178 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
179 group->psize_total += size;
5258
1fffd36401eb Log the mailbox name, unless it's INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5205
diff changeset
180 }
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181
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
182 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
183 (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
184 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
185 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
186 }
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 }
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 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
190 {
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 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
192
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 /* 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
194 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
195 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
196 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
197 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
198 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
199 }
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 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
203 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
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 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
206 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
207 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
208
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 t_push();
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
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 = 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
212 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
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 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
215 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
216 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
217
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 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
219 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
220 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
221 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
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_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
224 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
225 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
226 }
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 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
228 }
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 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
231 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
232
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 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
234 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
235
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 (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
237 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
238 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
239 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
240 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
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 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
243 t_pop();
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
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 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
247 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
248 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
249 {
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 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
251 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
252
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 group = array_get(&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
254 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
255 mail_log_group(box, &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
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
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 static void mail_log_action(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
259 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
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 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
262 MAIL_LOG_CONTEXT(mail->transaction);
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 const char *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
264 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
265 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
266 pool_t pool;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
267
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
268 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
269 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
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 if (lt == 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
272 pool = pool_alloconly_create("mail log transaction", 1024);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
273 lt = p_new(pool, struct mail_log_transaction_context, 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
274 lt->pool = pool;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
275 MODULE_CONTEXT_SET(mail->transaction,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
276 mail_log_storage_module, 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
277 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
278 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
279
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
280 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
281 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
282 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
283 }
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
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 t_push();
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
286 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
287 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
288
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 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
290 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
291
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 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
293 mail_log_append_mailbox_name(str, mail->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
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 (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
296 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
297
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 if ((mail_log_set.fields & MAIL_LOG_FIELD_MSGID) != 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
299 if (mail_get_first_header(mail, "Message-ID", &msgid) <= 0)
6284
2392908727b8 typofix: "(null" -> "(null)"
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
300 msgid = "(null)";
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
301 str_printfa(str, "msgid=%s, ",
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
302 str_sanitize(msgid, MSGID_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
303 }
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
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 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
306 (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
307 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
308 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
309 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
310 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
311 (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
312 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
313 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
314 }
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_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
316
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
317 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
318 t_pop();
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
319 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
320
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6274
diff changeset
321 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
322 {
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
323 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
324 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
325
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
326 mail_log_action(_mail, MAIL_LOG_EVENT_EXPUNGE, NULL);
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6274
diff changeset
327 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
328 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
329
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6274
diff changeset
330 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
331 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
332 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
333 {
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
334 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
335 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
336 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
337
5205
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
338 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
339 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
340
5205
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
341 new_flags = old_flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
342 switch (modify_type) {
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
343 case MODIFY_ADD:
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
344 new_flags |= flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
345 break;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
346 case MODIFY_REMOVE:
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
347 new_flags &= ~flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
348 break;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
349 case MODIFY_REPLACE:
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
350 new_flags = flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
351 break;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
352 }
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
353 if (((old_flags ^ new_flags) & MAIL_DELETED) == 0)
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6274
diff changeset
354 return;
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
355
5205
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
356 mail_log_action(_mail, (new_flags & MAIL_DELETED) != 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
357 MAIL_LOG_EVENT_DELETE : MAIL_LOG_EVENT_UNDELETE, NULL);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
358 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
359
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
360 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
361 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
362 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
363 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
364 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
365 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
366 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
367 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
368 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
369
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
370 _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
371 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
372
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
373 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
374 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
375
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
376 mail->v.update_flags = mail_log_mail_update_flags;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
377 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
378 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
379 return _mail;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
380 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
381
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
382 static int
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
383 mail_log_copy(struct mailbox_transaction_context *t, 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
384 enum mail_flags flags, struct mail_keywords *keywords,
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
385 struct mail *dest_mail)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
386 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
387 union mailbox_module_context *lbox = MAIL_LOG_CONTEXT(t->box);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
388 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
389
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
390 if (lbox->super.copy(t, mail, flags, keywords, dest_mail) < 0)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
391 return -1;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
392
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
393 t_push();
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
394 name = str_sanitize(mailbox_get_name(t->box), MAILBOX_NAME_LOG_LEN);
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
395 mail_log_action(mail, MAIL_LOG_EVENT_COPY, name);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
396 t_pop();
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397 return 0;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
398 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
399
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
400 static int
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
401 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
402 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
403 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
404 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
405 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
406 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
407 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
408
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
409 if (lt != 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
410 if (lt->changes > 0 && 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
411 mail_log_group_changes(t->box, lt);
6428
7cad076906eb pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents: 6284
diff changeset
412 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
413 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
414
6512
1a3604c8ee05 mailbox_transaction_commit*() doesn't sync the mailbox anymore, so it
Timo Sirainen <tss@iki.fi>
parents: 6430
diff changeset
415 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
416 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
417 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
418 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
419
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
420 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
421 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
422 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
423 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
424 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
425
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
426 if (lt != 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
427 if (lt->changes > 0 && !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
428 i_info("Transaction rolled back: "
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
429 "Ignore last %u changes", 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
430 }
6428
7cad076906eb pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents: 6284
diff changeset
431 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
432 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
433
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
434 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
435 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
436
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437 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
438 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
439 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
440 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
441 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
442 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
443 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
444
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
445 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
446 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
447 return NULL;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
448
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
449 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
450 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
451
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
452 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
453 box->v.copy = mail_log_copy;
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 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
455 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
456 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
457 return box;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
458 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
459
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
460 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
461 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
462 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
463 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
464
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
465 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
466 return -1;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467
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
468 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
469 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
470
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
471 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
472 return 0;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
474
6536
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
475 static int
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
476 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
477 const char *newname)
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
478 {
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
479 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
480
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
481 if (llist->super.rename_mailbox(list, oldname, newname) < 0)
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
482 return -1;
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
483
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
484 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
485 return 0;
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
486
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
487 i_info("Mailbox renamed: %s -> %s",
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
488 str_sanitize(oldname, MAILBOX_NAME_LOG_LEN),
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
489 str_sanitize(newname, MAILBOX_NAME_LOG_LEN));
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
490 return 0;
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
491 }
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
492
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
493 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
494 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
495 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
496
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
497 if (mail_log_next_hook_mail_storage_created != NULL)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
498 mail_log_next_hook_mail_storage_created(storage);
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
499
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
500 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
501 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
502 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
503
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
504 MODULE_CONTEXT_SET_SELF(storage, mail_log_storage_module, lstorage);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
505 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
506
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
507 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
508 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
509 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
510
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
511 if (mail_log_next_hook_mailbox_list_created != NULL)
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
512 mail_log_next_hook_mailbox_list_created(list);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
513
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
514 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
515 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
516 list->v.delete_mailbox = mail_log_mailbox_list_delete;
6536
2a2fd5c3b42e Log mailbox renames also.
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
517 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
518
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
519 MODULE_CONTEXT_SET_SELF(list, mail_log_mailbox_list_module, llist);
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
520 }
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
521
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
522 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
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 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
525 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
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 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
528 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
529 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
530 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
531 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
532 }
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 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
534 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
535
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
536 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
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 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
539 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
540
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
541 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
542 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
543 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
544 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
545 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
546 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
547 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
548 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
549
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
550 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
551 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
552 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
553
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
554 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
555
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
556 t_push();
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
557 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
558 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
559 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
560
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 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
562 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
563 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
564
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
565 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
566 t_pop();
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
567 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
568
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
569 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
570 {
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
571 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
572
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
573 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
574 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
575
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
576 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
577 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
578 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
579
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
580 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
581 {
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
582 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
583 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
584 }