]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
push-notification-event-messageappend: Include date information parsed from headers
authorAki Tuomi <aki.tuomi@dovecot.fi>
Fri, 28 Sep 2018 10:30:01 +0000 (13:30 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Wed, 14 Nov 2018 12:01:53 +0000 (14:01 +0200)
Consistency with MessageNew

src/plugins/push-notification/push-notification-event-messageappend.c
src/plugins/push-notification/push-notification-event-messageappend.h

index 41a391d63bde7e6092abb906856bcc637c7dfbf1..1c6e01fee9739ef76a7c51a47e740490e08f85c9 100644 (file)
@@ -4,8 +4,11 @@
 #include "array.h"
 #include "hash.h"
 #include "istream.h"
+#include "iso8601-date.h"
 #include "mail-storage.h"
 
+#include <time.h>
+
 #include "push-notification-drivers.h"
 #include "push-notification-events.h"
 #include "push-notification-event-message-common.h"
@@ -29,6 +32,13 @@ static void push_notification_event_messageappend_debug_msg
 (struct push_notification_txn_event *event)
 {
     struct push_notification_event_messageappend_data *data = event->data;
+    struct tm *tm;
+
+    if (data->date != -1) {
+        tm = gmtime(&data->date);
+        i_debug("%s: Date [%s]", EVENT_NAME,
+                iso8601_date_create_tm(tm, data->date_tz));
+    }
 
     if (data->from != NULL) {
         i_debug("%s: From [%s]", EVENT_NAME, data->from);
@@ -57,6 +67,8 @@ push_notification_event_messageappend_event(struct push_notification_txn *ptxn,
         (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;
@@ -66,6 +78,7 @@ push_notification_event_messageappend_event(struct push_notification_txn *ptxn,
     if (data == NULL) {
         data = p_new(ptxn->pool,
                      struct push_notification_event_messageappend_data, 1);
+        data->date = -1;
         push_notification_txn_msg_set_eventdata(ptxn, msg, ec, data);
     }
 
@@ -94,6 +107,13 @@ push_notification_event_messageappend_event(struct push_notification_txn *ptxn,
         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;
+    }
 }
 
 
index d903de55d41ade2b67490df43c58c76ce2b6af26..c10a10c85d4b22c73850785e5dd880ae41308695 100644 (file)
@@ -13,6 +13,9 @@ struct push_notification_event_messageappend_data {
     const char *to;
     const char *subject;
     const char *snippet;
+    /* PUSH_NOTIFICATION_MESSAGE_HDR_DATE */
+    time_t date;
+    int date_tz;
 };