DecodeTNEF method decodes TNEF file (winmail.dat) to new plain POPMSG object.
[Syntax] C++: HRESULT DecodeTNEF( VARIANT data, long includeRTFBody, IPOPMSG* *pVal ) Visual Basic: DecodeTNEF( ByVal data As Variant, ByVal includeRTFBody As Long ) As ANPOPLib.POPMSG C#: ANPOPLib.POPMSGClass DecodeTNEF( byte[] data, int includeRTFBody )
Parameters
data
The winmail.dat attachment binary data.
includeRTFBody
If this parameter is greater than zero, this method also decodes RTF body as a RTF attachment.
Return Value
If this method decodes winmail.dat successfully, return value is a new decoded POPMSG object, otherwise an exception is thrown out.
Usage Example
[Visual Basic]
Sub ParseAttachments( emailFile As String )
Dim oMsg As ANPOPLib.POPMSG
Dim oTMsg As ANPOPLib.POPMSG
Dim i, nRet, nCount, nSize, x, y As Integer
Dim tempFolder, fileName, err As String
Set oMsg = new ANPOPLib.POPMSG
nRet = oMsg.ImportFile( emailFile )
If nRet <> 0 Then
err = "error with ImportFile"
GoTo ErrorHandler
End If
tempFolder = "c:\temp_attachments"
If oMsg.CreateFolder( tempFolder ) <> 0 Then
err = "error with Create temporary folder"
GoTo ErrorHandler
End If
nCount = oMsg.GetAttachmentCount() 'get total count of attachments
For i = 1 To nCount
fileName = oMsg.GetAttachmentName(i) 'get attachment name
If LCase(fileName) = "winmail.dat" Then
'this is a OUTLOOK RTF attachment, decode it.
Set oTMsg = oMsg.DecodeTNEF( oMsg.GetAttachmentChunk(i), 1 )
y = oTMsg.GetAttachmentCount()
For x = 1 To y
If oTMsg.SaveAttachment( tempFolder, x ) <> 0 Then
err = "error with SaveAttachment"
GoTo ErrorHandler
End If
Next
Else
nSize = oMsg.GetAttachmentSize(i) 'get attachment size
If oMsg.SaveAttachment( tempFolder, i ) <> 0 Then 'save attachment to temporary directory
err = "error with SaveAttachment"
GoTo ErrorHandler
End If
End If
Next
ErrorHandler:
Set oMsg = Nothing
End Sub
2001-2007 © Copyright AdminSystem Software Limited. All rights reserved.