Initial commit.

This commit is contained in:
Burak Kaan Köse
2024-04-18 01:44:37 +02:00
parent 524ea4c0e1
commit 12d3814626
671 changed files with 77295 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
using System.Collections.Specialized;
using System.Linq;
using MimeKit;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Enums;
namespace Wino.Core.Domain.Models.MailItem
{
public class DraftCreationOptions
{
public MimeMessage ReferenceMimeMessage { get; set; }
public MailCopy ReferenceMailCopy { get; set; }
public DraftCreationReason Reason { get; set; }
#region Mailto Protocol Related Stuff
public const string MailtoSubjectParameterKey = "subject";
public const string MailtoBodyParameterKey = "body";
public const string MailtoToParameterKey = "mailto";
public const string MailtoCCParameterKey = "cc";
public const string MailtoBCCParameterKey = "bcc";
public NameValueCollection MailtoParameters { get; set; }
private bool IsMailtoParameterExists(string parameterKey)
=> MailtoParameters != null
&& MailtoParameters.AllKeys.Contains(parameterKey);
public bool TryGetMailtoValue(string key, out string value)
{
bool valueExists = IsMailtoParameterExists(key);
value = valueExists ? MailtoParameters[key] : string.Empty;
return valueExists;
}
#endregion
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Text;
using MimeKit;
using Wino.Core.Domain.Entities;
namespace Wino.Core.Domain.Models.MailItem
{
public class DraftPreperationRequest : DraftCreationOptions
{
public DraftPreperationRequest(MailAccount account, MailCopy createdLocalDraftCopy, MimeMessage createdLocalDraftMimeMessage)
{
Account = account ?? throw new ArgumentNullException(nameof(account));
CreatedLocalDraftCopy = createdLocalDraftCopy ?? throw new ArgumentNullException(nameof(createdLocalDraftCopy));
CreatedLocalDraftMimeMessage = createdLocalDraftMimeMessage ?? throw new ArgumentNullException(nameof(createdLocalDraftMimeMessage));
}
public MailCopy CreatedLocalDraftCopy { get; set; }
public MimeMessage CreatedLocalDraftMimeMessage { get; set; }
public MailAccount Account { get; }
}
}

View File

@@ -0,0 +1,33 @@
using System;
using Wino.Core.Domain.Entities;
namespace Wino.Core.Domain.Models.MailItem
{
/// <summary>
/// Interface of simplest representation of a MailCopy.
/// </summary>
public interface IMailItem
{
Guid UniqueId { get; }
string Id { get; }
string Subject { get; }
string ThreadId { get; }
string MessageId { get; }
string References { get; }
string InReplyTo { get; }
string PreviewText { get; }
string FromName { get; }
DateTime CreationDate { get; }
string FromAddress { get; }
bool HasAttachments { get; }
bool IsFlagged { get; }
bool IsFocused { get; }
bool IsRead { get; }
string DraftId { get; }
bool IsDraft { get; }
Guid FileId { get; }
MailItemFolder AssignedFolder { get; }
MailAccount AssignedAccount { get; }
}
}

View File

@@ -0,0 +1,16 @@
using System.Collections.ObjectModel;
namespace Wino.Core.Domain.Models.MailItem
{
/// <summary>
/// Interface that represents conversation threads.
/// Even though this type has 1 single UI representation most of the time,
/// it can contain multiple IMailItem.
/// </summary>
public interface IMailItemThread : IMailItem
{
ObservableCollection<IMailItem> ThreadItems { get; }
IMailItem LatestMailItem { get; }
IMailItem FirstMailItem { get; }
}
}

View File

@@ -0,0 +1,18 @@
using System;
using Wino.Core.Domain.Enums;
namespace Wino.Core.Domain.Models.MailItem
{
public class MailDetailInformation
{
public string Id { get; set; }
public Guid AccountId { get; set; }
public Guid FolderId { get; set; }
public string RemoteFolderId { get; set; }
public SpecialFolderType SpecialFolderType { get; set; }
public bool IsRead { get; set; }
public bool IsFlagged { get; set; }
public bool IsDraft { get; set; }
}
}

View File

@@ -0,0 +1,25 @@
using System.Collections.Generic;
namespace Wino.Core.Domain.Models.MailItem
{
/// <summary>
/// Class that holds information when the drag/drop of mails are performed.
/// </summary>
public class MailDragPackage
{
public MailDragPackage(IEnumerable<IMailItem> draggingMails)
{
DraggingMails = draggingMails;
}
public MailDragPackage(IMailItem draggingMail)
{
DraggingMails =
[
draggingMail
];
}
public IEnumerable<IMailItem> DraggingMails { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
using System;
namespace Wino.Core.Domain.Models.MailItem
{
public class MailFolderPairMetadata
{
public Guid FolderId { get; set; }
public string RemoteFolderId { get; set; }
public string MailCopyId { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
using MimeKit;
using Wino.Core.Domain.Entities;
namespace Wino.Core.Domain.Models.MailItem
{
public record NewMailItemPackage(MailCopy Copy, MimeMessage Mime, string AssignedRemoteFolderId);
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Models.Folders;
namespace Wino.Core.Domain.Models.MailItem
{
public record MailListInitializationOptions(IEnumerable<IMailItemFolder> Folders,
FilterOptionType FilterType,
SortingOptionType SortingOptionType,
bool CreateThreads,
bool? IsFocusedOnly,
string SearchQuery,
IEnumerable<Guid> ExistingUniqueIds);
}

View File

@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Models.Folders;
namespace Wino.Core.Domain.Models.MailItem
{
/// <summary>
/// Encapsulates the options for preparing requests to execute mail operations for mail items like Move, Delete, MarkAsRead, etc.
/// </summary>
public class MailOperationPreperationRequest
{
public MailOperationPreperationRequest(MailOperation action,
IEnumerable<MailCopy> mailItems,
bool toggleExecution = false,
IMailItemFolder moveTargetFolder = null,
bool ignoreHardDeleteProtection = false)
{
Action = action;
MailItems = mailItems ?? throw new ArgumentNullException(nameof(mailItems));
ToggleExecution = toggleExecution;
MoveTargetFolder = moveTargetFolder;
IgnoreHardDeleteProtection = ignoreHardDeleteProtection;
}
public MailOperationPreperationRequest(MailOperation action,
MailCopy singleMailItem,
bool toggleExecution = false,
IMailItemFolder moveTargetFolder = null,
bool ignoreHardDeleteProtection = false)
{
Action = action;
MailItems = new List<MailCopy>() { singleMailItem };
ToggleExecution = toggleExecution;
MoveTargetFolder = moveTargetFolder;
IgnoreHardDeleteProtection = ignoreHardDeleteProtection;
}
/// <summary>
/// Action to execute.
/// </summary>
public MailOperation Action { get; set; }
/// <summary>
/// Mail copies execute the action on.
/// </summary>
public IEnumerable<MailCopy> MailItems { get; set; }
/// <summary>
/// Whether the operation can be reverted if needed.
/// eg. MarkAsRead on already read item will set the action to MarkAsUnread.
/// This is used in hover actions for example.
/// </summary>
public bool ToggleExecution { get; set; }
/// <summary>
/// Whether hard delete protection should be ignored.
/// Discard draft requests for example should ignore hard delete protection.
/// </summary>
public bool IgnoreHardDeleteProtection { get; set; }
/// <summary>
/// Moving folder for the Move operation.
/// If null and the action is Move, the user will be prompted to select a folder.
/// </summary>
public IMailItemFolder MoveTargetFolder { get; }
}
}

View File

@@ -0,0 +1,9 @@
using MimeKit;
namespace Wino.Core.Domain.Models.MailItem
{
/// <summary>
/// Encapsulates MimeMessage and the path to the file.
/// </summary>
public record MimeMessageInformation(MimeMessage MimeMessage, string Path);
}

View File

@@ -0,0 +1,13 @@
namespace Wino.Core.Domain.Models.MailItem
{
/// <summary>
/// Class that holds immutable information about special folders in Outlook.
/// </summary>
/// <param name="InboxId"></param>
/// <param name="TrashId"></param>
/// <param name="JunkId"></param>
/// <param name="DraftId"></param>
/// <param name="SentId"></param>
/// <param name="ArchiveId"></param>
public record OutlookSpecialFolderIdInformation(string InboxId, string TrashId, string JunkId, string DraftId, string SentId, string ArchiveId);
}

View File

@@ -0,0 +1,7 @@
using MimeKit;
using Wino.Core.Domain.Entities;
namespace Wino.Core.Domain.Models.MailItem
{
public record SendDraftPreparationRequest(MailCopy MailItem, MimeMessage Mime, MailItemFolder DraftFolder, MailItemFolder SentFolder, MailAccountPreferences AccountPreferences);
}

View File

@@ -0,0 +1,87 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using Wino.Core.Domain.Entities;
namespace Wino.Core.Domain.Models.MailItem
{
public class ThreadMailItem : IMailItemThread
{
// TODO: Ideally this should be SortedList.
public ObservableCollection<IMailItem> ThreadItems { get; } = new ObservableCollection<IMailItem>();
public IMailItem LatestMailItem => ThreadItems.LastOrDefault();
public IMailItem FirstMailItem => ThreadItems.FirstOrDefault();
public void AddThreadItem(IMailItem item)
{
if (item == null) return;
if (ThreadItems.Any(a => a.Id == item.Id))
{
return;
}
if (item != null && item.IsDraft)
{
ThreadItems.Insert(0, item);
return;
}
var insertItem = ThreadItems.FirstOrDefault(a => !a.IsDraft && a.CreationDate < item.CreationDate);
if (insertItem == null)
ThreadItems.Insert(ThreadItems.Count, item);
else
{
var index = ThreadItems.IndexOf(insertItem);
ThreadItems.Insert(index, item);
}
}
#region IMailItem
public Guid UniqueId => LatestMailItem?.UniqueId ?? Guid.Empty;
public string Id => LatestMailItem?.Id ?? string.Empty;
// Show subject from last item.
public string Subject => LatestMailItem?.Subject ?? string.Empty;
public string ThreadId => LatestMailItem?.ThreadId ?? string.Empty;
public string PreviewText => FirstMailItem?.PreviewText ?? string.Empty;
public string FromName => LatestMailItem?.FromName ?? string.Empty;
public string FromAddress => LatestMailItem?.FromAddress ?? string.Empty;
public bool HasAttachments => ThreadItems.Any(a => a.HasAttachments);
public bool IsFlagged => ThreadItems.Any(a => a.IsFlagged);
public bool IsFocused => LatestMailItem?.IsFocused ?? false;
public bool IsRead => ThreadItems.All(a => a.IsRead);
public DateTime CreationDate => FirstMailItem?.CreationDate ?? DateTime.MinValue;
public bool IsDraft => ThreadItems.Any(a => a.IsDraft);
public string DraftId => string.Empty;
public string MessageId => LatestMailItem?.MessageId;
public string References => LatestMailItem?.References ?? string.Empty;
public string InReplyTo => LatestMailItem?.InReplyTo ?? string.Empty;
public MailItemFolder AssignedFolder => LatestMailItem?.AssignedFolder;
public MailAccount AssignedAccount => LatestMailItem?.AssignedAccount;
public Guid FileId => LatestMailItem?.FileId ?? Guid.Empty;
#endregion
}
}