IMAPResult
   IMAPCommandMyRights::ExecuteCommand(std::shared_ptr<HM::IMAPConnection> pConnection, std::shared_ptr<IMAPCommandArgument> pArgument)
   {
      if (!pConnection->IsAuthenticated())
         return IMAPResult(IMAPResult::ResultNo, "Authenticate first");

      if (!Configuration::Instance()->GetIMAPConfiguration()->GetUseIMAPACL())
         return IMAPResult(IMAPResult::ResultBad, "ACL is not enabled.");

      std::shared_ptr<IMAPSimpleCommandParser> pParser = std::shared_ptr<IMAPSimpleCommandParser>(new IMAPSimpleCommandParser());
      pParser->Parse(pArgument);

      if (pParser->WordCount() < 2)
         return IMAPResult(IMAPResult::ResultBad, "MYRIGHTS command requires at least 1 parameter.");

      String sOriginalFolderName;
      String sFolderName;

      if (pParser->Word(1)->Clammerized())
      {
         sFolderName = pArgument->Literal(0);
         sOriginalFolderName = sFolderName;
      }
      else
      {
         sOriginalFolderName = pParser->Word(1)->Value();
         
         sFolderName = sOriginalFolderName;
         IMAPFolder::UnescapeFolderString(sFolderName);
      }
      
      std::shared_ptr<IMAPFolder> pSelectedFolder = pConnection->GetFolderByFullPath(sFolderName);
      if (!pSelectedFolder)
         return IMAPResult(IMAPResult::ResultBad, "Folder could not be found.");

	  ACLManager aclManager;
      std::shared_ptr<ACLPermission> pPermission = aclManager.GetPermissionForFolder(pConnection->GetAccount()->GetID(), pSelectedFolder);
      String sRightsString;
      if (pPermission)
         sRightsString = pPermission->GetRights();

      String sResponse;
      sResponse.Format(_T("* MYRIGHTS \"%s\" %s\r\n"), sOriginalFolderName.c_str(), sRightsString.c_str());
      sResponse += pArgument->Tag() + _T(" OK Myrights complete\r\n");

      pConnection->SendAsciiData(sResponse);   

      return IMAPResult();
   }
	bool
	MessageUtilities::MoveToIMAPFolder(boost::shared_ptr<Message> pMessage, __int64 iAccountID, const String &sFolderName, bool bAutoSubscribe, bool bSetByGlobalRule, __int64 &iResultAccount, __int64 &iResultFolder)
   //---------------------------------------------------------------------------()
   // DESCRIPTION:
   // Moves a message to an IMAP folder. The message should not be saved when this
   // function is called.
   // Returns the ID of the folder the message was moved to.
   //---------------------------------------------------------------------------()
	{
      LOG_DEBUG("Moving message to " + sFolderName);

      // Set default values in case we fail to move the message to another folder later on.
      iResultAccount = iAccountID;
      iResultFolder = 0;
      
      String sTempFolderName = sFolderName;

      // Start of by cleaning the string:
      CleanIMAPFolderRuleString(sTempFolderName);

      std::vector<String> vecFolderPath = StringParser::SplitString(sTempFolderName, Configuration::Instance()->GetIMAPConfiguration()->GetHierarchyDelimiter());

      boost::shared_ptr<IMAPFolders> pFolders;

      bool isPublicFolder = IMAPFolderUtilities::IsPublicFolder(vecFolderPath);

      if (isPublicFolder)
      {
         pFolders = IMAPFolderContainer::Instance()->GetPublicFolders();
         vecFolderPath.erase(vecFolderPath.begin());
      }
      else
         pFolders = IMAPFolderContainer::Instance()->GetFoldersForAccount(iAccountID);

      // Check if this folder exist
      boost::shared_ptr<IMAPFolder> pFolder = pFolders->GetFolderByFullPath(vecFolderPath);

      if (pFolder && pFolder->IsPublicFolder())
      {
         // Do we have permissions to append?
		   ACLManager aclManager;
         boost::shared_ptr<ACLPermission> pPermission = aclManager.GetPermissionForFolder(iAccountID, pFolder);
         if (!pPermission)
            return false;

         if (!pPermission->GetAllow((ACLPermission::ePermission) ACLPermission::PermissionInsert))
            return false;
      }

      if (!pFolder)
      {
         // The folder does not exist. Are we allowed to create it?
         if (isPublicFolder)
         {
            if (!bSetByGlobalRule)
            {
               // iterate over folders until we find an already existing one.
               boost::shared_ptr<IMAPFolders> pPublicFolders = Configuration::Instance()->GetIMAPConfiguration()->GetPublicFolders();
               boost::shared_ptr<IMAPFolder> pTempFolder = IMAPFolderUtilities::GetTopMostExistingFolder(pPublicFolders, vecFolderPath);
               
               if (!pTempFolder)
               {
                  // User doesn't have permissions to create this folder.
                  return false;
               }

               // Do we have permissions to append?
               ACLManager aclManager;
			      boost::shared_ptr<ACLPermission> pPermission = aclManager.GetPermissionForFolder(iAccountID, pTempFolder);

               if (!pPermission)
                  return false;

               if (!pPermission->GetAllow((ACLPermission::ePermission) ACLPermission::PermissionCreate))
                  return false;
            }
         }

         pFolders->CreatePath(pFolders, vecFolderPath, bAutoSubscribe );

         // Fetch the newly created folder.
         pFolder = pFolders->GetFolderByFullPath(vecFolderPath);

         if (!pFolder)
         {
            // Something is fishy. If the folder didn't exist, it
            // should be created now. 
            String sErrorMessage;
            sErrorMessage.Format(_T("Failed to locate folder. Account id: %d Path: %s"), iAccountID, sFolderName);
            ErrorManager::Instance()->ReportError(ErrorManager::Medium, 5053, "MessageUtilities::MoveToIMAPFolder", sErrorMessage);

            iResultAccount = iAccountID;
            iResultFolder = 0;
            return false;
         }

      }  
      
      // Connect the message to the folder.
      pMessage->SetFolderID(pFolder->GetID());
      iResultAccount = pFolder->GetAccountID();
      iResultFolder = pFolder->GetID();

      LOG_DEBUG("Message moved to folder " + StringParser::IntToString(iResultFolder));

      return true;
	}