It would have been simpler to share their structs, but that can't be done cleanly
without breaking the API's backwards compatibility.
push-notification-event-messagenew.c \
push-notification-event-messageread.c \
push-notification-event-messagetrash.c \
+ push-notification-event-message-common.c \
push-notification-events.c \
push-notification-events-rfc5423.c \
push-notification-plugin.c \
--- /dev/null
+/* Copyright (c) 2015-2019 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "array.h"
+#include "mail-storage.h"
+#include "push-notification-event-message-common.h"
+
+void push_notification_message_fill(struct mail *mail, pool_t pool,
+ enum push_notification_event_message_flags event_flags,
+ const char **from, const char **to,
+ const char **subject,
+ time_t *date, int *date_tz,
+ const char **message_id,
+ enum mail_flags *flags, bool *flags_set,
+ const char *const **keywords,
+ const char **snippet)
+{
+ const char *value;
+ time_t tmp_date;
+ int tmp_tz;
+
+ if ((*from == NULL) &&
+ (event_flags & PUSH_NOTIFICATION_MESSAGE_HDR_FROM) != 0 &&
+ (mail_get_first_header(mail, "From", &value) >= 0)) {
+ *from = p_strdup(pool, value);
+ }
+
+ if ((*to == NULL) &&
+ (event_flags & PUSH_NOTIFICATION_MESSAGE_HDR_TO) != 0 &&
+ (mail_get_first_header(mail, "To", &value) >= 0)) {
+ *to = p_strdup(pool, value);
+ }
+
+ if ((*subject == NULL) &&
+ (event_flags & PUSH_NOTIFICATION_MESSAGE_HDR_SUBJECT) != 0 &&
+ (mail_get_first_header(mail, "Subject", &value) >= 0)) {
+ *subject = p_strdup(pool, value);
+ }
+
+ if ((*date == -1) &&
+ (event_flags & PUSH_NOTIFICATION_MESSAGE_HDR_DATE) != 0 &&
+ (mail_get_date(mail, &tmp_date, &tmp_tz) >= 0)) {
+ *date = tmp_date;
+ *date_tz = tmp_tz;
+ }
+
+ if ((*message_id == NULL) &&
+ (event_flags & PUSH_NOTIFICATION_MESSAGE_HDR_MESSAGE_ID) != 0 &&
+ (mail_get_first_header(mail, "Message-ID", &value) >= 0)) {
+ *message_id = p_strdup(pool, value);
+ }
+
+ if (!*flags_set &&
+ (event_flags & PUSH_NOTIFICATION_MESSAGE_FLAGS) != 0) {
+ *flags = mail_get_flags(mail);
+ *flags_set = TRUE;
+ }
+
+ if ((*keywords == NULL) &&
+ (event_flags & PUSH_NOTIFICATION_MESSAGE_KEYWORDS) != 0) {
+ const char *const *mail_kws = mail_get_keywords(mail);
+ ARRAY_TYPE(const_string) kws;
+ p_array_init(&kws, pool, 2);
+ for (;*mail_kws != NULL; mail_kws++) {
+ value = p_strdup(pool, *mail_kws);
+ array_append(&kws, &value, 1);
+ }
+ array_append_zero(&kws);
+ *keywords = array_idx(&kws, 0);
+ }
+
+ if ((*snippet == NULL) &&
+ (event_flags & PUSH_NOTIFICATION_MESSAGE_BODY_SNIPPET) != 0 &&
+ (mail_get_special(mail, MAIL_FETCH_BODY_SNIPPET, &value) >= 0)) {
+ /* [0] contains the snippet algorithm, skip over it */
+ i_assert(value[0] != '\0');
+ *snippet = p_strdup(pool, value + 1);
+ }
+}
PUSH_NOTIFICATION_MESSAGE_HDR_MESSAGE_ID = 0x80,
};
+void push_notification_message_fill(struct mail *mail, pool_t pool,
+ enum push_notification_event_message_flags event_flags,
+ const char **from, const char **to,
+ const char **subject,
+ time_t *date, int *date_tz,
+ const char **message_id,
+ enum mail_flags *flags, bool *flags_set,
+ const char *const **keywords,
+ const char **snippet);
#endif /* PUSH_NOTIFICATION_EVENT_MESSAGE_COMMON_H */
struct push_notification_event_messageappend_config *config =
(struct push_notification_event_messageappend_config *)ec->config;
struct push_notification_event_messageappend_data *data;
- const char *value;
- time_t date;
- int tz;
if (config->flags == 0) {
return;
push_notification_txn_msg_set_eventdata(ptxn, msg, ec, data);
}
- if ((data->to == NULL) &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_HDR_TO) != 0 &&
- (mail_get_first_header(mail, "To", &value) >= 0)) {
- data->to = p_strdup(ptxn->pool, value);
- }
-
- if ((data->from == NULL) &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_HDR_FROM) != 0 &&
- (mail_get_first_header(mail, "From", &value) >= 0)) {
- data->from = p_strdup(ptxn->pool, value);
- }
-
- if ((data->subject == NULL) &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_HDR_SUBJECT) != 0 &&
- (mail_get_first_header(mail, "Subject", &value) >= 0)) {
- data->subject = p_strdup(ptxn->pool, value);
- }
-
- if ((data->snippet == NULL) &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_BODY_SNIPPET) != 0 &&
- (mail_get_special(mail, MAIL_FETCH_BODY_SNIPPET, &value) >= 0)) {
- /* [0] contains the snippet algorithm, skip over it */
- i_assert(value[0] != '\0');
- data->snippet = p_strdup(ptxn->pool, value + 1);
- }
-
- if ((data->date == -1) &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_HDR_DATE) != 0 &&
- (mail_get_date(mail, &date, &tz) >= 0)) {
- data->date = date;
- data->date_tz = tz;
- }
-
- if (!data->flags_set &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_FLAGS) != 0) {
- data->flags = mail_get_flags(mail);
- data->flags_set = TRUE;
- }
-
- if ((data->keywords == NULL) &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_KEYWORDS) != 0) {
- const char *const *mail_kws = mail_get_keywords(mail);
- ARRAY_TYPE(const_string) kws;
- p_array_init(&kws, ptxn->pool, 2);
- for (;*mail_kws != NULL; mail_kws++) {
- value = p_strdup(ptxn->pool, *mail_kws);
- array_append(&kws, &value, 1);
- }
- array_append_zero(&kws);
- data->keywords = array_idx(&kws, 0);
- }
-
- if ((data->message_id == NULL) &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_HDR_MESSAGE_ID) != 0 &&
- (mail_get_first_header(mail, "Message-ID", &value) >= 0)) {
- data->message_id = p_strdup(ptxn->pool, value);
- }
+ push_notification_message_fill(mail, ptxn->pool, config->flags,
+ &data->from, &data->to, &data->subject,
+ &data->date, &data->date_tz,
+ &data->message_id,
+ &data->flags, &data->flags_set,
+ &data->keywords,
+ &data->snippet);
}
struct push_notification_event_messagenew_config *config =
(struct push_notification_event_messagenew_config *)ec->config;
struct push_notification_event_messagenew_data *data;
- time_t date;
- int tz;
- const char *value;
if (config->flags == 0) {
return;
push_notification_txn_msg_set_eventdata(ptxn, msg, ec, data);
}
- if ((data->to == NULL) &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_HDR_TO) != 0 &&
- (mail_get_first_header(mail, "To", &value) >= 0)) {
- data->to = p_strdup(ptxn->pool, value);
- }
-
- if ((data->from == NULL) &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_HDR_FROM) != 0 &&
- (mail_get_first_header(mail, "From", &value) >= 0)) {
- data->from = p_strdup(ptxn->pool, value);
- }
-
- if ((data->subject == NULL) &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_HDR_SUBJECT) != 0 &&
- (mail_get_first_header(mail, "Subject", &value) >= 0)) {
- data->subject = p_strdup(ptxn->pool, value);
- }
-
- if ((data->date == -1) &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_HDR_DATE) != 0 &&
- (mail_get_date(mail, &date, &tz) >= 0)) {
- data->date = date;
- data->date_tz = tz;
- }
-
- if ((data->snippet == NULL) &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_BODY_SNIPPET) != 0 &&
- (mail_get_special(mail, MAIL_FETCH_BODY_SNIPPET, &value) >= 0)) {
- /* [0] contains the snippet algorithm, skip over it */
- i_assert(value[0] != '\0');
- data->snippet = p_strdup(ptxn->pool, value + 1);
- }
-
- if (!data->flags_set &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_FLAGS) != 0) {
- data->flags = mail_get_flags(mail);
- data->flags_set = TRUE;
- }
-
- if ((data->keywords == NULL) &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_KEYWORDS) != 0) {
- const char *const *mail_kws = mail_get_keywords(mail);
- ARRAY_TYPE(const_string) kws;
- p_array_init(&kws, ptxn->pool, 2);
- for (;*mail_kws != NULL; mail_kws++) {
- value = p_strdup(ptxn->pool, *mail_kws);
- array_append(&kws, &value, 1);
- }
- array_append_zero(&kws);
- data->keywords = array_idx(&kws, 0);
- }
-
- if ((data->message_id == NULL) &&
- (config->flags & PUSH_NOTIFICATION_MESSAGE_HDR_MESSAGE_ID) != 0 &&
- (mail_get_first_header(mail, "Message-ID", &value) >= 0)) {
- data->message_id = p_strdup(ptxn->pool, value);
- }
+ push_notification_message_fill(mail, ptxn->pool, config->flags,
+ &data->from, &data->to, &data->subject,
+ &data->date, &data->date_tz,
+ &data->message_id,
+ &data->flags, &data->flags_set,
+ &data->keywords,
+ &data->snippet);
}