#ifndef __MailFileSystem_h__ # define __MailFileSystem_h__ # include "MString.h" # include # include # include # include namespace mail { class MailFileSystem { public: MailFileSystem(coreutils::ZString &mailPath); bool ifMailBoxExists(coreutils::ZString &mailbox); bool ifAliasExists(coreutils::ZString &alias); coreutils::MString getMailBoxPath(coreutils::ZString &mailbox); std::vector getAliasMailboxes(coreutils::ZString &alias); coreutils::ZString& getMailPath(); coreutils::ZString& getQueuePath(); coreutils::ZString& getSendLogPath(); // Shared by every protocol's login (SMTP AUTH LOGIN, IMAP LOGIN, // POP3 USER/PASS) so there is exactly one place that reads // /.password and compares it - previously // __SMTP_AUTH::authLogin() carried this logic alone, and IMAP/POP3 // login would otherwise have needed their own copies. Still a // plaintext file comparison (a separately tracked, pre-existing // gap) - not something this change fixes, just no longer // triplicated. bool checkPassword(coreutils::ZString &userName, coreutils::ZString &password); // Folder names (Inbox/Spam/Trash/anything CREATEd) as immediate // subdirectories of a mailbox's own directory - used by IMAP // LIST/LSUB/SELECT/CREATE/DELETE/RENAME to enumerate and validate // folders without each command re-implementing the same // directory scan and dotfile-skipping rule. std::vector listFolders(coreutils::ZString &mailbox); coreutils::MString getFolderPath(coreutils::ZString &mailbox, std::string folder); bool ifFolderExists(coreutils::ZString &mailbox, std::string folder); // Domain/mailbox/alias maintenance for the admin console (see // __ADMIN_DOMAIN/__ADMIN_MAILBOX/__ADMIN_ALIAS) - a domain is // just a directory directly under mailPath; a mailbox is a // directory under that with Inbox/Spam/Trash and a .password // file (matching checkPassword()'s own expectations exactly); // an alias is a plain FILE at that same level (matching // ifAliasExists()'s own S_ISREG check) listing its target // mailboxes one per line. Each returns false and fills `error` // with a human-readable reason on failure, rather than throwing - // the console commands calling these want to report a clean // failure line to the operator, not crash the whole server on a // typo'd domain name. bool createDomain(coreutils::ZString &domain, std::string &error); bool removeDomain(coreutils::ZString &domain, std::string &error); std::vector listDomains(); bool createMailbox(coreutils::ZString &mailbox, coreutils::ZString &password, std::string &error); bool removeMailbox(coreutils::ZString &mailbox, std::string &error); std::vector listMailboxes(coreutils::ZString &domain); bool createAlias(coreutils::ZString &alias, coreutils::ZString &targets, std::string &error); bool removeAlias(coreutils::ZString &alias, std::string &error); std::vector listAliases(coreutils::ZString &domain); bool setPassword(coreutils::ZString &mailbox, coreutils::ZString &newPassword, std::string &error); private: coreutils::ZString &mailPath; coreutils::MString queuePath; coreutils::MString sendLogPath; struct stat statbuf; }; } #endif