Skip to content

Commit

Permalink
Merge pull request #7 from Pa1yn-dev/srvside-rewrite
Browse files Browse the repository at this point in the history
Server-side rewrite
  • Loading branch information
Pa1yn-dev committed Nov 11, 2023
2 parents 6387498 + 8df8dbf commit b0d15cc
Show file tree
Hide file tree
Showing 37 changed files with 808 additions and 668 deletions.
21 changes: 7 additions & 14 deletions src/MailLobbyer/Data/Email.cs
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;
}
}
1 change: 0 additions & 1 deletion src/MailLobbyer/Data/FileUpload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public FileUpload(string filename, long filesize, byte[] filecontents)
Filename = filename;
Filesize = filesize;
Filecontents = filecontents;

}
}

Expand Down
26 changes: 26 additions & 0 deletions src/MailLobbyer/Data/SettingsProfiles.cs
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;
}
}
}
50 changes: 50 additions & 0 deletions src/MailLobbyer/Hubs/CSVHub.cs
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);
}

}
62 changes: 62 additions & 0 deletions src/MailLobbyer/Hubs/EmailHub.cs
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);
}

}
35 changes: 35 additions & 0 deletions src/MailLobbyer/Hubs/SettingsHub.cs
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;
}
}
2 changes: 1 addition & 1 deletion src/MailLobbyer/MailLobbyer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="MailKit" Version="4.1.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.10" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

Expand Down
15 changes: 0 additions & 15 deletions src/MailLobbyer/Modules/CSVService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,8 @@ namespace MailLobbyer.CSVServiceComponent
{
public class CSVService
{
public List<CSVFile> CSVFilesindir = new List<CSVFile>();
public List<Contact> contacts = new List<Contact>();

public void CSVFileSeeker(string directory)
{
string[] filepaths = Directory.GetFiles(directory);

foreach (string filepath in filepaths)
{
CSVFile newcsvfile = new CSVFile(Path.GetFileNameWithoutExtension(filepath), filepath);
//System.Console.WriteLine(newcsvfile.Filename);
CSVFilesindir.Add(newcsvfile);
}


}

public async Task CSVParser(string csvfilepath)
{
await Task.Run(() =>
Expand Down
74 changes: 0 additions & 74 deletions src/MailLobbyer/Modules/EmailHandler.cs

This file was deleted.

12 changes: 0 additions & 12 deletions src/MailLobbyer/Modules/SmtpClientSettings.cs

This file was deleted.

Loading

0 comments on commit b0d15cc

Please sign in to comment.