]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add mail_get_message_id_no_validation()
authorMarco Bettini <marco.bettini@open-xchange.com>
Tue, 9 May 2023 07:22:15 +0000 (07:22 +0000)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 24 Aug 2023 17:39:19 +0000 (17:39 +0000)
src/lib-storage/mail-storage.h
src/lib-storage/mail.c

index 64e0e49a34f88f192e0c3bf31da3754e3bbe2787..1abf5d4cbdf5138a4bb2670dc04156d8359ecdba 100644 (file)
@@ -983,6 +983,9 @@ int mail_get_backend_mail(struct mail *mail, struct mail **real_mail_r);
    '>' in the *value_r return parameter or NULL if the header wasn't found or
    its value was invalid. */
 int mail_get_message_id(struct mail *mail, const char **value_r);
+/* Try to retrieve a properly parsed Message-ID header, if that fails return
+   the raw header value as it is. */
+int mail_get_message_id_no_validation(struct mail *mail, const char **value_r);
 
 /* Update message flags. */
 void mail_update_flags(struct mail *mail, enum modify_type modify_type,
index b3991d6f65c575ae4a60d78026a39c2be9c71585..0054ba80df7f8d510804c944358ec928e3b7e141 100644 (file)
@@ -427,24 +427,43 @@ int mail_get_backend_mail(struct mail *mail, struct mail **real_mail_r)
        return p->v.get_backend_mail(mail, real_mail_r);
 }
 
-int mail_get_message_id(struct mail *mail, const char **value_r)
+static int mail_get_message_id_full(struct mail *mail,
+                                   const char **value_r,
+                                   bool require_valid)
 {
        const char *hdr_value, *msgid_bare;
        int ret;
 
-       *value_r = NULL;
-
        ret = mail_get_first_header(mail, "Message-ID", &hdr_value);
-       if (ret <= 0)
+       if (ret <= 0) {
+               *value_r = NULL;
                return ret;
+       }
 
+       *value_r = hdr_value; /* save it now as next function alters it */
        msgid_bare = message_id_get_next(&hdr_value);
-       if (msgid_bare == NULL)
+
+       if (msgid_bare != NULL) {
+               /* Complete the message ID with surrounding `<' and `>'. */
+               *value_r = t_strconcat("<",  msgid_bare, ">", NULL);
+               return 1;
+       } else if (!require_valid) {
+               /* *value_r already set above */
+               return 1;
+       } else {
+               *value_r = NULL;
                return 0;
+       }
+}
+
+int mail_get_message_id(struct mail *mail, const char **value_r)
+{
+       return mail_get_message_id_full(mail, value_r, TRUE/*require_valid*/);
+}
 
-       /* Complete the message ID with surrounding `<' and `>'. */
-       *value_r = t_strconcat("<",  msgid_bare, ">", NULL);
-       return 1;
+int mail_get_message_id_no_validation(struct mail *mail, const char **value_r)
+{
+       return mail_get_message_id_full(mail, value_r, FALSE/*require_valid*/);
 }
 
 void mail_update_flags(struct mail *mail, enum modify_type modify_type,