tnef.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #ifndef TNEF_H
  18. #define TNEF_H
  19. #include <list>
  20. #include <kopano/zcdefs.h>
  21. #include <mapidefs.h>
  22. // We loosely follow the MS class ITNEF with the following main exceptions:
  23. //
  24. // - No special RTF handling
  25. // - No recipient handling
  26. // - No problem reporting
  27. //
  28. namespace KC {
  29. #pragma pack(push,1)
  30. struct AttachRendData {
  31. unsigned short usType;
  32. unsigned int ulPosition;
  33. unsigned short usWidth;
  34. unsigned short usHeight;
  35. unsigned int ulFlags;
  36. };
  37. #pragma pack(pop)
  38. #define AttachTypeFile 0x0001
  39. #define AttachTypeOle 0x0002
  40. class ECTNEF _kc_final {
  41. public:
  42. ECTNEF(ULONG ulFlags, IMessage *lpMessage, IStream *lpStream);
  43. virtual ~ECTNEF();
  44. // Add properties to the TNEF stream from the message
  45. virtual HRESULT AddProps(ULONG ulFlags, const SPropTagArray *lpPropList);
  46. // Extract properties from the TNEF stream to the message
  47. virtual HRESULT ExtractProps(ULONG ulFlags, LPSPropTagArray lpPropList);
  48. // Set some extra properties (warning!, make sure that this pointer stays in memory until Finish() is called!)
  49. virtual HRESULT SetProps(ULONG cValues, LPSPropValue lpProps);
  50. // Add other components (currently only attachments supported)
  51. virtual HRESULT FinishComponent(ULONG ulFlags, ULONG ulComponentID, const SPropTagArray *lpPropList);
  52. // Finish up and write the data (write stream with TNEF_ENCODE, write to message with TNEF_DECODE)
  53. virtual HRESULT Finish();
  54. private:
  55. HRESULT HrReadDWord(IStream *lpStream, ULONG *ulData);
  56. HRESULT HrReadWord(IStream *lpStream, unsigned short *ulData);
  57. HRESULT HrReadByte(IStream *lpStream, unsigned char *ulData);
  58. HRESULT HrReadData(IStream *lpStream, char *lpData, ULONG ulLen);
  59. HRESULT HrWriteDWord(IStream *lpStream, ULONG ulData);
  60. HRESULT HrWriteWord(IStream *lpStream, unsigned short ulData);
  61. HRESULT HrWriteByte(IStream *lpStream, unsigned char ulData);
  62. HRESULT HrWriteData(IStream *, const char *buf, ULONG len);
  63. HRESULT HrWritePropStream(IStream *lpStream, std::list<SPropValue *> &proplist);
  64. HRESULT HrWriteSingleProp(IStream *lpStream, LPSPropValue lpProp);
  65. HRESULT HrReadPropStream(const char *buf, ULONG size, std::list<SPropValue *> &proplist);
  66. HRESULT HrReadSingleProp(const char *buf, ULONG size, ULONG *have_read, LPSPropValue *out);
  67. HRESULT HrGetChecksum(IStream *lpStream, ULONG *lpulChecksum);
  68. ULONG GetChecksum(const char *data, unsigned int ulLen) const;
  69. HRESULT HrWriteBlock(IStream *lpDest, IStream *lpSrc, ULONG ulBlockID, ULONG ulLevel);
  70. HRESULT HrWriteBlock(IStream *lpDest, const char *buf, unsigned int len, ULONG block_id, ULONG level);
  71. HRESULT HrReadStream(IStream *lpStream, void *lpBase, BYTE **lppData, ULONG *lpulSize);
  72. IStream *m_lpStream;
  73. IMessage *m_lpMessage;
  74. ULONG ulFlags;
  75. // Accumulator for properties from AddProps and SetProps
  76. std::list<SPropValue *> lstProps;
  77. struct tnefattachment {
  78. std::list<SPropValue *> lstProps;
  79. ULONG size;
  80. BYTE *data;
  81. AttachRendData rdata;
  82. };
  83. std::list<tnefattachment*> lstAttachments;
  84. void FreeAttachmentData(tnefattachment* lpTnefAtt);
  85. };
  86. // Flags for constructor
  87. #define TNEF_ENCODE 0x00000001
  88. #define TNEF_DECODE 0x00000002
  89. // Flags for FinishComponent
  90. #define TNEF_COMPONENT_MESSAGE 0x00001000
  91. #define TNEF_COMPONENT_ATTACHMENT 0x00002000
  92. // Flags for ExtractProps
  93. #define TNEF_PROP_EXCLUDE 0x00000003
  94. #define TNEF_PROP_INCLUDE 0x00000004
  95. // Flags for AddProps
  96. // #define TNEF_PROP_EXCLUDE 0x00000001
  97. // #define TNEF_PROP_INCLUDE 0x00000002
  98. #define TNEF_SIGNATURE 0x223e9f78
  99. } /* namespace */
  100. #endif