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) }