forked from sara-gaballa/Email
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91b07ee
commit 28ee2aa
Showing
14 changed files
with
288 additions
and
23 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
back-end/parent/[email protected]/inbox/69c58548-c9f7-411f-87f9-c8f2aefac48b.json
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,11 @@ | ||
{ | ||
"id" : "69c58548-c9f7-411f-87f9-c8f2aefac48b", | ||
"from" : "[email protected]", | ||
"to" : "[email protected]", | ||
"date" : "12/26/22", | ||
"time" : "8:31", | ||
"subject" : "test", | ||
"body" : "did that arrive?", | ||
"priority" : null, | ||
"attachments" : null | ||
} |
11 changes: 11 additions & 0 deletions
11
back-end/parent/[email protected]/sent/69c58548-c9f7-411f-87f9-c8f2aefac48b.json
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,11 @@ | ||
{ | ||
"id" : "69c58548-c9f7-411f-87f9-c8f2aefac48b", | ||
"from" : "[email protected]", | ||
"to" : "[email protected]", | ||
"date" : "12/26/22", | ||
"time" : "8:31", | ||
"subject" : "test", | ||
"body" : "did that arrive?", | ||
"priority" : null, | ||
"attachments" : null | ||
} |
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,16 +1,24 @@ | ||
package com.example.email.controller; | ||
|
||
import com.example.email.model.Email; | ||
import com.example.email.model.User; | ||
import com.example.email.service.Logging; | ||
import com.example.email.service.LoggingProxy; | ||
import com.example.email.service.MailService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.PriorityQueue; | ||
import java.util.Queue; | ||
|
||
@RestController | ||
@CrossOrigin("https://localhost:4200") | ||
@RequestMapping("/mail") | ||
public class MailController { | ||
@Autowired | ||
MailService service = new MailService(); | ||
Logging logging = new LoggingProxy(); | ||
|
||
@RequestMapping("/signUp") | ||
|
@@ -24,4 +32,20 @@ public void signUp() { | |
} | ||
System.out.println(mockUser.getEmail()); | ||
} | ||
|
||
@RequestMapping("/send") | ||
public void send() { | ||
User mockUser = logging.findUser("[email protected]"); | ||
Queue<String> q = new PriorityQueue<>(); | ||
q.add("[email protected]"); | ||
Email email = new Email("[email protected]", "[email protected]", "12/26/22", "8:31", "test", | ||
"did that arrive?", null, null); | ||
try { | ||
this.service.sendMail(mockUser, email, q); | ||
} catch (Exception e) { | ||
} | ||
System.out.println(mockUser.getEmail()); | ||
} | ||
// sign in / send / add folder / rename folder/ delete folder/ delete mails/ get all mails / move mails | ||
|
||
} |
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
61 changes: 61 additions & 0 deletions
61
back-end/src/main/java/com/example/email/mailmanager/FileAdapter.java
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,61 @@ | ||
package com.example.email.mailmanager; | ||
|
||
import com.example.email.model.Email; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class FileAdapter implements MailManager { | ||
private static ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
// return all mails in specific folder | ||
@Override | ||
public List<Email> getAllMails(String path) throws IOException { | ||
File[] files = FileManager.getAllFiles(path); | ||
List<Email> emails = new ArrayList<>(); | ||
for (File file : files) { | ||
emails.add(objectMapper.readValue(file, Email.class)); | ||
} | ||
return emails; | ||
} | ||
|
||
// return one mail with given folder and name | ||
@Override | ||
public Email getMail(String path, String name) throws IOException { | ||
File file = FileManager.getFile(path, name); | ||
return objectMapper.readValue(file, Email.class); | ||
} | ||
|
||
// delete all mails with the given named from the given folder | ||
@Override | ||
public void deleteMails(String path, String[] fileNames) { | ||
for (String name : fileNames) { | ||
name = name.concat(".json"); | ||
} | ||
FileManager.deleteFiles(path, fileNames); | ||
} | ||
|
||
// add mail to the given path | ||
@Override | ||
public void addMail(String path, String fileName, Email email) throws IOException { | ||
File file = FileManager.addFile(path, fileName + ".json"); | ||
//configure objectMapper for pretty input | ||
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true); | ||
|
||
//write email object to json file | ||
objectMapper.writeValue(file, email); | ||
} | ||
|
||
// move mails from one folder to another | ||
@Override | ||
public void moveMails(String fromPath, String toPath, String[] fileNames) { | ||
for (String name : fileNames) { | ||
name = name.concat(".json"); | ||
} | ||
FileManager.moveFiles(fromPath, toPath, fileNames); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
back-end/src/main/java/com/example/email/mailmanager/FileManager.java
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,74 @@ | ||
package com.example.email.mailmanager; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public class FileManager { | ||
private final static String parentFolder = "parent"; | ||
private static ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
//create new folder in the given path | ||
public static boolean addFolder(String path) { | ||
File folder = new File(parentFolder + "/" + path); | ||
return folder.mkdirs(); | ||
} | ||
|
||
//delete folder with the given path | ||
public static boolean deleteFolder(String path) { | ||
File folder = new File(parentFolder + "/" + path); | ||
for (File file : folder.listFiles()) { | ||
// delete files and empty sub-folders | ||
file.delete(); | ||
} | ||
return folder.delete(); | ||
} | ||
|
||
//rename folder with the given path | ||
public static boolean renameFolder(String oldPath, String newPath) { | ||
File folder = new File(parentFolder + "/" + oldPath); | ||
return folder.renameTo(new File(parentFolder + "/" + newPath)); | ||
} | ||
|
||
public static File[] getAllFiles(String path) { | ||
File file = new File(parentFolder + "/" + path); | ||
return file.listFiles(); | ||
} | ||
|
||
public static File getFile(String path, String name) { | ||
File file = new File(parentFolder + "/" + path + "/" + name); | ||
return file; | ||
} | ||
|
||
// delete files move them to trash folder | ||
public static void deleteFiles(String path, String[] fileNames) { | ||
String folder = parentFolder + "/" + path; | ||
moveFiles(folder, parentFolder + "/" + FoldersName.TRASH, fileNames); | ||
/*List<File> deletedFiles = new ArrayList<>(); | ||
for (String name : fileNames) { | ||
File file = new File(folder + "/" + name); | ||
deletedFiles.add(file); | ||
file.delete(); | ||
} | ||
return deletedFiles;*/ | ||
} | ||
|
||
public static File addFile(String path, String fileName) throws IOException { | ||
addFolder(path); | ||
File file = new File(parentFolder + "/" + path + "/" + fileName); | ||
file.createNewFile(); | ||
return file; | ||
} | ||
|
||
public static File[] moveFiles(String fromPath, String toPath, String[] fileNames) { | ||
String fromFolder = parentFolder + "/" + fromPath; | ||
String toFolder = parentFolder + "/" + toPath; | ||
for (String name : fileNames) { | ||
File file = new File(fromFolder + "/" + name); | ||
file.renameTo(new File(toFolder + "/" + name)); | ||
} | ||
return new File(toFolder).listFiles(); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
back-end/src/main/java/com/example/email/mailmanager/FoldersName.java
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
26 changes: 26 additions & 0 deletions
26
back-end/src/main/java/com/example/email/mailmanager/MailManager.java
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 @@ | ||
package com.example.email.mailmanager; | ||
|
||
import com.example.email.model.Email; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public interface MailManager {//TODO: write email | ||
// TODO : get folders on sign in | ||
|
||
// get all emails from inbox folder | ||
//public List<Email> getAllMails(User user) throws IOException; | ||
|
||
// get all emails in specific folder | ||
List<Email> getAllMails(String path) throws IOException; | ||
|
||
// Check: Queue -> Array | ||
Email getMail(String path, String name) throws IOException; | ||
|
||
void addMail(String path, String fileName, Email email) throws IOException; | ||
|
||
// TODO : add ID | ||
void deleteMails(String path, String[] ids); | ||
|
||
void moveMails(String fromPath, String toPath, String[] ids); | ||
} |
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 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 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
Oops, something went wrong.