Fixed an issue where re-loading messages with attachments break the included attachment encodings.

This commit is contained in:
Burak Kaan Köse
2024-08-18 22:25:29 +02:00
parent cf51853eec
commit eec67ec7dc

View File

@@ -6,9 +6,8 @@ using Wino.Core.Extensions;
namespace Wino.Mail.ViewModels.Data namespace Wino.Mail.ViewModels.Data
{ {
public class MailAttachmentViewModel : ObservableObject public partial class MailAttachmentViewModel : ObservableObject
{ {
private bool isBusy;
private readonly MimePart _mimePart; private readonly MimePart _mimePart;
public MailAttachmentType AttachmentType { get; } public MailAttachmentType AttachmentType { get; }
@@ -22,23 +21,21 @@ namespace Wino.Mail.ViewModels.Data
/// <summary> /// <summary>
/// Gets or sets whether attachment is busy with opening or saving etc. /// Gets or sets whether attachment is busy with opening or saving etc.
/// </summary> /// </summary>
public bool IsBusy [ObservableProperty]
{ private bool isBusy;
get => isBusy;
set => SetProperty(ref isBusy, value);
}
public MailAttachmentViewModel(MimePart mimePart) public MailAttachmentViewModel(MimePart mimePart)
{ {
_mimePart = mimePart; _mimePart = mimePart;
var array = new byte[_mimePart.Content.Stream.Length]; var memoryStream = new MemoryStream();
_mimePart.Content.Stream.Read(array, 0, (int)_mimePart.Content.Stream.Length);
Content = array; using (memoryStream) mimePart.Content.DecodeTo(memoryStream);
Content = memoryStream.ToArray();
FileName = mimePart.FileName; FileName = mimePart.FileName;
ReadableSize = mimePart.Content.Stream.Length.GetBytesReadable(); ReadableSize = ((long)Content.Length).GetBytesReadable();
var extension = Path.GetExtension(FileName); var extension = Path.GetExtension(FileName);
AttachmentType = GetAttachmentType(extension); AttachmentType = GetAttachmentType(extension);