|
Summary
Set header information
Description
The OnSetHeader event will be fired during the create message process to obtain the
header information for a MIME message and for any attachments. This event occurs in
response to calling the CreateMessage method. The ContentId, Encoding, ContentType and
Subtype properties must be set appropriately. The Charset, FileName, Encoding,
MultipartStart, MultipartType, ContentBase, ContentLocation, FileSize, BinHexType,
BinHexCreator and BinHexFlag properties are optional and may be set in this event. Please
check the reference pages on each property for additional information.
Additional header information may also be sent in this event. Applications may want to
add specific information in the headers such as an "X-Mailer" field. Such fields
can be sent using this event by setting the Info parameter to the additional
information, and setting the Length parameter to the length of Info.
For non-MIME messages, set Status to 0 to indicate the end of the header. For
MIME messages, set the Status parameter to END_OF_LEVEL to indicate end of header.
Otherwise, set Status to 1.
If there is no header, set Status to NO_HEADER. This indicates that there is no
header and the body will not be encoded.
In some environments such as Visual J++, the new value assigned to the Status
and Info parameters can not be successfully retrieved by the control. In these
cases set UseProperty to True, and assign the status to the AttachmentStatus property
instead of the Status parameter, and additional information to the SendData
property instead of the Info parameter. The UseProperty property must be set to
True before attempting to create a message. In this case treat the AttachmentStatus
property exactly as you would the Status parameter, treat the SendData property
exactly as you would the Info parameter. If UseProperty is True the Length
parameter will be ignored
For a partial message, the first part must include the header of the encapsulated
message. The ContentType and Subtype properties must be specified for the encapsulated
message (such as "image", "audio", "video", etc.). All other
parts will not have a header
To abort the create message, set the Action property to ACTION_ABORT (or call the Abort
method) during this event. The action in progress will be canceled and no further such
events will occur.
Technical Note
The order of events will usually be OnSetHeader to get message header information,
followed by an OnSetBody to get the body of the message, and then this sequence is
repeated for any attachments.
If the message being created of type multipart or "message/external-body" the
sequence of the OnSetHeader and OnSetBody events may differ. This will be dependant on how
the application sets the ContentType and SubType properties in the OnSetHeader event.
In case of multipart or message/external messages the OnSetHeader event can be followed
by another OnSetHeader event instead of an OnSetBody event.
If the message is a non-MIME message it will have no initial header and therefore the
first event fired will be the OnSetBody event to get the message body. The OnSetHeader
event will then be fired to get the header information of any attachments. Note that for
non-MIME messages only the Encoding and the Filename properties need to be set in
the OnSetHeader event, and the info parameter should be set to NULL and the Length
parameter should be set to 0 because the attachments of a non-MIME message do not have any
separate header.
Example
Private Sub MIME_OnSetHeader(Info As String, Length As Integer, Status As Integer)
Info = "X-Mailer: <Distinct Sample Version 4.0>"
Length = Len (Info)
If (InitialHeader) Then
'set the message type
MIME.Encoding = "text"
MIME.ContentType = "multipart"
MIME.Charset = "us-ascii"
MIME.Subtype = "mixed"
InitialHeader = False
Status = 1
Exit Sub
ElseIf MsgBodyDone = False Then
' set the body type
MIME.ContentType = "text"
MIME.Subtype = "plain"
Status = 1
Exit Sub
End If
' no attachments
If (HeaderIndex = 0) Then
Status = 0
MIME.AttachmentStatus = 0
Exit Sub
End If
' increment Indx
Indx = Indx + 1
' finished all attachments
If (Indx >= HeaderIndex) Then
If (MsgType = 1 Or MsgType = 0) Then
Status = 0
Else
Status = END_OF_LEVEL
End If
Exit Sub
End If
' fill fields to set the attachment type
If MsgType = 1 Then ' plain message
'check encoding
If HeaderInfo(Indx).Encoding = TYPE_TEXT Then
MIME.Encoding = "text"
Else
MIME.Encoding = "uuencode"
End If
ElseIf MsgType = 2 Then ' mime message
'check encoding
If HeaderInfo(Indx).Encoding = BASE64_ENCODED Then
MIME.Encoding = "base64"
ElseIf HeaderInfo(Indx).Encoding = QUOTED_ENCODED Then
MIME.Encoding = "quoted-printable"
ElseIf HeaderInfo(Indx).Encoding = BINHEX_ENCODED Then
MIME.Encoding = "binhex"
Else
MIME.Encoding = "text"
End If
' check mime filetype
If HeaderInfo(Indx).Type = TYPE_AUDIO Then
MIME.ContentType = "audio"
MIME.Subtype = "basic"
ElseIf HeaderInfo(Indx).Type = TYPE_VIDEO Then
MIME.ContentType = "video"
MIME.Subtype = "basic"
ElseIf HeaderInfo(Indx).Type = TYPE_IMAGE Then
MIME.ContentType = "image"
MIME.Subtype = "gif"
ElseIf HeaderInfo(Indx).Type = TYPE_APPLICATION Then
MIME.ContentType = "application"
If HeaderInfo(Indx).Encoding = BINHEX_ENCODED Then
MIME.Subtype = "mac-binhex40"
Else
MIME.Subtype = "octet-stream"
End If
Else
MIME.ContentType = "text"
MIME.Subtype = "plain"
End If
End If
' set filename
MIME.Filename = HeaderInfo(Indx).Filename
AttachDone = False
Status = 1
End Sub
|