---
product: Chilkat
product_version: 11.7.0
language: foxpro
language_label: FoxPro
class: Imap
license: bundle
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/foxpro_ImapRef.html
---
# Chilkat Imap — FoxPro — v11.7.0

> Chilkat 11.7.0 · language=foxpro · class=Imap
> Other versions: replace `11.7.0` in this URL. Other languages: `https://www.chilkatsoft.com/ai-docs/v/11.7.0/<lang>/classes/Imap.md`.
> Language-wide rules (install, unlock, error model, strings/bytes): `https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/guide.md`.

## Purpose

**Access, search, download, organize, and monitor email on IMAP servers.**

`Chilkat.Imap` is a full-featured IMAP client class for applications that need reliable server-side email access and mailbox management. It supports secure connections, authentication, mailbox selection, message searching, downloading email and attachments, flag management, moving and copying messages, appending MIME, IDLE-based change monitoring, and detailed diagnostics for troubleshooting server behavior.

**Secure IMAP connections**

Connect with SSL/TLS, STARTTLS, OAuth2, password authentication, proxy settings, timeouts, and connection diagnostics.

**Mailbox selection and listing**

List mailboxes, select folders, inspect mailbox state, and work with server-side folders such as Inbox, Sent, Archive, or custom folders.

**Search and fetch messages**

Search by IMAP criteria, work with UIDs or sequence numbers, download full messages, headers, MIME, body text, or selected message parts.

**Message management**

Set and clear flags, mark messages read or unread, copy or move messages, delete messages, expunge mailboxes, and append MIME to folders.

**Attachments and MIME**

Retrieve email as Chilkat `Email` objects, process MIME content, and save or inspect attachments as needed.

**IDLE and diagnostics**

Monitor mailbox changes with IMAP IDLE and use detailed logging, response text, and `LastErrorText` to troubleshoot servers.

**Common pattern:** Connect securely, authenticate, select a mailbox, search or fetch messages using UIDs when possible, perform message or folder operations, then disconnect cleanly. Use detailed diagnostics when working with provider- specific IMAP behavior.

For an extended overview, see [Imap Class Overview](https://www.chilkatsoft.com/imap_class_overview.asp).

## Object creation, unlocking and error handling

**Object Creation**

```foxpro
loImap = CreateObject('Chilkat.Imap')
```

Visual FoxPro is a 32-bit application and therefore uses the 32-bit Chilkat ActiveX. To bind to a specific major version of Chilkat, append the major version number to the ProgID, such as `CreateObject('Chilkat.Imap.11')` for Chilkat v11.\*.\*.

Call `Global.UnlockBundle` once at the start of the program, before using this or any other Chilkat class. Any string unlocks a fully functional 30-day trial; a purchased unlock code is used in production. See `guide.md` for the exact code in FoxPro.

How failure is reported depends on the method's return type and is stated in the note under each method below. In every case the diagnostic text is in the `LastErrorText` property of the object whose method was called.

## Members common to every Chilkat class

Documented once per language in `common-members.md`; listed here so this page is self-contained.

| Property | Signature | Access | Meaning |
|---|---|---|---|
| `DebugLogFilePath` | `DebugLogFilePath As String` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastBinaryResult` | `LastBinaryResult As Variant (read-only)` | read-only | This property is mainly used in SQL Server stored procedures to retrieve binary data from the last method call that returned binary data. |
| `LastErrorHtml` | `LastErrorHtml As String (read-only)` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `LastErrorText As String (read-only)` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `LastErrorXml As String (read-only)` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `LastMethodSuccess As Number` | read/write | Indicates the success or failure of the most recent method call: `1` means success, `0` means failure. |
| `LastStringResult` | `LastStringResult As String (read-only)` | read-only | In SQL Server stored procedures, this property holds the string return value of the most recent method call that returns a string. |
| `LastStringResultLen` | `LastStringResultLen As Number (read-only)` | read-only | The length, in characters, of the string contained in the LastStringResult property. |
| `VerboseLogging` | `VerboseLogging As Number` | read/write | If set to `1`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `Version As String (read-only)` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `AbortCurrent` | property, read/write | `AbortCurrent As Number` |
| `AppendSeen` | property, read/write | `AppendSeen As Number` |
| `AppendUid` | property, read-only | `AppendUid As Number (read-only)` |
| `AuthMethod` | property, read/write | `AuthMethod As String` |
| `AuthzId` | property, read/write | `AuthzId As String` |
| `AutoDownloadAttachments` | property, read/write | `AutoDownloadAttachments As Number` |
| `AutoFix` | property, read/write | `AutoFix As Number` |
| `ClientIpAddress` | property, read/write | `ClientIpAddress As String` |
| `ConnectedToHost` | property, read-only | `ConnectedToHost As String (read-only)` |
| `ConnectTimeout` | property, read/write | `ConnectTimeout As Number` |
| `Domain` | property, read/write | `Domain As String` |
| `EnableSecrets` | property, read/write | `EnableSecrets As Number` |
| `HeartbeatMs` | property, read/write | `HeartbeatMs As Number` |
| `HighestModSeq` | property, read-only | `HighestModSeq As String (read-only)` |
| `HttpProxyAuthMethod` | property, read/write | `HttpProxyAuthMethod As String` |
| `HttpProxyDomain` | property, read/write | `HttpProxyDomain As String` |
| `HttpProxyHostname` | property, read/write | `HttpProxyHostname As String` |
| `HttpProxyPassword` | property, read/write | `HttpProxyPassword As String` |
| `HttpProxyPort` | property, read/write | `HttpProxyPort As Number` |
| `HttpProxyUsername` | property, read/write | `HttpProxyUsername As String` |
| `KeepSessionLog` | property, read/write | `KeepSessionLog As Number` |
| `LastAppendedMime` | property, read-only | `LastAppendedMime As String (read-only)` |
| `LastCommand` | property, read-only | `LastCommand As String (read-only)` |
| `LastIntermediateResponse` | property, read-only | `LastIntermediateResponse As String (read-only)` |
| `LastResponse` | property, read-only | `LastResponse As String (read-only)` |
| `LastResponseCode` | property, read-only | `LastResponseCode As String (read-only)` |
| `LoggedInUser` | property, read-only | `LoggedInUser As String (read-only)` |
| `NumMessages` | property, read-only | `NumMessages As Number (read-only)` |
| `PeekMode` | property, read/write | `PeekMode As Number` |
| `PercentDoneScale` | property, read/write | `PercentDoneScale As Number` |
| `Port` | property, read/write | `Port As Number` |
| `PreferIpv6` | property, read/write | `PreferIpv6 As Number` |
| `ReadTimeout` | property, read/write | `ReadTimeout As Number` |
| `RequireSslCertVerify` | property, read/write | `RequireSslCertVerify As Number` |
| `SearchCharset` | property, read/write | `SearchCharset As String` |
| `SelectedMailbox` | property, read-only | `SelectedMailbox As String (read-only)` |
| `SendBufferSize` | property, read/write | `SendBufferSize As Number` |
| `SeparatorChar` | property, read/write | `SeparatorChar As String` |
| `SessionLog` | property, read-only | `SessionLog As String (read-only)` |
| `SocksHostname` | property, read/write | `SocksHostname As String` |
| `SocksPassword` | property, read/write | `SocksPassword As String` |
| `SocksPort` | property, read/write | `SocksPort As Number` |
| `SocksUsername` | property, read/write | `SocksUsername As String` |
| `SocksVersion` | property, read/write | `SocksVersion As Number` |
| `SoRcvBuf` | property, read/write | `SoRcvBuf As Number` |
| `SortCriteria` | property, read/write | `SortCriteria As String` |
| `SoSndBuf` | property, read/write | `SoSndBuf As Number` |
| `Ssl` | property, read/write | `Ssl As Number` |
| `SslAllowedCiphers` | property, read/write | `SslAllowedCiphers As String` |
| `SslProtocol` | property, read/write | `SslProtocol As String` |
| `SslServerCertVerified` | property, read-only | `SslServerCertVerified As Number (read-only)` |
| `StartTls` | property, read/write | `StartTls As Number` |
| `TlsCipherSuite` | property, read-only | `TlsCipherSuite As String (read-only)` |
| `TlsPinSet` | property, read/write | `TlsPinSet As String` |
| `TlsVersion` | property, read-only | `TlsVersion As String (read-only)` |
| `UidNext` | property, read-only | `UidNext As Number (read-only)` |
| `UidValidity` | property, read-only | `UidValidity As Number (read-only)` |
| `UncommonOptions` | property, read/write | `UncommonOptions As String` |
| `AddPfxSourceBd` | method | `AddPfxSourceBd(bd As ChilkatBinData, password As String) As Number` |
| `AddPfxSourceData` | method | `AddPfxSourceData(pfxBytes As Variant, pfxPassword As String) As Number` |
| `AddPfxSourceFile` | method | `AddPfxSourceFile(pfxFilePath As String, pfxPassword As String) As Number` |
| `AppendMail` | method | `AppendMail(mailbox As String, email As ChilkatEmail) As Number` |
| `AppendMime` | method | `AppendMime(mailbox As String, mimeText As String) As Number` |
| `AppendMimeWithDateStr` | method | `AppendMimeWithDateStr(mailbox As String, mimeText As String, internalDateStr As String) As Number` |
| `AppendMimeWithFlags` | method | `AppendMimeWithFlags(mailbox As String, mimeText As String, seen As Number, flagged As Number, answered As Number, draft As Number) As Number` |
| `AppendMimeWithFlagsSb` | method | `AppendMimeWithFlagsSb(mailbox As String, sbMime As ChilkatStringBuilder, seen As Number, flagged As Number, answered As Number, draft As Number) As Number` |
| `Capability` | method | `Capability() As String` |
| `CheckConnection` | method | `CheckConnection() As Number` |
| `ClearSessionLog` | method | `ClearSessionLog()` |
| `CloseMailbox` | method | `CloseMailbox(mailbox As String) As Number` |
| `Connect` | method | `Connect(domainName As String) As Number` |
| `Copy` | method | `Copy(msgId As Number, bUid As Number, copyToMailbox As String) As Number` |
| `CopyMultiple` | method | `CopyMultiple(messageSet As MessageSet, copyToMailbox As String) As Number` |
| `CopySequence` | method | `CopySequence(startSeqNum As Number, count As Number, copyToMailbox As String) As Number` |
| `CreateMailbox` | method | `CreateMailbox(mailbox As String) As Number` |
| `DeleteMailbox` | method | `DeleteMailbox(mailbox As String) As Number` |
| `Disconnect` | method | `Disconnect() As Number` |
| `ExamineMailbox` | method | `ExamineMailbox(mailbox As String) As Number` |
| `Expunge` | method | `Expunge() As Number` |
| `ExpungeAndClose` | method | `ExpungeAndClose() As Number` |
| `FetchAttachment` | method | `FetchAttachment(emailObject As ChilkatEmail, attachmentIndex As Number, saveToPath As String) As Number` |
| `FetchAttachmentBd` | method | `FetchAttachmentBd(email As ChilkatEmail, attachmentIndex As Number, binData As ChilkatBinData) As Number` |
| `FetchAttachmentBytes` | method | `FetchAttachmentBytes(email As ChilkatEmail, attachIndex As Number) As Variant` |
| `FetchAttachmentSb` | method | `FetchAttachmentSb(email As ChilkatEmail, attachmentIndex As Number, charset As String, sb As ChilkatStringBuilder) As Number` |
| `FetchAttachmentString` | method | `FetchAttachmentString(emailObject As ChilkatEmail, attachmentIndex As Number, charset As String) As String` |
| `FetchChunk2` | method | `FetchChunk2(seqnum As Number, count As Number, failedSet As MessageSet, fetchedSet As MessageSet, bundle As ChilkatEmailBundle) As Number` |
| `FetchEmail` | method | `FetchEmail(headerOnly As Number, msgId As Number, bUid As Number, email As ChilkatEmail) As Number` |
| `FetchFlags` | method | `FetchFlags(msgId As Number, bUid As Number) As String` |
| `FetchMsgSet` | method | `FetchMsgSet(headersOnly As Number, msgSet As MessageSet, bundle As ChilkatEmailBundle) As Number` |
| `FetchRange` | method | `FetchRange(headersOnly As Number, seqnum As Number, count As Number, bundle As ChilkatEmailBundle) As Number` |
| `FetchSingleAsMime` | method | `FetchSingleAsMime(msgId As Number, bUid As Number) As String` |
| `FetchSingleAsMimeSb` | method | `FetchSingleAsMimeSb(msgId As Number, bUid As Number, sbMime As ChilkatStringBuilder) As Number` |
| `FetchSingleBd` | method | `FetchSingleBd(msgId As Number, bUid As Number, mimeData As ChilkatBinData) As Number` |
| `FetchSingleHeaderAsMime` | method | `FetchSingleHeaderAsMime(msgId As Number, bUID As Number) As String` |
| `GetMailAttachFilename` | method | `GetMailAttachFilename(email As ChilkatEmail, attachIndex As Number) As String` |
| `GetMailAttachSize` | method | `GetMailAttachSize(email As ChilkatEmail, attachIndex As Number) As Number` |
| `GetMailboxStatus` | method | `GetMailboxStatus(mailbox As String) As String` |
| `GetMailFlag` | method | `GetMailFlag(email As ChilkatEmail, flagName As String) As Number` |
| `GetMailNumAttach` | method | `GetMailNumAttach(email As ChilkatEmail) As Number` |
| `GetMailSize` | method | `GetMailSize(email As ChilkatEmail) As Number` |
| `GetQuota` | method | `GetQuota(quotaRoot As String) As String` |
| `GetQuotaRoot` | method | `GetQuotaRoot(mailboxName As String) As String` |
| `GetServerCert` | method | `GetServerCert(cert As ChilkatCert) As Number` |
| `HasCapability` | method | `HasCapability(name As String, capabilityResponse As String) As Number` |
| `IdleCheck` | method | `IdleCheck(timeoutMs As Number) As String` |
| `IdleDone` | method | `IdleDone() As Number` |
| `IdleStart` | method | `IdleStart() As Number` |
| `IsConnected` | method | `IsConnected() As Number` |
| `IsLoggedIn` | method | `IsLoggedIn() As Number` |
| `LoadTaskCaller` | method | `LoadTaskCaller(task As ChilkatTask) As Number` |
| `Login` | method | `Login(loginName As String, password As String) As Number` |
| `LoginSecure` | method | `LoginSecure(loginName As ChilkatSecureString, password As ChilkatSecureString) As Number` |
| `Logout` | method | `Logout() As Number` |
| `MbxList` | method | `MbxList(subscribed As Number, reference As String, mbxPattern As String, mboxes As Mailboxes) As Number` |
| `MoveMessages` | method | `MoveMessages(messageSet As MessageSet, destFolder As String) As Number` |
| `Noop` | method | `Noop() As Number` |
| `QueryMbx` | method | `QueryMbx(criteria As String, bUid As Number, msgSet As MessageSet) As Number` |
| `QueryThread` | method | `QueryThread(threadAlg As String, searchCriteria As String, bUid As Number, json As ChilkatJsonObject) As Number` |
| `RawCommandBd` | method | `RawCommandBd(bdCmd As ChilkatBinData, bdResp As ChilkatBinData) As Number` |
| `RefetchMailFlags` | method | `RefetchMailFlags(email As ChilkatEmail) As Number` |
| `RenameMailbox` | method | `RenameMailbox(fromMailbox As String, toMailbox As String) As Number` |
| `SelectMailbox` | method | `SelectMailbox(mailbox As String) As Number` |
| `SendRawCommand` | method | `SendRawCommand(cmd As String) As String` |
| `SendRawCommandB` | method | `SendRawCommandB(cmd As String) As Variant` |
| `SendRawCommandC` | method | `SendRawCommandC(cmd As Variant) As Variant` |
| `SetDecryptCert` | method | `SetDecryptCert(cert As ChilkatCert) As Number` |
| `SetDecryptCert2` | method | `SetDecryptCert2(cert As ChilkatCert, key As PrivateKey) As Number` |
| `SetFlag` | method | `SetFlag(msgId As Number, bUid As Number, flagName As String, value As Number) As Number` |
| `SetFlags` | method | `SetFlags(messageSet As MessageSet, flagName As String, value As Number) As Number` |
| `SetMailFlag` | method | `SetMailFlag(email As ChilkatEmail, flagName As String, value As Number) As Number` |
| `SetQuota` | method | `SetQuota(quotaRoot As String, resource As String, quota As Number) As Number` |
| `SetSslClientCert` | method | `SetSslClientCert(cert As ChilkatCert) As Number` |
| `SetSslClientCertPem` | method | `SetSslClientCertPem(pemDataOrFilename As String, pemPassword As String) As Number` |
| `SetSslClientCertPfx` | method | `SetSslClientCertPfx(pfxFilename As String, pfxPassword As String) As Number` |
| `SshAuthenticatePk` | method | `SshAuthenticatePk(sshLogin As String, privateKey As ChilkatSshKey) As Number` |
| `SshAuthenticatePw` | method | `SshAuthenticatePw(sshLogin As String, sshPassword As String) As Number` |
| `SshCloseTunnel` | method | `SshCloseTunnel() As Number` |
| `SshOpenTunnel` | method | `SshOpenTunnel(sshHostname As String, sshPort As Number) As Number` |
| `StoreFlags` | method | `StoreFlags(msgId As Number, bUid As Number, flagNames As String, value As Number) As Number` |
| `Subscribe` | method | `Subscribe(mailbox As String) As Number` |
| `Unsubscribe` | method | `Unsubscribe(mailbox As String) As Number` |
| `UseCertVault` | method | `UseCertVault(vault As ChilkatXmlCertVault) As Number` |
| `UseSsh` | method | `UseSsh(ssh As ChilkatSsh) As Number` |
| `UseSshTunnel` | method | `UseSshTunnel(tunnel As ChilkatSocket) As Number` |

Deprecated members are listed at the end of this file with their replacements; do not use them in new code.

## Properties

### Imap.AbortCurrent

`Chilkat 11.7.0 · foxpro · Imap · AbortCurrent · property · read/write · since 9.5.0.58`

```foxpro
AbortCurrent As Number
```

Controls cancellation of the method currently running on this `Imap` object.

- Set this property to `1` to request that a long-running network operation abort.
- Short methods that do not perform lengthy processing or network communication are generally unaffected.
- Both synchronous and asynchronous calls can be aborted. A synchronous call may be canceled by setting this property from another thread.

The property is automatically reset to `0` when the abort is processed. If no method is running, it is reset when the next method begins.

Canceling an operation can leave the connection in an uncertain state. Close the connection, reconnect, authenticate again, and reselect the mailbox before continuing. Output objects may contain partial results, and a server-side operation may already have been partially applied before cancellation.

### Imap.AppendSeen

`Chilkat 11.7.0 · foxpro · Imap · AppendSeen · property · read/write`

```foxpro
AppendSeen As Number
```

Controls the initial `\Seen` flag for these methods:

- `AppendMail`
- `AppendMime`
- `AppendMimeWithDateStr`

- `1` (the default): the appended message is marked as seen.
- `0`: the appended message is initially unseen.

The flag-specific append methods use their explicit arguments and do not use this property.

### Imap.AppendUid

`Chilkat 11.7.0 · foxpro · Imap · AppendUid · property · read-only`

```foxpro
AppendUid As Number (read-only)
```

Contains the UID assigned by the server to the message most recently appended successfully.

The default is `0`. After any successful append, this property is set to the UID reported by the server, or to `0` if the server succeeds but does not report an appended UID. A failed append leaves the previous value unchanged.

### Imap.AuthMethod

`Chilkat 11.7.0 · foxpro · Imap · AuthMethod · property · read/write`

```foxpro
AuthMethod As String
```

Selects the IMAP authentication mechanism. Matching is case-insensitive, but spelling matters.

| Value | Purpose |
| --- | --- |
| `LOGIN` | Username and password authentication. |
| `PLAIN` | SASL PLAIN authentication. `AuthzId` may also be used. |
| `CRAM-MD5` | Challenge-response authentication when supported by the server. |
| `NTLM` | Windows Integrated Authentication. |
| `XOAUTH2` | OAuth 2.0 access-token authentication. |

The default is `LOGIN`, and an empty or unrecognized value also uses the LOGIN method. If the selected mechanism fails or is not supported by the server, Chilkat does not fall back to another authentication method.

If NTLM authentication fails because of an NTLM-version compatibility issue, set `Global.DefaultNtlmVersion` to `1` and retry.

### Imap.AuthzId

`Chilkat 11.7.0 · foxpro · Imap · AuthzId · property · read/write`

```foxpro
AuthzId As String
```

Specifies the optional authorization identity used with the `PLAIN` authentication mechanism.

Leave this property empty unless the IMAP server requires an authorization identity that differs from the login identity supplied to `Login`.

### Imap.AutoDownloadAttachments

`Chilkat 11.7.0 · foxpro · Imap · AutoDownloadAttachments · property · read/write`

```foxpro
AutoDownloadAttachments As Number
```

Controls whether methods that download a complete email also download ordinary attachment bodies. The default is `1`.

- `1`: complete-email fetches include attachment bodies.
- `0`: complete-email fetches omit ordinary attachment bodies, whether the result is returned as an `Email` object or as MIME.

Header-only methods never download attachment bodies. They add `ckx-imap-*` metadata describing the attachments, which can be read with `GetMailNumAttach`, `GetMailAttachFilename`, and `GetMailAttachSize`. In this state, the `Email` object's ordinary attachment count can still be `0`.

Related MIME parts used by an HTML body are not treated as ordinary attachments. Signed or encrypted messages are always downloaded in full because their complete MIME is required for verification or decryption.

See also:

- [Fetching IMAP Attachments](http://www.cknotes.com/?p=393)
- [Getting Attachment Information](http://www.cknotes.com/?p=434)

### Imap.AutoFix

`Chilkat 11.7.0 · foxpro · Imap · AutoFix · property · read/write`

```foxpro
AutoFix As Number
```

When `1` (the default), changes the public `Ssl` and `StartTls` property values when `Connect` is called for a standard IMAP port:

- Port `993`: sets `Ssl` to `1` and `StartTls` to `0` for implicit TLS.
- Port `143`: sets `Ssl` to `0`. The existing `StartTls` value determines whether the connection is upgraded explicitly.

For a nonstandard port, this property makes no changes. Set it to `0` when the application must preserve an unusual port and TLS combination exactly as configured.

### Imap.ClientIpAddress

`Chilkat 11.7.0 · foxpro · Imap · ClientIpAddress · property · read/write`

```foxpro
ClientIpAddress As String
```

Specifies the local IP address to bind when the computer has multiple network interfaces or addresses.

Leave this property empty for the usual case. The operating system will select the default local interface. When set, use a numeric IP address such as `165.164.55.124`, not a hostname.

See also:

- [Important Bind to Adapter Notes for Windows](http://www.cknotes.com/?p=376)

### Imap.ConnectedToHost

`Chilkat 11.7.0 · foxpro · Imap · ConnectedToHost · property · read-only`

```foxpro
ConnectedToHost As String (read-only)
```

Contains the hostname or IP address of the IMAP server to which the object is currently connected.

Returns an empty string when no connection is active.

### Imap.ConnectTimeout

`Chilkat 11.7.0 · foxpro · Imap · ConnectTimeout · property · read/write`

```foxpro
ConnectTimeout As Number
```

The maximum number of seconds to wait while establishing the TCP connection to the IMAP server.

The default is `30` seconds. This timeout applies to connection establishment, not to later reads from the server.

### Imap.Domain

`Chilkat 11.7.0 · foxpro · Imap · Domain · property · read/write`

```foxpro
Domain As String
```

Specifies the Windows domain used for NTLM authentication.

This property is optional and may be left empty when the login name already identifies the domain or when NTLM is not used.

### Imap.EnableSecrets

`Chilkat 11.7.0 · foxpro · Imap · EnableSecrets · property · read/write · since 11.5.0`

```foxpro
EnableSecrets As Number
```

**Full documentation for this property (same in every language):** [More Detailed Information About EnableSecrets](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/secret_specification_strings.md)

Enables automatic resolution of credential values from secure operating-system storage. The default is `0`.

When `1`, supported password arguments and properties may contain a secret specification beginning with `!!` instead of a literal secret. Chilkat resolves the value from Windows Credential Manager or Apple Keychain.

```
!![appName|]service[|domain]|username
```

This applies to `HttpProxyPassword`, `SocksPassword`, the password supplied to `Login`, and the password supplied to `SshAuthenticatePw`.

### Imap.HeartbeatMs

`Chilkat 11.7.0 · foxpro · Imap · HeartbeatMs · property · read/write`

```foxpro
HeartbeatMs As Number
```

**Full documentation for this property (same in every language):** [Event Callback Examples](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/event_callback_examples.md)

Sets the interval, in milliseconds, between `AbortCheck` event callbacks during operations that support cancellation.

The default is `0`, which disables periodic `AbortCheck` callbacks.

### Imap.HighestModSeq

`Chilkat 11.7.0 · foxpro · Imap · HighestModSeq · property · read-only · since 9.5.0.87`

```foxpro
HighestModSeq As String (read-only)
```

Contains the `HIGHESTMODSEQ` value of the currently selected mailbox as a decimal string.

The value is `0` when no mailbox is selected or the server does not provide this information. A string is used because the value may exceed the integer range of some programming languages.

### Imap.HttpProxyAuthMethod

`Chilkat 11.7.0 · foxpro · Imap · HttpProxyAuthMethod · property · read/write`

```foxpro
HttpProxyAuthMethod As String
```

Specifies the authentication mechanism used by an HTTP proxy.

Valid values are `Basic` and `NTLM`. This property is used only when `HttpProxyHostname` identifies an HTTP proxy that requires authentication.

### Imap.HttpProxyDomain

`Chilkat 11.7.0 · foxpro · Imap · HttpProxyDomain · property · read/write`

```foxpro
HttpProxyDomain As String
```

Specifies the optional Windows domain for HTTP-proxy NTLM authentication.

It is ignored when the proxy does not use NTLM authentication.

### Imap.HttpProxyHostname

`Chilkat 11.7.0 · foxpro · Imap · HttpProxyHostname · property · read/write`

```foxpro
HttpProxyHostname As String
```

Specifies the hostname or numeric IPv4 address of an HTTP proxy through which the IMAP connection is established.

Leave this property empty to connect directly or to use another configured transport such as SOCKS or SSH tunneling.

### Imap.HttpProxyPassword

`Chilkat 11.7.0 · foxpro · Imap · HttpProxyPassword · property · read/write`

```foxpro
HttpProxyPassword As String
```

Specifies the password used to authenticate with the configured HTTP proxy.

It is used only when the proxy requires authentication.

### Imap.HttpProxyPort

`Chilkat 11.7.0 · foxpro · Imap · HttpProxyPort · property · read/write`

```foxpro
HttpProxyPort As Number
```

Specifies the TCP port of the configured HTTP proxy.

Common values include `8080` and `3128`, but the correct value is determined by the proxy server configuration.

### Imap.HttpProxyUsername

`Chilkat 11.7.0 · foxpro · Imap · HttpProxyUsername · property · read/write`

```foxpro
HttpProxyUsername As String
```

Specifies the username used to authenticate with the configured HTTP proxy.

It is used only when the proxy requires authentication.

### Imap.KeepSessionLog

`Chilkat 11.7.0 · foxpro · Imap · KeepSessionLog · property · read/write`

```foxpro
KeepSessionLog As Number
```

Enables or disables the in-memory IMAP protocol log. The default is `0`.

When enabled, `SessionLog` contains the raw commands sent to the server and the raw responses received. Use `ClearSessionLog` to reset it.

### Imap.LastAppendedMime

`Chilkat 11.7.0 · foxpro · Imap · LastAppendedMime · property · read-only`

```foxpro
LastAppendedMime As String (read-only)
```

Contains the MIME source sent by the most recent successful call to one of the following methods:

- `AppendMail`
- `AppendMime`
- `AppendMimeWithDateStr`
- `AppendMimeWithFlags`
- `AppendMimeWithFlagsSb`

A failed append leaves the previous value unchanged. Therefore, read this property only after confirming that the append method succeeded.

### Imap.LastCommand

`Chilkat 11.7.0 · foxpro · Imap · LastCommand · property · read-only`

```foxpro
LastCommand As String (read-only)
```

Contains the most recent raw IMAP command sent to the server.

This property is primarily intended for diagnostics when an IMAP operation fails or produces an unexpected response.

### Imap.LastIntermediateResponse

`Chilkat 11.7.0 · foxpro · Imap · LastIntermediateResponse · property · read-only`

```foxpro
LastIntermediateResponse As String (read-only)
```

Contains the most recent intermediate response received from the IMAP server while a command was in progress.

Use it for protocol-level diagnostics when a command involves continuations or multiple response stages.

### Imap.LastResponse

`Chilkat 11.7.0 · foxpro · Imap · LastResponse · property · read-only`

```foxpro
LastResponse As String (read-only)
```

Contains the raw response most recently received from the IMAP server.

This property is cleared when Chilkat sends a new command. If a method fails during local argument validation or before a command is sent, the previous response can remain here. Also, a method can return failure even when the last tagged server response is `OK`, such as when a syntactically successful `FETCH` returns no matching message. Use the method return value or `LastMethodSuccess` as the authoritative success indicator.

### Imap.LastResponseCode

`Chilkat 11.7.0 · foxpro · Imap · LastResponseCode · property · read-only · since 9.5.0.44`

```foxpro
LastResponseCode As String (read-only)
```

Contains the optional IMAP response code from the most recent server response, such as `NONEXISTENT` or `AUTHENTICATIONFAILED`. Response-code strings vary by server.

If a method fails before sending an IMAP command, this property can still contain the response code from an earlier command. Use the method return value or `LastMethodSuccess` to determine whether the current operation succeeded.

### Imap.LoggedInUser

`Chilkat 11.7.0 · foxpro · Imap · LoggedInUser · property · read-only`

```foxpro
LoggedInUser As String (read-only)
```

Contains the username of the authenticated IMAP session.

Returns an empty string when the object is not logged in.

### Imap.NumMessages

`Chilkat 11.7.0 · foxpro · Imap · NumMessages · property · read-only`

```foxpro
NumMessages As Number (read-only)
```

Contains the number of messages reported when the current mailbox was selected.

The value is updated by `SelectMailbox` and `ExamineMailbox`. Unsolicited `EXISTS` notifications returned by `IdleCheck` do not automatically update this property; use the notification value or reselect/query the mailbox when a refreshed count is needed.

### Imap.PeekMode

`Chilkat 11.7.0 · foxpro · Imap · PeekMode · property · read/write`

```foxpro
PeekMode As Number
```

Controls whether fetching full message content marks the message as seen.

- `0` (the default): fetching a full message or its raw MIME may set the `\Seen` flag.
- `1`: full message data and raw MIME are fetched without setting `\Seen`, using IMAP peek semantics.

Fetching headers only does not set `\Seen`, regardless of this property.

### Imap.PercentDoneScale

`Chilkat 11.7.0 · foxpro · Imap · PercentDoneScale · property · read/write · since 9.5.0.49`

```foxpro
PercentDoneScale As Number
```

Sets the scale used by `PercentDone` event callbacks. The default is `100`.

For example, a scale of `1000` gives tenths-of-a-percent precision, so a callback value of `453` represents 45.3% complete. Values are limited to the range `10` through `100000`.

This property applies only to languages and environments that support event callbacks and only to operations for which progress can be measured.

### Imap.Port

`Chilkat 11.7.0 · foxpro · Imap · Port · property · read/write`

```foxpro
Port As Number
```

Specifies the IMAP server port. The default is `143`.

- `993` is the standard port for implicit TLS and is normally used with `Ssl` set to `1`.
- `143` is the standard port for ordinary IMAP and for explicit TLS requested with `StartTls`.

When `AutoFix` is enabled, standard port values are used to adjust the effective TLS configuration when connecting.

### Imap.PreferIpv6

`Chilkat 11.7.0 · foxpro · Imap · PreferIpv6 · property · read/write`

```foxpro
PreferIpv6 As Number
```

Controls address-family preference when a hostname resolves to both IPv4 and IPv6 addresses.

- `0` (the default): prefer IPv4.
- `1`: prefer IPv6.

The other address family may still be used when the preferred one is unavailable.

### Imap.ReadTimeout

`Chilkat 11.7.0 · foxpro · Imap · ReadTimeout · property · read/write`

```foxpro
ReadTimeout As Number
```

The maximum number of seconds that an incoming IMAP response may stall with no additional bytes received.

The default is `60` seconds. This is an inactivity timeout, not a limit on the total time allowed for a large response.

### Imap.RequireSslCertVerify

`Chilkat 11.7.0 · foxpro · Imap · RequireSslCertVerify · property · read/write`

```foxpro
RequireSslCertVerify As Number
```

Controls verification of the IMAP server's TLS certificate chain.

- `0` (the default): a connection is not rejected solely because normal certificate-chain verification fails.
- `1`: the connection fails when the certificate is expired, is not yet valid, its signature is invalid, or its chain cannot be verified to a trusted root.

Certificate-chain verification is separate from hostname matching and public-key pinning. Hostname matching, when required, is enforced independently even when this property is `0`. `TlsPinSet` supplements rather than replaces normal certificate verification.

The hostname used for the TLS connection is also used for Server Name Indication (SNI) and certificate hostname comparison.

### Imap.SearchCharset

`Chilkat 11.7.0 · foxpro · Imap · SearchCharset · property · read/write`

```foxpro
SearchCharset As String
```

Specifies the IMAP `CHARSET` used by `Search`, `QueryMbx`, and `QueryThread` when search criteria contain non-ASCII characters. The default is `UTF-8`.

If the criteria contain only 7-bit ASCII characters, no `CHARSET` is needed and this property has no effect. The value `AUTO` enables the legacy behavior of selecting a charset by examining the criteria text.

Most applications should leave this property unchanged unless a particular server rejects non-English search text.

### Imap.SelectedMailbox

`Chilkat 11.7.0 · foxpro · Imap · SelectedMailbox · property · read-only`

```foxpro
SelectedMailbox As String (read-only)
```

Contains the name of the currently selected or examined mailbox.

Returns an empty string when no mailbox is selected.

### Imap.SendBufferSize

`Chilkat 11.7.0 · foxpro · Imap · SendBufferSize · property · read/write`

```foxpro
SendBufferSize As Number
```

Specifies the application-level buffer size used when sending data through the underlying TCP connection.

The default is `32767` bytes. Most applications should leave this setting unchanged.

### Imap.SeparatorChar

`Chilkat 11.7.0 · foxpro · Imap · SeparatorChar · property · read/write`

```foxpro
SeparatorChar As String
```

Contains the mailbox-hierarchy delimiter reported by the IMAP server, typically `/` or `.`.

`MbxList` and the legacy mailbox-listing methods update this property from the server's LIST response. The value is a string containing one character.

### Imap.SessionLog

`Chilkat 11.7.0 · foxpro · Imap · SessionLog · property · read-only`

```foxpro
SessionLog As String (read-only)
```

Contains the in-memory log of raw IMAP commands and server responses.

`KeepSessionLog` must be `1` for logging to occur. Call `ClearSessionLog` to remove previously collected entries.

Chilkat redacts sensitive credentials, including passwords and OAuth access tokens, from session logs, diagnostic logs, and `LastErrorText`.

### Imap.SocksHostname

`Chilkat 11.7.0 · foxpro · Imap · SocksHostname · property · read/write`

```foxpro
SocksHostname As String
```

Specifies the hostname or numeric IP address of the SOCKS proxy.

This property is used only when `SocksVersion` is `4` or `5`.

### Imap.SocksPassword

`Chilkat 11.7.0 · foxpro · Imap · SocksPassword · property · read/write`

```foxpro
SocksPassword As String
```

Specifies the SOCKS5 proxy password.

It is ignored for SOCKS4 because SOCKS4 does not define password authentication.

### Imap.SocksPort

`Chilkat 11.7.0 · foxpro · Imap · SocksPort · property · read/write`

```foxpro
SocksPort As Number
```

Specifies the SOCKS proxy port. The default is `1080`.

This property is used only when `SocksVersion` is `4` or `5`.

### Imap.SocksUsername

`Chilkat 11.7.0 · foxpro · Imap · SocksUsername · property · read/write`

```foxpro
SocksUsername As String
```

Specifies the username sent to a SOCKS4 or SOCKS5 proxy.

This property is used only when `SocksVersion` is `4` or `5`.

### Imap.SocksVersion

`Chilkat 11.7.0 · foxpro · Imap · SocksVersion · property · read/write`

```foxpro
SocksVersion As Number
```

Selects whether the IMAP connection uses a SOCKS proxy.

| Value | Behavior |
| --- | --- |
| `0` | Do not use a SOCKS proxy. This is the default. |
| `4` | Connect through a SOCKS4 proxy. |
| `5` | Connect through a SOCKS5 proxy. |

### Imap.SoRcvBuf

`Chilkat 11.7.0 · foxpro · Imap · SoRcvBuf · property · read/write`

```foxpro
SoRcvBuf As Number
```

Sets the operating system's TCP receive-buffer size. The default is `4194304` bytes.

Most applications should leave this unchanged. Increasing it may improve download throughput on high-latency or high-bandwidth networks. Values that are multiples of `4096` are recommended.

See also:

- [More Information about TCP performance and Buffer Sizes](http://www.cknotes.com/?p=446)

### Imap.SortCriteria

`Chilkat 11.7.0 · foxpro · Imap · SortCriteria · property · read/write · since 11.0.0`

```foxpro
SortCriteria As String
```

Specifies the sort order used by `QueryMbx`. The default is the empty string, which uses an ordinary IMAP `SEARCH`.

Set this property to a space-separated list of sort keys. Sorting is ascending unless `REVERSE` precedes a key. Supported keys are `ARRIVAL`, `CC`, `DATE`, `FROM`, `SIZE`, `SUBJECT`, and `TO`.

Examples:

- `SUBJECT REVERSE DATE`
- `REVERSE SIZE`
- `ARRIVAL`

If the server does not support the IMAP `SORT` extension, Chilkat automatically falls back to an ordinary `SEARCH`.

### Imap.SoSndBuf

`Chilkat 11.7.0 · foxpro · Imap · SoSndBuf · property · read/write`

```foxpro
SoSndBuf As Number
```

Sets the operating system's TCP send-buffer size. The default is `262144` bytes.

Most applications should leave this unchanged. Increasing it may improve upload throughput; values such as `524288` or `1048576` may be tested when needed.

See also:

- [More Information about TCP performance and Buffer Sizes](http://www.cknotes.com/?p=446)

### Imap.Ssl

`Chilkat 11.7.0 · foxpro · Imap · Ssl · property · read/write`

```foxpro
Ssl As Number
```

Controls implicit TLS for the IMAP connection. The default is `0`.

- `1`: begin the connection with a TLS handshake, typically on port `993`.
- `0`: begin with ordinary IMAP. Use `StartTls` when the server requires an explicit STARTTLS upgrade.

If both this property and `StartTls` are `1`, implicit TLS takes precedence and STARTTLS is not used.

### Imap.SslAllowedCiphers

`Chilkat 11.7.0 · foxpro · Imap · SslAllowedCiphers · property · read/write · since 9.5.0.48`

```foxpro
SslAllowedCiphers As String
```

Restricts the cipher suites and selected TLS security requirements offered for an IMAP TLS connection.

Leave this property empty to allow all cipher suites implemented by the installed Chilkat version. To restrict negotiation, provide a comma-separated list in preference order, for example:

```
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
```

The server chooses from the cipher suites offered by the client; the client cannot force a suite the server does not support.

The list may also contain these policy keywords:

- `rsa1024` or `rsa2048` to require a minimum RSA server-key size.
- `secure-renegotiation` to require secure TLS renegotiation.
- `best-practices` to use the security policy recommended by the installed Chilkat version.

Legacy keywords such as `aes256-cbc`, `aes128-cbc`, `3des-cbc`, and `rc4` remain recognized for compatibility, but explicitly listing acceptable suites is preferred.

### Imap.SslProtocol

`Chilkat 11.7.0 · foxpro · Imap · SslProtocol · property · read/write`

```foxpro
SslProtocol As String
```

Selects the TLS protocol version or minimum version allowed for secure IMAP connections.

The complete list of accepted values is:

- `default`
- `TLS 1.3`
- `TLS 1.2`
- `TLS 1.1`
- `TLS 1.0`
- `SSL 3.0`
- `TLS 1.3 or higher`
- `TLS 1.2 or higher`
- `TLS 1.1 or higher`
- `TLS 1.0 or higher`

The default is `default`, which allows Chilkat to negotiate a protocol supported by both client and server. A minimum-version setting is generally more interoperable than requiring one exact version.

### Imap.SslServerCertVerified

`Chilkat 11.7.0 · foxpro · Imap · SslServerCertVerified · property · read-only`

```foxpro
SslServerCertVerified As Number (read-only)
```

Indicates whether the IMAP server certificate chain was successfully verified for the current or most recent TLS connection.

This property reports certificate-chain verification only. It does not report hostname matching or public-key pinning. If hostname matching or pinning is required and the check fails, the connection itself fails.

### Imap.StartTls

`Chilkat 11.7.0 · foxpro · Imap · StartTls · property · read/write`

```foxpro
StartTls As Number
```

Controls explicit TLS using the IMAP `STARTTLS` command. The default is `0`.

- `1`: connect in clear text, issue `STARTTLS`, and then continue through an encrypted channel.
- `0`: do not request an explicit TLS upgrade.

Explicit TLS is commonly used on port `143`. For implicit TLS, set `Ssl` to `1` and normally use port `993`. If both properties are `1`, `Ssl` takes precedence.

### Imap.TlsCipherSuite

`Chilkat 11.7.0 · foxpro · Imap · TlsCipherSuite · property · read-only · since 9.5.0.49`

```foxpro
TlsCipherSuite As String (read-only)
```

Contains the cipher suite negotiated for the current or most recent TLS connection, for example `TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384`.

The value is empty before a TLS connection has been established or after a failed TLS negotiation.

### Imap.TlsPinSet

`Chilkat 11.7.0 · foxpro · Imap · TlsPinSet · property · read/write · since 9.5.0.55`

```foxpro
TlsPinSet As String
```

**Full documentation for this property (same in every language):** [Encodings Supported by Chilkat](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/binary_encodings.md)

Specifies one or more expected SPKI fingerprints for TLS public-key pinning. If none of the configured pins matches the server certificate, the TLS handshake fails.

Pinning supplements normal certificate-chain verification; it does not replace it. A matching pin does not make an expired or otherwise invalid certificate acceptable. When a pin set is configured, pin matching is enforced even if `RequireSslCertVerify` is `0`.

The format is:

```
hashAlgorithm, encoding, fingerprint1, fingerprint2, ...
```

Example:

```
sha256, base64, lKg1SIqyhPSK19tlPbjl8s02yChsVTDklQpkMCHvsTE=
```

Supported hash algorithms include `sha1`, `sha256`, `sha384`, `sha512`, `md2`, `md5`, `haval`, `ripemd128`, `ripemd160`, `ripemd256`, and `ripemd320`. Supported encodings include `base64`, `hex`, and other Chilkat-supported binary encodings.

### Imap.TlsVersion

`Chilkat 11.7.0 · foxpro · Imap · TlsVersion · property · read-only · since 9.5.0.49`

```foxpro
TlsVersion As String (read-only)
```

Contains the protocol version negotiated for the current or most recent TLS connection, such as `TLS 1.2` or `TLS 1.3`.

The value is empty before a TLS connection has been established or after a failed TLS negotiation.

### Imap.UidNext

`Chilkat 11.7.0 · foxpro · Imap · UidNext · property · read-only`

```foxpro
UidNext As Number (read-only)
```

Contains the mailbox's reported `UIDNEXT` value—the UID expected to be assigned to the next appended message.

The value is `0` when no mailbox is selected or when the server did not provide `UIDNEXT`.

### Imap.UidValidity

`Chilkat 11.7.0 · foxpro · Imap · UidValidity · property · read-only`

```foxpro
UidValidity As Number (read-only)
```

Contains the `UIDVALIDITY` value of the currently selected mailbox, or `0` when no mailbox is selected.

An application that stores message UIDs should also store this value. If `UIDVALIDITY` changes in a later session, previously stored UIDs must no longer be assumed to identify the same messages.

### Imap.UncommonOptions

`Chilkat 11.7.0 · foxpro · Imap · UncommonOptions · property · read/write · since 9.5.0.80`

```foxpro
UncommonOptions As String
```

Provides comma-separated compatibility or platform-specific options for uncommon cases. The default is an empty string, and most applications should leave it unchanged.

- `ProtectFromVpn`: on Android, bypasses an installed or active VPN.
- `EnableTls13`: legacy option that enabled offering TLS 1.3 in versions where it was not yet enabled by default.

## Methods

### Imap.AddPfxSourceBd

`Chilkat 11.7.0 · foxpro · Imap · AddPfxSourceBd · method · since 11.0.0`

```foxpro
AddPfxSourceBd(bd As ChilkatBinData, password As String) As Number
```

Adds the PKCS #12/PFX data in the `BinData` in `bd` as a source of certificates and private keys for S/MIME processing.

`password` contains the PFX password. Call this method once for each additional source.

Returns 1 for success, 0 for failure.

### Imap.AddPfxSourceData

`Chilkat 11.7.0 · foxpro · Imap · AddPfxSourceData · method · since 9.5.0.46`

```foxpro
AddPfxSourceData(pfxBytes As Variant, pfxPassword As String) As Number
```

Adds a PKCS #12/PFX source that may be searched for certificates and private keys needed for S/MIME decryption or signature processing.

`pfxBytes` contains the PFX bytes, and `pfxPassword` contains its password. Call this method once for each additional source. Common file extensions are `.pfx` and `.p12`.

Returns 1 for success, 0 for failure.

### Imap.AddPfxSourceFile

`Chilkat 11.7.0 · foxpro · Imap · AddPfxSourceFile · method`

```foxpro
AddPfxSourceFile(pfxFilePath As String, pfxPassword As String) As Number
```

Adds a PKCS #12/PFX file that may be searched for certificates and private keys needed for S/MIME decryption or signature processing.

`pfxFilePath` is the local filesystem path of the PFX file, and `pfxPassword` contains its password. Call this method once for each additional source.

On Windows, system certificate stores are also searched automatically. On macOS, the Keychain is searched automatically.

Returns 1 for success, 0 for failure.

### Imap.AppendMail

`Chilkat 11.7.0 · foxpro · Imap · AppendMail · method`

```foxpro
AppendMail(mailbox As String, email As ChilkatEmail) As Number
```

Appends the `Email` in `email` to the mailbox named by `mailbox`.

`AppendSeen` controls the initial `\Seen` flag. After success, `AppendUid` contains the UID reported by the server, or `0` if no UID was reported, and `LastAppendedMime` contains the MIME sent.

Rendering for the append does not generate or replace `email`'s `Date`, `Message-ID`, or MIME boundary values. If `email` uses an `8bit` or `binary` transfer encoding that would produce non-text binary bytes, Chilkat changes the rendered transfer encoding to a text-safe encoding such as Base64.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `AppendMailAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.AppendMime

`Chilkat 11.7.0 · foxpro · Imap · AppendMime · method`

```foxpro
AppendMime(mailbox As String, mimeText As String) As Number
```

Appends the complete RFC 822/MIME message in `mimeText` to the mailbox named by `mailbox`.

`AppendSeen` controls the initial `\Seen` flag. After success, `AppendUid` contains the UID reported by the server, or `0` if no UID was reported, and `LastAppendedMime` contains the MIME sent.

The MIME text is sent exactly as supplied. Chilkat does not normalize line endings, add a final CRLF, or re-encode headers or body content. The supplied text must not contain non-text binary bytes.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `AppendMimeAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.AppendMimeWithDateStr

`Chilkat 11.7.0 · foxpro · Imap · AppendMimeWithDateStr · method`

```foxpro
AppendMimeWithDateStr(mailbox As String, mimeText As String, internalDateStr As String) As Number
```

Appends the MIME message in `mimeText` to the mailbox named by `mailbox` while explicitly setting the server-side internal date from `internalDateStr`.

`internalDateStr` is an RFC 822 date/time string, for example `Fri, 10 Jul 2026 20:15:30 GMT`. The internal date is mailbox metadata and is distinct from the message's `Date` header. `AppendSeen` controls the initial `\Seen` flag.

The MIME text is sent exactly as supplied. Chilkat does not normalize line endings, add a final CRLF, or re-encode headers or body content. The supplied text must not contain non-text binary bytes.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `AppendMimeWithDateStrAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.AppendMimeWithFlags

`Chilkat 11.7.0 · foxpro · Imap · AppendMimeWithFlags · method`

```foxpro
AppendMimeWithFlags(mailbox As String, mimeText As String, seen As Number, flagged As Number, answered As Number, draft As Number) As Number
```

Appends the MIME message in `mimeText` to the mailbox named by `mailbox` and sets its initial system flags.

- `seen` controls `\Seen`.
- `flagged` controls `\Flagged`.
- `answered` controls `\Answered`.
- `draft` controls `\Draft`.

Use `1` to set a flag and `0` to leave it unset. The explicit flag arguments are used instead of `AppendSeen`.

The MIME text is sent exactly as supplied. Chilkat does not normalize line endings, add a final CRLF, or re-encode headers or body content. The supplied text must not contain non-text binary bytes.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `AppendMimeWithFlagsAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.AppendMimeWithFlagsSb

`Chilkat 11.7.0 · foxpro · Imap · AppendMimeWithFlagsSb · method · since 9.5.0.62`

```foxpro
AppendMimeWithFlagsSb(mailbox As String, sbMime As ChilkatStringBuilder, seen As Number, flagged As Number, answered As Number, draft As Number) As Number
```

Appends the MIME contained in the `StringBuilder` in `sbMime` to mailbox `mailbox` and sets its initial system flags.

- `seen` controls `\Seen`.
- `flagged` controls `\Flagged`.
- `answered` controls `\Answered`.
- `draft` controls `\Draft`.

The explicit flag arguments are used instead of `AppendSeen`.

The MIME text is sent exactly as supplied. Chilkat does not normalize line endings, add a final CRLF, or re-encode headers or body content. The supplied text must not contain non-text binary bytes.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `AppendMimeWithFlagsSbAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.Capability

`Chilkat 11.7.0 · foxpro · Imap · Capability · method`

```foxpro
Capability() As String
```

Sends the IMAP `CAPABILITY` command and returns the server's raw capability response.

Use `HasCapability` to test the returned text for a particular capability such as `IDLE`, `MOVE`, `SORT`, or `QUOTA`.

Returns `.NULL.` on failure

Async variant: `CapabilityAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.CheckConnection

`Chilkat 11.7.0 · foxpro · Imap · CheckConnection · method · since 9.5.0.46`

```foxpro
CheckConnection() As Number
```

Checks whether the underlying TCP socket is currently connected to the IMAP server.

This performs a low-level socket-state check and does not send an IMAP command. To verify that the server is responsive and the session remains usable, call `Noop`.

### Imap.ClearSessionLog

`Chilkat 11.7.0 · foxpro · Imap · ClearSessionLog · method`

```foxpro
ClearSessionLog()
```

Clears the in-memory text returned by `SessionLog`.

Session logging remains enabled or disabled according to `KeepSessionLog`.

### Imap.CloseMailbox

`Chilkat 11.7.0 · foxpro · Imap · CloseMailbox · method`

```foxpro
CloseMailbox(mailbox As String) As Number
```

Closes the currently selected mailbox while keeping the authenticated IMAP connection open.

`mailbox` is retained for backward compatibility but is ignored. It may be the empty string. Messages marked with `\Deleted` are permanently removed as part of the close operation. After success, `SelectedMailbox` is empty, but another mailbox can be selected on the same connection.

Returns 1 for success, 0 for failure.

Async variant: `CloseMailboxAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.Connect

`Chilkat 11.7.0 · foxpro · Imap · Connect · method`

```foxpro
Connect(domainName As String) As Number
```

Establishes a TCP connection to the IMAP server identified by `domainName` but does not authenticate.

`domainName` may be a hostname, IPv4 address, or IPv6 address. Configure `Port`, `Ssl`, `StartTls`, proxy settings, and timeouts before calling this method. The TLS hostname is used for Server Name Indication (SNI) and certificate hostname comparison. Call `Login` after the connection succeeds.

If this method is called while already connected, Chilkat tears down the existing connection and establishes a new connection to `domainName`. This applies even when `domainName` names the same server.

Imap does not automatically reconnect after a connection is dropped. The application must call this method again, authenticate again, reselect a mailbox when needed, and retry the interrupted operation.

Connection failures can also be caused by DNS, local or remote firewalls, antivirus software, routing, or other network infrastructure outside Chilkat.

Returns 1 for success, 0 for failure.

Async variant: `ConnectAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.Copy

`Chilkat 11.7.0 · foxpro · Imap · Copy · method`

```foxpro
Copy(msgId As Number, bUid As Number, copyToMailbox As String) As Number
```

Copies one message from the currently selected mailbox to the destination mailbox in `copyToMailbox`.

`msgId` identifies the source message. If `bUid` is `1`, `msgId` is a UID; otherwise, `msgId` is a sequence number. The original message remains in the selected mailbox.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `CopyAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.CopyMultiple

`Chilkat 11.7.0 · foxpro · Imap · CopyMultiple · method`

```foxpro
CopyMultiple(messageSet As MessageSet, copyToMailbox As String) As Number
```

Copies the messages identified by the `MessageSet` in `messageSet` from the selected mailbox to destination mailbox `copyToMailbox` using one IMAP command.

`MessageSet.HasUids` determines whether `messageSet` contains UIDs or sequence numbers. For sequence numbers, one invalid value causes the entire command to fail and no messages are copied. For UIDs, nonexistent values are silently ignored and valid messages are copied. The original messages remain in the selected mailbox.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `CopyMultipleAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.CopySequence

`Chilkat 11.7.0 · foxpro · Imap · CopySequence · method`

```foxpro
CopySequence(startSeqNum As Number, count As Number, copyToMailbox As String) As Number
```

**Full documentation for this method (same in every language):** [IMAP Sequence Numbers Explained](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/imap_message_sequence_numbers.md)

Copies a contiguous range of messages, identified by sequence number, from the selected mailbox to the destination mailbox in `copyToMailbox`.

`startSeqNum` is the first sequence number and `count` is the number of messages to copy. IMAP sequence numbers begin at `1` and can change when messages are expunged.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `CopySequenceAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.CreateMailbox

`Chilkat 11.7.0 · foxpro · Imap · CreateMailbox · method`

```foxpro
CreateMailbox(mailbox As String) As Number
```

Creates the mailbox named by `mailbox` on the IMAP server.

Use the hierarchy delimiter reported in `SeparatorChar` when creating a nested mailbox. In IMAP terminology, *mailbox* and *folder* are synonymous.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `CreateMailboxAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.DeleteMailbox

`Chilkat 11.7.0 · foxpro · Imap · DeleteMailbox · method`

```foxpro
DeleteMailbox(mailbox As String) As Number
```

Deletes the mailbox named by `mailbox` from the IMAP server.

This deletes the mailbox itself, not merely the messages it contains. Server rules may require the mailbox to be empty first.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `DeleteMailboxAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.Disconnect

`Chilkat 11.7.0 · foxpro · Imap · Disconnect · method`

```foxpro
Disconnect() As Number
```

Closes the connection to the IMAP server.

A failure indicates that the connection could not be closed cleanly; the socket is nevertheless no longer intended for further use. In many applications, a disconnect failure during shutdown can be treated as nonfatal.

Returns 1 for success, 0 for failure.

Async variant: `DisconnectAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.ExamineMailbox

`Chilkat 11.7.0 · foxpro · Imap · ExamineMailbox · method`

```foxpro
ExamineMailbox(mailbox As String) As Number
```

Opens the mailbox in `mailbox` as read-only.

Use this instead of `SelectMailbox` when the application must not change message flags or mailbox state. Successful examination updates properties such as `NumMessages`, `UidValidity`, and `UidNext`.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `ExamineMailboxAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.Expunge

`Chilkat 11.7.0 · foxpro · Imap · Expunge · method`

```foxpro
Expunge() As Number
```

Permanently removes all messages marked with the `\Deleted` flag from the currently selected mailbox.

The mailbox remains selected and the authenticated connection remains open. Expunging can change sequence numbers for the remaining messages.

Returns 1 for success, 0 for failure.

Async variant: `ExpungeAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.ExpungeAndClose

`Chilkat 11.7.0 · foxpro · Imap · ExpungeAndClose · method`

```foxpro
ExpungeAndClose() As Number
```

Permanently removes all messages marked with `\Deleted` from the selected mailbox and then closes the mailbox.

After success, `SelectedMailbox` is empty. The authenticated IMAP connection remains open and can be used to select another mailbox.

Returns 1 for success, 0 for failure.

Async variant: `ExpungeAndCloseAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.FetchAttachment

`Chilkat 11.7.0 · foxpro · Imap · FetchAttachment · method`

```foxpro
FetchAttachment(emailObject As ChilkatEmail, attachmentIndex As Number, saveToPath As String) As Number
```

Obtains attachment `attachmentIndex` from the `Email` in `emailObject` and writes it to the filesystem path in `saveToPath`. Attachment indexes are zero-based.

`saveToPath` may be a filename, a relative path ending in a filename, or an absolute path ending in a filename. Missing parent directories are not created. An existing file is overwritten. A failed operation should not leave a partial output file.

If `emailObject` already contains the attachment bytes, the data is saved without contacting the IMAP server. If `emailObject` was fetched without attachment bodies, Chilkat uses its `ckx-imap-*` metadata to locate and download the requested MIME part. The same IMAP session is not required, and a copied `Email` can be used if the metadata is preserved.

The corresponding mailbox must be selected when a server fetch is required. If `ckx-imap-isUid` is `YES`, the permanent UID is used and the operation can work after reconnecting. If it is `NO`, the stored value is a sequence number, which can identify a different message after an expunge. UID-based metadata is therefore preferred for deferred attachment operations. The method fails if the referenced message or MIME part no longer exists, such as after the message is moved or expunged.

Related MIME parts used by an HTML body are not counted as ordinary attachments. Signed and encrypted messages are fetched in full because their complete MIME is required.

Returns 1 for success, 0 for failure.

Async variant: `FetchAttachmentAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.FetchAttachmentBd

`Chilkat 11.7.0 · foxpro · Imap · FetchAttachmentBd · method · since 9.5.0.62`

```foxpro
FetchAttachmentBd(email As ChilkatEmail, attachmentIndex As Number, binData As ChilkatBinData) As Number
```

Obtains attachment `attachmentIndex` from the `Email` in `email` and stores its bytes in the `BinData` in `binData`.

Attachment indexes are zero-based. `binData` is always cleared first. On success it contains the complete attachment bytes; on failure it remains empty.

See `FetchAttachment` for details about downloading attachment data not already present in `email`.

Returns 1 for success, 0 for failure.

Async variant: `FetchAttachmentBdAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.FetchAttachmentBytes

`Chilkat 11.7.0 · foxpro · Imap · FetchAttachmentBytes · method`

```foxpro
FetchAttachmentBytes(email As ChilkatEmail, attachIndex As Number) As Variant
```

Obtains attachment `attachIndex` from the `Email` in `email` and returns its bytes. Attachment indexes are zero-based.

If the attachment is not already present in `email`, Chilkat downloads it from the IMAP server using the message metadata stored in the email. See `FetchAttachment` for attachment-fetching details.

Returns a zero-length byte array (as a Variant) on failure.

Async variant: `FetchAttachmentBytesAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.FetchAttachmentSb

`Chilkat 11.7.0 · foxpro · Imap · FetchAttachmentSb · method · since 9.5.0.62`

```foxpro
FetchAttachmentSb(email As ChilkatEmail, attachmentIndex As Number, charset As String, sb As ChilkatStringBuilder) As Number
```

Obtains text attachment `attachmentIndex` from the `Email` in `email`, decodes it using the charset in `charset`, and stores the text in the `StringBuilder` in `sb`.

Attachment indexes are zero-based. `sb` is always cleared first. On success it contains the complete decoded attachment text; on failure it remains empty. Use this method only for text attachments.

See `FetchAttachment` for details about downloading data not already present in `email`.

Returns 1 for success, 0 for failure.

Async variant: `FetchAttachmentSbAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.FetchAttachmentString

`Chilkat 11.7.0 · foxpro · Imap · FetchAttachmentString · method`

```foxpro
FetchAttachmentString(emailObject As ChilkatEmail, attachmentIndex As Number, charset As String) As String
```

Obtains text attachment `attachmentIndex` from the `Email` in `emailObject` and decodes its bytes using the character encoding named by `charset`.

Use this only when the attachment contains text. Attachment indexes are zero-based. See `FetchAttachment` for information about downloading attachment data that is not already present in `emailObject`.

Returns `.NULL.` on failure

Async variant: `FetchAttachmentStringAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.FetchChunk2

`Chilkat 11.7.0 · foxpro · Imap · FetchChunk2 · method · since 11.0.0`

```foxpro
FetchChunk2(seqnum As Number, count As Number, failedSet As MessageSet, fetchedSet As MessageSet, bundle As ChilkatEmailBundle) As Number
```

Attempts to download `count` full messages beginning with sequence number `seqnum`.

`failedSet` and `fetchedSet` are cleared before use. `failedSet` receives sequence numbers that failed or were not yet fetched, `fetchedSet` receives sequence numbers fetched successfully, and both sets have `MessageSet.HasUids` set to `0`. Downloaded messages are appended to the `EmailBundle` in `bundle`, which is not cleared.

Sequence numbers beyond the end of the mailbox are added to `failedSet`. The method can return success even when `failedSet` is nonempty; success indicates that the requested range was processed, not that every sequence number existed.

If a network failure occurs, messages already fetched remain in `bundle`, `fetchedSet` retains the successfully fetched sequence numbers, and `failedSet` contains the failed and not-yet-fetched sequence numbers. Processing stops and the connection must be considered unusable.

Returns 1 for success, 0 for failure.

Async variant: `FetchChunk2Async` — same arguments, returns a `Task` (see Async variants below).

### Imap.FetchEmail

`Chilkat 11.7.0 · foxpro · Imap · FetchEmail · method · since 11.0.0`

```foxpro
FetchEmail(headerOnly As Number, msgId As Number, bUid As Number, email As ChilkatEmail) As Number
```

Downloads one message or its headers into the `Email` in `email`.

- `headerOnly` = `1`: download headers only.
- `headerOnly` = `0`: download the full message.
- `bUid` = `1`: `msgId` is a UID.
- `bUid` = `0`: `msgId` is a sequence number.

On success, `email` is replaced with the fetched email. On failure, `email` remains unchanged.

A header-only result contains no body or attachment bodies, but includes `ckx-imap-*` metadata for the message identifier, flags, total size, and attachment information. For a full download, ordinary attachment bodies are included according to `AutoDownloadAttachments`. `PeekMode` controls whether a full fetch sets `\Seen`; a header-only fetch does not set it.

Returns 1 for success, 0 for failure.

Async variant: `FetchEmailAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.FetchFlags

`Chilkat 11.7.0 · foxpro · Imap · FetchFlags · method`

```foxpro
FetchFlags(msgId As Number, bUid As Number) As String
```

Returns the space-separated IMAP flags for the message identified by `msgId`.

If `bUid` is `1`, `msgId` is a UID; otherwise, it is a sequence number. A result might be `\Flagged \Seen $label1`.

An existing message with no flags returns the empty string. A nonexistent message is an error.

Returns `.NULL.` on failure

Async variant: `FetchFlagsAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.FetchMsgSet

`Chilkat 11.7.0 · foxpro · Imap · FetchMsgSet · method · since 11.0.0`

```foxpro
FetchMsgSet(headersOnly As Number, msgSet As MessageSet, bundle As ChilkatEmailBundle) As Number
```

Downloads the existing messages identified by the `MessageSet` in `msgSet` and appends them to the `EmailBundle` in `bundle`. `bundle` is not cleared.

- `headersOnly` = `1`: download headers only.
- `headersOnly` = `0`: download full messages, with ordinary attachments controlled by `AutoDownloadAttachments`.

`MessageSet.HasUids` determines whether `msgSet` contains UIDs or sequence numbers. A `MessageSet` is a true set, so duplicate identifiers are collapsed before any command is sent. Identifiers that do not exist are omitted without causing the method to fail. Do not rely on insertion order; fetched messages are returned in the order supplied by the IMAP server, normally mailbox order.

If a network failure occurs after some messages have been downloaded, those messages remain appended to `bundle`, fetching stops immediately, and the connection must be considered unusable. Reconnect, authenticate, and reselect the mailbox before retrying.

Returns 1 for success, 0 for failure.

Async variant: `FetchMsgSetAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.FetchRange

`Chilkat 11.7.0 · foxpro · Imap · FetchRange · method · since 11.0.0`

```foxpro
FetchRange(headersOnly As Number, seqnum As Number, count As Number, bundle As ChilkatEmailBundle) As Number
```

Downloads `count` messages beginning with sequence number `seqnum` and appends them to the `EmailBundle` in `bundle`. `bundle` is not cleared.

- `headersOnly` = `1`: download headers only.
- `headersOnly` = `0`: download full messages, with ordinary attachments controlled by `AutoDownloadAttachments`.

`seqnum` and `count` must both be greater than `0`. IMAP sequence numbers begin at `1`; passing `0` for `seqnum`, `0` for `count`, or a negative count fails without changing `bundle`. Only messages that exist in the requested sequence-number range are appended. Sequence numbers can change after messages are expunged.

If a network failure occurs after some messages have been downloaded, those messages remain appended to `bundle`, fetching stops immediately, and the connection must be considered unusable.

Returns 1 for success, 0 for failure.

Async variant: `FetchRangeAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.FetchSingleAsMime

`Chilkat 11.7.0 · foxpro · Imap · FetchSingleAsMime · method`

```foxpro
FetchSingleAsMime(msgId As Number, bUid As Number) As String
```

Downloads one message and returns its MIME source as a string.

If `bUid` is `1`, `msgId` is a UID; otherwise, `msgId` is a sequence number. Ordinary attachment bodies are included according to `AutoDownloadAttachments`.

Chilkat interprets the received MIME bytes as UTF-8. MIME using Base64 or quoted-printable transfer encoding is safe because the encoded bytes are ASCII. Raw `8bit` or `binary` content, or unencoded text in another charset such as ISO-8859-1 or Shift_JIS, can be misinterpreted or cause an error. Use `FetchSingleBd` whenever byte-exact MIME is required.

Returns `.NULL.` on failure

Async variant: `FetchSingleAsMimeAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.FetchSingleAsMimeSb

`Chilkat 11.7.0 · foxpro · Imap · FetchSingleAsMimeSb · method · since 9.5.0.62`

```foxpro
FetchSingleAsMimeSb(msgId As Number, bUid As Number, sbMime As ChilkatStringBuilder) As Number
```

Downloads one message's MIME into the `StringBuilder` in `sbMime`.

If `bUid` is `1`, `msgId` is a UID; otherwise, `msgId` is a sequence number. Ordinary attachment bodies are included according to `AutoDownloadAttachments`. `sbMime` is cleared before the operation; on failure it remains empty.

Chilkat interprets the received MIME bytes as UTF-8. MIME using Base64 or quoted-printable transfer encoding is safe because the encoded bytes are ASCII. Raw `8bit` or `binary` content, or unencoded text in another charset such as ISO-8859-1 or Shift_JIS, can be misinterpreted or cause an error. Use `FetchSingleBd` whenever byte-exact MIME is required.

Returns 1 for success, 0 for failure.

Async variant: `FetchSingleAsMimeSbAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.FetchSingleBd

`Chilkat 11.7.0 · foxpro · Imap · FetchSingleBd · method · since 9.5.0.76`

```foxpro
FetchSingleBd(msgId As Number, bUid As Number, mimeData As ChilkatBinData) As Number
```

Downloads one message's MIME bytes into the `BinData` in `mimeData`.

If `bUid` is `1`, `msgId` is a UID; otherwise, it is a sequence number. Ordinary attachment bodies are included according to `AutoDownloadAttachments`, and `PeekMode` controls whether the fetch sets `\Seen`.

`mimeData` is cleared before the operation. On success it contains the downloaded MIME bytes; on failure it remains empty.

Returns 1 for success, 0 for failure.

Async variant: `FetchSingleBdAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.FetchSingleHeaderAsMime

`Chilkat 11.7.0 · foxpro · Imap · FetchSingleHeaderAsMime · method`

```foxpro
FetchSingleHeaderAsMime(msgId As Number, bUID As Number) As String
```

Downloads and returns the MIME header block for one message, without downloading the body.

If `bUID` is `1`, `msgId` is a UID; otherwise, `msgId` is a sequence number.

Returns `.NULL.` on failure

Async variant: `FetchSingleHeaderAsMimeAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.GetMailAttachFilename

`Chilkat 11.7.0 · foxpro · Imap · GetMailAttachFilename · method`

```foxpro
GetMailAttachFilename(email As ChilkatEmail, attachIndex As Number) As String
```

Returns the filename for attachment `attachIndex` represented by `email`. Attachment indexes are zero-based.

This method can obtain the filename from `ckx-imap-*` metadata in a header-only email even when the attachment body has not been downloaded.

Returns `.NULL.` on failure

See also:

- [Getting Attachment Information](http://www.cknotes.com/?p=434)

### Imap.GetMailAttachSize

`Chilkat 11.7.0 · foxpro · Imap · GetMailAttachSize · method`

```foxpro
GetMailAttachSize(email As ChilkatEmail, attachIndex As Number) As Number
```

Returns the size in bytes of attachment `attachIndex` represented by `email`. Attachment indexes are zero-based.

This method can obtain the size from `ckx-imap-*` metadata in a header-only email even when the attachment body has not been downloaded.

See also:

- [Getting Attachment Information](http://www.cknotes.com/?p=434)

### Imap.GetMailboxStatus

`Chilkat 11.7.0 · foxpro · Imap · GetMailboxStatus · method · since 9.5.0.46`

```foxpro
GetMailboxStatus(mailbox As String) As String
```

Sends the IMAP `STATUS` command for the mailbox in `mailbox` and returns the reported values as XML attributes.

- `messages`: total number of messages.
- `recent`: messages having the `\Recent` flag.
- `uidnext`: expected UID for the next appended message.
- `uidvalidity`: mailbox UID-validity value.
- `unseen`: messages without the `\Seen` flag.

```
<status messages="240" recent="0" uidnext="3674" uidvalidity="3" unseen="213" />
```

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns `.NULL.` on failure

Async variant: `GetMailboxStatusAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.GetMailFlag

`Chilkat 11.7.0 · foxpro · Imap · GetMailFlag · method`

```foxpro
GetMailFlag(email As ChilkatEmail, flagName As String) As Number
```

Returns the state of the flag named by `flagName` from the IMAP metadata stored in the `Email` in `email`.

- `1`: the flag is set.
- `0`: the flag is not set.
- `-1`: the required `ckx-imap-*` metadata is missing.

Standard flags include `\Seen`, `\Answered`, `\Flagged`, `\Draft`, and `\Deleted`. Custom keywords such as `$label1` or `NonJunk` are also supported.

Integer-returning methods do not use `LastMethodSuccess` to report this condition; test the return value directly.

### Imap.GetMailNumAttach

`Chilkat 11.7.0 · foxpro · Imap · GetMailNumAttach · method`

```foxpro
GetMailNumAttach(email As ChilkatEmail) As Number
```

Returns the number of ordinary attachments represented by `email`.

This method also works with a header-only email or an email fetched while `AutoDownloadAttachments` was `0`. In those cases it reads the `ckx-imap-numAttach` metadata, even though the `Email` object's downloaded attachment count can be `0`.

See also:

- [Getting Attachment Information](http://www.cknotes.com/?p=434)

### Imap.GetMailSize

`Chilkat 11.7.0 · foxpro · Imap · GetMailSize · method`

```foxpro
GetMailSize(email As ChilkatEmail) As Number
```

Returns the complete server-reported size of the `Email` in `email`, in bytes, including attachment data.

This value may be available even when only the message headers were downloaded.

### Imap.GetQuota

`Chilkat 11.7.0 · foxpro · Imap · GetQuota · method · since 9.5.0.58`

```foxpro
GetQuota(quotaRoot As String) As String
```

Sends the IMAP `GETQUOTA` command for the quota root in `quotaRoot` and returns the server response as JSON.

The server must advertise the IMAP `QUOTA` capability.

Returns `.NULL.` on failure

Async variant: `GetQuotaAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.GetQuotaRoot

`Chilkat 11.7.0 · foxpro · Imap · GetQuotaRoot · method · since 9.5.0.58`

```foxpro
GetQuotaRoot(mailboxName As String) As String
```

Sends the IMAP `GETQUOTAROOT` command for the mailbox in `mailboxName` and returns the server response as JSON. The server must advertise the IMAP `QUOTA` capability.

A response can contain both the mailbox-to-root mapping and the quota values:

```
{
  "QUOTAROOT": {"mailbox":"Inbox","root":"Mailbox"},
  "QUOTA": {"root":"Mailbox","resource":"STORAGE","used":9,"max":256000}
}
```

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns `.NULL.` on failure

Async variant: `GetQuotaRootAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.GetServerCert

`Chilkat 11.7.0 · foxpro · Imap · GetServerCert · method · since 11.0.0`

```foxpro
GetServerCert(cert As ChilkatCert) As Number
```

Stores the certificate presented by the IMAP server for the current or most recent TLS connection in the `Cert` object supplied as `cert`.

This is useful for certificate inspection, diagnostics, or implementing application-specific trust checks.

Returns 1 for success, 0 for failure.

### Imap.HasCapability

`Chilkat 11.7.0 · foxpro · Imap · HasCapability · method · since 9.5.0.58`

```foxpro
HasCapability(name As String, capabilityResponse As String) As Number
```

Tests whether the capability named by `name` appears in the raw capability response in `capabilityResponse`.

`capabilityResponse` is typically the string returned by `Capability`. Capability-name matching follows IMAP capability-token semantics.

### Imap.IdleCheck

`Chilkat 11.7.0 · foxpro · Imap · IdleCheck · method · since 9.5.0.26`

```foxpro
IdleCheck(timeoutMs As Number) As String
```

Waits up to `timeoutMs` milliseconds for unsolicited mailbox updates after `IdleStart` has entered IMAP IDLE mode.

`timeoutMs` = `0` performs a strict poll: it checks for already available data and returns immediately. Positive values wait for up to the requested time, including very large values. If the connection is lost while waiting, the method fails.

This method does not send a polling command. It consumes the notifications currently waiting on the existing connection and returns them as XML. A second call returns only notifications that arrived after the previous call.

- `flags`: flags changed for a message.
- `expunge`: a sequence number was removed.
- `exists`: the mailbox message count changed.
- `recent`: the recent-message count changed.
- `raw`: an unrecognized response line retained for diagnostics.

```
<idle><exists>115</exists><recent>1</recent></idle>
```

When no update is available, the result is `<idle></idle>`. An `exists` notification does not automatically change `NumMessages`.

Chilkat does not automatically refresh IDLE. The application should periodically call `IdleDone` and `IdleStart`, typically before 29 minutes have elapsed, to prevent servers with a 30-minute limit from dropping the connection.

Returns `.NULL.` on failure

Async variant: `IdleCheckAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.IdleDone

`Chilkat 11.7.0 · foxpro · Imap · IdleDone · method · since 9.5.0.26`

```foxpro
IdleDone() As Number
```

Ends IMAP IDLE mode by sending the protocol's `DONE` continuation.

The authenticated connection remains open and usable. Calling this method when IDLE is not active fails.

Applications maintaining a long-lived IDLE connection should call this method shortly before the server's IDLE limit, commonly at about 29 minutes, and then immediately call `IdleStart` again.

Returns 1 for success, 0 for failure.

Async variant: `IdleDoneAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.IdleStart

`Chilkat 11.7.0 · foxpro · Imap · IdleStart · method · since 9.5.0.26`

```foxpro
IdleStart() As Number
```

Sends the IMAP `IDLE` command and begins listening for unsolicited mailbox updates.

The session must be connected, authenticated, and have a mailbox selected with `SelectMailbox` or `ExamineMailbox`. The server must advertise the `IDLE` capability.

Calling this method while IDLE is already active fails. While IDLE is active, any other method that sends an IMAP command also fails; call `IdleDone` first.

Chilkat does not automatically renew IDLE. To avoid common server time limits, the application should end and restart IDLE before the server timeout, typically about every 29 minutes.

Returns 1 for success, 0 for failure.

Async variant: `IdleStartAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.IsConnected

`Chilkat 11.7.0 · foxpro · Imap · IsConnected · method`

```foxpro
IsConnected() As Number
```

Returns the last known connection state without sending data to the IMAP server.

A `1` result does not prove that an idle connection is still usable. Call `Noop` to send a command and verify that the server responds.

### Imap.IsLoggedIn

`Chilkat 11.7.0 · foxpro · Imap · IsLoggedIn · method`

```foxpro
IsLoggedIn() As Number
```

Indicates whether this object is in an authenticated IMAP session.

This reports the last known state and does not send a command to the server.

### Imap.LoadTaskCaller

`Chilkat 11.7.0 · foxpro · Imap · LoadTaskCaller · method · since 9.5.0.80`

```foxpro
LoadTaskCaller(task As ChilkatTask) As Number
```

Associates this `Imap` object with the original `Imap` caller that created the asynchronous `Task` in `task`.

This works with a task returned by any `Imap` async method, and the task does not need to be complete. The operation does not copy the caller's state; this object becomes another reference to the same underlying `Imap` state. Any previously associated state in this object is replaced.

Use this when code has a `Task`—for example in a task-completed callback—but no longer has a reference to the object that started the async operation.

Returns 1 for success, 0 for failure.

### Imap.Login

`Chilkat 11.7.0 · foxpro · Imap · Login · method`

```foxpro
Login(loginName As String, password As String) As Number
```

Authenticates the connected IMAP session using the login name in `loginName` and the credential in `password`.

Call `Connect` first. The mechanism is selected by `AuthMethod`.

For `XOAUTH2`, `loginName` is the normal IMAP login name or email address and `password` is the raw OAuth 2.0 access token without a `Bearer` prefix. A failed XOAUTH2 login leaves the connection open so the application may correct the credentials and try again.

Do not call this method again after the session is already authenticated. A repeated login attempt fails, although the existing authenticated session remains logged in.

Returns 1 for success, 0 for failure.

Async variant: `LoginAsync` — same arguments, returns a `Task` (see Async variants below).

See also:

- [Non-standard Yahoo! IMAP Server Requirements](http://www.cknotes.com/?p=326)

### Imap.LoginSecure

`Chilkat 11.7.0 · foxpro · Imap · LoginSecure · method · since 9.5.0.71`

```foxpro
LoginSecure(loginName As ChilkatSecureString, password As ChilkatSecureString) As Number
```

Authenticates the connected IMAP session using the `SecureString` login name in `loginName` and credential in `password`.

This is the secure-string counterpart of `Login`. The authentication mechanism is selected by `AuthMethod`.

For `XOAUTH2`, `loginName` contains the normal login name or email address and `password` contains the raw access token without a `Bearer` prefix.

Returns 1 for success, 0 for failure.

Async variant: `LoginSecureAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.Logout

`Chilkat 11.7.0 · foxpro · Imap · Logout · method`

```foxpro
Logout() As Number
```

Sends the IMAP `LOGOUT` command and ends the authenticated session.

The server normally closes the connection as part of a successful logout.

Returns 1 for success, 0 for failure.

Async variant: `LogoutAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.MbxList

`Chilkat 11.7.0 · foxpro · Imap · MbxList · method · since 11.0.0`

```foxpro
MbxList(subscribed As Number, reference As String, mbxPattern As String, mboxes As Mailboxes) As Number
```

Lists matching mailboxes and appends them to the `Mailboxes` object in `mboxes`. `mboxes` is not cleared on success, so repeated calls on the same object can add duplicate entries. If the method fails, `mboxes` is unchanged.

- `subscribed` = `1`: list only subscribed mailboxes.
- `subscribed` = `0`: list all matching mailboxes.

`reference` is the IMAP reference name, usually an empty string. `mbxPattern` is the mailbox pattern: `*` matches zero or more hierarchy levels, while `%` matches one hierarchy level.

Applications may use normal Unicode mailbox names and patterns. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

The method also updates `SeparatorChar` from the server's response.

Returns 1 for success, 0 for failure.

Async variant: `MbxListAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.MoveMessages

`Chilkat 11.7.0 · foxpro · Imap · MoveMessages · method · since 9.5.0.64`

```foxpro
MoveMessages(messageSet As MessageSet, destFolder As String) As Number
```

Moves the messages identified by the `MessageSet` in `messageSet` from the selected mailbox to destination mailbox `destFolder` using one IMAP `MOVE` command.

The server must advertise the `MOVE` capability. If it does not, this method fails and does not emulate the operation with copy, delete, and expunge commands.

`MessageSet.HasUids` determines whether `messageSet` contains UIDs or sequence numbers. For sequence numbers, one invalid value causes complete failure and nothing is moved. For UIDs, nonexistent values are silently ignored and valid messages are moved.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `MoveMessagesAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.Noop

`Chilkat 11.7.0 · foxpro · Imap · Noop · method`

```foxpro
Noop() As Number
```

Sends the IMAP `NOOP` command and waits for the server response.

This is useful for verifying that an existing authenticated connection is still responsive and for receiving unsolicited mailbox-state updates.

Returns 1 for success, 0 for failure.

Async variant: `NoopAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.QueryMbx

`Chilkat 11.7.0 · foxpro · Imap · QueryMbx · method · since 11.0.0`

```foxpro
QueryMbx(criteria As String, bUid As Number, msgSet As MessageSet) As Number
```

**Full documentation for this method (same in every language):** [Explaining the IMAP Search Criteria](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/imap_search_criteria.md)

Searches the selected mailbox using the IMAP criteria in `criteria` and stores matching identifiers in the `MessageSet` in `msgSet`.

On success, `msgSet` is replaced with the result. If `bUid` is `1`, `msgSet` contains UIDs and `MessageSet.HasUids` is `1`; otherwise, `msgSet` contains sequence numbers and `MessageSet.HasUids` is `0`. If the method fails, `msgSet` is unchanged. `SearchCharset` applies when the criteria contain non-ASCII text.

For the special criterion `new-email`, Chilkat records each `UIDNEXT` received from `SELECT`, `EXAMINE`, or another IMAP response and uses it as the baseline for detecting later UIDs. If no `UIDNEXT` is available, Chilkat searches for messages having the `\Recent` flag. Results are always UIDs regardless of `bUid`, and an empty result clears `msgSet`.

When `SortCriteria` is nonempty, Chilkat uses IMAP `SORT` if the server supports it. Otherwise, it automatically falls back to an ordinary `SEARCH`.

Returns 1 for success, 0 for failure.

Async variant: `QueryMbxAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.QueryThread

`Chilkat 11.7.0 · foxpro · Imap · QueryThread · method · since 11.0.0`

```foxpro
QueryThread(threadAlg As String, searchCriteria As String, bUid As Number, json As ChilkatJsonObject) As Number
```

Sends the IMAP `THREAD` command for the selected mailbox.

`threadAlg` is the threading algorithm, commonly `ORDEREDSUBJECT` or `REFERENCES`. `searchCriteria` contains ordinary IMAP search criteria and is interpreted using `SearchCharset`. If `bUid` is `1`, message identifiers in the result are UIDs; otherwise, they are sequence numbers.

On success, `json` is completely replaced with the thread hierarchy. On failure, `json` is unchanged; there is no partial-success JSON result.

The returned JSON has a top-level `threads` array. Each element represents one thread, and nested arrays encode parent/child relationships. For example:

```
{"threads":[[1],[2],[3]]}
```

The server must advertise the IMAP `THREAD` capability and support the selected algorithm.

Returns 1 for success, 0 for failure.

Async variant: `QueryThreadAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.RawCommandBd

`Chilkat 11.7.0 · foxpro · Imap · RawCommandBd · method · since 11.0.0`

```foxpro
RawCommandBd(bdCmd As ChilkatBinData, bdResp As ChilkatBinData) As Number
```

Sends the raw IMAP command bytes in the `BinData` in `bdCmd` and stores the raw response bytes in `bdResp`.

`bdCmd` contains the command without an IMAP command tag or trailing CRLF; Chilkat supplies both. `bdResp` is cleared and replaced with the response.

Use raw commands only for rare server extensions that are not otherwise exposed by the API, have an expected one-line response, and do not change Imap object state such as the selected mailbox, message count, `UidNext`, or `UidValidity`. State-changing raw commands can leave cached properties inconsistent with the server.

Returns 1 for success, 0 for failure.

Async variant: `RawCommandBdAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.RefetchMailFlags

`Chilkat 11.7.0 · foxpro · Imap · RefetchMailFlags · method`

```foxpro
RefetchMailFlags(email As ChilkatEmail) As Number
```

Fetches the current IMAP flags for the server message represented by `email` and updates its `ckx-imap-*` metadata headers.

Chilkat reads the identifier from `ckx-imap-uid` and checks `ckx-imap-isUid` to determine whether it is a UID or sequence number. A copied `Email` can be used as long as this metadata is preserved.

When `ckx-imap-isUid` is `NO`, the stored sequence number may identify a different message after an expunge. UID-based emails are preferred for later operations. Methods such as `GetMailFlag` read the refreshed flag metadata.

Returns 1 for success, 0 for failure.

Async variant: `RefetchMailFlagsAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.RenameMailbox

`Chilkat 11.7.0 · foxpro · Imap · RenameMailbox · method`

```foxpro
RenameMailbox(fromMailbox As String, toMailbox As String) As Number
```

Renames the mailbox in `fromMailbox` to the name in `toMailbox`.

Changing hierarchy components can also move a mailbox within the server's folder tree, for example from `INBOX.old.project` to `INBOX.archive.project`.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `RenameMailboxAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.SelectMailbox

`Chilkat 11.7.0 · foxpro · Imap · SelectMailbox · method`

```foxpro
SelectMailbox(mailbox As String) As Number
```

Opens the mailbox in `mailbox` for read-write access.

A mailbox must be selected before message fetch, search, flag, copy, move, or expunge operations that act on mailbox contents. Successful selection updates `SelectedMailbox`, `NumMessages`, `UidValidity`, and related mailbox-state properties.

Use `ExamineMailbox` when read-only access is required.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `SelectMailboxAsync` — same arguments, returns a `Task` (see Async variants below).

See also:

- [Selecting Public Folders](http://www.cknotes.com/?p=284)

### Imap.SendRawCommand

`Chilkat 11.7.0 · foxpro · Imap · SendRawCommand · method`

```foxpro
SendRawCommand(cmd As String) As String
```

Sends the raw IMAP command text in `cmd` and returns the raw server response.

Pass the command itself, such as `NOOP`, without an IMAP command tag or trailing CRLF. Chilkat generates the tag and command line termination.

Use raw commands only for rare server extensions that are not otherwise exposed by the API, have an expected one-line response, and do not change Imap object state such as the selected mailbox, message count, `UidNext`, or `UidValidity`. State-changing raw commands can leave cached properties inconsistent with the server.

Returns `.NULL.` on failure

Async variant: `SendRawCommandAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.SendRawCommandB

`Chilkat 11.7.0 · foxpro · Imap · SendRawCommandB · method`

```foxpro
SendRawCommandB(cmd As String) As Variant
```

Sends the raw IMAP command text in `cmd` and returns the server response as bytes.

Pass the command without an IMAP tag or trailing CRLF; Chilkat supplies both. This is the byte-response counterpart of `SendRawCommand`.

Use raw commands only for rare server extensions that are not otherwise exposed by the API, have an expected one-line response, and do not change Imap object state such as the selected mailbox, message count, `UidNext`, or `UidValidity`. State-changing raw commands can leave cached properties inconsistent with the server.

Returns a zero-length byte array (as a Variant) on failure.

Async variant: `SendRawCommandBAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.SendRawCommandC

`Chilkat 11.7.0 · foxpro · Imap · SendRawCommandC · method`

```foxpro
SendRawCommandC(cmd As Variant) As Variant
```

Sends the raw IMAP command bytes in `cmd` and returns the server response as bytes.

`cmd` contains the command without an IMAP tag or trailing CRLF; Chilkat supplies both.

Use raw commands only for rare server extensions that are not otherwise exposed by the API, have an expected one-line response, and do not change Imap object state such as the selected mailbox, message count, `UidNext`, or `UidValidity`. State-changing raw commands can leave cached properties inconsistent with the server.

Returns a zero-length byte array (as a Variant) on failure.

Async variant: `SendRawCommandCAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.SetDecryptCert

`Chilkat 11.7.0 · foxpro · Imap · SetDecryptCert · method · since 9.5.0.40`

```foxpro
SetDecryptCert(cert As ChilkatCert) As Number
```

Specifies the `Cert` in `cert` for decrypting S/MIME messages downloaded by this `Imap` object.

The certificate must have access to its associated private key. Use `SetDecryptCert2` when the private key is supplied separately.

Returns 1 for success, 0 for failure.

### Imap.SetDecryptCert2

`Chilkat 11.7.0 · foxpro · Imap · SetDecryptCert2 · method`

```foxpro
SetDecryptCert2(cert As ChilkatCert, key As PrivateKey) As Number
```

Specifies the certificate in `cert` and its separately supplied `PrivateKey` in `key` for decrypting S/MIME messages.

Use this when the certificate object does not already provide access to the private key.

Returns 1 for success, 0 for failure.

### Imap.SetFlag

`Chilkat 11.7.0 · foxpro · Imap · SetFlag · method`

```foxpro
SetFlag(msgId As Number, bUid As Number, flagName As String, value As Number) As Number
```

Sets or clears one flag on the message identified by `msgId` in the selected mailbox.

If `bUid` is `1`, `msgId` is a UID; otherwise, it is a sequence number. `flagName` is the flag name, and `value` is `1` to set the flag or `0` to clear it.

Standard flags include `\Deleted`, `\Seen`, `\Answered`, `\Flagged`, and `\Draft`. Server-supported custom keywords may also be used.

Returns 1 for success, 0 for failure.

Async variant: `SetFlagAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.SetFlags

`Chilkat 11.7.0 · foxpro · Imap · SetFlags · method`

```foxpro
SetFlags(messageSet As MessageSet, flagName As String, value As Number) As Number
```

Sets or clears one flag for every identifier in the `MessageSet` supplied in `messageSet`.

`flagName` is the flag name, and `value` is `1` to set it or `0` to clear it. `MessageSet.HasUids` determines whether the identifiers are UIDs or sequence numbers. Chilkat sends one IMAP `STORE` or `UID STORE` command containing the complete identifier set.

IMAP bulk flag changes are not atomic and have no all-or-nothing rollback. Changes applied before a failure remain applied. For UID-based operations, nonexistent UIDs are silently ignored as required by IMAP. For sequence-number operations, an out-of-range sequence number causes the server to return an error; whether valid sequence numbers in the same command were changed before that error is server-dependent.

This method changes server state only. It does not update metadata in any previously fetched `Email` objects.

Returns 1 for success, 0 for failure.

Async variant: `SetFlagsAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.SetMailFlag

`Chilkat 11.7.0 · foxpro · Imap · SetMailFlag · method`

```foxpro
SetMailFlag(email As ChilkatEmail, flagName As String, value As Number) As Number
```

Sets or clears a flag for the server message represented by the `Email` in `email`.

Chilkat reads the message identifier from `ckx-imap-uid` and uses `ckx-imap-isUid` to determine whether the value is a UID or sequence number. `flagName` is the flag name, and `value` is `1` to set it or `0` to clear it. The method fails if the required metadata is absent.

A copied `Email` can be used as long as the metadata is preserved. When `ckx-imap-isUid` is `NO`, the stored value is a sequence number and may no longer identify the same message after an expunge. UID-based emails are preferred for operations performed later or after reconnecting.

Setting `\Deleted` marks the message for deletion; call `Expunge` to remove it permanently.

Returns 1 for success, 0 for failure.

Async variant: `SetMailFlagAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.SetQuota

`Chilkat 11.7.0 · foxpro · Imap · SetQuota · method · since 9.5.0.58`

```foxpro
SetQuota(quotaRoot As String, resource As String, quota As Number) As Number
```

Sends the IMAP `SETQUOTA` command for quota root `quotaRoot`.

`resource` is `STORAGE` to set the combined message-storage limit or `MESSAGE` to set the message-count limit. For `STORAGE`, `quota` is measured in units of 1024 octets; for example, `500000` represents approximately 500,000,000 bytes.

The server must support the IMAP `QUOTA` extension and the requested resource type.

Returns 1 for success, 0 for failure.

Async variant: `SetQuotaAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.SetSslClientCert

`Chilkat 11.7.0 · foxpro · Imap · SetSslClientCert · method`

```foxpro
SetSslClientCert(cert As ChilkatCert) As Number
```

Specifies the client certificate in `cert` for TLS client-certificate authentication.

Most IMAP servers do not require a client certificate. When one is required, `cert` must provide access to the corresponding private key.

Returns 1 for success, 0 for failure.

### Imap.SetSslClientCertPem

`Chilkat 11.7.0 · foxpro · Imap · SetSslClientCertPem · method`

```foxpro
SetSslClientCertPem(pemDataOrFilename As String, pemPassword As String) As Number
```

Specifies a TLS client certificate and private key from PEM data or a PEM file.

`pemDataOrFilename` may contain the PEM text itself or a local filesystem path to the PEM file; Chilkat detects which form was supplied. `pemPassword` contains the password when the private key is encrypted.

Returns 1 for success, 0 for failure.

### Imap.SetSslClientCertPfx

`Chilkat 11.7.0 · foxpro · Imap · SetSslClientCertPfx · method`

```foxpro
SetSslClientCertPfx(pfxFilename As String, pfxPassword As String) As Number
```

Specifies a TLS client certificate and private key from a PKCS #12/PFX file.

`pfxFilename` is the local filesystem path of the `.pfx` or `.p12` file, and `pfxPassword` contains its password.

Returns 1 for success, 0 for failure.

### Imap.SshAuthenticatePk

`Chilkat 11.7.0 · foxpro · Imap · SshAuthenticatePk · method`

```foxpro
SshAuthenticatePk(sshLogin As String, privateKey As ChilkatSshKey) As Number
```

Authenticates the SSH tunnel using the username in `sshLogin` and the `SshKey` private key in `privateKey`.

Call `SshOpenTunnel` first. The corresponding public key must already be authorized for `sshLogin` on the SSH server. After authentication, call `Connect` and `Login` for the IMAP server.

Returns 1 for success, 0 for failure.

Async variant: `SshAuthenticatePkAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.SshAuthenticatePw

`Chilkat 11.7.0 · foxpro · Imap · SshAuthenticatePw · method`

```foxpro
SshAuthenticatePw(sshLogin As String, sshPassword As String) As Number
```

Authenticates the SSH tunnel using the username in `sshLogin` and password in `sshPassword`.

Call `SshOpenTunnel` first. After SSH authentication succeeds, call `Connect` and `Login`; the IMAP traffic then flows through the tunnel automatically.

Returns 1 for success, 0 for failure.

Async variant: `SshAuthenticatePwAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.SshCloseTunnel

`Chilkat 11.7.0 · foxpro · Imap · SshCloseTunnel · method · since 9.5.0.50`

```foxpro
SshCloseTunnel() As Number
```

Closes the SSH tunnel opened by `SshOpenTunnel`.

Any IMAP connection using that tunnel must no longer be used after the tunnel is closed.

Returns 1 for success, 0 for failure.

Async variant: `SshCloseTunnelAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.SshOpenTunnel

`Chilkat 11.7.0 · foxpro · Imap · SshOpenTunnel · method · since 9.5.0.50`

```foxpro
SshOpenTunnel(sshHostname As String, sshPort As Number) As Number
```

Connects to the SSH server in `sshHostname` on port `sshPort` and prepares an SSH tunnel for the later IMAP connection.

Port `22` is the usual SSH port. After this succeeds, authenticate with `SshAuthenticatePw` or `SshAuthenticatePk`, then call `Connect` and `Login` for IMAP.

Returns 1 for success, 0 for failure.

Async variant: `SshOpenTunnelAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.StoreFlags

`Chilkat 11.7.0 · foxpro · Imap · StoreFlags · method`

```foxpro
StoreFlags(msgId As Number, bUid As Number, flagNames As String, value As Number) As Number
```

Sets or clears multiple flags on one message in the selected mailbox.

If `bUid` is `1`, `msgId` is a UID; otherwise, it is a sequence number. `flagNames` is a space-separated list such as `\Seen \Answered $label1`. `value` is `1` to set all listed flags or `0` to clear them.

The operation uses IMAP `STORE` or `UID STORE` and is not transactional. A nonexistent UID can be silently ignored and the command can still succeed. An invalid sequence number causes failure. This method changes server state only and does not update metadata in previously fetched `Email` objects.

Returns 1 for success, 0 for failure.

Async variant: `StoreFlagsAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.Subscribe

`Chilkat 11.7.0 · foxpro · Imap · Subscribe · method`

```foxpro
Subscribe(mailbox As String) As Number
```

Subscribes the authenticated IMAP account to the mailbox named by `mailbox`.

Subscription controls which mailboxes are returned by subscribed-mailbox listing operations; it does not create the mailbox.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `SubscribeAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.Unsubscribe

`Chilkat 11.7.0 · foxpro · Imap · Unsubscribe · method`

```foxpro
Unsubscribe(mailbox As String) As Number
```

Removes the subscription to the mailbox named by `mailbox`.

The mailbox itself and its messages are not deleted.

Mailbox names may be supplied as normal Unicode strings. Chilkat automatically handles IMAP modified UTF-7 or UTF-8 mailbox-name encoding as required by the server.

Returns 1 for success, 0 for failure.

Async variant: `UnsubscribeAsync` — same arguments, returns a `Task` (see Async variants below).

### Imap.UseCertVault

`Chilkat 11.7.0 · foxpro · Imap · UseCertVault · method · since 9.5.0.40`

```foxpro
UseCertVault(vault As ChilkatXmlCertVault) As Number
```

Associates the `XmlCertVault` in `vault` with this `Imap` object as a source of certificates and private keys for S/MIME operations.

Only one vault can be associated at a time. Calling this method again replaces the previously associated vault.

Returns 1 for success, 0 for failure.

### Imap.UseSsh

`Chilkat 11.7.0 · foxpro · Imap · UseSsh · method · since 9.5.0.55`

```foxpro
UseSsh(ssh As ChilkatSsh) As Number
```

Uses an already connected and authenticated `Ssh` object as the transport for subsequent IMAP connections.

SSH supports multiple logical channels, so the same SSH connection may be shared by IMAP and other Chilkat objects. Call this method before `Connect`.

Returns 1 for success, 0 for failure.

### Imap.UseSshTunnel

`Chilkat 11.7.0 · foxpro · Imap · UseSshTunnel · method · since 9.5.0.50`

```foxpro
UseSshTunnel(tunnel As ChilkatSocket) As Number
```

Uses the existing SSH tunnel represented by the `Socket` in `tunnel` for subsequent IMAP connections.

This allows a tunnel to be shared with other objects. Call this method before `Connect`.

Returns 1 for success, 0 for failure.

## Events and callbacks

A Visual FoxPro application receives Chilkat ActiveX events by defining a class that `IMPLEMENTS` the `_IChilkatEvents` interface, creating an instance of it, and binding that instance to the Chilkat object with `EVENTHANDLER()`. Visual FoxPro requires the class to implement every method of the interface, so the class below includes a `PROCEDURE` for each event; leave the ones you do not need empty. The `TextData` and `BinaryData` events are defunct: they are deprecated and are never called, but their procedures must still exist because the interface declares them.

**Important:** Event callbacks from ***asynchronous method calls*** are generally not possible from the ActiveX. Events fire during synchronous method calls.

```foxpro
imapEventHandler = CREATEOBJECT("MyImapEvents")
loImap = CreateObject('Chilkat.Imap')
EVENTHANDLER(loImap, imapEventHandler)

DEFINE CLASS MyImapEvents AS SESSION OLEPUBLIC
IMPLEMENTS _IChilkatEvents IN "Chilkat.Imap"

PROCEDURE _IChilkatEvents_AbortCheck(abort As Number)
? "AbortCheck"
ENDPROC

* The BinaryData event is defunct: it is deprecated and is never called.
* The procedure must exist because the interface declares it, but it can be left empty.
PROCEDURE _IChilkatEvents_BinaryData(data As Variant)
ENDPROC

PROCEDURE _IChilkatEvents_PercentDone(pctDone As Number, abort As Number)
? "PercentDone"
ENDPROC

PROCEDURE _IChilkatEvents_ProgressInfo(name As String, value As String)
? "ProgressInfo"
ENDPROC

PROCEDURE _IChilkatEvents_TaskCompleted(task As Generic)
? "TaskCompleted"
ENDPROC

* The TextData event is defunct: it is deprecated and is never called.
* The procedure must exist because the interface declares it, but it can be left empty.
PROCEDURE _IChilkatEvents_TextData(data As String)
ENDPROC


ENDDEFINE
```

### Imap.AbortCheck (event)

`Chilkat 11.7.0 · foxpro · Imap · AbortCheck · event`

```foxpro
AbortCheck(abort As Number)
```

Enables a method call to be aborted by triggering the AbortCheck event at intervals defined by the `HeartbeatMs` property. If HeartbeatMs is set to its default value of 0, no events will occur. For instance, set HeartbeatMs to 200 to trigger 5 AbortCheck events per second.

**FoxPro event implementation:**

```foxpro
* Add to the MyImapEvents class shown in the Events overview above.
PROCEDURE _IChilkatEvents_AbortCheck(abort As Number)
    * Set abort to 1 to abort the method in progress.
ENDPROC
```

### Imap.PercentDone (event)

`Chilkat 11.7.0 · foxpro · Imap · PercentDone · event`

```foxpro
PercentDone(pctDone As Number, abort As Number)
```

This provides the percentage completion for any method involving network communications or time-consuming processing, assuming the progress can be measured as a percentage. This event is triggered only when it's possible and logical to express the operation's progress as a percentage. The `pctDone` argument will range from 1 to 100. For methods that finish quickly, the number of PercentDone callbacks may vary, but the final callback will have `pctDone` equal to 100. For longer operations, callbacks will not exceed one per percentage point (e.g., 1, 2, 3, ..., 98, 99, 100).

The PercentDone callback also acts as an `AbortCheck` event. For fast methods where PercentDone fires, an AbortCheck event may not trigger since the PercentDone callback already provides an opportunity to abort. For longer operations, where time between PercentDone callbacks is extended, AbortCheck callbacks enable more responsive operation termination.

To abort the operation, set the `abort` output argument to `1`. This will cause the method to terminate and return a failure status or corresponding failure value.

**FoxPro event implementation:**

```foxpro
* Add to the MyImapEvents class shown in the Events overview above.
PROCEDURE _IChilkatEvents_PercentDone(pctDone As Number, abort As Number)
    * pctDone ranges from 1 to 100.  Set abort to 1 to abort the method in progress.
ENDPROC
```

### Imap.ProgressInfo (event)

`Chilkat 11.7.0 · foxpro · Imap · ProgressInfo · event`

```foxpro
ProgressInfo(name As String, value As String)
```

This event callback provides `tag name`/value pairs that detail what occurs during a method call. To discover existing tag names, create code to handle the event, emit the pairs, and review them. Most tag names are self-explanatory.

Note: Some Chilkat methods don't fire any ProgressInfo events.

**FoxPro event implementation:**

```foxpro
* Add to the MyImapEvents class shown in the Events overview above.
PROCEDURE _IChilkatEvents_ProgressInfo(name As String, value As String)
    ? name + ": " + value
ENDPROC
```

### Imap.TaskCompleted (event)

`Chilkat 11.7.0 · foxpro · Imap · TaskCompleted · event`

```foxpro
TaskCompleted(task As ChilkatTask)
```

Called from the background thread when an asynchronous task completes.

**FoxPro event implementation:**

```foxpro
* Add to the MyImapEvents class shown in the Events overview above.
PROCEDURE _IChilkatEvents_TaskCompleted(task As Generic)
    * task is the Task object that has completed.
ENDPROC
```

## Async variants

Each returns a `Task` instead of the result and takes the same arguments as the synchronous method; run the task, wait for `Finished`, then read the result from the task. No new Async methods are added from 11.7.0 on.

```foxpro
AppendMailAsync(mailbox As String, email As ChilkatEmail) As ChilkatTask
AppendMimeAsync(mailbox As String, mimeText As String) As ChilkatTask
AppendMimeWithDateStrAsync(mailbox As String, mimeText As String, internalDateStr As String) As ChilkatTask
AppendMimeWithFlagsAsync(mailbox As String, mimeText As String, seen As Number, flagged As Number, answered As Number, draft As Number) As ChilkatTask
AppendMimeWithFlagsSbAsync(mailbox As String, sbMime As ChilkatStringBuilder, seen As Number, flagged As Number, answered As Number, draft As Number) As ChilkatTask
CapabilityAsync() As ChilkatTask
CloseMailboxAsync(mailbox As String) As ChilkatTask
ConnectAsync(domainName As String) As ChilkatTask
CopyAsync(msgId As Number, bUid As Number, copyToMailbox As String) As ChilkatTask
CopyMultipleAsync(messageSet As MessageSet, copyToMailbox As String) As ChilkatTask
CopySequenceAsync(startSeqNum As Number, count As Number, copyToMailbox As String) As ChilkatTask
CreateMailboxAsync(mailbox As String) As ChilkatTask
DeleteMailboxAsync(mailbox As String) As ChilkatTask
DisconnectAsync() As ChilkatTask
ExamineMailboxAsync(mailbox As String) As ChilkatTask
ExpungeAsync() As ChilkatTask
ExpungeAndCloseAsync() As ChilkatTask
FetchAttachmentAsync(emailObject As ChilkatEmail, attachmentIndex As Number, saveToPath As String) As ChilkatTask
FetchAttachmentBdAsync(email As ChilkatEmail, attachmentIndex As Number, binData As ChilkatBinData) As ChilkatTask
FetchAttachmentBytesAsync(email As ChilkatEmail, attachIndex As Number) As ChilkatTask
FetchAttachmentSbAsync(email As ChilkatEmail, attachmentIndex As Number, charset As String, sb As ChilkatStringBuilder) As ChilkatTask
FetchAttachmentStringAsync(emailObject As ChilkatEmail, attachmentIndex As Number, charset As String) As ChilkatTask
FetchChunk2Async(seqnum As Number, count As Number, failedSet As MessageSet, fetchedSet As MessageSet, bundle As ChilkatEmailBundle) As ChilkatTask
FetchEmailAsync(headerOnly As Number, msgId As Number, bUid As Number, email As ChilkatEmail) As ChilkatTask
FetchFlagsAsync(msgId As Number, bUid As Number) As ChilkatTask
FetchMsgSetAsync(headersOnly As Number, msgSet As MessageSet, bundle As ChilkatEmailBundle) As ChilkatTask
FetchRangeAsync(headersOnly As Number, seqnum As Number, count As Number, bundle As ChilkatEmailBundle) As ChilkatTask
FetchSingleAsMimeAsync(msgId As Number, bUid As Number) As ChilkatTask
FetchSingleAsMimeSbAsync(msgId As Number, bUid As Number, sbMime As ChilkatStringBuilder) As ChilkatTask
FetchSingleBdAsync(msgId As Number, bUid As Number, mimeData As ChilkatBinData) As ChilkatTask
FetchSingleHeaderAsMimeAsync(msgId As Number, bUID As Number) As ChilkatTask
GetMailboxStatusAsync(mailbox As String) As ChilkatTask
GetQuotaAsync(quotaRoot As String) As ChilkatTask
GetQuotaRootAsync(mailboxName As String) As ChilkatTask
IdleCheckAsync(timeoutMs As Number) As ChilkatTask
IdleDoneAsync() As ChilkatTask
IdleStartAsync() As ChilkatTask
LoginAsync(loginName As String, password As String) As ChilkatTask
LoginSecureAsync(loginName As ChilkatSecureString, password As ChilkatSecureString) As ChilkatTask
LogoutAsync() As ChilkatTask
MbxListAsync(subscribed As Number, reference As String, mbxPattern As String, mboxes As Mailboxes) As ChilkatTask
MoveMessagesAsync(messageSet As MessageSet, destFolder As String) As ChilkatTask
NoopAsync() As ChilkatTask
QueryMbxAsync(criteria As String, bUid As Number, msgSet As MessageSet) As ChilkatTask
QueryThreadAsync(threadAlg As String, searchCriteria As String, bUid As Number, json As ChilkatJsonObject) As ChilkatTask
RawCommandBdAsync(bdCmd As ChilkatBinData, bdResp As ChilkatBinData) As ChilkatTask
RefetchMailFlagsAsync(email As ChilkatEmail) As ChilkatTask
RenameMailboxAsync(fromMailbox As String, toMailbox As String) As ChilkatTask
SelectMailboxAsync(mailbox As String) As ChilkatTask
SendRawCommandAsync(cmd As String) As ChilkatTask
SendRawCommandBAsync(cmd As String) As ChilkatTask
SendRawCommandCAsync(cmd As Variant) As ChilkatTask
SetFlagAsync(msgId As Number, bUid As Number, flagName As String, value As Number) As ChilkatTask
SetFlagsAsync(messageSet As MessageSet, flagName As String, value As Number) As ChilkatTask
SetMailFlagAsync(email As ChilkatEmail, flagName As String, value As Number) As ChilkatTask
SetQuotaAsync(quotaRoot As String, resource As String, quota As Number) As ChilkatTask
SshAuthenticatePkAsync(sshLogin As String, privateKey As ChilkatSshKey) As ChilkatTask
SshAuthenticatePwAsync(sshLogin As String, sshPassword As String) As ChilkatTask
SshCloseTunnelAsync() As ChilkatTask
SshOpenTunnelAsync(sshHostname As String, sshPort As Number) As ChilkatTask
StoreFlagsAsync(msgId As Number, bUid As Number, flagNames As String, value As Number) As ChilkatTask
SubscribeAsync(mailbox As String) As ChilkatTask
UnsubscribeAsync(mailbox As String) As ChilkatTask
```

## Deprecated members — do not use in new code

| Member | Kind | Deprecated in | Use instead |
|---|---|---|---|
| `CheckForNewEmail` | method | before 11.6.1 | `QueryMbx` |
| `FetchBundle` | method | before 11.6.1 | `FetchMsgSet` |
| `FetchBundleAsMime` | method | before 11.6.1 | — |
| `FetchChunk` | method | before 11.6.1 | `FetchRange` |
| `FetchHeaders` | method | before 11.6.1 | `FetchMsgSet` |
| `FetchSequence` | method | before 11.6.1 | `FetchRange` |
| `FetchSequenceAsMime` | method | before 11.6.1 | — |
| `FetchSequenceHeaders` | method | before 11.6.1 | `FetchRange` |
| `FetchSingle` | method | before 11.6.1 | `FetchEmail` |
| `FetchSingleHeader` | method | before 11.6.1 | `FetchEmail` |
| `GetAllUids` | method | before 11.6.1 | `QueryMbx` |
| `GetSslServerCert` | method | before 11.6.1 | `GetServerCert` |
| `ListMailboxes` | method | before 11.6.1 | `MbxList` |
| `ListSubscribed` | method | before 11.6.1 | `MbxList` |
| `Search` | method | before 11.6.1 | `QueryMbx` |
| `Sort` | method | before 11.6.1 | `QueryMbx` |
| `ThreadCmd` | method | before 11.6.1 | `QueryThread` |

## Related classes

[`BinData`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/BinData.md), [`Cert`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/Cert.md), [`Email`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/Email.md), [`EmailBundle`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/EmailBundle.md), [`JsonObject`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/JsonObject.md), [`Mailboxes`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/Mailboxes.md), [`MessageSet`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/MessageSet.md), [`PrivateKey`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/PrivateKey.md), [`SecureString`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/SecureString.md), [`Socket`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/Socket.md), [`Ssh`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/Ssh.md), [`SshKey`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/SshKey.md), [`StringBuilder`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/StringBuilder.md), [`Task`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/Task.md), [`XmlCertVault`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/foxpro/classes/XmlCertVault.md)

