
#include "MailFileSystem.h"
# include "INotify.h"
# include "Log.h"

namespace mail {

   MailFileSystem::MailFileSystem(coreutils::ZString &mailPath) : mailPath(mailPath) {
      queuePath << mailPath << "/.queue/";
   }

   bool MailFileSystem::ifMailBoxExists(coreutils::ZString &mailbox) {
      coreutils::Log(coreutils::LOG_DEBUG_2) << "if exists mailbox: " << mailbox << ".";
      if(stat(getMailBoxPath(mailbox).c_str(), &statbuf) != -1)
     	  if(S_ISDIR(statbuf.st_mode))
	       return true;
      coreutils::Log(coreutils::LOG_DEBUG_2) << "doesnt exist mailbox: " << mailbox << ".";
      return false;
   }

   bool MailFileSystem::ifAliasExists(coreutils::ZString &alias) {
      if(stat(getMailBoxPath(alias).c_str(), &statbuf) != -1)
	     if(S_ISREG(statbuf.st_mode))
	       return true;
      return false;
   }

   coreutils::MString MailFileSystem::getMailBoxPath(coreutils::ZString &mailbox) {
      mailbox.split("@", 1);
      coreutils::MString path;
      path << mailPath << "/" << mailbox[1] << "/" << mailbox[0];
      return path;
   }

   std::vector<coreutils::MString> MailFileSystem::getAliasMailboxes(coreutils::ZString &alias) {
      std::vector<coreutils::MString> returnValue;
      return returnValue;
   }

   coreutils::ZString& MailFileSystem::getMailPath() {
      return mailPath;
   }

   coreutils::ZString& MailFileSystem::getQueuePath() {
      return queuePath;
   }

}
