ImapGetFolderSize Method
Downloads the size of each message in the currently selected folder and returns the total size occupied by all messages in this folder.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public long GetFolderSize()

Return Value

Type: Int64
On success, return the total size occupied by all messages in this folder; otherwise, -1.
Exceptions
ExceptionCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.
Remarks
If the application needs to calculate the total size of all messages in all folders of the mail account, it should use QUOTA extension (GetAccountQuota method) and fall back to multiple GetFolderSize calls only if QUOTA is not supported. However, iterating through all the folders and downloading messages' sizes may take considerable amount of time. Also, it's not possible to determine sizes of non-selectable folders and sizes of folders themselves (without their contained messages) using non-QUOTA approach. Thus, the storage size obtained from GetAccountQuota is usually larger (by 1% or so) than the size determined via a series of SelectFolder(String) and GetFolderSize calls.
Note Note
GetFolderSize method considers only messages belonging to the folder itself. If the folder contains any sub-folders, the sizes of messages in these subfolders will not be included into the returned value.
Examples
This sample attempts to gets the size of the currently used account storage using QUOTA extension. If QUOTA is not supported by the server, the sample selects all selectable folders in the account one by another, and calls GetFolderSize for each folder.
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("mail.company.com");
        imp.Login("jdoe@company.com", "secret");

        long accountStorageUsedSize = -1;

        if (imp.GetExtension("QUOTA") != null)
        {
            // This may still return -1 if the QUOTA is supported
            // in general but storage quota in bytes is not.
            accountStorageUsedSize = imp.GetAccountQuota().CurrentStorageSize;
        }

        if (accountStorageUsedSize < 0)
        {
            // Fall back to a series of SelectFolder/GetFolderSize calls.
            accountStorageUsedSize = 0;
            FolderCollection folders = imp.DownloadFolders();

            foreach (Folder fold in folders)
            {
                // For each selectable folder, select it and
                // determine the total size of all messages.
                if ((fold.Flags & FolderFlags.Noselect) == 0)
                {
                    imp.SelectFolder(fold.Name);
                    accountStorageUsedSize += imp.GetFolderSize();
                }
            }
        }

        Console.WriteLine("Currently used account storage size is " +
            accountStorageUsedSize + " bytes");

        // Disconnect from the server.
        imp.Disconnect();
    }
}
See Also