From: Stephan Bosch Date: Tue, 18 Feb 2020 22:30:29 +0000 (+0100) Subject: lib-storage: mail - Add mail_get_message_id(). X-Git-Tag: 2.3.11.2~135 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=810866dccc28be9e6f271e807b75f0e316a01751;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: mail - Add mail_get_message_id(). It is a convenience function that reads and parses the Message-ID. --- diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index 501a815317..aeac791c6b 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -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); diff --git a/src/lib-storage/mail.c b/src/lib-storage/mail.c index aab7c4e77c..a1b0e3d7db 100644 --- a/src/lib-storage/mail.c +++ b/src/lib-storage/mail.c @@ -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) {