+1 vote
by (240 points)


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
by (143k points)
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("imap.gmail.com", 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.

by (240 points)

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