Create sub folder, delete folder, storage settings, some ui adjustments on threads.

This commit is contained in:
Burak Kaan Köse
2026-02-07 19:47:21 +01:00
parent 2cd03d5fec
commit 5bfa61a218
30 changed files with 900 additions and 58 deletions
+13
View File
@@ -1183,4 +1183,17 @@ public class MailService : BaseDatabaseService, IMailService
return await Connection.QueryScalarsAsync<string>(sql, mailCopyIds.Cast<object>().ToArray());
}
public Task<List<MailCopy>> GetMailCopiesBeforeDateAsync(Guid accountId, DateTime cutoffDateUtc)
{
const string query = """
SELECT MailCopy.*
FROM MailCopy
INNER JOIN MailItemFolder ON MailCopy.FolderId = MailItemFolder.Id
WHERE MailItemFolder.MailAccountId = ?
AND MailCopy.CreationDate < ?
""";
return Connection.QueryAsync<MailCopy>(query, accountId, cutoffDateUtc);
}
}
+111
View File
@@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Serilog;
using Wino.Core.Domain.Interfaces;
namespace Wino.Services;
public class MimeStorageService : IMimeStorageService
{
private readonly INativeAppService _nativeAppService;
private readonly IMailService _mailService;
private readonly ILogger _logger = Log.ForContext<MimeStorageService>();
public MimeStorageService(INativeAppService nativeAppService, IMailService mailService)
{
_nativeAppService = nativeAppService;
_mailService = mailService;
}
public Task<string> GetMimeRootPathAsync() => _nativeAppService.GetMimeMessageStoragePath();
public async Task<Dictionary<Guid, long>> GetAccountsMimeStorageSizesAsync(IEnumerable<Guid> accountIds)
{
var mimeRoot = await GetMimeRootPathAsync().ConfigureAwait(false);
var result = new Dictionary<Guid, long>();
foreach (var accountId in accountIds)
{
var accountPath = Path.Combine(mimeRoot, accountId.ToString());
result[accountId] = GetDirectorySizeSafe(accountPath);
}
return result;
}
public async Task DeleteAccountMimeStorageAsync(Guid accountId)
{
var mimeRoot = await GetMimeRootPathAsync().ConfigureAwait(false);
var accountPath = Path.Combine(mimeRoot, accountId.ToString());
if (Directory.Exists(accountPath))
{
Directory.Delete(accountPath, true);
}
}
public async Task<int> DeleteAccountMimeStorageOlderThanAsync(Guid accountId, DateTime cutoffDateUtc)
{
var mailCopies = await _mailService.GetMailCopiesBeforeDateAsync(accountId, cutoffDateUtc).ConfigureAwait(false);
if (mailCopies.Count == 0)
return 0;
var mimeRoot = await GetMimeRootPathAsync().ConfigureAwait(false);
var accountPath = Path.Combine(mimeRoot, accountId.ToString());
var fileIds = mailCopies.Select(a => a.FileId).Distinct().ToList();
int deletedFolderCount = 0;
foreach (var fileId in fileIds)
{
var mimeDirectory = Path.Combine(accountPath, fileId.ToString());
if (!Directory.Exists(mimeDirectory))
continue;
try
{
Directory.Delete(mimeDirectory, true);
deletedFolderCount++;
}
catch (Exception ex)
{
_logger.Warning(ex, "Failed to delete MIME directory {DirectoryPath}", mimeDirectory);
}
}
return deletedFolderCount;
}
private static long GetDirectorySizeSafe(string directoryPath)
{
if (!Directory.Exists(directoryPath))
return 0;
long total = 0;
try
{
foreach (var filePath in Directory.EnumerateFiles(directoryPath, "*", SearchOption.AllDirectories))
{
try
{
total += new FileInfo(filePath).Length;
}
catch
{
// Ignore unreadable files and continue calculating.
}
}
}
catch
{
return 0;
}
return total;
}
}
+1
View File
@@ -14,6 +14,7 @@ public static class ServicesContainerSetup
services.AddSingleton<IWinoLogger, WinoLogger>();
services.AddSingleton<ILaunchProtocolService, LaunchProtocolService>();
services.AddSingleton<IMimeFileService, MimeFileService>();
services.AddTransient<IMimeStorageService, MimeStorageService>();
services.AddTransient<ICalendarService, CalendarService>();
services.AddTransient<IMailService, MailService>();