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.ImapMailAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax public long GetFolderSize()
Public Function GetFolderSize As Long
Return Value
Type:
Int64On success, return the total size occupied by all messages in this folder; otherwise, -1.
Exceptions 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 |
---|
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();
imp.Connect("mail.company.com");
imp.Login("jdoe@company.com", "secret");
long accountStorageUsedSize = -1;
if (imp.GetExtension("QUOTA") != null)
{
accountStorageUsedSize = imp.GetAccountQuota().CurrentStorageSize;
}
if (accountStorageUsedSize < 0)
{
accountStorageUsedSize = 0;
FolderCollection folders = imp.DownloadFolders();
foreach (Folder fold in folders)
{
if ((fold.Flags & FolderFlags.Noselect) == 0)
{
imp.SelectFolder(fold.Name);
accountStorageUsedSize += imp.GetFolderSize();
}
}
}
Console.WriteLine("Currently used account storage size is " +
accountStorageUsedSize + " bytes");
imp.Disconnect();
}
}
Imports System
Imports MailBee
Imports MailBee.ImapMail
Module Sample
Sub Main(ByVal args As String())
Dim imp As New Imap
imp.Connect("mail.domain.com")
imp.Login("jdoe", "secret")
Dim accountStorageUsedSize As Long = -1
If Not imp.GetExtension("QUOTA") Is Nothing Then
accountStorageUsedSize = imp.GetAccountQuota().CurrentStorageSize
End If
If accountStorageUsedSize < 0 Then
accountStorageUsedSize = 0
Dim folders As FolderCollection = imp.DownloadFolders()
For Each fold As Folder In folders
If (fold.Flags And FolderFlags.Noselect) = 0 Then
imp.SelectFolder(fold.Name)
accountStorageUsedSize += imp.GetFolderSize()
End If
Next
End If
Console.WriteLine("Currently used account storage size is " & _
accountStorageUsedSize & " bytes")
imp.Disconnect()
End Sub
End Module
See Also