diff options
-rw-r--r-- | src/message/sender.cpp | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/src/message/sender.cpp b/src/message/sender.cpp index a561392..8b5371a 100644 --- a/src/message/sender.cpp +++ b/src/message/sender.cpp @@ -66,41 +66,42 @@ namespace smtp::message //TODO сделать деинициализацию через регистратор деинициализаторов curl_slist_free_all( recipients ); curl_easy_cleanup( curl ); - } - - // - //Private methods - // - bool smtp::message::Sender::InitCurl( CURL* curl, WriteThis const& upload_ctx, std::string const& mail_from ) - { - if( !curl ) - { - return false; - } - - if( mSettingsStorage.IsNeedAuth()) - { - curl_easy_setopt( curl, CURLOPT_USERNAME, mSettingsStorage.GetUserName().c_str()); - curl_easy_setopt( curl, CURLOPT_PASSWORD, mSettingsStorage.GetPassword().c_str()); - } - - curl_easy_setopt( curl, CURLOPT_URL, GetHostPortData().c_str()); - - mSettingsStorage.IsNeedSsl() ? curl_easy_setopt( curl, CURLOPT_USE_SSL, ( long ) CURLUSESSL_ALL ) : - curl_easy_setopt( curl, CURLOPT_USE_SSL, ( long ) CURLUSESSL_NONE ); - - curl_easy_setopt( curl, CURLOPT_MAIL_FROM, mail_from.c_str()); - - curl_easy_setopt( curl, CURLOPT_READFUNCTION, ReadCallBack ); - curl_easy_setopt( curl, CURLOPT_READDATA, &upload_ctx ); + } + + // + //Private methods + // + bool smtp::message::Sender::InitCurl( CURL* curl, WriteThis const& upload_ctx, std::string const& mail_from ) + { + if( !curl ) + { + return false; + } + + if( mSettingsStorage.IsNeedAuth()) + { + curl_easy_setopt( curl, CURLOPT_USERNAME, mSettingsStorage.GetUserName().c_str()); + curl_easy_setopt( curl, CURLOPT_PASSWORD, mSettingsStorage.GetPassword().c_str()); + } + + curl_easy_setopt( curl, CURLOPT_URL, GetHostPortData().c_str()); + + mSettingsStorage.IsNeedSsl() ? curl_easy_setopt( curl, CURLOPT_USE_SSL, ( long ) CURLUSESSL_ALL ) : + curl_easy_setopt( curl, CURLOPT_USE_SSL, ( long ) CURLUSESSL_NONE ); + + curl_easy_setopt( curl, CURLOPT_MAIL_FROM, mail_from.c_str()); + + curl_easy_setopt( curl, CURLOPT_READFUNCTION, ReadCallBack ); + curl_easy_setopt( curl, CURLOPT_READDATA, &upload_ctx ); curl_easy_setopt( curl, CURLOPT_UPLOAD, 1L ); - curl_easy_setopt( curl, CURLOPT_VERBOSE, 1L ); - return true; - } + curl_easy_setopt( curl, CURLOPT_NOPROGRESS, 1L ); - void - Sender::UpdateMailText( std::string const& mail_from, std::string const& subject, std::string const& text ) const - { + return true; + } + + void + Sender::UpdateMailText( std::string const& mail_from, std::string const& subject, std::string const& text ) const + { auto mail_to = mMailTo.GetMailToSend(); auto text_decorator = std::make_shared < builder::Text >( text ); text_decorator->Apply( std::make_shared < builder::Date >()) @@ -108,40 +109,39 @@ namespace smtp::message .Apply( std::make_shared < builder::Cc >( mail_to )) .Apply( std::make_shared < builder::From >( mail_from )) .Apply( std::make_shared < builder::MailTo >( mail_to )); - - mText = text_decorator->Get(); - } - - void Sender::FillRecipients( CURL* curl, curl_slist* recipients ) - { - auto mail_to = mMailTo.GetMailToSend(); - for( const auto& recipient: mail_to ) - { - recipients = curl_slist_append( recipients, recipient.c_str()); - } - - curl_easy_setopt( curl, CURLOPT_MAIL_RCPT, recipients ); - } - - std::string Sender::GetHostPortData() const - { - auto result = "smtp://" + mSettingsStorage.GetHost(); - if( !mSettingsStorage.GetPort().empty()) - { - result += ":" + mSettingsStorage.GetPort(); - } - return result; - } - - //TODO Надо убрать этот ужас. Без статики!!! - size_t Sender::ReadCallBack( void* ptr, size_t size, size_t nmemb, void* userp ) - { - auto pooh = reinterpret_cast<WriteThis*>( userp ); - if( size * nmemb < 1 || pooh->counter++ > 0 ) - { - return 0; - } - memcpy( ptr, mText.c_str(), mText.size()); - return mText.size(); - } + mText = text_decorator->Get(); + } + + void Sender::FillRecipients( CURL* curl, curl_slist* recipients ) + { + auto mail_to = mMailTo.GetMailToSend(); + for( const auto& recipient: mail_to ) + { + recipients = curl_slist_append( recipients, recipient.c_str()); + } + + curl_easy_setopt( curl, CURLOPT_MAIL_RCPT, recipients ); + } + + std::string Sender::GetHostPortData() const + { + auto result = "smtp://" + mSettingsStorage.GetHost(); + if( !mSettingsStorage.GetPort().empty()) + { + result += ":" + mSettingsStorage.GetPort(); + } + return result; + } + + //TODO Надо убрать этот ужас. Без статики!!! + size_t Sender::ReadCallBack( void* ptr, size_t size, size_t nmemb, void* userp ) + { + auto pooh = reinterpret_cast<WriteThis*>( userp ); + if( size * nmemb < 1 || pooh->counter++ > 0 ) + { + return 0; + } + memcpy( ptr, mText.c_str(), mText.size()); + return mText.size(); + } } |