Re-implemented `createMail`
This commit is contained in:
parent
e7c0be3e4b
commit
3d03450296
|
@ -125,10 +125,14 @@ public final class ButterflyClient : Thread
|
|||
/* Make sure the connection is from a client */
|
||||
if(connectionType == ClientType.CLIENT)
|
||||
{
|
||||
/* TODO: Implement me */
|
||||
Mail mail = new Mail(commandBlock["mail"]);
|
||||
//Folder storeFolder = new Folder(mailbox)
|
||||
//mailbox.storeMessage()
|
||||
/* Get the mail block */
|
||||
JSONValue mailBlock = commandBlock["request"]["mail"];
|
||||
|
||||
/* Get the folder to store the mail message in */
|
||||
Folder storeFolder = new Folder(mailbox, commandBlock["request"]["folder"].str());
|
||||
|
||||
/* Store the message in the mailbox */
|
||||
storeMail(storeMail, mailBlock);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -258,6 +262,18 @@ public final class ButterflyClient : Thread
|
|||
clientSocket.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a mail message in the users Mailbox
|
||||
* at in the given Folder, `folder`.
|
||||
*/
|
||||
private Mail storeMail(Folder folder, JSONValue mailBlock)
|
||||
{
|
||||
/* Create the Mail message to store it */
|
||||
Mail savedMail = Mail.createMail(mailbox, folder, mailBlock);
|
||||
|
||||
return savedMail;
|
||||
}
|
||||
|
||||
private bool authenticate(string username, string password)
|
||||
{
|
||||
/* TODO: Implement me */
|
||||
|
|
|
@ -74,7 +74,7 @@ public final class Mailbox
|
|||
return newFolder;
|
||||
}
|
||||
|
||||
public void storeMessage(Folder folder, Mail message)
|
||||
public void storeMessage(Folder folder, string mailID, JSONValue mailBlock)
|
||||
{
|
||||
/* TODO: Traverse the folder path */
|
||||
string kaka;
|
||||
|
@ -153,8 +153,7 @@ public final class Folder
|
|||
/* Only append files */
|
||||
if(dirEntry.isFile())
|
||||
{
|
||||
messages ~= new Mail()
|
||||
folders ~= new Folder(mailbox, folderPath~"/"~dirEntry.name());
|
||||
messages ~= new Mail(mailbox, this, dirEntry.name());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -230,26 +229,41 @@ public final class Folder
|
|||
public final class Mail
|
||||
{
|
||||
|
||||
private JSONValue messageBlock;
|
||||
|
||||
/* TODO (think about): Before id of mail (for creating) and also for existing */
|
||||
private string[] recipients;
|
||||
/**
|
||||
* The associated Mailbox
|
||||
*/
|
||||
|
||||
private string id;
|
||||
|
||||
public static Mail createMail(Mailbox mailbox, JSONValue mailBlock)
|
||||
public static Mail createMail(Mailbox mailbox, Folder folder, JSONValue mailBlock)
|
||||
{
|
||||
Mail newMail;
|
||||
|
||||
/* TODO: Store to disk in mailstore */
|
||||
//mailbox.getIDFor(mailBlock);
|
||||
/* Generate a unique mailID of this message */
|
||||
string mailID = getNameForMail(mailBlock);
|
||||
|
||||
/* Save the mail into the mailbox */
|
||||
mailbox.storeMessage(folder, mailID, mailBlock);
|
||||
|
||||
/* fetch the mail object */
|
||||
newMail = new Mail(mailbox, folder, mailID);
|
||||
|
||||
/* TODO: Re think our system */
|
||||
return newMail;
|
||||
}
|
||||
|
||||
this(Folder folder, string id)
|
||||
/**
|
||||
* Returns a name unique to this message
|
||||
*/
|
||||
private static string getNameForMail(JSONValue mailBlock)
|
||||
{
|
||||
/* TODO: Hash message here and return hex of hash */
|
||||
return "fhjdkshfjsdgfjk";
|
||||
}
|
||||
|
||||
this(Mailbox mailbox, Folder folder, string id)
|
||||
{
|
||||
|
||||
this.id = id;
|
||||
|
||||
/* TODO: Fetch mail here, or rather in a method */
|
||||
|
|
Loading…
Reference in New Issue