Joshi.Utils.Imap.Imap.GetQuota C# (CSharp) Method

GetQuota() public method

Get the quota for specific folder
public GetQuota ( string sFolderName, bool &bUnlimitedQuota, int &nUsedKBytes, int &nTotalKBytes ) : void
sFolderName string Mailbox folder
bUnlimitedQuota bool Is unlimited quota
nUsedKBytes int Used quota in Kbytes
nTotalKBytes int Total quota in KBytes
return void
        public void GetQuota(string sFolderName, ref bool bUnlimitedQuota,
            ref int nUsedKBytes, ref int nTotalKBytes)
        {
            ImapResponseEnum eImapResponse = ImapResponseEnum.IMAP_SUCCESS_RESPONSE;
            bool bResult = false;
            bUnlimitedQuota = false;
            nUsedKBytes = 0;
            nTotalKBytes = 0;
            if (!m_bIsLoggedIn)
            {
                try
                {
                    Restore(false);
                }
                catch (ImapException e)
                {
                    if (e.Type != ImapException.ImapErrorEnum.IMAP_ERR_INSUFFICIENT_DATA)
                        throw e;

                    throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_NOTCONNECTED);
                }
            }
            if (sFolderName.Length == 0)
            {
                throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_INVALIDPARAM);
            }

            ArrayList asResultArray = new ArrayList();
            string sCommand = IMAP_GETQUOTA_COMMAND;
            sCommand += " " + sFolderName +IMAP_COMMAND_EOL;
            try
            {
                eImapResponse = SendAndReceive(sCommand, ref asResultArray);
                if (eImapResponse == ImapResponseEnum.IMAP_SUCCESS_RESPONSE)
                {
                    m_sMailboxName = sFolderName;
                    m_bIsFolderExamined = true;
                    string quotaPrefix = IMAP_UNTAGGED_RESPONSE_PREFIX + " ";
                    quotaPrefix += IMAP_QUOTA_RESPONSE + " ";
                    foreach (string sLine in asResultArray)
                    {
                        if (sLine.StartsWith(quotaPrefix) == true)
                        {
                            // Find the open and close paranthesis, and extract
                            // the part inside out.
                            int nStart = sLine.IndexOf('(');
                            int nEnd = sLine.IndexOf(')', nStart);
                            if (nStart != -1 &&
                                nEnd != -1 &&
                                nEnd > nStart)
                            {
                                string sQuota = sLine.Substring(nStart+1, nEnd-nStart-1 );
                                if (sQuota.Length > 0)
                                {
                                    // Parse the space-delimited quota information which
                                    // will look like "STORAGE <used> <total>"
                                    string [] asArrList; // = new ArrayList();
                                    asArrList = sQuota.Split(' ');

                                    // get the used and total kbytes from these tokens
                                    if (asArrList.Length == 3 &&
                                        asArrList[0] == "STORAGE")
                                    {
                                        nUsedKBytes = Convert.ToInt32(asArrList[1],10);;
                                        nTotalKBytes = Convert.ToInt32(asArrList[2],10);
                                    }
                                    else
                                    {
                                        string error = "Invalid Quota information :" + sQuota;
                                        Log(LogTypeEnum.ERROR, error);
                                        break;
                                    }
                                }
                                else
                                {
                                    bUnlimitedQuota = true;
                                }
                            }
                            else
                            {
                                string error = "Invalid Quota IMAP Response : " + sLine;
                                Log(LogTypeEnum.ERROR, error);
                                break;
                            }
                        }
                            // If the line looks like "<command-tag> OK ..."
                        else if (sLine.IndexOf(IMAP_SERVER_RESPONSE_OK) != -1)
                        {
                            bResult = true;
                            break;
                        }
                    }

                    if (!bResult)
                        throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_QUOTA);
                    if (bUnlimitedQuota)
                        Log(LogTypeEnum.INFO, "GETQUOTA quota=[unlimited].");
                    else
                    {
                        string sLogStr ="GETQUOTA used=[" + nUsedKBytes.ToString() +
                            "], total=[" + nTotalKBytes.ToString() + "]";
                        //Log(LogTypeEnum.INFO, sLogStr);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }