WIP: Segfault somewhere, maybe I should strt over or check idk

This commit is contained in:
Tristan B. Kildaire 2021-01-23 19:07:26 +02:00
parent ebed47b58c
commit d5a8b4827c
2 changed files with 16 additions and 8 deletions

View File

@ -21,7 +21,7 @@ public final class ButterflyClient : Thread
/**
* The associated listener
*/
private ButterflyListener listener;
public ButterflyListener listener;
/**
* Socket of the client connection
@ -48,7 +48,7 @@ public final class ButterflyClient : Thread
* The Mailbox (if client) of the connected
* user.
*/
private Mailbox mailbox;
public Mailbox mailbox;
this(ButterflyListener listener, Socket clientSocket)
{
@ -638,7 +638,7 @@ public final class ButterflyClient : Thread
* Sends the mail message `mail` to the servers
* listed in the recipients field.
*/
private void sendMail(JSONValue mailBlock)
public void sendMail(JSONValue mailBlock)
{
/* Filter the mail */
bool reject = filterMailOutgoing(&mailBlock);
@ -725,7 +725,7 @@ public final class ButterflyClient : Thread
* Create a new MailSender for delivering remote mail
* off of this thread
*/
MailSender remoteMailSender = new MailSender(remoteRecipients, mailBlock, failedRecipients);
MailSender remoteMailSender = new MailSender(remoteRecipients, mailBlock, failedRecipients, this);
gprintln("Mail delivered (there may be remote mail delivery ongoing)");

View File

@ -7,6 +7,7 @@ import std.socket;
import gogga;
import std.string;
import std.conv : to;
import client.client;
/**
* The MailSender class is used to instantiate an object
@ -26,11 +27,13 @@ public final class MailSender : Thread
/* Failed recipients (at the beginning it will be only local) */
private string[] failedRecipients;
private ButterflyClient client;
/**
* Constructs a new MailSender with the given
* email to be delivered (remotely)
*/
this(string[] remoteRecipients, JSONValue mailBlock, string[] failedRecipients)
this(string[] remoteRecipients, JSONValue mailBlock, string[] failedRecipients, ButterflyClient client)
{
/* Set the worker function */
super(&run);
@ -144,15 +147,20 @@ public final class MailSender : Thread
*/
private void mailReport()
{
/* Create the error message */
JSONValue deliveryReport;
JSONValue[] errorRecipients = [
JSONValue(mailbox.username ~ "@" ~ listener.getDomain())
JSONValue(client.mailbox.username ~ "@" ~ client.listener.getDomain())
];
deliveryReport["recipients"] = errorRecipients;
/* TODO: Make more indepth, and have copy of the mail that was tried to be sent */
/* Get a list of the recipients of the mail message */
string[] recipients;
foreach(JSONValue recipient; mailBlock["recipients"].array())
{
recipients ~= recipient.str();
}
string errorMessage = "There was an error delivery the mail to: " ~ to!(
string)(recipients) ~ "\n";
errorMessage ~= "\nThe message was:\n\n" ~ mailBlock.toPrettyString();
@ -161,7 +169,7 @@ public final class MailSender : Thread
gprintln(deliveryReport);
/* Deliver the error message */
sendMail(deliveryReport);
client.sendMail(deliveryReport);
gprintln("Mail delivery report sent: " ~ deliveryReport.toPrettyString());