-
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.
Merge pull request #7 from Pa1yn-dev/srvside-rewrite
Server-side rewrite
- Loading branch information
Showing
37 changed files
with
808 additions
and
668 deletions.
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 |
---|---|---|
@@ -1,23 +1,16 @@ | ||
using MailLobbyer.ContactClass; | ||
using MailLobbyer.FileUploadClass; | ||
using MailLobbyer.SettingsProfilesClass; | ||
using MimeKit; | ||
|
||
namespace MailLobbyer.EmailClass; | ||
|
||
public class Email | ||
{ | ||
public string Subject { get; set; } | ||
public string Body { get; set; } | ||
public FileUpload[] Attachments { get; set; } | ||
public MimeMessage ProcessedEmailContents { get; set; } | ||
public SettingsProfiles SelectedProfile { get; set; } | ||
|
||
public Contact[] Selectedcontacts { get; set; } | ||
|
||
|
||
|
||
public Email(string subject, string body, FileUpload[] attachments, Contact[] selectedcontacts) | ||
public Email(MimeMessage processedemailcontents, SettingsProfiles selectedprofile) | ||
{ | ||
Subject = subject; | ||
Body = body; | ||
Attachments = attachments; | ||
Selectedcontacts = selectedcontacts; | ||
ProcessedEmailContents = processedemailcontents; | ||
SelectedProfile = selectedprofile; | ||
} | ||
} |
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
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,26 @@ | ||
namespace MailLobbyer.SettingsProfilesClass | ||
{ | ||
public class SettingsProfiles | ||
{ | ||
public Guid Id { get; } | ||
public string? ProfileName { get; set;} | ||
public string? SenderName { get; set; } | ||
public string? SenderEmail { get; set; } | ||
public string? Username { get; set; } | ||
public string? Password { get; set; } | ||
public string? Host { get; set; } | ||
public int Port { get; set; } | ||
|
||
public SettingsProfiles(Guid id, string profilename,string sendername, string senderemail, string username, string password, string host, int port) | ||
{ | ||
Id = id; | ||
ProfileName = profilename; | ||
SenderName = sendername; | ||
SenderEmail = senderemail; | ||
Username = username; | ||
Password = password; | ||
Host = host; | ||
Port = port; | ||
} | ||
} | ||
} |
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,50 @@ | ||
using Microsoft.AspNetCore.SignalR; | ||
using MailLobbyer.CSVFileClass; | ||
using MailLobbyer.ContactClass; | ||
|
||
namespace MailLobbyer.Server.Hubs; | ||
|
||
public class CSVHub : Hub | ||
{ | ||
private static List<CSVFile> csvfilesinmemory = new List<CSVFile>(); | ||
|
||
public async Task CSVFileSeeker() | ||
{ | ||
string directorypath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MailLobbyer"); | ||
|
||
if (!Directory.Exists(directorypath)) | ||
{ | ||
Directory.CreateDirectory(directorypath); | ||
System.Console.WriteLine("CSV contact-grouping directory created successfully."); | ||
} | ||
|
||
else | ||
{ | ||
System.Console.WriteLine("CSV contact-grouping directory already exists."); | ||
} | ||
|
||
// Later on change to use config values set by the user | ||
string[] filepaths = Directory.GetFiles(directorypath); | ||
|
||
foreach (string filepath in filepaths) | ||
{ | ||
CSVFile newcsvfile = new CSVFile(Path.GetFileNameWithoutExtension(filepath), filepath); | ||
csvfilesinmemory.Add(newcsvfile); | ||
System.Console.WriteLine(newcsvfile.Filename); | ||
} | ||
} | ||
|
||
|
||
|
||
public async Task<List<CSVFile>> GetCSVFilesInMemory() | ||
{ | ||
return csvfilesinmemory; | ||
} | ||
|
||
public override async Task OnDisconnectedAsync(Exception exception) | ||
{ | ||
csvfilesinmemory.Clear(); | ||
await base.OnDisconnectedAsync(exception); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,8 +1,70 @@ | ||
using Microsoft.AspNetCore.SignalR; | ||
using MailLobbyer.ContactClass; | ||
using MailLobbyer.FileUploadClass; | ||
using MailKit.Net.Smtp; | ||
using MailKit.Security; | ||
using MimeKit; | ||
using MailLobbyer.EmailClass; | ||
using MailLobbyer.SettingsProfilesClass; | ||
|
||
namespace MailLobbyer.Server.Hubs; | ||
|
||
public class EmailHub : Hub | ||
{ | ||
|
||
public async Task EmailHandler(string subject, string body, Contact contact, List<FileUpload> fileuploads, SettingsProfiles profile) | ||
{ | ||
await Task.Run(async () => | ||
{ | ||
string prefixsyntax = "/P"; | ||
string fullnamesyntax = "/FN"; | ||
string forenamesyntax = "/F"; | ||
string surnamesyntax = "/S"; | ||
subject = subject.Replace(prefixsyntax, contact.Prefix, StringComparison.OrdinalIgnoreCase) | ||
.Replace(fullnamesyntax, string.Concat(contact.Forename, " ", contact.Surname), StringComparison.OrdinalIgnoreCase) | ||
.Replace(forenamesyntax, contact.Forename, StringComparison.OrdinalIgnoreCase) | ||
.Replace(surnamesyntax, contact.Surname, StringComparison.OrdinalIgnoreCase); | ||
body = body.Replace(prefixsyntax, contact.Prefix, StringComparison.OrdinalIgnoreCase) | ||
.Replace(fullnamesyntax, string.Concat(contact.Forename, " ", contact.Surname), StringComparison.OrdinalIgnoreCase) | ||
.Replace(forenamesyntax, contact.Forename, StringComparison.OrdinalIgnoreCase) | ||
.Replace(surnamesyntax, contact.Surname, StringComparison.OrdinalIgnoreCase); | ||
var message = new MimeMessage(); | ||
message.From.Add(new MailboxAddress(profile.SenderName, profile.SenderEmail)); | ||
message.To.Add(new MailboxAddress(string.Concat(contact.Forename, " ", contact.Surname), contact.Email)); | ||
message.Subject = subject; | ||
var builder = new BodyBuilder(); | ||
builder.TextBody = body; | ||
if(fileuploads.Any()) | ||
{ | ||
foreach (FileUpload fileupload in fileuploads) | ||
{ | ||
builder.Attachments.Add(fileupload.Filename, fileupload.Filecontents); | ||
} | ||
} | ||
message.Body = builder.ToMessageBody(); | ||
using (var client = new SmtpClient()) | ||
{ | ||
await client.ConnectAsync(profile.Host, profile.Port, SecureSocketOptions.StartTls); | ||
await client.AuthenticateAsync(profile.Username, profile.Password); | ||
await client.SendAsync(message); | ||
await client.DisconnectAsync(true); | ||
} | ||
}); | ||
|
||
} | ||
|
||
public override async Task OnDisconnectedAsync(Exception exception) | ||
{ | ||
await base.OnDisconnectedAsync(exception); | ||
} | ||
|
||
} |
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,35 @@ | ||
using MailLobbyer.SettingsProfilesClass; | ||
using Microsoft.AspNetCore.SignalR; | ||
|
||
namespace MailLobbyer.Server.Hubs; | ||
|
||
public class SettingsHub : Hub | ||
{ | ||
private static List<SettingsProfiles> profiles = new List<SettingsProfiles>(); | ||
|
||
public async Task AddSettingProfile(string profilename,string sendername, string senderemail, string username, string password, string host, int port) | ||
{ | ||
SettingsProfiles profile = new SettingsProfiles(Guid.NewGuid(),profilename,sendername, senderemail, username, password, host, port); | ||
profiles.Add(profile); | ||
} | ||
|
||
public async Task RemoveSettingsProfile(Guid ident) | ||
{ | ||
foreach (SettingsProfiles profile in profiles) | ||
{ | ||
if(profile.Id == ident) | ||
{ | ||
profiles.Remove(profile); | ||
} | ||
else | ||
{ | ||
System.Console.WriteLine("Profile not found on server"); | ||
} | ||
} | ||
} | ||
|
||
public async Task<List<SettingsProfiles>> GetProfiles() | ||
{ | ||
return profiles; | ||
} | ||
} |
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.