Indy 9
|
TIdMessageDecoderMIME = class(TIdMessageDecoder)
property BodyEncoded: Boolean;
BodyEncoded is initialized in the Create constructor, and may contain False when the TIdMessage has a MIMEBoundary. BodyEncoded is also used in ReadHeader and ReadBody methods to determine if the ContentTransferEncoding, ContentType, and ContentDisposition values are read from mesasage headers or the acutal body of the message.
property MIMEBoundary: string;
constructor Create(AOwner: TComponent); overload; reintroduce; constructor Create(AOwner: TComponent; ALine: string); overload; reintroduce;
function ReadBody(ADestStream: TStream; var VMsgEnd: Boolean): TIdMessageDecoder; override;
ReadBody examines the message part type to determine the TIdMessageDecoder used for the encoded message part. ReadBody returns the TIdMessageDecoder instance to be used for the message part, or Nil when the message part is not an encoded attachment. When an attachment is detected, the content-transfer-encoding header is used to determine the proper decoder based on the following values of the header:
When the content-transfer-encoding does not match the preceeding values, an EIdException will be raised with the constant message RSMessageCoderMIMEUnrecognizedContentTrasnferEncoding and the value for the message header.
ReadBody reads the message part content, on line at a time, using ReadLn. If a MIMEBoundary is detected in the line, a new TIdMessageDecoderMIME instance is created for the new message part, and the method is exited. ReadBody used the message decoder, when present, to convert the encoded data using TIdMessageDecoder. Decoded message part contents are written to ADestStream until a blank line is read from the encoded message part.
procedure ReadHeader; override;
When BodyEncoded is True, ReadHeader will read header values from the message using the Content-Type and Content-Disposition headers to determine the PartType, ContentType, ContentDisposition, and Filename (for an attachment).
When BodyEncoded is False, ReadHeader calls ReadLn to retrieve lines from the message part until a blank line, that signals the end of message headers, is retrieved. Message headers are added to the Headers property, with folded header lines being added to the most recent message header.
When ReadHeader has retrieved all message header line, the content-disposition header is examined to determine if the message part contains an attachment.
ReadHeader will update the message part type to ptText when an attachment is not found. When an attachment is indicated in the content-disposition message header, ReadHeader sets the message part type to ptAttachment and parses an optional filename into the Filename property.