annotate src/plugins/mail-log/mail-log-plugin.c @ 6280:eb7c9d8ece54 HEAD

mail_*() APIs changed to return int and return the actual data as pointer. Changed some code to do error handling a bit better.
author Timo Sirainen <tss@iki.fi>
date Sun, 12 Aug 2007 19:40:54 +0300
parents 5f66277bbe40
children 2392908727b8
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) {
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
177 if (mail_get_physical_size(mail, &size) == 0)
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
178 group->psize_total += size;
5258
1fffd36401eb Log the mailbox name, unless it's INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5205
diff changeset
179 }
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180
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
181 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
182 (event & (MAIL_LOG_EVENT_EXPUNGE | MAIL_LOG_EVENT_COPY)) != 0) {
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
183 if (mail_get_virtual_size(mail, &size) == 0)
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
184 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
185 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
186 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
187
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
188 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
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 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
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 /* 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
193 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
194 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
195 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
196 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
197 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
198 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
199 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
200
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
201 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
202 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
203 {
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 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
205 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
206 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
207
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 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
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 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
211 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
212
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 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
214 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
215 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
216
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 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
218 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
219 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
220 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
221
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_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
223 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
224 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
225 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
226 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
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
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 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
230 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
231
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
232 if (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
233 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
234
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
235 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
236 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
237 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
238 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
239 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
240
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
241 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
242 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
243 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
244
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
245 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
246 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
247 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
248 {
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 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
250 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
251
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 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
253 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
254 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
255 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
256
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
257 static void 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
258 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
259 {
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 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
261 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
262 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
263 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
264 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
265 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
266
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 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
268 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
269
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 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
271 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
272 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
273 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
274 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
275 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
276 }
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 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
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 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
280 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
281 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
282 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
283
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
284 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
285 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
286 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
287
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 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
289 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
290
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 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
292 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
293
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 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
295 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
296
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 if ((mail_log_set.fields & MAIL_LOG_FIELD_MSGID) != 0) {
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
298 if (mail_get_first_header(mail, "Message-ID", &msgid) <= 0)
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
299 msgid = "(null";
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
300 str_printfa(str, "msgid=%s, ",
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
301 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
302 }
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 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
305 (event & (MAIL_LOG_EVENT_EXPUNGE | MAIL_LOG_EVENT_COPY)) != 0) {
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
306 if (mail_get_physical_size(mail, &size) == 0)
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
307 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
308 }
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 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
310 (event & (MAIL_LOG_EVENT_EXPUNGE | MAIL_LOG_EVENT_COPY)) != 0) {
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
311 if (mail_get_virtual_size(mail, &size) == 0)
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
312 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
313 }
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 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
315
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 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
317 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
318 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
319
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6274
diff changeset
320 static void mail_log_mail_expunge(struct mail *_mail)
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
321 {
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
322 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
323 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
324
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
325 mail_log_action(_mail, MAIL_LOG_EVENT_EXPUNGE, NULL);
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6274
diff changeset
326 lmail->super.expunge(_mail);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
327 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
328
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6274
diff changeset
329 static void
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
330 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
331 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
332 {
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
333 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
334 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
335 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
336
5205
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
337 old_flags = mail_get_flags(_mail);
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6274
diff changeset
338 lmail->super.update_flags(_mail, modify_type, flags);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
339
5205
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
340 new_flags = old_flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
341 switch (modify_type) {
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
342 case MODIFY_ADD:
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
343 new_flags |= flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
344 break;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
345 case MODIFY_REMOVE:
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
346 new_flags &= ~flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
347 break;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
348 case MODIFY_REPLACE:
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
349 new_flags = flags;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
350 break;
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
351 }
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
352 if (((old_flags ^ new_flags) & MAIL_DELETED) == 0)
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6274
diff changeset
353 return;
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
354
5205
f33e5ce7a73c Fixed deleted/undeleted logging.
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
355 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
356 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
357 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
358
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
359 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
360 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
361 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
362 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
363 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
364 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
365 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
366 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
367 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
368
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
369 _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
370 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
371
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
372 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
373 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
374
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
375 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
376 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
377 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
378 return _mail;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
379 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
380
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
381 static int
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
382 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
383 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
384 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
385 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
386 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
387 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
388
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
389 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
390 return -1;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
391
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
392 t_push();
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
393 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
394 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
395 t_pop();
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
396 return 0;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
398
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
399 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
400 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
401 enum mailbox_sync_flags flags,
6274
bd67afb92ee5 More transaction_commit() compile fixes.
Timo Sirainen <tss@iki.fi>
parents: 5794
diff changeset
402 uint32_t *uid_validity_r,
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
403 uint32_t *first_saved_uid_r,
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
404 uint32_t *last_saved_uid_r)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
405 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
406 struct mail_log_transaction_context *lt = MAIL_LOG_CONTEXT(t);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
407 union mailbox_module_context *lbox = MAIL_LOG_CONTEXT(t->box);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
408
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
409 if (lt != NULL) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
410 if (lt->changes > 0 && mail_log_set.group_events)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
411 mail_log_group_changes(t->box, lt);
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 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
413 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
414
6274
bd67afb92ee5 More transaction_commit() compile fixes.
Timo Sirainen <tss@iki.fi>
parents: 5794
diff changeset
415 return lbox->super.transaction_commit(t, flags, uid_validity_r,
bd67afb92ee5 More transaction_commit() compile fixes.
Timo Sirainen <tss@iki.fi>
parents: 5794
diff changeset
416 first_saved_uid_r,
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
417 last_saved_uid_r);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
418 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
419
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
420 static void
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
421 mail_log_transaction_rollback(struct mailbox_transaction_context *t)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
422 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
423 struct mail_log_transaction_context *lt = MAIL_LOG_CONTEXT(t);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
424 union mailbox_module_context *lbox = MAIL_LOG_CONTEXT(t->box);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
425
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
426 if (lt != NULL) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
427 if (lt->changes > 0 && !mail_log_set.group_events) {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
428 i_info("Transaction rolled back: "
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
429 "Ignore last %u changes", lt->changes);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
430 }
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 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
432 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
433
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
434 lbox->super.transaction_rollback(t);
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
435 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
436
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437 static struct mailbox *
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
438 mail_log_mailbox_open(struct mail_storage *storage, const char *name,
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
439 struct istream *input, enum mailbox_open_flags flags)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
440 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
441 union mail_storage_module_context *lstorage = MAIL_LOG_CONTEXT(storage);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
442 struct mailbox *box;
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
443 union mailbox_module_context *lbox;
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
444
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
445 box = lstorage->super.mailbox_open(storage, name, input, flags);
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
446 if (box == NULL)
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
447 return NULL;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
448
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
449 lbox = p_new(box->pool, union mailbox_module_context, 1);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
450 lbox->super = box->v;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
452 box->v.mail_alloc = mail_log_mail_alloc;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
453 box->v.copy = mail_log_copy;
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
454 box->v.transaction_commit = mail_log_transaction_commit;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
455 box->v.transaction_rollback = mail_log_transaction_rollback;
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
456 MODULE_CONTEXT_SET_SELF(box, mail_log_storage_module, lbox);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
457 return box;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
458 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
459
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
460 static int
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
461 mail_log_mailbox_list_delete(struct mailbox_list *list, const char *name)
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
462 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
463 union mailbox_list_module_context *llist = MAIL_LOG_LIST_CONTEXT(list);
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
464
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
465 if (llist->super.delete_mailbox(list, name) < 0)
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466 return -1;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467
5794
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
468 if ((mail_log_set.events & MAIL_LOG_EVENT_MAILBOX_DELETE) == 0)
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
469 return 0;
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
470
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
471 i_info("Mailbox deleted: %s", str_sanitize(name, MAILBOX_NAME_LOG_LEN));
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
472 return 0;
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
474
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
475 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
476 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
477 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
478
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
479 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
480 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
481
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
482 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
483 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
484 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
485
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
486 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
487 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
488
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
489 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
490 {
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
491 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
492
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
493 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
494 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
495
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
496 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
497 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
498 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
499
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
500 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
501 }
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
502
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
503 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
504 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
505 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
506 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
507
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
508 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
509 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
510 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
511 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
512 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
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 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
515 }
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
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 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
518 {
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 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
520 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
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 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
523 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
524 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
525 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
526 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
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 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
529 }
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
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 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
532 {
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
533 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
534
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
535 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
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 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
538 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
539 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
540 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
541
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 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
543 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
544 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
545
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 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
547 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
548 }
ea050869097b Added mail_log_events, mail_log_group_events and mail_log_fields settings to
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
549
5034
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
550 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
551 {
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
552 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
553
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
554 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
555 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
556
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
557 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
558 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
559 }
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
560
1b28e0434d85 Added mail_log plugin to log various mail operations. Currently it logs mail
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
561 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
562 {
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5338
diff changeset
563 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
564 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
565 }