Encapsulates a MIME-encoded attachment or inline graphic.
TIdAttachment = class(TIdMessagePart);
TIdAttachment is a TIdMessagePart descendant that encapsulates a MIME-encoded attachment or inline graphic. TIdAttachment, TIdAttachmentFile, TIdAttachmentMemory, and TIdText are used as collection items in the TIdMessageParts collection.
TIdAttachment publishes properties that provide read and write access to additional header values common to mail message attachments.
TIdAttachment specifies abstract virtual methods that allow the Internet Message attachment to retrieve and store the contents of its headers and message body using a stream.
For sending a message with attachments, the following abstract virtual methods need to be overridden and reimplemented:
Create accepts an argument that indicates the file, string, or stream containing the contents of the attachment. TIdAttachment does not implement a constructor for the class that allows specifying the file, string, stream with the contents of the attachment.
When a TIdMessage instance is transmitted using TIdMessageClient, or a descendant class, the overridden OpenLoadStream and CloseLoadStream in an attachment are called. These overridden methods open and close the internal stream used for loading the contents of the message part during transmission.
OpenLoadStream accesses (or creates) a stream used for loading the contents of the message part. During transmission, values in the internal stream are encoded based on the properties specified in the message or message part in TIdMessageClient methods like SendHeader and SendBody.
CloseLoadStream ensures that the internal stream for accessing data in the message part is reset when all values have been read during transmission. If the internal stream is created in OpenLoadStream, it is freed in CloseLoadStream. An existing stream is repositioned to its initial position prior to reading values for the message part.
When loading or receiving a message with attachments, the following abstract virtual methods need to be overridden and reimplemented:
When a TIdMessage instance is received and processed using TIdMessageClient, or a descendant class, the overridden PrepareTempStream and FinishTempStream methods for the attachment are called. These methods apply to both receiving a message from a remote mail server or accessing a message from a local mail store. Essentially, the actions are the same - differing only in the type of stream used to read the message contents.
PrepareTempStream ensures that the temporary stream used for processing the contents of the message part are allocated, sized, and/or positioned prior to reading values to be stored in a TIdMessage instance.
FinishTempStream ensures that the temporary stream used for processing the contents of the message part are freed, and/or repositioned after reading values stored in a TIdMessage instance.
The ProcessMessage, ReceiveHeader, and ReceiveBody methods in TIdMessageClient rely on the overridden methods.
Applications do not normally create instances of TIdAttachment. Use TIdAttachmentFile or TIdAttachmentMemory, which implement the abstract virtual methods required to create, load, or save the attachment using the desired string, stream, or file.
Copyright © 1993-2006, Chad Z. Hower (aka Kudzu) and the Indy Pit Crew. All rights reserved.
|
Post feedback to the Indy Docs Newsgroup.
|