MAPIToVMIME.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 MAPITOVMIME
  18. #define MAPITOVMIME
  19. #include <kopano/zcdefs.h>
  20. #include <memory>
  21. #include <mapix.h>
  22. #include <string>
  23. #include <vmime/vmime.hpp>
  24. #include <vmime/mailbox.hpp>
  25. #include <inetmapi/options.h>
  26. #include <mapidefs.h>
  27. #include <kopano/charset/convert.h>
  28. #include "SMIMEMessage.h"
  29. namespace KC {
  30. /**
  31. * %MTV_SPOOL: add X-Mailer headers on message
  32. */
  33. enum {
  34. MTV_NONE = 0,
  35. MTV_SPOOL = 1 << 0,
  36. MTV_SKIP_CONTENT = 1 << 1,
  37. };
  38. class MAPIToVMIME _kc_final {
  39. public:
  40. MAPIToVMIME();
  41. MAPIToVMIME(IMAPISession *, IAddrBook *, sending_options);
  42. ~MAPIToVMIME();
  43. HRESULT convertMAPIToVMIME(IMessage *in, vmime::shared_ptr<vmime::message> *out, unsigned int = MTV_NONE);
  44. std::wstring getConversionError(void) const;
  45. private:
  46. sending_options sopt;
  47. LPADRBOOK m_lpAdrBook;
  48. LPMAPISESSION m_lpSession;
  49. std::wstring m_strError;
  50. convert_context m_converter;
  51. vmime::charset m_vmCharset; //!< charset to use in email
  52. std::string m_strCharset; //!< charset to use in email + //TRANSLIT tag
  53. std::string m_strHTMLCharset; //!< HTML body charset in MAPI message (input)
  54. enum eBestBody { plaintext, html, realRTF };
  55. HRESULT fillVMIMEMail(IMessage *lpMessage, bool bSkipContent, vmime::messageBuilder* lpVMMessageBuilder);
  56. HRESULT handleTextparts(IMessage* lpMessage, vmime::messageBuilder* lpVMMessageBuilder, eBestBody *bestBody);
  57. HRESULT getMailBox(LPSRow lpRow, vmime::shared_ptr<vmime::address> *mbox);
  58. HRESULT processRecipients(IMessage* lpMessage, vmime::messageBuilder* lpVMMessageBuilder);
  59. HRESULT handleExtraHeaders(IMessage *in, vmime::shared_ptr<vmime::header> out, unsigned int);
  60. HRESULT handleReplyTo(IMessage *in, vmime::shared_ptr<vmime::header> hdr);
  61. HRESULT handleContactEntryID(ULONG cValues, LPSPropValue lpProps, std::wstring &strName, std::wstring &strType, std::wstring &strEmail);
  62. HRESULT handleSenderInfo(IMessage* lpMessage, vmime::shared_ptr<vmime::header>);
  63. HRESULT handleAttachments(IMessage* lpMessage, vmime::messageBuilder* lpVMMessageBuilder);
  64. HRESULT handleSingleAttachment(IMessage* lpMessage, LPSRow lpRow, vmime::messageBuilder* lpVMMessageBuilder);
  65. HRESULT parseMimeTypeFromFilename(std::wstring strFilename, vmime::mediaType *lpMT, bool *lpbSendBinary);
  66. HRESULT setBoundaries(vmime::shared_ptr<vmime::header> hdr, vmime::shared_ptr<vmime::body> body, const std::string &boundary);
  67. HRESULT handleXHeaders(IMessage *in, vmime::shared_ptr<vmime::header> out, unsigned int);
  68. HRESULT handleTNEF(IMessage* lpMessage, vmime::messageBuilder* lpVMMessageBuilder, eBestBody bestBody);
  69. // build Messages
  70. HRESULT BuildNoteMessage(IMessage *in, vmime::shared_ptr<vmime::message> *out, unsigned int = MTV_NONE);
  71. HRESULT BuildMDNMessage(IMessage *in, vmime::shared_ptr<vmime::message> *out);
  72. // util
  73. void capitalize(char *s);
  74. void removeEnters(WCHAR *s);
  75. vmime::text getVmimeTextFromWide(const WCHAR* lpszwInput, bool bWrapInWord = true);
  76. vmime::text getVmimeTextFromWide(const std::wstring& strwInput, bool bWrapInWord = true);
  77. bool is_voting_request(IMessage *lpMessage);
  78. bool has_reminder(IMessage *);
  79. };
  80. } /* namespace */
  81. #endif