-
Notifications
You must be signed in to change notification settings - Fork 145
/
mboxevent.c
2058 lines (1761 loc) · 74.5 KB
/
mboxevent.c
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* 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
*/
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sysexits.h>
#include <syslog.h>
#include <time.h>
#include <unistd.h>
#include <jansson.h>
#include "annotate.h"
#include "assert.h"
#ifdef WITH_DAV
#include "caldav_db.h"
#include "carddav_db.h"
#endif /* WITH_DAV */
#include "global.h"
#include "imapurl.h"
#include "libconfig.h"
#include "map.h"
#include "times.h"
#include "xmalloc.h"
#include "xstrlcpy.h"
#include "jmap_util.h"
#include "mboxevent.h"
#include "mboxname.h"
#include "msgrecord.h"
#include "notify.h"
#define MESSAGE_EVENTS (EVENT_MESSAGE_APPEND|EVENT_MESSAGE_EXPIRE|\
EVENT_MESSAGE_EXPUNGE|EVENT_MESSAGE_NEW|\
EVENT_MESSAGE_COPY|EVENT_MESSAGE_MOVE)
#define FLAGS_EVENTS (EVENT_FLAGS_SET|EVENT_FLAGS_CLEAR|EVENT_MESSAGE_READ|\
EVENT_MESSAGE_TRASH)
#define MAILBOX_EVENTS (EVENT_MAILBOX_CREATE|EVENT_MAILBOX_DELETE|\
EVENT_MAILBOX_RENAME|EVENT_ACL_CHANGE|EVENT_MAILBOX_MODSEQ)
#define SUBS_EVENTS (EVENT_MAILBOX_SUBSCRIBE|EVENT_MAILBOX_UNSUBSCRIBE)
#define QUOTA_EVENTS (EVENT_QUOTA_EXCEED|EVENT_QUOTA_WITHIN|EVENT_QUOTA_CHANGE)
#define CALENDAR_EVENTS (EVENT_CALENDAR_ALARM)
#define APPLEPUSHSERVICE_EVENTS (EVENT_APPLEPUSHSERVICE|EVENT_APPLEPUSHSERVICE_DAV)
#define JMAP_EVENTS (EVENT_MESSAGES_UNSCHEDULED)
static const char *notifier = NULL;
static struct namespace namespace;
static const char *client_id = NULL;
static strarray_t *excluded_flags;
static strarray_t *excluded_specialuse;
static int enable_subfolder = 1;
static int enabled_events = 0;
static unsigned long extra_params;
static struct mboxevent event_template =
{ 0,
/* ordered to optimize the parsing of the notification message */
{
/* 0 */ { EVENT_TIMESTAMP, "timestamp", EVENT_PARAM_STRING, { 0 }, 0 },
/* 1 */ { EVENT_SERVICE, "service", EVENT_PARAM_STRING, { 0 }, 0 },
/* 2 */ { EVENT_SERVER_ADDRESS, "serverAddress", EVENT_PARAM_STRING, { 0 }, 0 },
/* 3 */ { EVENT_CLIENT_ADDRESS, "clientAddress", EVENT_PARAM_STRING, { 0 }, 0 },
/* 4 */ { EVENT_OLD_MAILBOX_ID, "oldMailboxID", EVENT_PARAM_STRING, { 0 }, 0 },
/* 5 */ { EVENT_OLD_UIDSET, "vnd.cmu.oldUidset", EVENT_PARAM_STRING, { 0 }, 0 },
/* 6 */ { EVENT_MAILBOX_ID, "mailboxID", EVENT_PARAM_STRING, { 0 }, 0 },
/* 7 */ { EVENT_URI, "uri", EVENT_PARAM_STRING, { 0 }, 0 },
/* 8 */ { EVENT_MODSEQ, "modseq", EVENT_PARAM_INT, { 0 }, 0 },
/* 9 */ { EVENT_QUOTA_STORAGE, "diskQuota", EVENT_PARAM_INT, { 0 }, 0 },
/* 10 */ { EVENT_DISK_USED, "diskUsed", EVENT_PARAM_INT, { 0 }, 0 },
/* 11 */ { EVENT_QUOTA_MESSAGES, "maxMessages", EVENT_PARAM_INT, { 0 }, 0 },
/* 12 */ { EVENT_MESSAGES, "messages", EVENT_PARAM_INT, { 0 }, 0 },
/* 13 */ { EVENT_UNSEEN_MESSAGES, "vnd.cmu.unseenMessages", EVENT_PARAM_INT, { 0 }, 0 },
/* 14 */ { EVENT_UIDNEXT, "uidnext", EVENT_PARAM_INT, { 0 }, 0 },
/* 15 */ { EVENT_UIDSET, "uidset", EVENT_PARAM_STRING, { 0 }, 0 },
/* 16 */ { EVENT_MIDSET, "vnd.cmu.midset", EVENT_PARAM_STRING, { 0 }, 0 },
/* 17 */ { EVENT_FLAG_NAMES, "flagNames", EVENT_PARAM_STRING, { 0 }, 0 },
/* 18 */ { EVENT_PID, "pid", EVENT_PARAM_INT, { 0 }, 0 },
/* 19 */ { EVENT_ACL_SUBJECT, "aclSubject", EVENT_PARAM_STRING, { 0 }, 0 },
/* 20 */ { EVENT_ACL_RIGHTS, "aclRights", EVENT_PARAM_STRING, { 0 }, 0 },
/* 21 */ { EVENT_USER, "user", EVENT_PARAM_STRING, { 0 }, 0 },
/* 22 */ { EVENT_MESSAGE_SIZE, "messageSize", EVENT_PARAM_INT, { 0 }, 0 },
/* 23 */ { EVENT_MBTYPE, "vnd.cmu.mbtype", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_SERVERFQDN, "serverFQDN", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_MAILBOX_ACL, "vnd.cmu.mailboxACL", EVENT_PARAM_STRING, { 0 }, 0 },
/* 24 */ { EVENT_DAV_FILENAME, "vnd.cmu.davFilename", EVENT_PARAM_STRING, { 0 }, 0 },
/* 25 */ { EVENT_DAV_UID, "vnd.cmu.davUid", EVENT_PARAM_STRING, { 0 }, 0 },
/* 26 */ { EVENT_ENVELOPE, "vnd.cmu.envelope", EVENT_PARAM_STRING, { 0 }, 0 },
/* 27 */ { EVENT_SESSIONID, "vnd.cmu.sessionId", EVENT_PARAM_STRING, { 0 }, 0 },
/* 28 */ { EVENT_BODYSTRUCTURE, "bodyStructure", EVENT_PARAM_STRING, { 0 }, 0 },
/* 29 */ { EVENT_CLIENT_ID, "vnd.fastmail.clientId", EVENT_PARAM_STRING, { 0 }, 0 },
/* 30 */ { EVENT_SESSION_ID, "vnd.fastmail.sessionId", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CONVEXISTS, "vnd.fastmail.convExists", EVENT_PARAM_INT, { 0 }, 0 },
{ EVENT_CONVUNSEEN, "vnd.fastmail.convUnseen", EVENT_PARAM_INT, { 0 }, 0 },
{ EVENT_MESSAGE_CID, "vnd.fastmail.cid", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_COUNTERS, "vnd.fastmail.counters", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_MESSAGE_EMAILID, "vnd.cmu.emailid", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_MESSAGE_THREADID, "vnd.cmu.threadid", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_JMAP_EMAIL, "vnd.fastmail.jmapEmail", EVENT_PARAM_JSON, { 0 }, 0 },
{ EVENT_JMAP_STATES, "vnd.fastmail.jmapStates", EVENT_PARAM_JSON, { 0 }, 0 },
/* calendar params for calalarmd/notifyd */
{ EVENT_CALENDAR_ALARM_TIME, "alarmTime", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_ALARM_RECIPIENTS, "alarmRecipients", EVENT_PARAM_ARRAY, { 0 }, 0 },
{ EVENT_CALENDAR_ALERTID, "alertId", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_USER_ID, "userId", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_CALENDAR_ID, "calendarId", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_CALENDAR_NAME, "calendarName", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_CALENDAR_COLOR, "calendarColor", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_CALENDAR_OWNER, "calendarOwner", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_UID, "uid", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_RECURID, "recurrenceId", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_EVENTID, "calendarEventId", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_ACTION, "action", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_SUMMARY, "summary", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_DESCRIPTION, "description", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_LOCATION, "location", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_TIMEZONE, "timezone", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_START, "start", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_END, "end", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_CALENDAR_ALLDAY, "allDay", EVENT_PARAM_INT, { 0 }, 0 },
{ EVENT_CALENDAR_ATTENDEE_NAMES, "attendeeNames", EVENT_PARAM_ARRAY, { 0 }, 0 },
{ EVENT_CALENDAR_ATTENDEE_EMAILS, "attendeeEmails", EVENT_PARAM_ARRAY, { 0 }, 0 },
{ EVENT_CALENDAR_ATTENDEE_STATUS, "attendeeStatus", EVENT_PARAM_ARRAY, { 0 }, 0 },
{ EVENT_CALENDAR_ORGANIZER, "organizer", EVENT_PARAM_STRING, { 0 }, 0 },
/* apple push params for notifyd */
{ EVENT_APPLEPUSHSERVICE_VERSION, "apsVersion", EVENT_PARAM_INT, { 0 }, 0 },
{ EVENT_APPLEPUSHSERVICE_ACCOUNT_ID, "apsAccountId", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_APPLEPUSHSERVICE_DEVICE_TOKEN, "apsDeviceToken", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_APPLEPUSHSERVICE_SUBTOPIC, "apsSubtopic", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_APPLEPUSHSERVICE_MAILBOXES, "mailboxes", EVENT_PARAM_ARRAY, { 0 }, 0 },
/* for dav push */
{ EVENT_APPLEPUSHSERVICE_DAV_TOPIC, "apsTopic", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_APPLEPUSHSERVICE_DAV_DEVICE_TOKEN, "apsDeviceToken", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_APPLEPUSHSERVICE_DAV_MAILBOX_USER, "mailboxUser", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_APPLEPUSHSERVICE_DAV_MAILBOX_UNIQUEID, "mailboxUniqueId", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_APPLEPUSHSERVICE_DAV_EXPIRY, "expiry", EVENT_PARAM_INT, { 0 }, 0 },
/* messages unscheduled send params for calalarmd/notifyd */
{ EVENT_MESSAGES_UNSCHEDULED_USERID, "userId", EVENT_PARAM_STRING, { 0 }, 0 },
{ EVENT_MESSAGES_UNSCHEDULED_COUNT, "count", EVENT_PARAM_INT, { 0 }, 0 },
/* always at end to let the parser to easily truncate this part */
/* 31 */ { EVENT_MESSAGE_CONTENT, "messageContent", EVENT_PARAM_STRING, { 0 }, 0 }
},
STRARRAY_INITIALIZER, { 0, 0 }, NULL, STRARRAY_INITIALIZER, NULL, NULL, NULL
};
static json_t *json_formatter(enum event_type type, struct event_parameter params[]);
static int filled_params(enum event_type type, struct mboxevent *mboxevent);
static int mboxevent_expected_param(enum event_type type, enum event_param param);
static int mboxevent_initialized = 0;
/* function to be used for IMAP IDLE/NOTIFY notification of changes/updates */
static mboxevent_idlenotifier_t *idle_notifier = NULL;
/*
* Set the idlenotifier function
*/
HIDDEN void mboxevent_set_idlenotifier(mboxevent_idlenotifier_t *notifyproc)
{
idle_notifier = notifyproc;
}
static void done_cb(void *rock __attribute__((unused))) {
/* do nothing */
}
static void init_internal() {
if (!mboxevent_initialized) {
mboxevent_init();
cyrus_modules_add(done_cb, NULL);
}
}
EXPORTED int mboxevent_init(void)
{
const char *options;
int groups;
if (!(notifier = config_getstring(IMAPOPT_EVENT_NOTIFIER)) && !idle_notifier)
return 0;
/* some don't want to notify events for some IMAP flags */
options = config_getstring(IMAPOPT_EVENT_EXCLUDE_FLAGS);
excluded_flags = strarray_split(options, NULL, 0);
/* some don't want to notify events on some folders (ie. Sent, Spam) */
/* identify those folders with IMAP SPECIAL-USE */
options = config_getstring(IMAPOPT_EVENT_EXCLUDE_SPECIALUSE);
excluded_specialuse = strarray_split(options, NULL, 0);
/* special meaning to disable event notification on all sub folders */
if (strarray_find_case(excluded_specialuse, "ALL", 0) >= 0)
enable_subfolder = 0;
/* get event types's extra parameters */
extra_params = config_getbitfield(IMAPOPT_EVENT_EXTRA_PARAMS);
/* groups of related events to turn on notification */
groups = config_getbitfield(IMAPOPT_EVENT_GROUPS);
if (groups & IMAP_ENUM_EVENT_GROUPS_MESSAGE)
enabled_events |= MESSAGE_EVENTS;
if (groups & IMAP_ENUM_EVENT_GROUPS_QUOTA)
enabled_events |= QUOTA_EVENTS;
if (groups & IMAP_ENUM_EVENT_GROUPS_FLAGS)
enabled_events |= FLAGS_EVENTS;
if (groups & IMAP_ENUM_EVENT_GROUPS_ACCESS)
enabled_events |= (EVENT_LOGIN|EVENT_LOGOUT|EVENT_ACL_CHANGE);
if (groups & IMAP_ENUM_EVENT_GROUPS_SUBSCRIPTION)
enabled_events |= SUBS_EVENTS;
if (groups & IMAP_ENUM_EVENT_GROUPS_MAILBOX)
enabled_events |= MAILBOX_EVENTS;
if (groups & IMAP_ENUM_EVENT_GROUPS_CALENDAR)
enabled_events |= CALENDAR_EVENTS;
if (groups & IMAP_ENUM_EVENT_GROUPS_APPLEPUSHSERVICE)
enabled_events |= APPLEPUSHSERVICE_EVENTS;
if (groups & IMAP_ENUM_EVENT_GROUPS_JMAP)
enabled_events |= JMAP_EVENTS;
mboxevent_initialized = 1;
return enabled_events;
}
EXPORTED void mboxevent_setnamespace(struct namespace *n)
{
namespace = *n;
/* standardize IMAP URL format */
namespace.isadmin = 1;
namespace.isalt = 0;
}
static int mboxevent_enabled_for_mailbox(struct mailbox *mailbox)
{
struct buf attrib = BUF_INITIALIZER;
char *userid = NULL;
strarray_t *specialuse = NULL;
int enabled = 1;
int i = 0;
int r = 0;
init_internal();
if (!enable_subfolder && !mboxname_isusermailbox(mailbox_name(mailbox), 1)) {
enabled = 0;
goto done;
}
/* test if the mailbox has a special-use attribute in the exclude list */
if (strarray_size(excluded_specialuse) > 0) {
userid = mboxname_to_userid(mailbox_name(mailbox));
r = annotatemore_lookup_mbox(mailbox, "/specialuse", userid, &attrib);
if (r) goto done; /* XXX - return -1? Failure? */
/* get info and set flags */
specialuse = strarray_split(buf_cstring(&attrib), NULL, 0);
for (i = 0; i < strarray_size(specialuse) ; i++) {
const char *attribute = strarray_nth(specialuse, i);
if (strarray_find(excluded_specialuse, attribute, 0) >= 0) {
enabled = 0;
goto done;
}
}
}
done:
strarray_free(specialuse);
buf_free(&attrib);
free(userid);
return enabled;
}
EXPORTED struct mboxevent *mboxevent_new(enum event_type type)
{
struct mboxevent *mboxevent = NULL;
init_internal();
/* event notification is completely disabled */
if (!notifier && !idle_notifier)
return NULL;
mboxevent = xmalloc(sizeof(struct mboxevent));
memcpy(mboxevent, &event_template, sizeof(struct mboxevent));
unsigned i;
for (i = 0; mboxevent->params[i].id; i++) {
assert(i == mboxevent->params[i].id);
}
mboxevent->type = type;
/* From RFC 5423:
* the time at which the event occurred that triggered the notification
* (...). This MAY be an approximate time.
*
* so it seems appropriate here */
if (mboxevent_expected_param(type, EVENT_TIMESTAMP))
gettimeofday(&mboxevent->timestamp, NULL);
FILL_UNSIGNED_PARAM(mboxevent, EVENT_PID, getpid());
if (mboxevent_expected_param(type, EVENT_SESSIONID)) {
FILL_STRING_PARAM(mboxevent, EVENT_SESSIONID, xstrdup(session_id()));
}
if (mboxevent_expected_param(type, EVENT_CLIENT_ID)) {
// OK to be blank
FILL_STRING_PARAM(mboxevent, EVENT_CLIENT_ID, xstrdupsafe(client_id));
}
if (mboxevent_expected_param(type, EVENT_SESSION_ID)) {
FILL_STRING_PARAM(mboxevent, EVENT_SESSION_ID, xstrdup(session_id()));
}
return mboxevent;
}
struct mboxevent *mboxevent_enqueue(enum event_type type,
struct mboxevent **mboxevents)
{
struct mboxevent *mboxevent = NULL;
struct mboxevent *ptr;
if (!(mboxevent = mboxevent_new(type)))
return NULL;
if (mboxevents) {
if (*mboxevents == NULL)
*mboxevents = mboxevent;
else {
/* append the newly created event at end of the chained list */
ptr = *mboxevents;
while (ptr->next)
ptr = ptr->next;
ptr->next = mboxevent;
mboxevent->prev = ptr;
}
}
return mboxevent;
}
EXPORTED void mboxevent_free(struct mboxevent **mboxevent)
{
struct mboxevent *event = *mboxevent;
int i;
if (!event)
return;
seqset_free(&event->uidset);
seqset_free(&event->olduidset);
strarray_fini(&event->midset);
strarray_fini(&event->flagnames);
for (i = 0; i <= MAX_PARAM; i++) {
if (event->params[i].filled) {
switch (event->params[i].type) {
case EVENT_PARAM_STRING:
free(event->params[i].value.s);
break;
case EVENT_PARAM_JSON:
json_decref(event->params[i].value.j);
break;
default:
break;
}
}
}
if (event->prev)
event->prev->next = event->next;
if (event->next)
event->next->prev = event->prev;
free(event);
*mboxevent = NULL;
}
void mboxevent_freequeue(struct mboxevent **mboxevent)
{
struct mboxevent *next, *event = *mboxevent;
if (!event)
return;
do {
next = event->next;
mboxevent_free(&event);
event = next;
}
while (event);
*mboxevent = NULL;
}
static int mboxevent_expected_calendar_param(enum event_param param)
{
switch (param) {
case EVENT_CALENDAR_ALARM_TIME:
case EVENT_CALENDAR_ALARM_RECIPIENTS:
case EVENT_CALENDAR_USER_ID:
case EVENT_CALENDAR_CALENDAR_ID:
case EVENT_CALENDAR_CALENDAR_NAME:
case EVENT_CALENDAR_CALENDAR_COLOR:
case EVENT_CALENDAR_UID:
case EVENT_CALENDAR_ACTION:
case EVENT_CALENDAR_SUMMARY:
case EVENT_CALENDAR_DESCRIPTION:
case EVENT_CALENDAR_LOCATION:
case EVENT_CALENDAR_TIMEZONE:
case EVENT_CALENDAR_START:
case EVENT_CALENDAR_END:
case EVENT_CALENDAR_ALLDAY:
case EVENT_CALENDAR_ATTENDEE_NAMES:
case EVENT_CALENDAR_ATTENDEE_EMAILS:
case EVENT_CALENDAR_ATTENDEE_STATUS:
case EVENT_CALENDAR_ORGANIZER:
return 1;
case EVENT_SERVERFQDN: /* needed to see who is master */
return 1;
default:
return 0;
}
}
static int mboxevent_expected_applepushservice_param(enum event_param param) {
switch (param) {
case EVENT_APPLEPUSHSERVICE_VERSION:
case EVENT_APPLEPUSHSERVICE_ACCOUNT_ID:
case EVENT_APPLEPUSHSERVICE_DEVICE_TOKEN:
case EVENT_APPLEPUSHSERVICE_SUBTOPIC:
case EVENT_APPLEPUSHSERVICE_MAILBOXES:
case EVENT_USER:
return 1;
default:
return 0;
}
}
static int mboxevent_expected_applepushservice_dav_param(enum event_param param) {
switch (param) {
case EVENT_APPLEPUSHSERVICE_DAV_TOPIC:
case EVENT_APPLEPUSHSERVICE_DAV_DEVICE_TOKEN:
case EVENT_APPLEPUSHSERVICE_DAV_MAILBOX_USER:
case EVENT_APPLEPUSHSERVICE_DAV_MAILBOX_UNIQUEID:
case EVENT_APPLEPUSHSERVICE_DAV_EXPIRY:
case EVENT_USER:
return 1;
default:
return 0;
}
}
static int mboxevent_expected_schedsend_failed_param(enum event_param param) {
switch (param) {
case EVENT_MESSAGES_UNSCHEDULED_USERID:
case EVENT_MESSAGES_UNSCHEDULED_COUNT:
return 1;
default:
return 0;
}
}
static int mboxevent_expected_param(enum event_type type, enum event_param param)
{
if (type == EVENT_CALENDAR_ALARM)
return mboxevent_expected_calendar_param(param);
if (type == EVENT_APPLEPUSHSERVICE)
return mboxevent_expected_applepushservice_param(param);
if (type == EVENT_APPLEPUSHSERVICE_DAV)
return mboxevent_expected_applepushservice_dav_param(param);
if (type == EVENT_MESSAGES_UNSCHEDULED)
return mboxevent_expected_schedsend_failed_param(param);
switch (param) {
case EVENT_BODYSTRUCTURE:
return (extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_BODYSTRUCTURE) &&
(type & (EVENT_MESSAGE_NEW|EVENT_MESSAGE_APPEND));
case EVENT_CLIENT_ADDRESS:
return (extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_CLIENTADDRESS) &&
(type & (EVENT_LOGIN|EVENT_LOGOUT));
case EVENT_QUOTA_STORAGE:
return type & QUOTA_EVENTS;
case EVENT_DISK_USED:
return (type & (EVENT_QUOTA_EXCEED|EVENT_QUOTA_WITHIN) ||
/* quota usage is not known on event MessageNew, MessageAppend,
* MessageCopy and MessageExpunge.
* Thus, some code refactoring is needed to support diskUsed
* extra parameter */
((extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_DISKUSED) &&
(type & (EVENT_QUOTA_CHANGE))));
case EVENT_ENVELOPE:
return (extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_CMU_ENVELOPE) &&
(type & (EVENT_MESSAGE_NEW|EVENT_MESSAGE_APPEND));
case EVENT_FLAG_NAMES:
return (type & (EVENT_FLAGS_SET|EVENT_FLAGS_CLEAR)) ||
((extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_FLAGNAMES) &&
(type & (EVENT_MESSAGE_APPEND|EVENT_MESSAGE_NEW)));
case EVENT_CLIENT_ID:
return extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_FASTMAIL_CLIENTID;
case EVENT_SESSION_ID:
return extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_FASTMAIL_SESSIONID;
case EVENT_MAILBOX_ID:
return (type & MAILBOX_EVENTS);
case EVENT_MBTYPE:
return (type & MAILBOX_EVENTS);
case EVENT_MAILBOX_ACL:
return (type & MAILBOX_EVENTS);
case EVENT_QUOTA_MESSAGES:
return type & QUOTA_EVENTS;
case EVENT_MESSAGE_CONTENT:
return (extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_MESSAGECONTENT) &&
(type & (EVENT_MESSAGE_APPEND|EVENT_MESSAGE_NEW));
case EVENT_MESSAGE_SIZE:
return (extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_MESSAGESIZE) &&
(type & (EVENT_MESSAGE_APPEND|EVENT_MESSAGE_NEW));
case EVENT_DAV_FILENAME:
return (extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_CMU_DAVFILENAME) &&
(type & EVENT_CALENDAR);
case EVENT_DAV_UID:
return (extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_CMU_DAVUID) &&
(type & EVENT_CALENDAR);
case EVENT_MESSAGE_CID:
return (extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_FASTMAIL_CID) &&
(type & (EVENT_MESSAGE_APPEND|EVENT_MESSAGE_NEW));
case EVENT_MESSAGE_EMAILID:
return (extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_CMU_EMAILID) &&
(type & (EVENT_MESSAGE_APPEND|EVENT_MESSAGE_NEW));
case EVENT_MESSAGE_THREADID:
return (extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_CMU_THREADID) &&
(type & (EVENT_MESSAGE_APPEND|EVENT_MESSAGE_NEW));
case EVENT_JMAP_EMAIL:
return (extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_FASTMAIL_JMAPEMAIL) &&
(type & (EVENT_MESSAGE_NEW|EVENT_MESSAGE_APPEND));
case EVENT_JMAP_STATES:
return extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_FASTMAIL_JMAPSTATES;
case EVENT_MESSAGES:
if (type & (EVENT_QUOTA_EXCEED|EVENT_QUOTA_WITHIN))
return 1;
if (!(extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_MESSAGES))
return 0;
break;
case EVENT_MODSEQ:
if (!(extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_MODSEQ))
return 0;
break;
case EVENT_OLD_MAILBOX_ID:
return type & (EVENT_MESSAGE_COPY|EVENT_MESSAGE_MOVE|EVENT_MAILBOX_RENAME);
case EVENT_SERVER_ADDRESS:
return type & (EVENT_LOGIN|EVENT_LOGOUT);
case EVENT_SERVICE:
return extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_SERVICE;
case EVENT_TIMESTAMP:
return extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_TIMESTAMP;
case EVENT_ACL_SUBJECT:
return type & EVENT_ACL_CHANGE;
case EVENT_ACL_RIGHTS:
return type & EVENT_ACL_CHANGE;
case EVENT_UIDNEXT:
if (!(extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_UIDNEXT))
return 0;
break;
case EVENT_UIDSET:
if (type & (EVENT_MESSAGE_NEW|EVENT_MESSAGE_APPEND))
return 0;
break;
case EVENT_URI:
return 1;
case EVENT_PID:
return 1;
case EVENT_SERVERFQDN:
return 1;
case EVENT_USER:
return (
type & MESSAGE_EVENTS ||
type & FLAGS_EVENTS ||
type & MAILBOX_EVENTS ||
type & SUBS_EVENTS ||
type & (EVENT_LOGIN|EVENT_LOGOUT|EVENT_QUOTA_CHANGE)
);
case EVENT_MIDSET:
if (!(extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_CMU_MIDSET))
return 0;
break;
case EVENT_SESSIONID:
return extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_CMU_SESSIONID;
case EVENT_UNSEEN_MESSAGES:
if (!(extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_CMU_UNSEENMESSAGES))
return 0;
break;
case EVENT_CONVEXISTS:
return extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_FASTMAIL_CONVEXISTS;
case EVENT_CONVUNSEEN:
return extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_FASTMAIL_CONVUNSEEN;
case EVENT_COUNTERS:
return extra_params & IMAP_ENUM_EVENT_EXTRA_PARAMS_VND_FASTMAIL_COUNTERS;
case EVENT_OLD_UIDSET:
return type & (EVENT_MESSAGE_COPY|EVENT_MESSAGE_MOVE);
default:
return 0;
}
/* test if the parameter is related to a message event */
return type & (MESSAGE_EVENTS|FLAGS_EVENTS);
}
#define TIMESTAMP_MAX 32
EXPORTED void mboxevent_notify(struct mboxevent **mboxevents)
{
enum event_type type;
struct mboxevent *event;
char stimestamp[TIMESTAMP_MAX+1];
char *formatted_message;
const char *fname = NULL;
/* nothing to notify */
if (!*mboxevents)
return;
init_internal();
/* loop over the chained list of events */
for (event = *mboxevents; event; event = event->next) {
if (event->type == EVENT_CANCELLED)
continue;
/* swap FlagsSet and FlagsClear notification order depending the presence of
* the \Seen flag because it changes the value of vnd.cmu.unseenMessages.
* kinda bogus because it only finds two next to each other, but hey */
if (event->type == EVENT_FLAGS_SET &&
event->next &&
event->next->type == EVENT_FLAGS_CLEAR &&
strarray_find_case(&event->next->flagnames, "\\Seen", 0) >= 0) {
struct mboxevent *other = event->next;
// swap the outsides first
other->prev = event->prev;
event->next = other->next;
// swap the insides
event->prev = other;
other->next = event;
// switch the head if needed
if (event == *mboxevents) *mboxevents = other;
// and jump to this one for further processing
event = other;
}
/* verify that at least one message has been added depending the event type */
if (event->type & (MESSAGE_EVENTS|FLAGS_EVENTS)) {
if (event->type & (EVENT_MESSAGE_NEW|EVENT_MESSAGE_APPEND)) {
if (!event->params[EVENT_URI].filled)
continue;
}
else
if (event->uidset == NULL)
continue;
}
/* others quota are not supported by RFC 5423 */
if ((event->type & QUOTA_EVENTS) &&
!event->params[EVENT_QUOTA_STORAGE].filled &&
!event->params[EVENT_QUOTA_MESSAGES].filled)
continue;
/* finish to fill event parameters structure */
if (mboxevent_expected_param(event->type, EVENT_SERVICE)) {
FILL_STRING_PARAM(event, EVENT_SERVICE, xstrdup(config_ident));
}
if (mboxevent_expected_param(event->type, EVENT_SERVERFQDN)) {
FILL_STRING_PARAM(event, EVENT_SERVERFQDN, xstrdup(config_servername));
}
if (mboxevent_expected_param(event->type, EVENT_TIMESTAMP)) {
timeval_to_iso8601(&event->timestamp, timeval_ms,
stimestamp, sizeof(stimestamp));
FILL_STRING_PARAM(event, EVENT_TIMESTAMP, xstrdup(stimestamp));
}
if (event->uidset) {
FILL_STRING_PARAM(event, EVENT_UIDSET, seqset_cstring(event->uidset));
}
if (strarray_size(&event->midset) > 0) {
FILL_ARRAY_PARAM(event, EVENT_MIDSET, &event->midset);
}
if (event->olduidset) {
FILL_STRING_PARAM(event, EVENT_OLD_UIDSET, seqset_cstring(event->olduidset));
}
/* may split FlagsSet event in several event notifications */
do {
type = event->type;
/* prefer MessageRead and MessageTrash to FlagsSet as
* advised in RFC 5423 section 4.2
*/
if (type == EVENT_FLAGS_SET) {
int i;
if ((i = strarray_find(&event->flagnames, "\\Deleted", 0)) >= 0) {
type = EVENT_MESSAGE_TRASH;
free(strarray_remove(&event->flagnames, i));
}
else if ((i = strarray_find(&event->flagnames, "\\Seen", 0)) >= 0) {
type = EVENT_MESSAGE_READ;
free(strarray_remove(&event->flagnames, i));
}
}
if (strarray_size(&event->flagnames) > 0) {
/* don't send flagNames parameter for those events */
if (type != EVENT_MESSAGE_TRASH && type != EVENT_MESSAGE_READ) {
char *flagnames = strarray_join(&event->flagnames, " ");
FILL_STRING_PARAM(event, EVENT_FLAG_NAMES, flagnames);
/* stop to loop for flagsSet event here */
strarray_fini(&event->flagnames);
}
}
/* notification is ready to send */
json_t *jevent = json_formatter(type, event->params);
if (notifier && (type & enabled_events)) {
/* check if expected event parameters are filled */
assert(filled_params(type, event));
formatted_message = json_dumps(jevent,
JSON_PRESERVE_ORDER|JSON_COMPACT);
notify(notifier, "EVENT", NULL, NULL, NULL, 0, NULL,
formatted_message, fname);
free(formatted_message);
}
if (idle_notifier &&
(type & (MESSAGE_EVENTS|FLAGS_EVENTS|MAILBOX_EVENTS|SUBS_EVENTS))) {
/* the group to which the event belongs is for IMAP IDLE/NOTIFY */
json_object_set_new(jevent, "@type", json_string("notify"));
idle_notifier(jevent);
}
json_decref(jevent);
}
while (strarray_size(&event->flagnames) > 0);
}
return;
}
EXPORTED void mboxevent_add_flags(struct mboxevent *event, char *flagnames[MAX_USER_FLAGS],
bit32 system_flags, bit32 user_flags[MAX_USER_FLAGS/32])
{
unsigned flag, flagmask = 0;
if (!event)
return;
/* add system flags */
if (system_flags & FLAG_DELETED) {
if (strarray_find_case(excluded_flags, "\\Deleted", 0) < 0)
strarray_add_case(&event->flagnames, "\\Deleted");
}
if (system_flags & FLAG_ANSWERED) {
if (strarray_find_case(excluded_flags, "\\Answered", 0) < 0)
strarray_add_case(&event->flagnames, "\\Answered");
}
if (system_flags & FLAG_FLAGGED) {
if (strarray_find_case(excluded_flags, "\\Flagged", 0) < 0)
strarray_add_case(&event->flagnames, "\\Flagged");
}
if (system_flags & FLAG_DRAFT) {
if (strarray_find_case(excluded_flags, "\\Draft", 0) < 0)
strarray_add_case(&event->flagnames, "\\Draft");
}
if (system_flags & FLAG_SEEN) {
if (strarray_find_case(excluded_flags, "\\Seen", 0) < 0)
strarray_add_case(&event->flagnames, "\\Seen");
}
/* add user flags */
for (flag = 0; flag < MAX_USER_FLAGS; flag++) {
if ((flag & 31) == 0) {
flagmask = user_flags[flag/32];
}
if (!(flagnames[flag] && (flagmask & (1<<(flag & 31)))))
continue;
if (strarray_find_case(excluded_flags, flagnames[flag], 0) < 0)
strarray_add_case(&event->flagnames, flagnames[flag]);
}
}
EXPORTED void mboxevent_add_flag(struct mboxevent *event, const char *flag)
{
if (!event)
return;
if (mboxevent_expected_param(event->type, EVENT_FLAG_NAMES))
strarray_add_case(&event->flagnames, flag);
}
EXPORTED void mboxevent_set_access(struct mboxevent *event,
const char *serveraddr, const char *clientaddr,
const char *userid, const char *mailboxname,
const int ext_name __attribute__((unused)))
{
struct imapurl imapurl;
int r;
if (!event)
return;
init_internal();
/* only notify Logout after successful Login */
if (!userid && event->type & EVENT_LOGOUT) {
event->type = EVENT_CANCELLED;
return;
}
/* all events needs uri parameter */
memset(&imapurl, 0, sizeof(struct imapurl));
imapurl.server = config_servername;
mbname_t *mbname = mbname_from_intname(mailboxname);
char *extname = xstrdupnull(mbname_extname(mbname, &namespace, NULL));
imapurl.mailbox = extname;
mbname_free(&mbname);
// All events want a URI parameter, which in the case of Login/Logout
// might be useful if it took in to account TLS SNI for example.
if (!event->params[EVENT_URI].filled) {
struct buf url = BUF_INITIALIZER;
imapurl_toURL(&url, &imapurl);
FILL_STRING_PARAM(event, EVENT_URI, buf_release(&url));
}
// Login and Logout events do not have a mailboxname, so avoid looking that up...
if (mailboxname) {
mbentry_t *mbentry = NULL;
r = mboxlist_lookup(mailboxname, &mbentry, NULL);
if (!r && mbentry->uniqueid) {
/* mboxevent_extract_mailbox may already have set EVENT_MAILBOX_ID,
* so make sure to deallocate its previous value */
if (event->params[EVENT_MAILBOX_ID].filled) {
free(event->params[EVENT_MAILBOX_ID].value.s);
}
FILL_STRING_PARAM(event, EVENT_MAILBOX_ID, xstrdup(mbentry->uniqueid));
}
mboxlist_entry_free(&mbentry);
}
if (serveraddr && mboxevent_expected_param(event->type, EVENT_SERVER_ADDRESS)) {
FILL_STRING_PARAM(event, EVENT_SERVER_ADDRESS, xstrdup(serveraddr));
}
if (clientaddr && mboxevent_expected_param(event->type, EVENT_CLIENT_ADDRESS)) {
FILL_STRING_PARAM(event, EVENT_CLIENT_ADDRESS, xstrdup(clientaddr));
}
if (userid && mboxevent_expected_param(event->type, EVENT_USER)) {
FILL_STRING_PARAM(event, EVENT_USER, xstrdupsafe(userid));
}
free(extname);
}
EXPORTED void mboxevent_set_acl(struct mboxevent *event, const char *identifier,
const char *rights)
{
if (!event)
return;
init_internal();
FILL_STRING_PARAM(event, EVENT_ACL_SUBJECT, xstrdup(identifier));
// If rights == 0x0, perhaps this is a Deleteacl command, that
// deletes the rights for a subject, rather than a *setting* the
// acl to an empty string like Setacl: Setacl <folder> <subject> ""
if (rights == 0x0) {
// Pretend it is filled, but do it with null or mboxevent_free
// will trip.
FILL_STRING_PARAM(event, EVENT_ACL_RIGHTS, NULL);
} else {
FILL_STRING_PARAM(event, EVENT_ACL_RIGHTS, xstrdup(rights));
}
}
static const char *threadid(bit64 cid)
{
static char id[JMAP_THREADID_SIZE];
if (!cid) {
strlcpy(id, "NIL", JMAP_THREADID_SIZE);
}
else {
jmap_set_threadid(cid, id);
}
return id;
}
static json_t *jmap_email(struct message_guid *guid, bit64 cid, struct body *body)
{
char emailid[JMAP_EMAILID_SIZE];
jmap_set_emailid(guid, emailid);
return json_pack("{ s:s s:s s:o s:o s:o s:o s:o s:o s:o s:o s:o s:o }",
"id", emailid,
"threadId", threadid(cid),
"sentAt", jmap_header_as_date(body->date),
"subject", jmap_header_as_text(body->subject),
"from",
jmap_emailaddresses_from_addr(body->from,
HEADER_FORM_ADDRESSES),
"sender",
jmap_emailaddresses_from_addr(body->sender,
HEADER_FORM_ADDRESSES),
"replyTo",
jmap_emailaddresses_from_addr(body->reply_to,
HEADER_FORM_ADDRESSES),
"to",
jmap_emailaddresses_from_addr(body->to,
HEADER_FORM_ADDRESSES),
"cc",
jmap_emailaddresses_from_addr(body->cc,
HEADER_FORM_ADDRESSES),
"bcc",
jmap_emailaddresses_from_addr(body->bcc,