]> 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)
committerMarco Bettini <marco.bettini@open-xchange.com>
Wed, 10 May 2023 08:08:24 +0000 (08:08 +0000)
src/lib-storage/mail-storage.h
src/lib-storage/mail.c

index bf889ec4acd3a582e73b693b25b0a098546b889b..78a4bf1058f4f51f0415ff757f6a0d2cf24fac56 100644 (file)
@@ -990,6 +990,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 08968bc3a834fc67d5fe7f08690988b5d1afcf24..9bd76b4eb1357c83fee9ce513f35af2ac7b162e6 100644 (file)
@@ -437,24 +437,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,