IMAPResult IMAPCommandEXAMINE::ExecuteCommand(boost::shared_ptr<HM::IMAPConnection> pConnection, boost::shared_ptr<IMAPCommandArgument> pArgument) { if (!pConnection->IsAuthenticated()) return IMAPResult(IMAPResult::ResultNo, "Authenticate first"); boost::shared_ptr<IMAPSimpleCommandParser> pParser = boost::shared_ptr<IMAPSimpleCommandParser>(new IMAPSimpleCommandParser()); pParser->Parse(pArgument); if (pParser->ParamCount() < 1) return IMAPResult(IMAPResult::ResultBad, "EXAMINE Command requires at least 1 parameter."); // Fetch the folder String sFolderName = pParser->GetParamValue(pArgument, 0); boost::shared_ptr<IMAPFolder> pSelectedFolder = pConnection->GetFolderByFullPath(sFolderName); if (!pSelectedFolder) return IMAPResult(IMAPResult::ResultBad, "Folder could not be found."); if (!pConnection->CheckPermission(pSelectedFolder, ACLPermission::PermissionRead)) return IMAPResult(IMAPResult::ResultBad, "ACL: Read permission denied (Required for EXAMINE command)."); pConnection->SetCurrentFolder(pSelectedFolder, true); boost::shared_ptr<Messages> pMessages = pSelectedFolder->GetMessages(); long lCount = pMessages->GetCount(); __int64 lFirstUnseenID = pMessages->GetFirstUnseenUID(); long lRecentCount = pMessages->GetNoOfRecent(); String sRespTemp; sRespTemp.Format(_T("* %d EXISTS\r\n"), lCount); String sResponse = sRespTemp; // EXISTS sRespTemp.Format(_T("* %d RECENT\r\n"), lRecentCount); sResponse += sRespTemp; sResponse += _T("* FLAGS (\\Deleted \\Seen \\Draft \\Answered \\Flagged)\r\n"); sRespTemp.Format(_T("* OK [UIDVALIDITY %d] current uidvalidity\r\n"), pSelectedFolder->GetCreationTime().ToInt()); sResponse += sRespTemp; if (lFirstUnseenID > 0) { sRespTemp.Format(_T("* OK [UNSEEN %d] unseen messages\r\n"), lFirstUnseenID); sResponse += sRespTemp; } sRespTemp.Format(_T("* OK [UIDNEXT %d] next uid\r\n"), pSelectedFolder->GetCurrentUID()+1); sResponse += sRespTemp; sResponse += _T("* OK [PERMANENTFLAGS ()] limited\r\n"); sResponse += pArgument->Tag() + _T(" OK [READ-ONLY] EXAMINE completed\r\n"); pConnection->SendAsciiData(sResponse); return IMAPResult(); }
IMAPResult IMAPCommandCLOSE::ExecuteCommand(boost::shared_ptr<HM::IMAPConnection> pConnection, boost::shared_ptr<IMAPCommandArgument> pArgument) { if (!pConnection->IsAuthenticated()) return IMAPResult(IMAPResult::ResultNo, "Authenticate first"); // Iterate through mail boxes and delete messages marked for deletion. boost::shared_ptr<IMAPFolder> pCurFolder = pConnection->GetCurrentFolder(); if (!pCurFolder) return IMAPResult(IMAPResult::ResultBad, "No folder selected."); // Check if user has permission to expunge. If so, do that. if (!pConnection->GetCurrentFolderReadOnly() && pConnection->CheckPermission(pConnection->GetCurrentFolder(), ACLPermission::PermissionExpunge)) { pCurFolder->Expunge(); } pConnection->CloseCurrentFolder(); String sResponse = pArgument->Tag() + " OK CLOSE completed\r\n"; pConnection->SendAsciiData(sResponse); return IMAPResult(); }