Add a GetQuota command for the IMAP QUOTA extension.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40975 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler 2011-03-16 19:12:30 +00:00
parent f96f677b90
commit 3f9320c6a2
4 changed files with 86 additions and 0 deletions

View File

@ -85,6 +85,20 @@ IMAPFolders::UnsubscribeFolder(const char* folder)
}
status_t
IMAPFolders::GetQuota(double& used, double& total)
{
GetQuotaCommand quotaCommand;
status_t status = ProcessCommand(&quotaCommand);
if (status != B_OK)
return status;
used = quotaCommand.UsedStorage();
total = quotaCommand.TotalStorage();
return status;
}
status_t
IMAPFolders::_GetAllFolders(StringList& folders)
{

View File

@ -39,6 +39,7 @@ public:
status_t SubscribeFolder(const char* folder);
status_t UnsubscribeFolder(const char* folder);
status_t GetQuota(double& used, double& total);
private:
status_t _GetAllFolders(StringList& folders);
status_t _GetSubscribedFolders(StringList& folders);

View File

@ -852,3 +852,56 @@ UnsubscribeCommand::Handle(const BString& response)
{
return false;
}
GetQuotaCommand::GetQuotaCommand(const char* mailboxName)
:
fMailboxName(mailboxName),
fUsedStorage(-1),
fTotalStorage(-1)
{
}
BString
GetQuotaCommand::Command()
{
BString command = "GETQUOTA \"";
command += fMailboxName;
command += "\"";
return command;
}
bool
GetQuotaCommand::Handle(const BString& response)
{
if (response.FindFirst("QUOTA") < 0)
return false;
BString data = IMAPParser::ExtractBetweenBrackets(response, "(", ")");
IMAPParser::RemovePrimitiveFromLeft(data);
fUsedStorage = IMAPParser::RemoveIntegerFromLeft(data);
fUsedStorage *= 1024;
fTotalStorage = IMAPParser::RemoveIntegerFromLeft(data);
fTotalStorage *= 1024;
return true;
}
double
GetQuotaCommand::UsedStorage()
{
return fUsedStorage;
}
double
GetQuotaCommand::TotalStorage()
{
return fTotalStorage;
}

View File

@ -280,4 +280,22 @@ private:
};
class GetQuotaCommand : public IMAPCommand {
public:
GetQuotaCommand(const char* mailboxName = "");
BString Command();
bool Handle(const BString& response);
double UsedStorage();
double TotalStorage();
private:
BString fMailboxName;
double fUsedStorage;
double fTotalStorage;
};
#endif // IMAP_HANDLER_H