annotate src/plugins/mail-log/mail-log-plugin.c @ 5794:ea050869097b HEAD

Added mail_log_events, mail_log_group_events and mail_log_fields settings to mail_log plugin.
author Timo Sirainen <tss@iki.fi>
date Thu, 21 Jun 2007 00:51:34 +0300
parents 7a6db5ec047d
children bd67afb92ee5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (C) 2007 Timo Sirainen */
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,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
40
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
41 MAIL_LOG_EVENT_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
42 };
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 #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
44
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 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
46 "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
47 "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
48 "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
49 "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
50 "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
51 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
52 };
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
53
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 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
55 "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
56 "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
57 "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
58 "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
59 "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
60 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
61 };
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 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
64 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
65 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
66
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 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
68 };
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 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
71 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
72 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
73
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 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
75 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
76 };
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
77
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 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
79 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
80 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
81
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 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
83
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
84 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
85 };
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
5185
24f4a959a24c Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents: 5117
diff changeset
87 const char *mail_log_plugin_version = PACKAGE_VERSION;
24f4a959a24c Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents: 5117
diff changeset
88
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
89 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
90
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 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
92 (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
93 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
94 (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
95
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
96 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
97 &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
98 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
99 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
100 &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
101
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
102 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
103 {
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 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
105
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 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
107 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
108 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
109 }
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 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
111 }
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 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
114 {
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
115 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
116
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 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
118 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
119 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
120 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
121 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
122 }
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 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
125 {
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 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
127
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
128 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
129 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
130 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
131 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
132 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
133 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
134 }
5258
1fffd36401eb Log the mailbox name, unless it's INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5205
diff changeset
135
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
136 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
137 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
138 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
139 {
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 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
141 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
142
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
143 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
144 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
145
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 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
147 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
148 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
149 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
150 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
151 }
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 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
154 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
155 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
156 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
157 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
158
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 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
160 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
161 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
162 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
163 {
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 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
165 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
166
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
167 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
168
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 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
170 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
171 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
172 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
173 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
174
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 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
176 (event & (MAIL_LOG_EVENT_EXPUNGE | MAIL_LOG_EVENT_COPY)) != 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 size = mail_get_physical_size(mail);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
178 if (size != (uoff_t)-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
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) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
184 size = mail_get_virtual_size(mail);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
185 if (size != (uoff_t)-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
186 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
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
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 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
191 {
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 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
193
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 /* 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
195 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
196 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
197 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
198 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
199 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
200 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
201 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
202
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
203 static void
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 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
205 {
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 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
207 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
208 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
209
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 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
211
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 = 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
213 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
214
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
215 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
216 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
217 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
218
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
219 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
220 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
221 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
222 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
223
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
224 str_printfa(str, "%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
225 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
226 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
227 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
228 str_append(str, ", ");
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
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 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
232 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
233
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 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
235 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
236
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 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
238 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
239 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
240 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
241 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
242
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 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
244 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
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
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 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
248 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
249 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
250 {
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 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
252 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
253
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
254 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
255 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
256 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
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
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 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
260 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
261 {
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 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
263 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
264 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
265 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
266 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
267 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
268
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 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
270 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
271
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 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
273 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
274 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
275 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
276 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
277 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
278 }
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 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
280
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 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
282 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
283 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
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
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 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
287 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
288 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
289
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
290 if ((mail_log_set.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
291 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
292
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
293 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
294 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
295
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 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
297 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
298
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
299 if ((mail_log_set.fields & MAIL_LOG_FIELD_MSGID) != 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
300 msgid = mail_get_first_header(mail, "Message-ID");
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
301 str_printfa(str, "msgid=%s, ", msgid == NULL ? "(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
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) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
307 size = mail_get_physical_size(mail);
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 if (size != (uoff_t)-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
309 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
310 }
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 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
312 (event & (MAIL_LOG_EVENT_EXPUNGE | MAIL_LOG_EVENT_COPY)) != 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
313 size = mail_get_virtual_size(mail);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
314 if (size != (uoff_t)-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
315 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
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 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
318
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
319 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
320 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
321 }
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 static int mail_log_mail_expunge(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
324 {
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
325 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
326 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
327
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
328 if (lmail->super.expunge(_mail) < 0)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
329 return -1;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
330
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
331 mail_log_action(_mail, MAIL_LOG_EVENT_EXPUNGE, NULL);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
332 return 0;
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
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
335 static int
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
336 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
337 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
338 {
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
339 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
340 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
341 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
342
5205
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
343 old_flags = mail_get_flags(_mail);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
344 if (lmail->super.update_flags(_mail, modify_type, flags) < 0)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
345 return -1;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
346
5205
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
347 new_flags = old_flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
348 switch (modify_type) {
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
349 case MODIFY_ADD:
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 case MODIFY_REMOVE:
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
353 new_flags &= ~flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
354 break;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
355 case MODIFY_REPLACE:
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
356 new_flags = flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
357 break;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
358 }
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
359 if (((old_flags ^ new_flags) & MAIL_DELETED) == 0)
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
360 return 0;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
361
5205
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
362 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
363 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
364 return 0;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
365 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
366
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
367 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
368 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
369 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
370 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
371 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
372 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
373 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
374 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
375 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
376
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
377 _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
378 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
379
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
380 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
381 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
382
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
383 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
384 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
385 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
386 return _mail;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
387 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
388
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
389 static int
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
390 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
391 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
392 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
393 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
394 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
395 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
396
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397 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
398 return -1;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
399
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
400 t_push();
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
401 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
402 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
403 t_pop();
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
404 return 0;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
405 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
406
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
407 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
408 mail_log_transaction_commit(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
409 enum mailbox_sync_flags flags,
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 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
411 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
412 {
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 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
414 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
415
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
416 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
417 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
418 mail_log_group_changes(t->box, 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
419 pool_unref(lt->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
420 }
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
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 return lbox->super.transaction_commit(t, flags, 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
423 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
424 }
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 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
427 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
428 {
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 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
430 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
431
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 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
433 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
434 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
435 "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
436 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
437 pool_unref(lt->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
438 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
439
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
440 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
441 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
442
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
443 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
444 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
445 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
446 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
447 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
448 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
449 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
450
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451 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
452 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
453 return NULL;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
454
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
455 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
456 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
457
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
458 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
459 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
460 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
461 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
462 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
463 return box;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
464 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
465
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466 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
467 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
468 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
469 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
470
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
471 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
472 return -1;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473
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
474 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
475 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
476
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
477 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
478 return 0;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
479 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
480
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
481 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
482 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
483 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
484
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
485 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
486 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
487
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
488 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
489 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
490 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
491
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
492 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
493 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
494
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
495 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
496 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
497 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
498
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
499 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
500 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
501
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
502 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
503 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
504 list->v.delete_mailbox = mail_log_mailbox_list_delete;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
505
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
506 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
507 }
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
508
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
509 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
510 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
511 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
512 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
513
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
514 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
515 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
516 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
517 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
518 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
519 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
520 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
521 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
522
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
523 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
524 {
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 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
526 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
527
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 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
529 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
530 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
531 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
532 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
533 }
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 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
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
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 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
538 {
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 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
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 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
542
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 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
544 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
545 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
546 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
547
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 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
549 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
550 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
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 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
553 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
554 }
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
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
556 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
557 {
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
558 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
559
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
560 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
561 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
562
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
563 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
564 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
565 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
566
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
567 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
568 {
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
569 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
570 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
571 }