MailBee.NET Objects 4.0

Imap.GetAccountQuota Method 

Gets the quota (resource usage limit) of the entire mail account on the server.

public FolderQuota GetAccountQuota();

Return Value

FolderQuota object if the quota information was downloaded successfully; otherwise, a null reference (Nothing in Visual Basic).

Remarks

This method can be used to obtain the account quota and current usage (in bytes). Also, the current and the maximum number of messages in the account can be set too. However, most servers limit account usage in bytes only. Number of messages is usually not limited and not counted.

Note    This method uses QUOTA capability be supported by the IMAP4 server. The developer can check if QUOTA capability is supported using GetExtension method.

Exceptions

Exception TypeCondition
MailBeeProtocolExtensionNotSupportedExceptionQUOTA not supported by the server and ThrowExceptions is true.
MailBeeExceptionAn error occurred and ThrowExceptions is true.

Example

This sample gets the account quota information and displays the maximum size (in bytes) and the current usage (in percent) of the account storage.

[C#]
using System;
using MailBee;
using MailBee.ImapMail;

class Sample
{
    static void Main(string[] args)
    {
        Imap imp = new Imap();

        // Connect to the server and log in the account.
        imp.Connect("imap.company.com");
        imp.Login("jdoe", "secret");

        if (imp.GetExtension("QUOTA") != null)
        {
            // Download quota information for the entire account.
            FolderQuota quota = imp.GetAccountQuota();

            if (quota.MaxStorageSize > -1 && quota.CurrentStorageSize > -1)
            {
                long percent = (quota.CurrentStorageSize * 100) / quota.MaxStorageSize;
                Console.WriteLine("You are using " + percent.ToString() + "% of your " +
                    quota.MaxStorageSize + " space");
            }
        }
        else
        {
            Console.WriteLine("QUOTA capability not supported, sorry");
        }

        imp.Disconnect();
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail

Module Sample
    Sub Main(ByVal args As String())
        Dim imp As New Imap

        ' Connect to the server and log in the account.
        imp.Connect("imap4.company.com")
        imp.Login("jdoe@company.com", "secret")

        If Not imp.GetExtension("QUOTA") Is Nothing Then
            ' Download Inbox folder status information.
            Dim quota As FolderQuota = imp.GetAccountQuota()

            If quota.MaxStorageSize > -1 AndAlso quota.CurrentStorageSize > -1 Then
                Console.WriteLine(quota.MaxStorageSize & _
                " is the maximum allowed total size (in bytes) " & _
                "of all messages in the folder.")
            End If
        Else
            Console.WriteLine("QUOTA capability not supported, sorry")
        End If

        imp.Disconnect()
    End Sub
End Module

See Also

Imap Class | MailBee.ImapMail Namespace | GetFolderQuota