diff options
Diffstat (limited to 'libproto/dotmail/message.c')
-rw-r--r-- | libproto/dotmail/message.c | 106 |
1 files changed, 62 insertions, 44 deletions
diff --git a/libproto/dotmail/message.c b/libproto/dotmail/message.c index 1a8761648..3b9a174f1 100644 --- a/libproto/dotmail/message.c +++ b/libproto/dotmail/message.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 2019 Free Software Foundation, Inc. + Copyright (C) 2019-2024 Free Software Foundation, Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -156,7 +156,8 @@ mu_dotmail_message_attr_load (struct mu_dotmail_message *dmsg) if (!dmsg->attr_scanned) { if (dmsg->hdr[mu_dotmail_hdr_status]) - mu_string_to_flags (dmsg->hdr[mu_dotmail_hdr_status], &dmsg->attr_flags); + mu_attribute_string_to_flags (dmsg->hdr[mu_dotmail_hdr_status], + &dmsg->attr_flags); else dmsg->attr_flags = 0; dmsg->attr_scanned = 1; @@ -233,6 +234,13 @@ dotmail_message_qid (mu_message_t msg, mu_message_qid_t *pqid) return mu_asprintf (pqid, "%lu", (unsigned long) dmsg->message_start); } +static void +dotmail_message_detach (mu_message_t msg) +{ + struct mu_dotmail_message *dmsg = mu_message_get_owner (msg); + dmsg->message = NULL; +} + static int dotmail_message_setup (mu_message_t msg) { @@ -271,7 +279,8 @@ mu_dotmail_message_get (struct mu_dotmail_message *dmsg, mu_message_t *mptr) mu_message_destroy (&msg, dmsg); return rc; } - + msg->_detach = dotmail_message_detach; + /* Set the UID. */ mu_message_set_uid (msg, dotmail_message_uid, dmsg); mu_message_set_qid (msg, dotmail_message_qid, dmsg); @@ -313,7 +322,7 @@ dotmail_message_uid_save (mu_stream_t dst, int dotmail_message_copy_with_uid (mu_stream_t dst, struct mu_dotmail_message const *dmsg, - struct mu_dotmail_message_ref *ref) + struct mu_dotmail_message *ref) { int rc; mu_stream_t src; @@ -325,10 +334,6 @@ dotmail_message_copy_with_uid (mu_stream_t dst, src = dmsg->mbox->mailbox->stream; - rc = mu_stream_seek (dst, 0, MU_SEEK_CUR, &ref->message_start); - if (rc) - return rc; - rc = mu_stream_seek (src, dmsg->message_start, MU_SEEK_SET, NULL); if (rc) return rc; @@ -405,59 +410,72 @@ msg_header_to_stream (mu_stream_t dst, mu_stream_t src, int mu_dotmail_message_reconstruct (mu_stream_t dest, struct mu_dotmail_message *dmsg, - struct mu_dotmail_message_ref *ref) + struct mu_dotmail_message *ref) { int rc; mu_header_t hdr; mu_body_t body; mu_stream_t str, flt; + struct mu_dotmail_message tmp; + int same_ref; - if (!dmsg->message) - return dotmail_message_copy_with_uid (dest, dmsg, ref); - + if ((same_ref = (ref == dmsg)) != 0) + { + /* Operate on temporary copy of dmsg */ + tmp = *ref; + ref = &tmp; + } + rc = mu_stream_seek (dest, 0, MU_SEEK_CUR, &ref->message_start); if (rc) return rc; - rc = mu_message_get_header (dmsg->message, &hdr); - if (rc) - return rc; - rc = mu_header_get_streamref (hdr, &str); - if (rc) - return rc; - rc = msg_header_to_stream (dest, str, dmsg); - mu_stream_unref (str); - if (rc) - return rc; - - rc = mu_stream_seek (dest, 0, MU_SEEK_CUR, &ref->body_start); - if (rc) - return rc; + if (!dmsg->message) + rc = dotmail_message_copy_with_uid (dest, dmsg, ref); + else + { + rc = mu_message_get_header (dmsg->message, &hdr); + if (rc) + return rc; + rc = mu_header_get_streamref (hdr, &str); + if (rc) + return rc; + rc = msg_header_to_stream (dest, str, dmsg); + mu_stream_unref (str); + if (rc) + return rc; - /* Copy body */ - rc = mu_message_get_body (dmsg->message, &body); - if (rc) - return rc; - rc = mu_body_get_streamref (body, &str); - if (rc) + rc = mu_stream_seek (dest, 0, MU_SEEK_CUR, &ref->body_start); + if (rc) return rc; - rc = mu_filter_create (&flt, str, "DOT", - MU_FILTER_ENCODE, MU_STREAM_READ); - mu_stream_unref (str); - if (rc) - return rc; - rc = mu_stream_copy (dest, flt, 0, NULL); - mu_stream_unref (flt); - if (rc == 0) - { - rc = mu_stream_seek (dest, 0, MU_SEEK_CUR, &ref->message_end); + /* Copy body */ + rc = mu_message_get_body (dmsg->message, &body); + if (rc) + return rc; + rc = mu_body_get_streamref (body, &str); + if (rc) + return rc; + rc = mu_filter_create (&flt, str, "DOT", + MU_FILTER_ENCODE, MU_STREAM_READ); + mu_stream_unref (str); if (rc) return rc; - ref->message_end -= 2; - ref->rescan = 1; + rc = mu_stream_copy (dest, flt, 0, NULL); + mu_stream_unref (flt); + if (rc == 0) + { + rc = mu_stream_seek (dest, 0, MU_SEEK_CUR, &ref->message_end); + if (rc) + return rc; + + ref->message_end -= 2; + } } + if (same_ref) + *dmsg = tmp; + return rc; } |