From eec67ec7dc133967693c99615b96d00df237677f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Sun, 18 Aug 2024 22:25:29 +0200 Subject: [PATCH] Fixed an issue where re-loading messages with attachments break the included attachment encodings. --- .../Data/MailAttachmentViewModel.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Wino.Mail.ViewModels/Data/MailAttachmentViewModel.cs b/Wino.Mail.ViewModels/Data/MailAttachmentViewModel.cs index 90387ce4..469b55ba 100644 --- a/Wino.Mail.ViewModels/Data/MailAttachmentViewModel.cs +++ b/Wino.Mail.ViewModels/Data/MailAttachmentViewModel.cs @@ -6,9 +6,8 @@ using Wino.Core.Extensions; namespace Wino.Mail.ViewModels.Data { - public class MailAttachmentViewModel : ObservableObject + public partial class MailAttachmentViewModel : ObservableObject { - private bool isBusy; private readonly MimePart _mimePart; public MailAttachmentType AttachmentType { get; } @@ -22,23 +21,21 @@ namespace Wino.Mail.ViewModels.Data /// /// Gets or sets whether attachment is busy with opening or saving etc. /// - public bool IsBusy - { - get => isBusy; - set => SetProperty(ref isBusy, value); - } + [ObservableProperty] + private bool isBusy; public MailAttachmentViewModel(MimePart mimePart) { _mimePart = mimePart; - var array = new byte[_mimePart.Content.Stream.Length]; - _mimePart.Content.Stream.Read(array, 0, (int)_mimePart.Content.Stream.Length); + var memoryStream = new MemoryStream(); - Content = array; + using (memoryStream) mimePart.Content.DecodeTo(memoryStream); + + Content = memoryStream.ToArray(); FileName = mimePart.FileName; - ReadableSize = mimePart.Content.Stream.Length.GetBytesReadable(); + ReadableSize = ((long)Content.Length).GetBytesReadable(); var extension = Path.GetExtension(FileName); AttachmentType = GetAttachmentType(extension);