From: Timo Sirainen Date: Sun, 10 Nov 2019 12:09:18 +0000 (+0200) Subject: push-notification: Support UTF8-decoded from/to/subject X-Git-Tag: 2.3.9~42 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=276e2f799ec47e486cf608e704dbb63fa0b5d0a6;p=thirdparty%2Fdovecot%2Fcore.git push-notification: Support UTF8-decoded from/to/subject 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. --- diff --git a/src/plugins/push-notification/push-notification-event-message-common.c b/src/plugins/push-notification/push-notification-event-message-common.c index 46a6319b20..36795a2376 100644 --- a/src/plugins/push-notification/push-notification-event-message-common.c +++ b/src/plugins/push-notification/push-notification-event-message-common.c @@ -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) && diff --git a/src/plugins/push-notification/push-notification-event-message-common.h b/src/plugins/push-notification/push-notification-event-message-common.h index 0c68e08f92..370e6b3cc9 100644 --- a/src/plugins/push-notification/push-notification-event-message-common.h +++ b/src/plugins/push-notification/push-notification-event-message-common.h @@ -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 */ diff --git a/src/plugins/push-notification/push-notification-event-messageappend.c b/src/plugins/push-notification/push-notification-event-messageappend.c index 4bc4c6651b..d2059596fd 100644 --- a/src/plugins/push-notification/push-notification-event-messageappend.c +++ b/src/plugins/push-notification/push-notification-event-messageappend.c @@ -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); } diff --git a/src/plugins/push-notification/push-notification-event-messageappend.h b/src/plugins/push-notification/push-notification-event-messageappend.h index ba4e070896..2072244108 100644 --- a/src/plugins/push-notification/push-notification-event-messageappend.h +++ b/src/plugins/push-notification/push-notification-event-messageappend.h @@ -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; }; diff --git a/src/plugins/push-notification/push-notification-event-messagenew.c b/src/plugins/push-notification/push-notification-event-messagenew.c index 20a6dd21c8..1a047b98da 100644 --- a/src/plugins/push-notification/push-notification-event-messagenew.c +++ b/src/plugins/push-notification/push-notification-event-messagenew.c @@ -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); } diff --git a/src/plugins/push-notification/push-notification-event-messagenew.h b/src/plugins/push-notification/push-notification-event-messagenew.h index 149f2def6b..4c1b1a2874 100644 --- a/src/plugins/push-notification/push-notification-event-messagenew.h +++ b/src/plugins/push-notification/push-notification-event-messagenew.h @@ -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; };