Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Get an IMAP Mailbox Quota (GETQUOTAROOT)

See more IMAP Examples

Demonstrates the Chilkat Imap.GetQuotaRoot method, which sends the IMAP GETQUOTAROOT command for a mailbox and returns the server response as JSON. The only argument is the mailbox name. The server must advertise the IMAP QUOTA capability. This example queries the quota that applies to the Inbox.

Tip: JSON parsing code for this result can be generated at Chilkat Tools.

Background: This is how a client shows a storage bar such as "9 of 256000 used." A mailbox maps to a quota root, and a single root may govern several mailboxes that share the same allowance. The JSON response can include both the mailbox-to-root mapping (QUOTAROOT) and the resource usage and limit (QUOTA).

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Imap;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  imap: TImap;
  jsonStr: string;

begin
  success := False;

  //  Demonstrates the Imap.GetQuotaRoot method, which sends the IMAP GETQUOTAROOT command for a
  //  mailbox and returns the server response as JSON.  The only argument is the mailbox name.

  imap := TImap.Create;

  imap.Ssl := True;
  imap.Port := 993;

  success := imap.Connect('imap.example.com');
  if (success = False) then
    begin
      WriteLn(imap.LastErrorText);
      Exit;
    end;
  success := imap.Login('user@example.com','myPassword');
  if (success = False) then
    begin
      WriteLn(imap.LastErrorText);
      Exit;
    end;

  //  GetQuotaRoot returns a JSON string, so assign it to a string variable and check success.
  jsonStr := imap.GetQuotaRoot('Inbox');
  if (imap.LastMethodSuccess = False) then
    begin
      WriteLn(imap.LastErrorText);
      Exit;
    end;
  WriteLn(jsonStr);
  //  JSON parsing code for this result can be generated at Chilkat's online tool:
  //  https://tools.chilkat.io/jsonParse

  success := imap.Disconnect();
  if (success = False) then
    begin
      WriteLn(imap.LastErrorText);
      Exit;
    end;


  imap.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.