VMIMEToMAPI.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 VMIMETOMAPI
  18. #define VMIMETOMAPI
  19. #include <list>
  20. #include <kopano/zcdefs.h>
  21. #include <vmime/vmime.hpp>
  22. #include <mapix.h>
  23. #include <mapidefs.h>
  24. #include <inetmapi/options.h>
  25. #include <kopano/charset/convert.h>
  26. namespace KC {
  27. #define MAPI_CHARSET vmime::charset(vmime::charsets::UTF_8)
  28. #define MAPI_CHARSET_STRING "UTF-8"
  29. enum BODYLEVEL { BODY_NONE, BODY_PLAIN, BODY_HTML };
  30. enum ATTACHLEVEL { ATTACH_NONE, ATTACH_INLINE, ATTACH_NORMAL };
  31. struct sMailState {
  32. BODYLEVEL bodyLevel; //!< the current body state. plain upgrades none, html upgrades plain and none.
  33. ULONG ulLastCP;
  34. ATTACHLEVEL attachLevel; //!< the current attachment state
  35. unsigned int mime_vtag_nest; //!< number of nested MIME-Version tags seen
  36. bool bAttachSignature; //!< add a signed signature at the end
  37. ULONG ulMsgInMsg; //!< counter for msg-in-msg level
  38. std::string strHTMLBody; //!< cache for the current complete untouched HTML body, used for finding CIDs or locations (inline images)
  39. sMailState() {
  40. this->reset();
  41. ulMsgInMsg = 0;
  42. };
  43. void reset() {
  44. bodyLevel = BODY_NONE;
  45. ulLastCP = 0;
  46. attachLevel = ATTACH_NONE;
  47. mime_vtag_nest = 0;
  48. bAttachSignature = false;
  49. strHTMLBody.clear();
  50. };
  51. };
  52. void ignoreError(void *ctx, const char *msg, ...);
  53. class VMIMEToMAPI _kc_final {
  54. public:
  55. VMIMEToMAPI();
  56. VMIMEToMAPI(LPADRBOOK lpAdrBook, delivery_options dopt);
  57. virtual ~VMIMEToMAPI();
  58. HRESULT convertVMIMEToMAPI(const std::string &input, IMessage *lpMessage);
  59. HRESULT createIMAPProperties(const std::string &input, std::string *lpEnvelope, std::string *lpBody, std::string *lpBodyStructure);
  60. private:
  61. delivery_options m_dopt;
  62. LPADRBOOK m_lpAdrBook;
  63. IABContainer *m_lpDefaultDir = nullptr;
  64. sMailState m_mailState;
  65. convert_context m_converter;
  66. HRESULT fillMAPIMail(vmime::shared_ptr<vmime::message>, IMessage *lpMessage);
  67. HRESULT dissect_body(vmime::shared_ptr<vmime::header>, vmime::shared_ptr<vmime::body>, IMessage *lpMessage, bool filterDouble = false, bool appendBody = false);
  68. void dissect_message(vmime::shared_ptr<vmime::body>, IMessage *);
  69. HRESULT dissect_multipart(vmime::shared_ptr<vmime::header>, vmime::shared_ptr<vmime::body>, IMessage *, bool filterDouble = false, bool appendBody = false);
  70. HRESULT dissect_ical(vmime::shared_ptr<vmime::header>, vmime::shared_ptr<vmime::body>, IMessage *, bool bIsAttachment);
  71. HRESULT handleHeaders(vmime::shared_ptr<vmime::header>, IMessage* lpMessage);
  72. HRESULT handleRecipients(vmime::shared_ptr<vmime::header>, IMessage* lpMessage);
  73. HRESULT modifyRecipientList(LPADRLIST lpRecipients, vmime::shared_ptr<vmime::addressList>, ULONG ulRecipType);
  74. HRESULT modifyFromAddressBook(LPSPropValue *lppPropVals, ULONG *lpulValues, const char *email, const wchar_t *fullname, ULONG ulRecipType, const SPropTagArray *lpPropsList);
  75. std::string content_transfer_decode(vmime::shared_ptr<vmime::body>) const;
  76. vmime::charset get_mime_encoding(vmime::shared_ptr<vmime::header>, vmime::shared_ptr<vmime::body>) const;
  77. int renovate_encoding(std::string &, const std::vector<std::string> &);
  78. int renovate_encoding(std::wstring &, std::string &, const std::vector<std::string> &);
  79. HRESULT handleTextpart(vmime::shared_ptr<vmime::header>, vmime::shared_ptr<vmime::body>, IMessage* lpMessage, bool bAppendBody);
  80. HRESULT handleHTMLTextpart(vmime::shared_ptr<vmime::header>, vmime::shared_ptr<vmime::body>, IMessage* lpMessage, bool bAppendBody);
  81. HRESULT handleAttachment(vmime::shared_ptr<vmime::header>, vmime::shared_ptr<vmime::body>, IMessage* lpMessage, bool bAllowEmpty = true);
  82. HRESULT handleMessageToMeProps(IMessage *lpMessage, LPADRLIST lpRecipients);
  83. int getCharsetFromHTML(const std::string &strHTML, vmime::charset *htmlCharset);
  84. vmime::charset getCompatibleCharset(const vmime::charset &vmCharset);
  85. std::wstring getWideFromVmimeText(const vmime::text &vmText);
  86. HRESULT postWriteFixups(IMessage *lpMessage);
  87. std::string mailboxToEnvelope(vmime::shared_ptr<vmime::mailbox>);
  88. std::string addressListToEnvelope(vmime::shared_ptr<vmime::addressList> mbox);
  89. HRESULT createIMAPEnvelope(vmime::shared_ptr<vmime::message>, IMessage* lpMessage);
  90. std::string createIMAPEnvelope(vmime::shared_ptr<vmime::message>);
  91. HRESULT createIMAPBody(const std::string &input, vmime::shared_ptr<vmime::message>, IMessage* lpMessage);
  92. HRESULT messagePartToStructure(const std::string &input, vmime::shared_ptr<vmime::bodyPart>, std::string *lpSimple, std::string *lpExtended);
  93. HRESULT bodyPartToStructure(const std::string &input, vmime::shared_ptr<vmime::bodyPart>, std::string *lpSimple, std::string *lpExtended);
  94. std::string getStructureExtendedFields(vmime::shared_ptr<vmime::header> vmHeaderPart);
  95. std::string parameterizedFieldToStructure(vmime::shared_ptr<vmime::parameterizedHeaderField>);
  96. std::string::size_type countBodyLines(const std::string &input, std::string::size_type start, std::string::size_type length);
  97. bool filter_html(IMessage *, IStream *, ULONG, const std::string &);
  98. };
  99. } /* namespace */
  100. #endif