Implemented `isLocalDomain` function to check if the domain of a recipient is that of this mail server

This commit is contained in:
Tristan B. Kildaire 2020-07-27 14:18:03 +02:00
parent 5ea1ac2ba5
commit 1d50c30e29
2 changed files with 19 additions and 7 deletions

View File

@ -574,7 +574,7 @@ public final class ButterflyClient : Thread
* Check if the domain of this recipient is this server
* or if it is a remote server.
*/
if(cmp(domain, server.domain) == 0)
if(server.isLocalDomain(domain))
{
writeln("Local delivery occurring...");

View File

@ -5,6 +5,7 @@ import client.client : ButterflyClient;
import std.file : mkdir, exists, isDir;
import server.listener : ButterflyListener;
import std.stdio : writeln;
import std.string : cmp;
public final class ButterflyServer
{
@ -24,9 +25,6 @@ public final class ButterflyServer
*/
private bool active = true;
/* TODO: Server domain */
public string domain;
this(ButterflyListener[] listeners)
{
/**
@ -39,9 +37,6 @@ public final class ButterflyServer
*/
this.listeners = listeners;
/* Set the domain of the server */
this.domain = domain;
/* Start accepting connections */
run();
}
@ -101,4 +96,21 @@ public final class ButterflyServer
}
}
public bool isLocalDomain(string domain)
{
/**
* Loop through each listener and check if the requested domain
* appears in one of them.
*/
foreach(ButterflyListener listener; listeners)
{
if(cmp(listener.getDomain(), domain) == 0)
{
return true;
}
}
return false;
}
}