bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#include "push-notification-event-flagsclear.h"
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic struct push_notification_event_flagsclear_config default_config;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic void *push_notification_event_flagsclear_default_config(void)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic void push_notification_event_flagsclear_debug_msg
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz(struct push_notification_txn_event *event)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsclear_data *data = event->data;
23bdbb7b1831785c6ba6df190f6369da882d2b9dTimo Sirainen if ((data->flags_clear & MAIL_ANSWERED) != 0) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz i_debug("%s: Answered flag cleared", EVENT_NAME);
23bdbb7b1831785c6ba6df190f6369da882d2b9dTimo Sirainen if ((data->flags_clear & MAIL_FLAGGED) != 0) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz i_debug("%s: Flagged flag cleared", EVENT_NAME);
23bdbb7b1831785c6ba6df190f6369da882d2b9dTimo Sirainen if ((data->flags_clear & MAIL_DELETED) != 0) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz i_debug("%s: Deleted flag cleared", EVENT_NAME);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz i_debug("%s: Seen flag cleared", EVENT_NAME);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz i_debug("%s: Draft flag cleared", EVENT_NAME);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz array_foreach(&data->keywords_clear, keyword) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz i_debug("%s: Keyword clear [%s]", EVENT_NAME, *keyword);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic struct push_notification_event_flagsclear_data *
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzpush_notification_event_flagsclear_get_data(struct push_notification_txn *ptxn,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_config *ec)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsclear_config *config =
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz (struct push_notification_event_flagsclear_config *)ec->config;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsclear_data *data;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz data = push_notification_txn_msg_get_eventdata(msg, EVENT_NAME);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsclear_data, 1);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz p_array_init(&data->keywords_clear, ptxn->pool, 4);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz p_array_init(&data->keywords_old, ptxn->pool, 4);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz push_notification_txn_msg_set_eventdata(ptxn, msg, ec, data);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic void push_notification_event_flagsclear_flags_event(
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_config *ec,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsclear_config *config =
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz (struct push_notification_event_flagsclear_config *)ec->config;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsclear_data *data;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz unsigned int i;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz data = push_notification_event_flagsclear_get_data(ptxn, msg, ec);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz for (i = 0; i < N_ELEMENTS(flag_check_always); i++) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz data->flags_clear |= flag_check_always[i];
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic void push_notification_event_flagsclear_keywords_event(
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_config *ec,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz const char *const *old_keywords)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsclear_config *config =
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz (struct push_notification_event_flagsclear_config *)ec->config;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsclear_data *data;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz const char *const *keywords, *const *kp, *ok;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz data = push_notification_event_flagsclear_get_data(ptxn, msg, ec);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz for (; *old_keywords != NULL; old_keywords++) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz array_append(&data->keywords_clear, &ok, 1);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz array_append(&data->keywords_old, &ok, 1);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic void push_notification_event_flagsclear_free_msg(
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_txn_event *event)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsclear_data *data = event->data;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz if (array_is_created(&data->keywords_clear)) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz if (array_is_created(&data->keywords_old)) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz/* Event definition */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzextern struct push_notification_event push_notification_event_flagsclear;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_event push_notification_event_flagsclear = {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz .default_config = push_notification_event_flagsclear_default_config
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz .debug_msg = push_notification_event_flagsclear_debug_msg,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz .free_msg = push_notification_event_flagsclear_free_msg
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz .flagchange = push_notification_event_flagsclear_flags_event,