' ########################################################################################
' Microsoft Windows
' File: TNEF.inc
' Copyright (c) 2010 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_TNEF_PBI)
#DEFINE PBX_TNEF_PBI
%EQUATE `TNEF_INC = 1
'/*
' * T N E F . H
' *
' *
' * This file contains structure and function definitions for the
' * MAPI implementation of the Transport Neutral Encapsilation Format
' * used by MAPI providers for the neutral serialization of a MAPI
' * message. This implementation sits on top of the IStream object as
' * documented in the OLE 2 Specs.
' *
' * Copyright 1986-1999 Microsoft Corporation. All Rights Reserved.
' */
#INCLUDE ONCE "Legacy/System/MAPIX.inc"
'/* ------------------------------------ */
'/* TNEF Problem and TNEF Problem Arrays */
'/* ------------------------------------ */
' // Size = 16 bytes
TYPE STnefProblem DWORD
 ulComponent AS DWORD ' ULONG
 ulAttribute AS DWORD ' ULONG
 ulPropTag AS DWORD ' ULONG
 scode AS LONG ' SCODE
END TYPE
' // Size = 20 bytes
TYPE STnefProblemArray DWORD
 cProblem AS DWORD ' ULONG
 aProblem(%MAPI_DIM - 1) AS STnefProblem ' STnefProblem [variable-length array]
END TYPE
'#define CbNewSTnefProblemArray(_cprob) \
' (offsetof(STnefProblemArray,aProblem) + (_cprob)*sizeof(STnefProblem))
'#define CbSTnefProblemArray(_lparray) \
' (offsetof(STnefProblemArray,aProblem) + \
' (UINT) ((_lparray)->cProblem*sizeof(STnefProblem)))
'/* Pointers to TNEF Interface ---------------------------------------- */
'/* OpenTNEFStream */
%EQUATE `TNEF_DECODE = 0
%EQUATE `TNEF_ENCODE = 2
%EQUATE `TNEF_PURE = &H00010000
%EQUATE `TNEF_COMPATIBILITY = &H00020000
%EQUATE `TNEF_BEST_DATA = &H00040000
%EQUATE `TNEF_COMPONENT_ENCODING = &H80000000
'/* AddProps, ExtractProps */
%EQUATE `TNEF_PROP_INCLUDE = &H00000001
%EQUATE `TNEF_PROP_EXCLUDE = &H00000002
%EQUATE `TNEF_PROP_CONTAINED = &H00000004
%EQUATE `TNEF_PROP_MESSAGE_ONLY = &H00000008
%EQUATE `TNEF_PROP_ATTACHMENTS_ONLY = &H00000010
%EQUATE `TNEF_PROP_CONTAINED_TNEF = &H00000040
'/* FinishComponent */
%EQUATE `TNEF_COMPONENT_MESSAGE = &H00001000
%EQUATE `TNEF_COMPONENT_ATTACHMENT = &H00002000
' ========================================================================================
' ITnef interface
' $IID_ITNEF = GUID$("{00020319-0000-0000-C000-000000000046}")
' The ITnef interface provides methods for encapsulating those MAPI properties not
' supported by a messaging system into binary streams that can be attached to messages.
' The format used for this encapsulation is Transport-Neutral Encapsulation Format (TNEF).
' The target transport provider or MAPI-based client application can then, on receiving a
' message including a TNEF attachment, recover the properties from the attachment.
' ========================================================================================
INTERFACE ITnef $IID_ITNEF
 INHERIT IUnknown
 ' =====================================================================================
 METHOD AddProps ( ' VTable offset = 12
 BYVAL ulFlags AS DWORD
 , BYVAL ulElemID AS DWORD
 , BYVAL lpvData AS DWORD
 , BYVAL lpPropList AS SPropTagArray PTR
 ) AS LONG
 ' =====================================================================================
 METHOD ExtractProps ( ' VTable offset = 16
 BYVAL ulFlags AS DWORD
 , BYVAL lpPropList AS SPropTagArray PTR
 , BYREF lpProblems AS DWORD
 ) AS LONG
 ' =====================================================================================
 METHOD Finish ( ' VTable offset = 20
 BYVAL ulFlags AS DWORD
 , BYREF lpKey AS DWORD
 , BYREF lpProblems AS DWORD
 ) AS LONG
 ' =====================================================================================
 METHOD OpenTaggedBody ( ' VTable offset = 24
 BYVAL lpMessage AS IMessage
 , BYVAL ulFlags AS DWORD
 , BYREF lppStream AS IStream
 ) AS LONG
 ' =====================================================================================
 METHOD SetProps ( ' VTable offset = 28
 BYVAL ulFlags AS DWORD
 , BYVAL ulElemID AS DWORD
 , BYVAL cValues AS DWORD
 , BYREF lpProps AS SPropValue
 ) AS LONG
 ' =====================================================================================
 METHOD EncodeRecips ( ' VTable offset = 32
 BYVAL ulFlags AS DWORD
 , BYVAL lpRecipientTable AS IMAPITable
 ) AS LONG
 ' =====================================================================================
 METHOD FinishComponent ( ' VTable offset = 36
 BYVAL ulFlags AS DWORD
 , BYVAL ulComponentID AS DWORD
 , BYVAL lpCustomPropList AS SPropTagArray PTR
 , BYREF lpCustomProps AS SPropValue
 , BYVAL lpPropList AS SPropTagArray PTR
 , BYREF lpProblems AS DWORD
 ) AS LONG
 ' =====================================================================================
END INTERFACE
' ========================================================================================
' OpenTnefStream
' The OpenTnefStream function is called by a transport provider to initiate a MAPI
' Transport Neutral Encapsulation Format (TNEF) session.
' ========================================================================================
DECLARE FUNCTION OpenTnefStream LIB "mapi32.dll" ALIAS "OpenTnefStream" ( BYVAL lpvSupport AS IUnknown , BYVAL lpStream AS IStream , BYREF lpszStreamName AS ASCIIZ , BYVAL ulFlags AS QUAD , BYVAL lpMessage AS IMessage , BYVAL wKey AS WORD , BYREF lppTNEF AS ITnef ) AS LONG
' ========================================================================================
' ========================================================================================
' OpenTnefStreamEx
' The OpenTnefStreamEx function creates a TNEF object that can be used to encode or decode
' a message object into a TNEF data stream for use by transports or gateways and message
' stores. This is the entry point for TNEF access.
' ========================================================================================
DECLARE FUNCTION OpenTnefStreamEx LIB "mapi32.dll" ALIAS "OpenTnefStreamEx" ( BYVAL lpvSupport AS IUnknown , BYVAL lpStreamName AS IStream , BYREF lpszStreamName AS ASCIIZ , BYVAL ulFlags AS QUAD , BYVAL lpMessage AS IMessage , BYVAL wKeyVal AS WORD , BYVAL lpAdressBook AS IAddrBook , BYREF lppTNEF AS ITnef ) AS LONG
' ========================================================================================
DECLARE FUNCTION GetTnefStreamCodepage LIB "mapi32.dll" ALIAS "GetTnefStreamCodepage" ( BYVAL lpStream AS IStream , BYREF lpulCodepage AS QUAD , BYREF lpulSubCodepage AS QUAD ) AS LONG
$OPENTNEFSTREAM = "OpenTnefStream"
$OPENTNEFSTREAMEX = "OpenTnefStreamEx"
$GETTNEFSTREAMCODEPAGE = "GetTnefStreamCodePage"
'/* -------------------------- */
'/* TNEF Signature and Version */
'/* -------------------------- */
'#define MAKE_TNEF_VERSION(_mj,_mn) (((ULONG)(0x0000FFFF & _mj) << 16) | (ULONG)(0x0000FFFF & _mn))
FUNCTION MAKE_TNEF_VERSION (BYVAL mj AS DWORD, BYVAL mn AS DWORD) AS DWORD
 LOCAL v AS DWORD
 v = &H0000FFFF AND mj
 SHIFT LEFT v, 16
 FUNCTION = v OR (&H0000FFFF AND mn)
END FUNCTION
%EQUATE `TNEF_SIGNATURE = &H223E9F78
'#define TNEF_VERSION ((ULONG) MAKE_TNEF_VERSION(1,0))
%EQUATE `TNEF_VERSION = 65536
'/* ------------------------------------------- */
'/* TNEF Down-level Attachment Types/Structures */
'/* ------------------------------------------- */
'typedef WORD ATYP;
'enum { atypNull, atypFile, atypOle, atypPicture, atypMax };
%EQUATE `atypNull = 0
%EQUATE `atypFile = 1
%EQUATE `atypOle = 2
%EQUATE `atypPicture = 3
%EQUATE `atypMax = 4
%EQUATE `MAC_BINARY = &H00000001
'#include <pshpack1.h>
' // Size = 14 bytes
TYPE RENDDATA BYTE
 atyp AS WORD ' ATYP
 ulPosition AS DWORD ' ULONG
 dxWidth AS WORD ' WORD
 dyHeight AS WORD ' WORD
 dwFlags AS DWORD
END TYPE
'#include <poppack.h>
'/* ----------------------------------- */
'/* TNEF Down-level Date/Time Structure */
'/* ----------------------------------- */
'#include <pshpack1.h>
' // Size = 14 bytes
TYPE DTR BYTE
 wYear AS WORD
 wMonth AS WORD
 wDay AS WORD
 wHour AS WORD
 wMinute AS WORD
 wSecond AS WORD
 wDayOfWeek AS WORD
END TYPE
'#include <poppack.h>
'/* ----------------------------- */
'/* TNEF Down-level Message Flags */
'/* ----------------------------- */
%EQUATE `fmsNull = &H00
%EQUATE `fmsModified = &H01
%EQUATE `fmsLocal = &H02
%EQUATE `fmsSubmitted = &H04
%EQUATE `fmsRead = &H20
%EQUATE `fmsHasAttach = &H80
'/* ----------------------------------------- */
'/* TNEF Down-level Triple Address Structures */
'/* ----------------------------------------- */
%EQUATE `trpidNull = &H0000
%EQUATE `trpidUnresolved = &H0001
%EQUATE `trpidResolvedNSID = &H0002
%EQUATE `trpidResolvedAddress = &H0003
%EQUATE `trpidOneOff = &H0004
%EQUATE `trpidGroupNSID = &H0005
%EQUATE `trpidOffline = &H0006
%EQUATE `trpidIgnore = &H0007
%EQUATE `trpidClassEntry = &H0008
%EQUATE `trpidResolvedGroupAddress = &H0009
' // Size = 8 bytes
TYPE TRP WORD
 trpid AS WORD
 cbgrtrp AS WORD
 cch AS WORD
 cbRgb AS WORD
END TYPE
'#define CbOfTrp(_p) (sizeof(TRP) + (_p)->cch + (_p)->cbRgb)
'#define LpszOfTrp(_p) ((LPSTR)(((LPTRP) (_p)) + 1))
'#define LpbOfTrp(_p) (((LPBYTE)(((LPTRP)(_p)) + 1)) + (_p)->cch)
'#define LptrpNext(_p) ((LPTRP)((LPBYTE)(_p) + CbOfTrp(_p)))
'typedef DWORD XTYPE;
%EQUATE `xtypeUnknown = 0
%EQUATE `xtypeInternet = 6
%EQUATE `cbDisplayName = 41
%EQUATE `cbEmailName = 11
%EQUATE `cbSeverName = 12
' // Size = 72 bytes
TYPE ADDRALIAS
 rgchName AS ASCIIZ * %cbDisplayName ' char rgchName[cbDisplayName]
 rgchEName AS ASCIIZ * %cbEmailName ' char rgchEName[cbEmailName]
 rgchSrvr AS ASCIIZ * %cbSeverName ' char rgchSrvr[cbSeverName]
 dibDetail AS DWORD ' ULONG
 type AS WORD ' WORD
 alignment__ AS WORD
END TYPE
'#define cbALIAS sizeof(ALIAS)
%EQUATE `cbTYPE = 16
%EQUATE `cbMaxIdData = 200
' // Size = 72 bytes
UNION NSID_Address_UNION
 alias AS ADDRALIAS ' ADDRALIAS alias
 rgchInterNet(0) AS BYTE ' char rgchInterNet[1]
END UNION
' // Size = 100 bytes
TYPE NSID DWORD
 dwSize AS DWORD
 uchType AS ASCIIZ * %cbType ' unsigned char[cbTYPE];
 xtype AS DWORD ' XTYPE
 lTime AS LONG
 address AS NSID_Address_UNION
END TYPE
'#define cbNSID sizeof(NSID)
'/* -------------------------- */
'/* TNEF Down-level Priorities */
'/* -------------------------- */
%EQUATE `prioLow = 3
%EQUATE `prioNorm = 2
%EQUATE `prioHigh = 1
'/* ------------------------------------- */
'/* TNEF Down-level Attributes/Properties */
'/* ------------------------------------- */
%EQUATE `atpTriples = &H0000
%EQUATE `atpString = &H0001
%EQUATE `atpText = &H0002
%EQUATE `atpDate = &H0003
%EQUATE `atpShort = &H0004
%EQUATE `atpLong = &H0005
%EQUATE `atpByte = &H0006
%EQUATE `atpWord = &H0007
%EQUATE `atpDword = &H0008
%EQUATE `atpMax = &H0009
%EQUATE `LVL_MESSAGE = &H01
%EQUATE `LVL_ATTACHMENT = &H02
'#define ATT_ID(_att) ((WORD) ((_att) & 0x0000FFFF))
FUNCTION ATT_ID (BYVAL att_ AS DWORD) AS WORD
 FUNCTION = att_ AND &H0000FFFF
END FUNCTION
'#define ATT_TYPE(_att) ((WORD) (((_att) >> 16) & 0x0000FFFF))
FUNCTION ATT_TYPE (BYVAL att_ AS DWORD) AS WORD
 SHIFT RIGHT att_, 16
 FUNCTION = att_ AND &H0000FFFF
END FUNCTION
'#define ATT(_atp, _id) ((((DWORD) (_atp)) << 16) | ((WORD) (_id)))
FUNCTION ATT (BYVAL atp AS WORD, BYVAL id AS WORD) AS DWORD
 LOCAL dwatp AS DWORD
 dwatp = atp
 SHIFT LEFT dwatp, 16
 FUNCTION = dwatp OR id
END FUNCTION
%EQUATE `attNull = &H00000000 ' ATT(0, 0x0000)
%EQUATE `attFrom = &H00008000 ' ATT(atpTriples, 0x8000) /* PR_ORIGINATOR_RETURN_ADDRESS */
%EQUATE `attSubject = &H00018004 ' ATT(atpString, 0x8004) /* PR_SUBJECT */
%EQUATE `attDateSent = &H00038005 ' ATT(atpDate, 0x8005) /* PR_CLIENT_SUBMIT_TIME */
%EQUATE `attDateRecd = &H00038006 ' ATT(atpDate, 0x8006) /* PR_MESSAGE_DELIVERY_TIME */
%EQUATE `attMessageStatus = &H00058007 ' ATT(atpByte, 0x8007) /* PR_MESSAGE_FLAGS */
%EQUATE `attMessageClass = &H00078008 ' ATT(atpWord, 0x8008) /* PR_MESSAGE_CLASS */
%EQUATE `attMessageID = &H00018009 ' ATT(atpString, 0x8009) /* PR_MESSAGE_ID */
%EQUATE `attParentID = &H0001800A ' ATT(atpString, 0x800A) /* PR_PARENT_ID */
%EQUATE `attConversationID = &H0001800B ' ATT(atpString, 0x800B) /* PR_CONVERSATION_ID */
%EQUATE `attBody = &H0002800C ' ATT(atpText, 0x800C) /* PR_BODY */
%EQUATE `attPriority = &H0004800D ' ATT(atpShort, 0x800D) /* PR_IMPORTANCE */
%EQUATE `attAttachData = &H0006800F ' ATT(atpByte, 0x800F) /* PR_ATTACH_DATA_xxx */
%EQUATE `attAttachTitle = &H00018010 ' ATT(atpString, 0x8010) /* PR_ATTACH_FILENAME */
%EQUATE `attAttachMetaFile = &H00068011 ' ATT(atpByte, 0x8011) /* PR_ATTACH_RENDERING */
%EQUATE `attAttachCreateDate = &H00038012 ' ATT(atpDate, 0x8012) /* PR_CREATION_TIME */
%EQUATE `attAttachModifyDate = &H00038013 ' ATT(atpDate, 0x8013) /* PR_LAST_MODIFICATION_TIME */
%EQUATE `attDateModified = &H00038020 ' ATT(atpDate, 0x8020) /* PR_LAST_MODIFICATION_TIME */
%EQUATE `attAttachTransportFilename = &H00069001 ' ATT(atpByte, 0x9001) /* PR_ATTACH_TRANSPORT_NAME */
%EQUATE `attAttachRenddata = &H00069002 ' ATT(atpByte, 0x9002)
%EQUATE `attMAPIProps = &H00069003 ' ATT(atpByte, 0x9003)
%EQUATE `attRecipTable = &H00069004 ' ATT(atpByte, 0x9004) /* PR_MESSAGE_RECIPIENTS */
%EQUATE `attAttachment = &H00069005 ' ATT(atpByte, 0x9005)
%EQUATE `attTnefVersion = &H00089006 ' ATT(atpDword, 0x9006)
%EQUATE `attOemCodepage = &H00069007 ' ATT(atpByte, 0x9007)
%EQUATE `attOriginalMessageClass = &H00070006 ' ATT(atpWord, 0x0006) /* PR_ORIG_MESSAGE_CLASS */
%EQUATE `attOwner = &H00060000 ' ATT(atpByte, 0x0000) /* PR_RCVD_REPRESENTING_xxx or PR_SENT_REPRESENTING_xxx */
%EQUATE `attSentFor = &H00060001 ' ATT(atpByte, 0x0001) /* PR_SENT_REPRESENTING_xxx */
%EQUATE `attDelegate = &H00060002 ' ATT(atpByte, 0x0002) /* PR_RCVD_REPRESENTING_xxx */
%EQUATE `attDateStart = &H00030006 ' ATT(atpDate, 0x0006) /* PR_DATE_START */
%EQUATE `attDateEnd = &H00030007 ' ATT(atpDate, 0x0007) /* PR_DATE_END */
%EQUATE `attAidOwner = &H00050008 ' ATT(atpLong, 0x0008) /* PR_OWNER_APPT_ID */
%EQUATE `attRequestRes = &H00040009 ' ATT(atpShort, 0x0009) /* PR_RESPONSE_REQUESTED */
#ENDIF
