From bf87c2f6634b992252857076a5eadc6d16e9e9df Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Fri, 3 May 2019 11:45:36 +0300 Subject: movemail: make sure UIDLs are properly stored. * movemail/movemail.c (main): When using POP3 UIDLs for message identification, be sure to store them in the X-UIDL header. --- movemail/movemail.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/movemail/movemail.c b/movemail/movemail.c index 5aad96d4e..0c3178604 100644 --- a/movemail/movemail.c +++ b/movemail/movemail.c @@ -1052,7 +1052,8 @@ main (int argc, char **argv) { struct mu_uidl *uidl; mu_message_t msg; - + mu_header_t hdr; + mu_iterator_current (itr, (void **)&uidl); if ((rc = mu_mailbox_get_message (source, uidl->msgno, &msg)) != 0) @@ -1062,6 +1063,40 @@ main (int argc, char **argv) get_err_count++; continue; } + + /* Check if the downloaded message has X-UIDL header. If not, + add one. This check should disappear one mailutils implements + alternative storage for mailbox meta-data. */ + if ((rc = mu_message_get_header (msg, &hdr))) + { + mu_error (_("%lu: cannot get header: %s"), + (unsigned long) uidl->msgno, mu_strerror (rc)); + } + else + { + char const *suidl = NULL; + + if ((rc = mu_header_sget_value (hdr, MU_HEADER_X_UIDL, &suidl))) + { + if (rc != MU_ERR_NOENT) + mu_error (_("%lu: cannot get %s: %s"), + (unsigned long) uidl->msgno, MU_HEADER_X_UIDL, + mu_strerror (rc)); + } + else if (strcmp (suidl, uidl->uidl)) + { + mu_error (_("%lu: stored and reported UIDL differ; fixing"), + (unsigned long) uidl->msgno); + suidl = NULL; + } + + if ((rc = mu_header_set_value (hdr, MU_HEADER_X_UIDL, + uidl->uidl, 1))) + { + mu_error (_("%lu: cannot set header: %s"), + (unsigned long) uidl->msgno, mu_strerror (rc)); + } + } progress_mark (itr); if (movemail (dest, msg, uidl->msgno)) break; -- cgit v1.2.1