MailSharp / MailSharp.MailClient / Models / CacheModels.cs
Code · 58 lines · 2172 bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58namespace MailSharp.MailClient.Models;

public class CachedMessageList
{
	public string Id { get; set; } = "";
	public DateTimeOffset CachedAt { get; set; }
	public List<MessageListItem> Messages { get; set; } = [];
}

public class SenderImagePreference
{
	public string Id { get; set; } = "";
	public bool AllowImages { get; set; }
}

// Maps an image's URL hash to its original source URL, so the /cache/images/{hash} handler can
// download it on the first request even though the hash itself can't be reversed back to a URL.
public class ImageUrlMapping
{
	public string Id { get; set; } = "";
	public string Url { get; set; } = "";
}

// Maps a (account, folder, uid) triple - the only thing we know before contacting IMAP - to the
// message's own globally-unique Message-ID, which is the actual cache key for the .eml file
// (uids are only unique within a single folder, not account-wide, and change when a message is
// moved between folders; Message-ID doesn't).
public class MessageIdMapping
{
	public string Id { get; set; } = "";
	public string MessageId { get; set; } = "";
}

public class ContactOverride
{
	public string Id { get; set; } = "";
	public string DisplayName { get; set; } = "";
}

// One row per account, holding the full contact address list scraped from Sent - fetching it
// requires walking the whole Sent folder over IMAP, so it's done once and then kept up to date
// incrementally (see IContactStore.AddContacts) instead of being re-fetched on every page load.
public class ContactCache
{
	public int Id { get; set; }
	public List<ContactAddress> Contacts { get; set; } = [];
}

// Caches the result of IImapService.SearchByAddressAsync (all mails to/from one contact), keyed
// by (account, email) - that search walks every folder over IMAP, so repeatedly opening the same
// contact shouldn't repeat it every time; a short TTL (like the message list cache) still lets it
// pick up newly arrived/sent mail without needing an explicit invalidation.
public class ContactMailSearchCache
{
	public string Id { get; set; } = "";
	public DateTimeOffset CachedAt { get; set; }
	public List<MessageSearchResult> Results { get; set; } = [];
}