bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#include "lib.h"
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#include "mail-storage.h"
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#include "mail-types.h"
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#include "push-notification-drivers.h"
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#include "push-notification-events.h"
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#include "push-notification-event-messageread.h"
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#include "push-notification-txn-msg.h"
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#define EVENT_NAME "MessageRead"
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic void push_notification_event_messageread_debug_msg
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz(struct push_notification_txn_event *event ATTR_UNUSED)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz{
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz i_debug("%s: Message was flagged as seen", EVENT_NAME);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz}
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic void push_notification_event_messageread_event(
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_txn *ptxn,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_config *ec,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_txn_msg *msg,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct mail *mail,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz enum mail_flags old_flags)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz{
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_messageread_data *data;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz enum mail_flags flags;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz /* If data struct exists, that means the read flag was changed. */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz data = push_notification_txn_msg_get_eventdata(msg, EVENT_NAME);
23bdbb7b1831785c6ba6df190f6369da882d2b9dTimo Sirainen if ((data == NULL) && (old_flags & MAIL_SEEN) == 0) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz flags = mail_get_flags(mail);
23bdbb7b1831785c6ba6df190f6369da882d2b9dTimo Sirainen if ((flags & MAIL_SEEN) != 0) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz data = p_new(ptxn->pool,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_messageread_data, 1);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz data->read = TRUE;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz push_notification_txn_msg_set_eventdata(ptxn, msg, ec, data);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz }
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz }
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz}
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz/* Event definition */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzextern struct push_notification_event push_notification_event_messageread;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_event push_notification_event_messageread = {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz .name = EVENT_NAME,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz .msg = {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz .debug_msg = push_notification_event_messageread_debug_msg
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz },
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz .msg_triggers = {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz .flagchange = push_notification_event_messageread_event
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz }
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz};