-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding site settings and a few models to work with
- Loading branch information
1 parent
68c64bf
commit fc54e24
Showing
19 changed files
with
486 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Lombiq.EmailClient.Constants; | ||
|
||
public class FeatureIds | ||
{ | ||
public const string Area = "Lombiq.EmailClient"; | ||
|
||
public const string Default = Area; | ||
public const string Imap = Area + ".Imap"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Lombiq.EmailClient.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
public ActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Lombiq.EmailClient.Models; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using OrchardCore.DisplayManagement.Entities; | ||
using OrchardCore.DisplayManagement.Handlers; | ||
using OrchardCore.DisplayManagement.Views; | ||
using OrchardCore.Settings; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Lombiq.EmailClient.Drivers; | ||
|
||
public class ImapSettingsDisplayDriver : SiteDisplayDriver<ImapSettings> | ||
{ | ||
public const string GroupId = nameof(ImapSettings); | ||
|
||
private readonly IAuthorizationService _authorizationService; | ||
private readonly IHttpContextAccessor _hca; | ||
|
||
protected override string SettingsGroupId => GroupId; | ||
|
||
public ImapSettingsDisplayDriver(IAuthorizationService authorizationService, IHttpContextAccessor hca) | ||
{ | ||
_authorizationService = authorizationService; | ||
_hca = hca; | ||
} | ||
|
||
public override async Task<IDisplayResult> EditAsync(ISite model, ImapSettings section, BuildEditorContext context) | ||
{ | ||
if (!await AuthorizeAsync(context)) return null; | ||
|
||
return Initialize<ImapSettings>($"{nameof(ImapSettings)}_Edit", section.CopyTo) | ||
.PlaceInContent() | ||
.OnGroup(GroupId); | ||
} | ||
|
||
public override async Task<IDisplayResult> UpdateAsync(ISite model, ImapSettings section, UpdateEditorContext context) | ||
{ | ||
if (await AuthorizeAsync(context) && | ||
await context.CreateModelAsync<ImapSettings>(Prefix) is { } viewModel) | ||
{ | ||
viewModel.CopyTo(section); | ||
} | ||
|
||
return await EditAsync(model, section, context); | ||
} | ||
|
||
private Task<bool> AuthorizeAsync(BuildEditorContext context) => | ||
_hca.HttpContext?.User is { } user && | ||
context.GroupId.EqualsOrdinalIgnoreCase(GroupId) | ||
? _authorizationService.AuthorizeAsync(user, Permissions.ImapPermissions.ManageImapSettings) | ||
: Task.FromResult(false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Razor"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<AddRazorSupportForMvc>true</AddRazorSupportForMvc> | ||
<DefaultItemExcludes>$(DefaultItemExcludes);.git*;node_modules\**</DefaultItemExcludes> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<Title>Lombiq Email Client</Title> | ||
<Authors>Lombiq Technologies</Authors> | ||
<Copyright>Copyright © 2021, Lombiq Technologies Ltd.</Copyright> | ||
<Description>Lombiq Email Client for Orchard Core: With the help of this module, you can do advanced email operations such as downloading them using IMAP.</Description> | ||
<PackageIcon>NuGetIcon.png</PackageIcon> | ||
<PackageTags>OrchardCore;Lombiq;AspNetCore;Email;IMAP</PackageTags> | ||
<RepositoryUrl>https://github.com/Lombiq/Orchard-Email-Client</RepositoryUrl> | ||
<PackageProjectUrl>https://github.com/Lombiq/Orchard-Email-Client/blob/dev/Readme.md</PackageProjectUrl> | ||
<PackageLicenseExpression>BSD-3-Clause</PackageLicenseExpression> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="node_modules\**" /> | ||
<None Include="../Readme.md" Link="Readme.md" /> | ||
<None Include="NuGetIcon.png" Pack="true" PackagePath="" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="MailKit" Version="4.9.0" /> | ||
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(NuGetBuild)' != 'true'"> | ||
<ProjectReference Include="..\..\..\Libraries\Lombiq.HelpfulLibraries\Lombiq.HelpfulLibraries.OrchardCore\Lombiq.HelpfulLibraries.OrchardCore.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(NuGetBuild)' == 'true'"> | ||
<PackageReference Include="Lombiq.HelpfulLibraries.OrchardCore" Version="11.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using OrchardCore.Modules.Manifest; | ||
using static Lombiq.EmailClient.Constants.FeatureIds; | ||
|
||
[assembly: Module( | ||
Name = "Lombiq Email Client", | ||
Author = "Lombiq Technologies", | ||
Website = "https://github.com/Lombiq/Orchard-EmailClient", | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
Version = "0.0.1" | ||
)] | ||
|
||
[assembly: Feature( | ||
Id = Default, | ||
Name = "Lombiq Email Client - Base", | ||
Category = "Email", | ||
Description = "Base functionality for the email client such as content types. Should be used along with a " + | ||
"specific email provider feature (e.g., IMAP)." | ||
)] | ||
|
||
[assembly: Feature( | ||
Id = Imap, | ||
Name = "Lombiq Email Client - IMAP", | ||
Category = "Email", | ||
Description = "IMAP email provider for the email client.", | ||
Dependencies = | ||
[ | ||
Default, | ||
] | ||
)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Lombiq.EmailClient.Models; | ||
|
||
/// <summary> | ||
/// Represents metadata for an attachment, such as its filename, MIME type, and size. | ||
/// </summary> | ||
public class AttachmentMetadata | ||
{ | ||
/// <summary> | ||
/// Gets or sets the filename of the attachment. | ||
/// </summary> | ||
public string FileName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the MIME type of the attachment (e.g., "application/pdf", "image/jpeg"). | ||
/// </summary> | ||
public string MimeType { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the size of the attachment in bytes. | ||
/// </summary> | ||
public long? Size { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the file path where the attachment has been downloaded. | ||
/// If null, the attachment has not been downloaded. | ||
/// </summary> | ||
public string DownloadedFilePath { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Lombiq.EmailClient.Models; | ||
|
||
/// <summary> | ||
/// Represents an email address with a display name and the actual address. | ||
/// </summary> | ||
public class EmailAddress | ||
{ | ||
/// <summary> | ||
/// Gets or sets the display name of the email address (e.g., "John Doe"). | ||
/// </summary> | ||
public string DisplayName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the actual email address (e.g., "[email protected]"). | ||
/// </summary> | ||
public string Address { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Lombiq.EmailClient.Models; | ||
|
||
/// <summary> | ||
/// Represents the body of an email, including its content and format. | ||
/// </summary> | ||
public class EmailBody | ||
{ | ||
/// <summary> | ||
/// Gets or sets the main body of the email as plain text or HTML. | ||
/// </summary> | ||
public string Body { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the body contains HTML content. | ||
/// </summary> | ||
public bool IsHtml { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Lombiq.EmailClient.Models; | ||
|
||
/// <summary> | ||
/// Represents the content of an email, including its body and attachments. | ||
/// </summary> | ||
public class EmailContent | ||
{ | ||
/// <summary> | ||
/// Gets or sets a value indicating whether the email body has been downloaded. | ||
/// </summary> | ||
public bool IsBodyDownloaded { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the body of the email, including its content and format information. | ||
/// </summary> | ||
public EmailBody Body { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the email's attachments have been downloaded. | ||
/// </summary> | ||
public bool AreAttachmentsDownloaded { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the metadata of the attachments associated with this email. | ||
/// </summary> | ||
public IList<AttachmentMetadata> Attachments { get; private set; } = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Lombiq.EmailClient.Models; | ||
|
||
/// <summary> | ||
/// Represents the headers of an email, including sender, recipients, subject, and dates. | ||
/// </summary> | ||
public class EmailHeader | ||
{ | ||
/// <summary> | ||
/// Gets or sets the subject line of the email. | ||
/// </summary> | ||
public string Subject { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the sender of the email, including their display name and email address. | ||
/// </summary> | ||
public EmailAddress Sender { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the primary recipients of the email (To field). | ||
/// </summary> | ||
public IList<EmailAddress> To { get; private set; } = []; | ||
|
||
/// <summary> | ||
/// Gets the carbon copy recipients of the email (Cc field). | ||
/// </summary> | ||
public IList<EmailAddress> Cc { get; private set; } = []; | ||
|
||
/// <summary> | ||
/// Gets the blind carbon copy recipients of the email (Bcc field). | ||
/// </summary> | ||
public IList<EmailAddress> Bcc { get; private set; } = []; | ||
|
||
/// <summary> | ||
/// Gets or sets the date and time when the email was sent by the sender's client. | ||
/// This value is in UTC but reflects the sender's system clock and timezone. | ||
/// </summary> | ||
public DateTime? SentDateUtc { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the date and time when the email was received by the recipient's mail server. | ||
/// This value is in UTC and is typically more reliable than the sent date. | ||
/// </summary> | ||
public DateTime? ReceivedDateUtc { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Lombiq.EmailClient.Models; | ||
|
||
/// <summary> | ||
/// Represents the metadata, headers, and content of an email, including protocol-specific details, | ||
/// sender and recipient information, and message body. | ||
/// </summary> | ||
public class EmailMessage | ||
{ | ||
/// <summary> | ||
/// Gets or sets the protocol-specific metadata of the email (e.g., Message-ID, protocol name, and folder information). | ||
/// </summary> | ||
public EmailMetadata Metadata { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the headers of the email, including sender, recipients, and subject. | ||
/// </summary> | ||
public EmailHeader Header { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the content of the email, including its body and format details. | ||
/// This is populated only after the email is downloaded. | ||
/// </summary> | ||
public EmailContent Content { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace Lombiq.EmailClient.Models; | ||
|
||
/// <summary> | ||
/// Represents protocol-specific metadata for an email. | ||
/// </summary> | ||
public class EmailMetadata | ||
{ | ||
/// <summary> | ||
/// Gets or sets the unique identifier of the email from the Message-ID header. | ||
/// This is globally unique across all emails. | ||
/// </summary> | ||
public string GlobalMessageId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the protocol used to fetch the email (e.g., "IMAP", "JMAP", "GMAIL_API"). | ||
/// </summary> | ||
public string Protocol { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the unique identifier of the email within the protocol (e.g., UID in IMAP). | ||
/// Note that this identifier is unique only within the context of a specific folder. | ||
/// </summary> | ||
public string ProtocolUniqueId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the folder where the email is stored (e.g., "INBOX", "Sent"). | ||
/// </summary> | ||
public string FolderName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the email is a reply to another email. | ||
/// </summary> | ||
public bool IsReply { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace Lombiq.EmailClient.Models; | ||
|
||
public class ImapSettings | ||
{ | ||
public string Server { get; set; } | ||
public int Port { get; set; } | ||
public string Username { get; set; } | ||
public string Password { get; set; } | ||
public bool UseSsl { get; set; } | ||
|
||
public void CopyTo(ImapSettings target) | ||
{ | ||
target.Server = Server; | ||
target.Port = Port; | ||
target.Username = Username; | ||
target.Password = Password; | ||
target.UseSsl = UseSsl; | ||
} | ||
} |
Oops, something went wrong.
A dash is missing.