// email_management_system.c // Tammy Zhong // Implementation file for email management system functions // Modified by Angela Finlayson // (TODO) #include #include #include #include "email_management_system.h" // Function prototypes // ADD YOUR OWN FUNCTION PROTOTYPES HERE // Function definitions // Creates a new empty email folder //(TODO) struct folder *create_folder(char name[]) { // TODO: implement this function printf("create_folder not yet implemented.\n"); exit(1); } // Add a new email to the folder at the head // Similar to previous lecture code insert_head // (TODO) void insert_email_at_head(struct folder *email_folder, char sender[], char subject[], double size, enum email_type type, int priority) { // TODO: implement this function printf("insert_email_at_head not yet implemented.\n"); exit(1); } // Given a string, look for email where the subject is this string // (TODO) struct email *search_email(struct folder *email_folder, char subject[]) { // TODO: implement this function printf("search_email not yet implemented.\n"); exit(1); } // Removes all emails from a folder // clears and delete associated memory of folder and emails in it void clear_folder(struct folder *email_folder) { // TODO: implement this function printf("clear_folder not yet implemented.\n"); exit(1); } // Remove email(s) with certain priority (e.g. filter out low priority emails) void delete_email_of_priority(struct folder *email_folder, int priority) { // TODO: implement this function printf("delete_email_of_priority not yet implemented.\n"); exit(1); } // Append emails from folder_2 after folder_1 and returns them in the one folder // Assumption made here assumes not same subject email in folder_1 and folder_2 struct folder *merge_folders(char merged_folder_name[], struct folder *folder_1, struct folder *folder_2) { // TODO: implement this function printf("merge_folders not yet implemented.\n"); exit(1); } // Split emails in a given folder into 3 folders based on email type // keeping original ordering // assumption: inbox, sent and draft are folders already malloc-ed and initialised void split_folder(struct folder *given_folder, struct folder *inbox, struct folder *sent, struct folder *draft) { // TODO: implement this function printf("split_folder not yet implemented.\n"); exit(1); } // CHALLENGE Returns number of emails in a given folder // (TODO: Improve this) int count_emails(struct folder *email_folder) { int counter = 0; struct email *current = email_folder->emails; while (current != NULL) { counter++; current = current->next; } return counter; } // CHALLENGE at home for fun: Sort emails in folder based on size // (slightly out of scope of COMP1511 - touches on sorting algorithms) // order doesn't matter if two emails of same size void sort_emails(struct folder *email_folder) { // TODO: implement this function printf("sort_emails not yet implemented.\n"); exit(1); } // Your functions here (include function comments): //////////////////////////////////////////////////////////////////////////////// // Provided Code // //////////////////////////////////////////////////////////////////////////////// // Print/display all emails in folder // Similar to previous lecture code print_list void print_emails(struct folder *email_folder) { printf("Folder Name: %s\n", email_folder->name); struct email *current = email_folder->emails; if (current == NULL) { printf("There are no emails in this folder.\n"); } while (current != NULL) { printf("---\n"); print_single_email(current); current = current->next; } } // Prints out details of a single email void print_single_email(struct email *email) { if (email == NULL) { printf("Email is NULL.\n"); return; } printf("Sender: %s\n", email->sender); printf("Subject: %s\n", email->subject); printf("Size: %lfmb\n", email->size); printf("Type: "); if (email->type == RECEIVED) { printf("RECEIVED\n"); } else if (email->type == SENT) { printf("SENT\n"); } else if (email->type == DRAFT) { printf("DRAFT\n"); } else { printf("UNKNOWN\n"); } printf("Priority: "); if (email->priority == HIGH_PRIORITY) { printf("HIGH_PRIORITY\n"); } else if (email->priority == NORMAL_PRIORITY) { printf("NORMAL_PRIORITY\n"); } else if (email->priority == LOW_PRIORITY) { printf("LOW_PRIORITY\n"); } else { printf("UNKNOWN\n"); } }