aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-03-08 08:11:41 +0530
committerBobby <[email protected]>2026-03-08 08:11:41 +0530
commitb2a231280ce3265d20cdc5f317ae1bcc5eb59924 (patch)
tree90eb1a5f5409025db47097e2e083361f8fa52555 /utils
parent662dd2069dc8590e8b54823a33726464cf10c4e7 (diff)
downloaddove-b2a231280ce3265d20cdc5f317ae1bcc5eb59924.tar.xz
dove-b2a231280ce3265d20cdc5f317ae1bcc5eb59924.zip
Add webmail email management templates and storage utilities
- Implemented email listing template with read/unread and star functionality. - Created empty state template for webmail when no emails are present. - Developed folder navigation template for managing email folders. - Added email preview template for displaying selected email details. - Introduced storage utilities for managing email files, including creation, reading, moving, and deletion. - Defined constants for storage paths and error messages related to file operations.
Diffstat (limited to 'utils')
-rw-r--r--utils/storage/defaults.go7
-rw-r--r--utils/storage/mail.go48
-rw-r--r--utils/storage/messages.go9
3 files changed, 64 insertions, 0 deletions
diff --git a/utils/storage/defaults.go b/utils/storage/defaults.go
new file mode 100644
index 0000000..910de6a
--- /dev/null
+++ b/utils/storage/defaults.go
@@ -0,0 +1,7 @@
+package storage
+
+const (
+ DataDirectory = "data"
+ MailDirectory = "mail"
+ EmlExtension = ".eml"
+)
diff --git a/utils/storage/mail.go b/utils/storage/mail.go
new file mode 100644
index 0000000..8f60f4f
--- /dev/null
+++ b/utils/storage/mail.go
@@ -0,0 +1,48 @@
+package storage
+
+import (
+ "os"
+ "path/filepath"
+)
+
+func MailFolderPath(mailboxAddress string, folderSlug string) string {
+ return filepath.Join(DataDirectory, MailDirectory, mailboxAddress, folderSlug)
+}
+
+func MailFilePath(mailboxAddress string, folderSlug string, filename string) string {
+ return filepath.Join(MailFolderPath(mailboxAddress, folderSlug), filename+EmlExtension)
+}
+
+func WriteMailFile(mailboxAddress string, folderSlug string, filename string, content []byte) error {
+ directoryPath := MailFolderPath(mailboxAddress, folderSlug)
+
+ if mkdirError := os.MkdirAll(directoryPath, 0750); mkdirError != nil {
+ return mkdirError
+ }
+
+ filePath := MailFilePath(mailboxAddress, folderSlug, filename)
+ return os.WriteFile(filePath, content, 0640)
+}
+
+func ReadMailFile(mailboxAddress string, folderSlug string, filename string) ([]byte, error) {
+ filePath := MailFilePath(mailboxAddress, folderSlug, filename)
+ return os.ReadFile(filePath)
+}
+
+func MoveMailFile(mailboxAddress string, sourceFolderSlug string, targetFolderSlug string, filename string) error {
+ targetDirectory := MailFolderPath(mailboxAddress, targetFolderSlug)
+
+ if mkdirError := os.MkdirAll(targetDirectory, 0750); mkdirError != nil {
+ return mkdirError
+ }
+
+ sourcePath := MailFilePath(mailboxAddress, sourceFolderSlug, filename)
+ targetPath := MailFilePath(mailboxAddress, targetFolderSlug, filename)
+
+ return os.Rename(sourcePath, targetPath)
+}
+
+func DeleteMailFile(mailboxAddress string, folderSlug string, filename string) error {
+ filePath := MailFilePath(mailboxAddress, folderSlug, filename)
+ return os.Remove(filePath)
+}
diff --git a/utils/storage/messages.go b/utils/storage/messages.go
new file mode 100644
index 0000000..7d5e883
--- /dev/null
+++ b/utils/storage/messages.go
@@ -0,0 +1,9 @@
+package storage
+
+const (
+ DirectoryCreateFailed = "Failed to create directory: %s."
+ FileWriteFailed = "Failed to write file: %s."
+ FileReadFailed = "Failed to read file: %s."
+ FileMoveFailed = "Failed to move file: %s."
+ FileDeleteFailed = "Failed to delete file: %s."
+)