MAPISMTPTransport.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. // based on vmime/messaging/smtp/SMTPTransport.hpp, but with additions
  18. // we cannot use a class derived from SMTPTransport, since that class has alot of privates
  19. //
  20. // VMime library (http://www.vmime.org)
  21. // Copyright (C) 2002-2009 Vincent Richard <vincent@vincent-richard.net>
  22. //
  23. // This program is free software; you can redistribute it and/or
  24. // modify it under the terms of the GNU General Public License as
  25. // published by the Free Software Foundation; either version 3 of
  26. // the License, or (at your option) any later version.
  27. //
  28. // This program is distributed in the hope that it will be useful,
  29. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  31. // General Public License for more details.
  32. //
  33. // You should have received a copy of the GNU General Public License along
  34. // with this program; if not, write to the Free Software Foundation, Inc.,
  35. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  36. //
  37. // Linking this library statically or dynamically with other modules is making
  38. // a combined work based on this library. Thus, the terms and conditions of
  39. // the GNU General Public License cover the whole combination.
  40. //
  41. #ifndef MAPI_NET_SMTP_SMTPTRANSPORT_HPP_INCLUDED
  42. #define MAPI_NET_SMTP_SMTPTRANSPORT_HPP_INCLUDED
  43. #include <kopano/zcdefs.h>
  44. #include <vmime/config.hpp>
  45. #include <vmime/net/transport.hpp>
  46. #include <vmime/net/socket.hpp>
  47. #include <vmime/net/timeoutHandler.hpp>
  48. #include <vmime/net/smtp/SMTPResponse.hpp>
  49. #include <vmime/net/smtp/SMTPServiceInfos.hpp>
  50. #include <inetmapi/inetmapi.h>
  51. namespace vmime {
  52. namespace net {
  53. namespace smtp {
  54. class SMTPResponse;
  55. /** SMTP transport service.
  56. */
  57. class MAPISMTPTransport _kc_final : public transport {
  58. public:
  59. MAPISMTPTransport(vmime::shared_ptr<session> sess, vmime::shared_ptr<security::authenticator> auth, const bool secured = false);
  60. ~MAPISMTPTransport();
  61. const std::string getProtocolName(void) const { return "mapismtp"; }
  62. static const serviceInfos &getInfosInstance(void) { return sm_infos; }
  63. const serviceInfos& getInfos() const { return sm_infos; }
  64. void connect();
  65. bool isConnected() const;
  66. void disconnect();
  67. void noop();
  68. void send(const mailbox &expeditor, const mailboxList &recipients, utility::inputStream &, size_t, utility::progressListener * = NULL, const mailbox &sender = mailbox());
  69. bool isSecuredConnection(void) const { return m_secured; }
  70. vmime::shared_ptr<connectionInfos> getConnectionInfos(void) const { return m_cntInfos; }
  71. // additional functions
  72. const std::vector<sFailedRecip> &getPermanentFailedRecipients(void) const { return mPermanentFailedRecipients; }
  73. const std::vector<sFailedRecip> &getTemporaryFailedRecipients(void) const { return mTemporaryFailedRecipients; }
  74. void requestDSN(BOOL bRequest, const std::string &strTrackid);
  75. private:
  76. void sendRequest(const string& buffer, const bool end = true);
  77. vmime::shared_ptr<SMTPResponse> readResponse(void);
  78. void internalDisconnect();
  79. void helo();
  80. void authenticate();
  81. #if VMIME_HAVE_SASL_SUPPORT
  82. void authenticateSASL();
  83. #endif // VMIME_HAVE_SASL_SUPPORT
  84. #if VMIME_HAVE_TLS_SUPPORT
  85. void startTLS();
  86. #endif // VMIME_HAVE_TLS_SUPPORT
  87. vmime::shared_ptr<socket> m_socket;
  88. bool m_authentified = false;
  89. bool m_extendedSMTP = false;
  90. std::map <string, std::vector <string> > m_extensions;
  91. vmime::shared_ptr<timeoutHandler> m_timeoutHandler;
  92. const bool m_isSMTPS;
  93. bool m_secured = false;
  94. vmime::shared_ptr<connectionInfos> m_cntInfos;
  95. // Service infos
  96. static SMTPServiceInfos sm_infos;
  97. // additional data
  98. std::vector<sFailedRecip> mTemporaryFailedRecipients;
  99. std::vector<sFailedRecip> mPermanentFailedRecipients;
  100. bool m_bDSNRequest = false;
  101. std::string m_strDSNTrackid;
  102. SMTPResponse::state m_response_state;
  103. };
  104. } // smtp
  105. } // net
  106. } // vmime
  107. #endif // MAPI_NET_SMTP_SMTPTRANSPORT_HPP_INCLUDED