How to get quota of IMAP account?

+1 vote
asked Mar 4, 2010 by Wakatake (240 points)
edited Jul 1, 2014


How do I get the quota of the account that I am currently connected to?

Thanks in advance!

Applies to: Rebex Secure Mail

1 Answer

+2 votes
answered Mar 4, 2010 by Lukas Pokorny (128,290 points)
edited Jul 1, 2014
Best answer

You can use Imap object's SendCommand/ReadResonse methods to achieve this if your IMAP server supports quotas:

    // initialize a connection
    Imap imap = new Imap();
    imap.Connect("", 993, null, ImapSecurity.Implicit);
    imap.Login(email, password);

    // determine Inbox quotas
    imap.SendCommand("GETQUOTAROOT", "Inbox");
    ImapResponse response = imap.ReadResponse();

    // display Inbox quotas returned by the server
    foreach (ImapResponseLine line in response.GetLines())
        if (line.Code == "QUOTA")
            // Format: quote_root_name (resource_name current_usage limit)
            // Sample: "" (STORAGE 546615 7599416)

Please be aware that quotas in IMAP are quite complex (see RFC 2087 for details): Each folder has zero or more implementation-defined named "quota roots". Each quota root has zero or more resource limits. All folders that share the same named quota root share the resource limits of the quota root.

However, many IMAP servers (such as Gmail) only have a single "quota root" shared by all folders, which makes it possible to determine all information about it using a single "GETQUOTAROOT Inbox" command as shown above.

commented Mar 4, 2010 by Wakatake (240 points)
edited Jun 22, 2014

Thank you very much! It worked perfectly. I will just have to format the reply accordingly to what I need.