// Copyright (c) 2005 Martin Knafve / hMailServer.com. // http://www.hmailserver.com #pragma once namespace HM { class Message; class Domain; class Account; class IMAPFolder; enum PersistenceMode; class PersistentMessage { public: PersistentMessage(); virtual ~PersistentMessage(); enum FileLocation { QueueFolder = 1, PublicFolder = 2, AccountFolder = 3 }; static std::shared_ptr CopyToQueue(std::shared_ptr sourceAccount, std::shared_ptr sourceMessage); static std::shared_ptr CopyToIMAPFolder(std::shared_ptr sourceAccount, std::shared_ptr sourceMessage, std::shared_ptr destinationFolder); static std::shared_ptr CopyFromQueueToInbox(std::shared_ptr sourceMessage, std::shared_ptr destinationAccount); static bool DeleteObject(std::shared_ptr pMessage); static bool SaveObject(std::shared_ptr pMessage); static bool SaveObject(std::shared_ptr pMessage, String &errorMessage, PersistenceMode mode); static bool AddObject(const std::shared_ptr pMessage); static bool LockObject(__int64 ObjectID); static bool LockObject(std::shared_ptr pMessage ); static bool UnlockObject(std::shared_ptr pMessage); static bool UnlockAll(); static bool DeleteFile(std::shared_ptr account, std::shared_ptr pMessage); static bool GetMessageID(const String &fileName, __int64 &messageID, bool &isPartialFilename); static bool ReadObject(std::shared_ptr pRS, std::shared_ptr pMessage, bool bReadRecipients = true); static bool ReadObject(std::shared_ptr pMessage, __int64 ObjectID); static bool ReadObject(std::shared_ptr pMessage, const SQLCommand &command); static bool SetNextTryTime(__int64 iMessageID, bool bUpdateNoOfTries, long lNoOfMinutes); static void EnsureFileExistance(std::shared_ptr account, std::shared_ptr pMessage); static bool MoveFileToPublicFolder(const String &sourceLocation, std::shared_ptr pMessage); static bool MoveFileToUserFolder(const String &sourceLocation, std::shared_ptr, std::shared_ptr destinationAccount); static bool GetAllMessageFilesAreInDataFolder(); static bool GetAllMessageFilesArePartialNames(); static int GetTotalMessageCount(); static int GetTotalMessageCountDelivered(); static bool DeleteByAccountID(__int64 iAccountID); static AnsiString LoadHeader(const String &fileName); static AnsiString LoadHeader(const String &fileName, bool reportError); static AnsiString LoadBody(const String &fileName); static String GetFileName(std::shared_ptr message); static String GetFileName(std::shared_ptr message, FileLocation location); static String GetFileName(std::shared_ptr account, std::shared_ptr message); static String GetFileName(std::shared_ptr account, std::shared_ptr message, FileLocation location); static String GetFileName(const String &accountAddress, std::shared_ptr message); static String GetFileName(const String &accountAddress, std::shared_ptr message, FileLocation location); static bool GetPartialFilename(const String &fullPath, String &partialPath); static bool SaveFlags(std::shared_ptr message); static bool IsPartialPath(const String &path); int GetLatestMessageId(); private: static std::shared_ptr CreateCopy_(std::shared_ptr sourceMessage, int destinationAccountID); // Recipient functions begin static bool ReadRecipients_(std::shared_ptr pMessage); static bool SaveRecipients_(std::shared_ptr pMessage); // Recipient functions end }; typedef std::shared_ptr MessageSP; }