]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
push-notification: Support UTF8-decoded from/to/subject
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Sun, 10 Nov 2019 12:09:18 +0000 (14:09 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 22 Nov 2019 10:35:55 +0000 (12:35 +0200)
Use a new struct push_notification_message_ext for this so both MessageNew
and MessageAppend events can share the same struct.

For From and To addresses keep the actual email address and display-name in
separate fields, since some drivers want them separated.

src/plugins/push-notification/push-notification-event-message-common.c
src/plugins/push-notification/push-notification-event-message-common.h
src/plugins/push-notification/push-notification-event-messageappend.c
src/plugins/push-notification/push-notification-event-messageappend.h
src/plugins/push-notification/push-notification-event-messagenew.c
src/plugins/push-notification/push-notification-event-messagenew.h

index 46a6319b201206f3a98db791a8d32a06ef2237a7..36795a2376c6677b56bed31a2ee75b0b30c060bf 100644 (file)
@@ -1,9 +1,37 @@
 /* Copyright (c) 2015-2019 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
+#include "str.h"
+#include "message-address.h"
+#include "message-header-decode.h"
 #include "mail-storage.h"
 #include "push-notification-event-message-common.h"
 
+static void decode_address_header(pool_t pool, const char *hdr,
+                                 const char **address_r, const char **name_r)
+{
+       struct message_address *addr;
+
+       if (hdr == NULL)
+               return;
+
+       addr = message_address_parse(pool_datastack_create(),
+               (const unsigned char *)hdr, strlen(hdr), 1, 0);
+       if (addr->domain[0] != '\0')
+               *address_r = p_strdup_printf(pool, "%s@%s", addr->mailbox,
+                                            addr->domain);
+       else if (addr->mailbox[0] != '\0')
+               *address_r = p_strdup(pool, addr->mailbox);
+
+       if (addr->name != NULL) {
+               string_t *name_utf8 = t_str_new(128);
+
+               message_header_decode_utf8((const unsigned char *)addr->name,
+                                          strlen(addr->name), name_utf8, NULL);
+               *name_r = p_strdup(pool, str_c(name_utf8));
+       }
+}
+
 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,
@@ -12,7 +40,8 @@ void push_notification_message_fill(struct mail *mail, pool_t pool,
                                    const char **message_id,
                                    enum mail_flags *flags, bool *flags_set,
                                    const char *const **keywords,
-                                   const char **snippet)
+                                   const char **snippet,
+                                   struct push_notification_message_ext *ext)
 {
        const char *value;
        time_t tmp_date;
@@ -22,18 +51,29 @@ void push_notification_message_fill(struct mail *mail, pool_t pool,
            (event_flags & PUSH_NOTIFICATION_MESSAGE_HDR_FROM) != 0 &&
            (mail_get_first_header(mail, "From", &value) >= 0)) {
                *from = p_strdup(pool, value);
+               decode_address_header(pool, value, &ext->from_address,
+                                     &ext->from_display_name_utf8);
        }
 
        if ((*to == NULL) &&
            (event_flags & PUSH_NOTIFICATION_MESSAGE_HDR_TO) != 0 &&
            (mail_get_first_header(mail, "To", &value) >= 0)) {
                *to = p_strdup(pool, value);
+               decode_address_header(pool, value, &ext->to_address,
+                                     &ext->to_display_name_utf8);
        }
 
        if ((*subject == NULL) &&
            (event_flags & PUSH_NOTIFICATION_MESSAGE_HDR_SUBJECT) != 0 &&
            (mail_get_first_header(mail, "Subject", &value) >= 0)) {
+               string_t *subject_utf8 = t_str_new(128);
+
                *subject = p_strdup(pool, value);
+               if (value != NULL) {
+                       message_header_decode_utf8((const unsigned char *)value,
+                                                  strlen(value), subject_utf8, NULL);
+                       ext->subject_utf8 = p_strdup(pool, str_c(subject_utf8));
+               }
        }
 
        if ((*date == -1) &&
index 0c68e08f92d39591db66a2e0b8e653d5bc93a6a3..370e6b3cc9cb629fd138059449c799b2843877f8 100644 (file)
@@ -23,6 +23,12 @@ enum push_notification_event_message_flags {
     PUSH_NOTIFICATION_MESSAGE_HDR_MESSAGE_ID = 0x80,
 };
 
+struct push_notification_message_ext {
+       const char *from_address, *from_display_name_utf8;
+       const char *to_address, *to_display_name_utf8;
+       const char *subject_utf8;
+};
+
 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,
@@ -31,7 +37,8 @@ void push_notification_message_fill(struct mail *mail, pool_t pool,
                                    const char **message_id,
                                    enum mail_flags *flags, bool *flags_set,
                                    const char *const **keywords,
-                                   const char **snippet);
+                                   const char **snippet,
+                                   struct push_notification_message_ext *ext);
 
 #endif /* PUSH_NOTIFICATION_EVENT_MESSAGE_COMMON_H */
 
index 4bc4c6651bab7e0044d0c5ca6ace5d8f262271f3..d2059596fd283072ff1a5d4c4bc05509e645698a 100644 (file)
@@ -85,7 +85,7 @@ push_notification_event_messageappend_event(struct push_notification_txn *ptxn,
                                   &data->message_id,
                                   &data->flags, &data->flags_set,
                                   &data->keywords,
-                                  &data->snippet);
+                                  &data->snippet, &data->ext);
 }
 
 
index ba4e0708966763c715b9e83de22a804e46d189f6..207224410864057def80d8015b9bdaf69f589cd6 100644 (file)
@@ -23,6 +23,8 @@ struct push_notification_event_messageappend_data {
     const char *const *keywords;
     /* PUSH_NOTIFICATION_MESSAGE_HDR_MESSAGE_ID */
     const char *message_id;
+
+    struct push_notification_message_ext ext;
 };
 
 
index 20a6dd21c8ff8a7f66dce4f219dad0a13d4a80b5..1a047b98daddea2e9241764ae140492c1982bf06 100644 (file)
@@ -86,7 +86,7 @@ push_notification_event_messagenew_event(struct push_notification_txn *ptxn,
                                   &data->message_id,
                                   &data->flags, &data->flags_set,
                                   &data->keywords,
-                                  &data->snippet);
+                                  &data->snippet, &data->ext);
 }
 
 
index 149f2def6bafa02955acc126de575dce0f0f5073..4c1b1a2874ef1467e65bff945d0fd55bdaf55e50 100644 (file)
@@ -30,6 +30,8 @@ struct push_notification_event_messagenew_data {
     const char *const *keywords;
     /* PUSH_NOTIFICATION_MESSAGE_HDR_MESSAGE_ID */
     const char *message_id;
+
+    struct push_notification_message_ext ext;
 };