Skip to main content

ContentType

property ContentType: string read write;

Example

procedure ConfigureTextPart(const Part: TIdMessagePart);
begin
Part.ContentType := 'text/plain; charset="utf-8"';
end;

Usage

ContentType stores the first Content-Type header after extracting charset and name parameters into independent fields that can later become stale.

Additional Technical Info

Reading returns the first stored Content-Type header. The setter parses the supplied String only to remove charset and name parameters, then stores the remaining value as the header.

Nonempty extracted charset and name values update CharSet and Name. Missing or empty parameters do not clear previous fields. Therefore replacing text/plain; charset=utf-8 with application/json leaves CharSet as utf-8 unless explicitly cleared.

The getter normally returns the stripped value, not the original assignment. Direct CharSet/Name writes do not recreate parameters. Empty ContentType removes only the first header and retains both fields; duplicates can surface.

No media-type/token/parameter compatibility is validated and no body conversion occurs. ResolveContentType supplies context defaults only when passed empty; it returns nonempty parameterized input unchanged.

Coordinate content bytes, runtime part type, media type, charset and transfer encoding explicitly. Header parsing/allocation failures can leave broader caller state non-transactional; the part is not thread-safe.

The source-reviewed example results in stored ContentType text/plain plus CharSet utf-8; it encoded no bytes.

External references

Created 2026-07-15