1 /* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
2
3 #include "lib.h"
4 #include "array.h"
5 #include "hash.h"
6 #include "istream.h"
7 #include "iso8601-date.h"
8 #include "mail-storage.h"
9
10 #include <time.h>
11
12 #include "push-notification-drivers.h"
13 #include "push-notification-events.h"
14 #include "push-notification-event-message-common.h"
15 #include "push-notification-event-messageappend.h"
16 #include "push-notification-txn-msg.h"
17
18 #define EVENT_NAME "MessageAppend"
19
20 static struct push_notification_event_messageappend_config default_config;
21
push_notification_event_messageappend_default_config(void)22 static void *push_notification_event_messageappend_default_config(void)
23 {
24 i_zero(&default_config);
25
26 return &default_config;
27 }
28
29 static void
push_notification_event_messageappend_debug_msg(struct push_notification_txn_event * event)30 push_notification_event_messageappend_debug_msg(
31 struct push_notification_txn_event *event)
32 {
33 struct push_notification_event_messageappend_data *data = event->data;
34 struct tm *tm;
35
36 if (data->date != -1) {
37 tm = gmtime(&data->date);
38 i_debug("%s: Date [%s]", EVENT_NAME,
39 iso8601_date_create_tm(tm, data->date_tz));
40 }
41
42 if (data->from != NULL)
43 i_debug("%s: From [%s]", EVENT_NAME, data->from);
44 if (data->snippet != NULL)
45 i_debug("%s: Snippet [%s]", EVENT_NAME, data->snippet);
46 if (data->subject != NULL)
47 i_debug("%s: Subject [%s]", EVENT_NAME, data->subject);
48 if (data->to != NULL)
49 i_debug("%s: To [%s]", EVENT_NAME, data->to);
50 }
51
52 static void
push_notification_event_messageappend_event(struct push_notification_txn * ptxn,struct push_notification_event_config * ec,struct push_notification_txn_msg * msg,struct mail * mail)53 push_notification_event_messageappend_event(
54 struct push_notification_txn *ptxn,
55 struct push_notification_event_config *ec,
56 struct push_notification_txn_msg *msg, struct mail *mail)
57 {
58 struct push_notification_event_messageappend_config *config =
59 (struct push_notification_event_messageappend_config *)
60 ec->config;
61 struct push_notification_event_messageappend_data *data;
62
63 if (config->flags == 0)
64 return;
65
66 data = push_notification_txn_msg_get_eventdata(msg, EVENT_NAME);
67 if (data == NULL) {
68 data = p_new(ptxn->pool,
69 struct push_notification_event_messageappend_data, 1);
70 data->date = -1;
71 push_notification_txn_msg_set_eventdata(ptxn, msg, ec, data);
72 }
73
74 push_notification_message_fill(mail, ptxn->pool, config->flags,
75 &data->from, &data->to, &data->subject,
76 &data->date, &data->date_tz,
77 &data->message_id,
78 &data->flags, &data->flags_set,
79 &data->keywords,
80 &data->snippet, &data->ext);
81 }
82
83 /* Event definition */
84
85 extern struct push_notification_event push_notification_event_messageappend;
86
87 struct push_notification_event push_notification_event_messageappend = {
88 .name = EVENT_NAME,
89 .init = {
90 .default_config =
91 push_notification_event_messageappend_default_config,
92 },
93 .msg = {
94 .debug_msg = push_notification_event_messageappend_debug_msg,
95 },
96 .msg_triggers = {
97 .append = push_notification_event_messageappend_event,
98 },
99 };
100