]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: mail - Add mail_get_message_id().
authorStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 18 Feb 2020 22:30:29 +0000 (23:30 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 4 May 2020 10:43:32 +0000 (10:43 +0000)
It is a convenience function that reads and parses the Message-ID.

src/lib-storage/mail-storage.h
src/lib-storage/mail.c

index 501a815317cd5babd65c55fe5ee048722b311c56..aeac791c6b15f20ca0ac2690e900cf2b6ed6fda4 100644 (file)
@@ -975,6 +975,14 @@ int mail_get_special(struct mail *mail, enum mail_fetch_field field,
    but in virtual mailboxes it points to the backend mailbox. */
 int mail_get_backend_mail(struct mail *mail, struct mail **real_mail_r);
 
+/* Retrieve and parse the value of the Message-ID header field. Returns 1 if the
+   header was found and it contains a valid message ID, 0 if the header was not
+   found or no valid message ID was contained in it, and -1 if an error occurred
+   while retrieving the header. Returns the message ID value including '<' and
+   '>' 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);
+
 /* Update message flags. */
 void mail_update_flags(struct mail *mail, enum modify_type modify_type,
                       enum mail_flags flags);
index aab7c4e77c7c72a31b39608bb58b514bc94bb6ba..a1b0e3d7db9b601f9a8d8015a6c090cf298fbd44 100644 (file)
@@ -11,6 +11,7 @@
 #include "istream.h"
 #include "mail-cache.h"
 #include "mail-storage-private.h"
+#include "message-id.h"
 #include "message-part-data.h"
 #include "imap-bodystructure.h"
 
@@ -362,6 +363,26 @@ 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)
+{
+       const char *hdr_value, *msgid_bare;
+       int ret;
+
+       *value_r = NULL;
+
+       ret = mail_get_first_header(mail, "Message-ID", &hdr_value);
+       if (ret <= 0)
+               return ret;
+
+       msgid_bare = message_id_get_next(&hdr_value);
+       if (msgid_bare == NULL)
+               return 0;
+
+       /* Complete the message ID with surrounding `<' and `>'. */
+       *value_r = t_strconcat("<",  msgid_bare, ">", NULL);
+       return 1;
+}
+
 void mail_update_flags(struct mail *mail, enum modify_type modify_type,
                       enum mail_flags flags)
 {