|
11 | 11 | #include <vmime/mailboxList.hpp> |
12 | 12 | #include <vmime/message.hpp> |
13 | 13 | #include <vmime/net/transport.hpp> |
| 14 | +#include <vmime/security/cert/defaultCertificateVerifier.hpp> |
14 | 15 | #include <vmime/utility/inputStreamStringAdapter.hpp> |
15 | 16 | #include <gromox/mail.hpp> |
16 | 17 | #include <gromox/mail_func.hpp> |
@@ -70,6 +71,27 @@ ec_error_t cu_rcpt_to_list(const TPROPVAL_ARRAY &props, const char *org_name, |
70 | 71 | return ecServerOOM; |
71 | 72 | } |
72 | 73 |
|
| 74 | +static vmime::shared_ptr<vmime::net::transport> make_transport(const char *url) |
| 75 | +{ |
| 76 | + vmime::utility::url vurl(url); |
| 77 | + bool uv = strncmp(url, "smtp+unverifiedtls:", 9) == 0; |
| 78 | + bool tls = uv || strncmp(url, "smtp+tls:", 9) == 0; |
| 79 | + if (tls) |
| 80 | + vurl.setProtocol("smtp"); |
| 81 | + auto xp = vmime::net::session::create()->getTransport(std::move(vurl)); |
| 82 | + if (!tls) |
| 83 | + return xp; |
| 84 | + xp->setProperty("connection.tls", true); |
| 85 | + if (!uv) |
| 86 | + return xp; |
| 87 | + |
| 88 | + struct uv_impl : public vmime::security::cert::certificateVerifier { |
| 89 | + void verify(const vmime::shared_ptr<vmime::security::cert::certificateChain> &chain, const std::string &host) {} |
| 90 | + }; |
| 91 | + xp->setCertificateVerifier(vmime::make_shared<uv_impl>()); |
| 92 | + return xp; |
| 93 | +} |
| 94 | + |
73 | 95 | ec_error_t cu_send_mail(MAIL &mail, const char *smtp_url, const char *sender, |
74 | 96 | const std::vector<std::string> &rcpt_list) try |
75 | 97 | { |
@@ -97,7 +119,7 @@ ec_error_t cu_send_mail(MAIL &mail, const char *smtp_url, const char *sender, |
97 | 119 | content.clear(); |
98 | 120 | vmime::shared_ptr<vmime::net::transport> xprt; |
99 | 121 | try { |
100 | | - xprt = vmime::net::session::create()->getTransport(vmime::utility::url(smtp_url)); |
| 122 | + xprt = make_transport(smtp_url); |
101 | 123 | /* vmime default timeout is 30s */ |
102 | 124 | xprt->connect(); |
103 | 125 | } catch (const vmime::exception &e) { |
@@ -140,7 +162,7 @@ ec_error_t cu_send_vmail(vmime::shared_ptr<vmime::message> msg, |
140 | 162 | vrcpt_list.appendMailbox(vmime::make_shared<vmime::mailbox>(r)); |
141 | 163 | vmime::shared_ptr<vmime::net::transport> xprt; |
142 | 164 | try { |
143 | | - xprt = vmime::net::session::create()->getTransport(vmime::utility::url(smtp_url)); |
| 165 | + xprt = make_transport(smtp_url); |
144 | 166 | /* vmime default timeout is 30s */ |
145 | 167 | xprt->connect(); |
146 | 168 | } catch (const vmime::exception &e) { |
|
0 commit comments