Codebase list cyrus-imapd / upstream/3.4.0_beta3 imap / mboxevent.h
upstream/3.4.0_beta3

Tree @upstream/3.4.0_beta3 (Download .tar.gz)

mboxevent.h @upstream/3.4.0_beta3raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/* mboxevent.h -- interface for message store event notifications
 *
 * Copyright (c) 1994-2012 Carnegie Mellon University.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The name "Carnegie Mellon University" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For permission or any legal
 *    details, please contact
 *      Carnegie Mellon University
 *      Center for Technology Transfer and Enterprise Creation
 *      4615 Forbes Avenue
 *      Suite 302
 *      Pittsburgh, PA  15213
 *      (412) 268-7393, fax: (412) 268-7395
 *      innovation@andrew.cmu.edu
 *
 * 4. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by Computing Services
 *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
 *
 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Author: Sébastien Michel from Atos Worldline
 */

#ifndef _MBOXEVENT_H
#define _MBOXEVENT_H

#include "strarray.h"

#include "mailbox.h"
#include "mboxname.h"

/* Forward declaration to avoid circular dependency */
typedef struct msgrecord msgrecord_t;

/*
 * event types defined in RFC 5423 - Internet Message Store Events
 */
enum event_type {
    EVENT_CANCELLED           = (0),
    /* Message Addition and Deletion */
    EVENT_MESSAGE_APPEND      = (1<<0),
    EVENT_MESSAGE_EXPIRE      = (1<<1),
    EVENT_MESSAGE_EXPUNGE     = (1<<2),
    EVENT_MESSAGE_NEW         = (1<<3),
    EVENT_MESSAGE_COPY        = (1<<4), /* additional event type to notify IMAP COPY */
    EVENT_MESSAGE_MOVE        = (1<<5), /* additional event type to notify IMAP MOVE */
    EVENT_QUOTA_EXCEED        = (1<<6),
    EVENT_QUOTA_WITHIN        = (1<<7),
    EVENT_QUOTA_CHANGE        = (1<<8),
    /* Message Flags */
    EVENT_MESSAGE_READ        = (1<<9),
    EVENT_MESSAGE_TRASH       = (1<<10),
    EVENT_FLAGS_SET           = (1<<11),
    EVENT_FLAGS_CLEAR         = (1<<12),
    /* Access Accounting */
    EVENT_LOGIN               = (1<<13),
    EVENT_LOGOUT              = (1<<14),
    /* Mailbox Management */
    EVENT_MAILBOX_CREATE      = (1<<15),
    EVENT_MAILBOX_DELETE      = (1<<16),
    EVENT_MAILBOX_RENAME      = (1<<17),
    EVENT_MAILBOX_SUBSCRIBE   = (1<<18),
    EVENT_MAILBOX_UNSUBSCRIBE = (1<<19),
    EVENT_ACL_CHANGE          = (1<<20),
    EVENT_CALENDAR            = (1<<21),
    EVENT_CALENDAR_ALARM      = (1<<22),
    /* Other */
    EVENT_APPLEPUSHSERVICE     = (1<<23),
    EVENT_APPLEPUSHSERVICE_DAV = (1<<24),
    EVENT_MAILBOX_MODSEQ       = (1<<25)
};

/*
 * event parameters defined in RFC 5423 - Internet Message Store Events
 *
 * ordered to optimize the parsing of the notification message
 *
 * NOTE that the order here needs to be the exact same as the order in
 * mboxevent.c's event_template mboxevent struct
 */
enum event_param {
    /*  0 */ EVENT_TIMESTAMP,
    /*  1 */ EVENT_SERVICE,
    /*  2 */ EVENT_SERVER_ADDRESS, /* gather serverDomain and serverPort together */
    /*  3 */ EVENT_CLIENT_ADDRESS, /* gather clientIP and clientPort together */
    /*  4 */ EVENT_OLD_MAILBOX_ID,
    /*  5 */ EVENT_OLD_UIDSET,
    /*  6 */ EVENT_MAILBOX_ID,
    /*  7 */ EVENT_URI,
    /*  8 */ EVENT_MODSEQ,
    /*  9 */ EVENT_QUOTA_STORAGE,
    /* 10 */ EVENT_DISK_USED,
    /* 11 */ EVENT_QUOTA_MESSAGES,
    /* 12 */ EVENT_MESSAGES,
    /* 13 */ EVENT_UNSEEN_MESSAGES,
    /* 14 */ EVENT_UIDNEXT,
    /* 15 */ EVENT_UIDSET,
    /* 16 */ EVENT_MIDSET,
    /* 17 */ EVENT_FLAG_NAMES,
    /* 18 */ EVENT_PID,
    /* 19 */ EVENT_ACL_SUBJECT,
    /* 20 */ EVENT_ACL_RIGHTS,
    /* 21 */ EVENT_USER,
    /* 22 */ EVENT_MESSAGE_SIZE,
    /* 23 */ EVENT_MBTYPE,
    EVENT_SERVERFQDN,
    EVENT_MAILBOX_ACL,
    /* 24 */ EVENT_DAV_FILENAME,
    /* 25 */ EVENT_DAV_UID,
    /* 26 */ EVENT_ENVELOPE,
    /* 27 */ EVENT_SESSIONID,
    /* 28 */ EVENT_BODYSTRUCTURE,
    /* 29 */ EVENT_CLIENT_ID,
    /* 30 */ EVENT_SESSION_ID,
    EVENT_CONVEXISTS,
    EVENT_CONVUNSEEN,
    EVENT_MESSAGE_CID,
    EVENT_COUNTERS,
    EVENT_MESSAGE_EMAILID,
    EVENT_MESSAGE_THREADID,
    EVENT_CALENDAR_ALARM_TIME,
    EVENT_CALENDAR_ALARM_RECIPIENTS,
    EVENT_CALENDAR_USER_ID,
    EVENT_CALENDAR_CALENDAR_ID,
    EVENT_CALENDAR_CALENDAR_NAME,
    EVENT_CALENDAR_CALENDAR_COLOR,
    EVENT_CALENDAR_UID,
    EVENT_CALENDAR_ACTION,
    EVENT_CALENDAR_SUMMARY,
    EVENT_CALENDAR_DESCRIPTION,
    EVENT_CALENDAR_LOCATION,
    EVENT_CALENDAR_TIMEZONE,
    EVENT_CALENDAR_START,
    EVENT_CALENDAR_END,
    EVENT_CALENDAR_ALLDAY,
    EVENT_CALENDAR_ATTENDEE_NAMES,
    EVENT_CALENDAR_ATTENDEE_EMAILS,
    EVENT_CALENDAR_ATTENDEE_STATUS,
    EVENT_CALENDAR_ORGANIZER,
    EVENT_APPLEPUSHSERVICE_VERSION,
    EVENT_APPLEPUSHSERVICE_ACCOUNT_ID,
    EVENT_APPLEPUSHSERVICE_DEVICE_TOKEN,
    EVENT_APPLEPUSHSERVICE_SUBTOPIC,
    EVENT_APPLEPUSHSERVICE_MAILBOXES,
    EVENT_APPLEPUSHSERVICE_DAV_TOPIC,
    EVENT_APPLEPUSHSERVICE_DAV_DEVICE_TOKEN,
    EVENT_APPLEPUSHSERVICE_DAV_MAILBOX_USER,
    EVENT_APPLEPUSHSERVICE_DAV_MAILBOX_UNIQUEID,
    EVENT_APPLEPUSHSERVICE_DAV_EXPIRY,
    /* 31 */ EVENT_MESSAGE_CONTENT
};

/* messageContent number that is always the last */
#define MAX_PARAM EVENT_MESSAGE_CONTENT

enum event_param_type {
    EVENT_PARAM_INT,
    EVENT_PARAM_STRING,
    EVENT_PARAM_ARRAY
};

struct event_parameter {
    enum event_param id;
    const char *name;
    enum event_param_type type;
    union {
        char *s;
        uint64_t u;
        strarray_t *a;
    } value;
    int filled;
};

struct mboxevent {
    enum event_type type;       /* event type */

    /* array of event parameters */
    struct event_parameter params[MAX_PARAM+1];

    strarray_t flagnames;
    struct timeval timestamp;
    struct seqset *uidset;
    strarray_t midset;
    struct seqset *olduidset;

    struct mboxevent *prev;
    struct mboxevent *next;
};


#define FILL_STRING_PARAM(e,p,v) do { \
    e->params[p].value.s = v; \
    e->params[p].type = EVENT_PARAM_STRING; \
    e->params[p].filled = 1; \
} while(0)
#define FILL_ARRAY_PARAM(e,p,v) do { \
    e->params[p].value.a = v; \
    e->params[p].type = EVENT_PARAM_ARRAY; \
    e->params[p].filled = 1; \
} while (0)
#define FILL_UNSIGNED_PARAM(e,p,v) do { \
    e->params[p].value.u = v; \
    e->params[p].type = EVENT_PARAM_INT; \
    e->params[p].filled = 1; \
} while (0)

/*
 * Call this initializer once only at start
 */
int mboxevent_init();

/*
 * Set the namespace to translate internal mailbox name to external name
 */
void mboxevent_setnamespace(struct namespace *n);

/*
 * Create a new mboxevent structure for the given event type.
 * Allocate resources for configured extra parameters.
 *
 * return the initialized event state or NULL if notification is disabled
 */
struct mboxevent *mboxevent_new(enum event_type type);

/*
 * Create a new mboxevent structure for the given event type.
 * Append this new structure at end of the given mboxevent list.
 * Allocate resources for configured extra parameters.
 *
 * return the initialized event state or NULL if notification is disabled
 */
struct mboxevent *mboxevent_enqueue(enum event_type type,
                                    struct mboxevent **events);

/*
 * Send the queue of event notifications
 */
void mboxevent_notify(struct mboxevent **mboxevents);

/*
 * Release any allocated resources of this given event
 */
void mboxevent_free(struct mboxevent **event);

/*
 * Release any allocated resources of this given list of events
 */
void mboxevent_freequeue(struct mboxevent **event);

/*
 * Add this set of system flags and user flags to flagNames parameter.
 * Exclude flags present in event_exclude_flags setting.
 */
void mboxevent_add_flags(struct mboxevent *event, char *flagnames[MAX_USER_FLAGS],
                         bit32 system_flags, bit32 user_flags[MAX_USER_FLAGS/32]);

/*
 * Add the given flag to flagNames parameter.
 * event_exclude_flags doesn't apply here
 */
void mboxevent_add_flag(struct mboxevent *event, const char *flag);

/*
 * Extract data related to message store access accounting
 */
void mboxevent_set_access(struct mboxevent *event,
                          const char *serveraddr, const char *clientaddr,
                          const char *userid, const char *mailboxname, const int ext_name);

/*
 * Shortcut to setting event notification parameters
 */
void mboxevent_set_acl(struct mboxevent *event, const char *identifier,
                           const char *rights);

/*
 * Extract data from the given record to fill these event parameters :
 * - uidset from UID
 * - vnd.cmu.midset from Message-Id in ENVELOPE structure
 * - messageSize
 * - bodyStructure
 *
 * Called once per message and always before mboxevent_extract_mailbox
 */
void mboxevent_extract_record(struct mboxevent *event,
                              struct mailbox *mailbox,
                              struct index_record *record);

/*
 * Extract data from the given message record to fill these event parameters :
 * - uidset from UID
 * - vnd.cmu.midset from Message-Id in ENVELOPE structure
 * - messageSize
 * - bodyStructure
 *
 * Called once per message and always before mboxevent_extract_mailbox
 */
void mboxevent_extract_msgrecord(struct mboxevent *event, msgrecord_t *msgrec);


/*
 * Fill event parameter about the copied message.
 * Called once per message and always before mboxevent_extract_mailbox
 */
void mboxevent_extract_copied_record(struct mboxevent *event,
                                     const struct mailbox *mailbox, struct index_record *record);

extern void mboxevent_extract_copied_msgrecord(struct mboxevent *event, msgrecord_t *msgrec);

/*
 * Extract message content to include to event notification
 */
void mboxevent_extract_content(struct mboxevent *event,
                               const struct index_record *record, FILE* content);

/*
 * Extract message content to include to event notification
 */
void mboxevent_extract_content_msgrec(struct mboxevent *event,
                               msgrecord_t *msgrec, FILE* content);

/*
 * Extract quota limit, quota usage and quota root to include to event
 * notification
 */
void mboxevent_extract_quota(struct mboxevent *event, const struct quota *quota,
                             enum quota_resource res);

/*
 * Set the given number of unseen message if positive or scan the entire mailbox
 * to count it.
 */
void mboxevent_set_numunseen(struct mboxevent *event, struct mailbox *mailbox,
                             int numunseen);
/*
 * Extract meta-data from the given mailbox to fill mailboxID event parameter and
 * optionally these ones depending the type of the event:
 * - messages
 * - uidnext
 * - vnd.cmu.unseenMessages
 *
 * Must be called once per event or the notification will failed (Except for
 * Login and Logout events)
 * Mailbox must be locked to count the number of \Seen flags
 *
 * It is necessary to call this function after all changes on mailbox to get the
 * right values of messages, uidnext and vnd.cmu.unseenMessages event parameters
 */
void mboxevent_extract_mailbox(struct mboxevent *event, struct mailbox *mailbox);

/*
 * Extract meta-data from the given mailbox to fill oldMailboxID event parameter
 */
void mboxevent_extract_old_mailbox(struct mboxevent *event,
                                   const struct mailbox *mailbox);

/*
 * set the client tag used by vnd.fastmail.clientTagj
 */
void mboxevent_set_client_id(const char *);

/* Arguments to XAPPLEPUSHSERVICE */
struct applepushserviceargs {
    unsigned int aps_version;
    struct buf   aps_account_id;
    struct buf   aps_device_token;
    struct buf   aps_subtopic;
    strarray_t   mailboxes;
};

/*
 * send event with APS channel data in it for the push service to sort out
 */
void mboxevent_set_applepushservice(struct mboxevent *event,
                                    struct applepushserviceargs *applepushserviceargs,
                                    strarray_t *mailboxes,
                                    const char *userid);

/*
 * APS subscription for DAV collection
 */
void mboxevent_set_applepushservice_dav(struct mboxevent *event,
                                        const char *aps_topic,
                                        const char *device_token,
                                        const char *userid,
                                        const char *mailbox_userid,
                                        const char *mailbox_uniqueid,
                                        int mbtype,
                                        unsigned int expiry);

#endif /* _MBOXEVENT_H */