Code · 47 lines · 2136 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
47namespace MailSharp.MailClient.Models;

public class Account
{
	public int Id { get; set; }
	public string DisplayName { get; set; } = "";
	public string EmailAddress { get; set; } = "";
	public string Username { get; set; } = "";

	// Encrypted at rest via IPasswordProtector
	public string ProtectedPassword { get; set; } = "";

	public string ImapHost { get; set; } = "";
	public int ImapPort { get; set; } = 993;
	public SecurityMode ImapSecurity { get; set; } = SecurityMode.SslTls;

	public string SmtpHost { get; set; } = "";
	public int SmtpPort { get; set; } = 587;
	public SecurityMode SmtpSecurity { get; set; } = SecurityMode.StartTls;

	// User-configurable preferences (Settings page). MessagesPerPage/ContactsPerPage of 0 means
	// "use the app-wide default" (see MailSettings) rather than a hardcoded per-account fallback.
	public string Signature { get; set; } = "";
	public int MessagesPerPage { get; set; }
	public int ContactsPerPage { get; set; }
	public int AutoCheckIntervalMinutes { get; set; } = 5;

	// Stored as an IANA id (e.g. "Europe/Amsterdam") even on Windows, where TimeZoneInfo itself
	// natively uses Windows ids ("W. Europe Standard Time") - the browser's Intl API (used for all
	// client-side date formatting) only understands IANA ids, so converting once here means every
	// other call site can just pass this straight through instead of re-converting.
	public string TimeZoneId { get; set; } = ResolveDefaultTimeZoneId();
	public string Language { get; set; } = "nl";

	// Grants access to the Maintenance page (logs, background process status, message metrics).
	// The first account ever created on a fresh install becomes admin automatically (see
	// AuthApiController.Login); later accounts default to false and can only be promoted via the
	// claim-admin bootstrap endpoint while no admin exists yet, or by an existing admin afterwards.
	public bool IsAdmin { get; set; }

	private static string ResolveDefaultTimeZoneId()
	{
		var id = TimeZoneInfo.Local.Id;
		if (OperatingSystem.IsWindows() && TimeZoneInfo.TryConvertWindowsIdToIanaId(id, out var iana)) return iana;
		return id;
	}
}