X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Femailer.cc;fp=src%2Flib%2Femailer.cc;h=2d4cf3976ba1334b62c3628abd75d94ef498d5ad;hb=3541f0b68d087998c9f73863f5b7ec7f7ed59523;hp=9f15df5dcf5bbf4aa5ad5690435ae41da634b475;hpb=1c601e4a63d19c75e6bd4438ba4b885b23e81de4;p=dcpomatic.git diff --git a/src/lib/emailer.cc b/src/lib/emailer.cc index 9f15df5dc..2d4cf3976 100644 --- a/src/lib/emailer.cc +++ b/src/lib/emailer.cc @@ -174,11 +174,6 @@ Emailer::send (shared_ptr job) throw NetworkError ("Could not initialise libcurl"); } - CURLM* mcurl = curl_multi_init (); - if (!mcurl) { - throw NetworkError ("Could not initialise libcurl"); - } - curl_easy_setopt (curl, CURLOPT_URL, String::compose ( "smtp://%1:%2", Config::instance()->mail_server().c_str(), @@ -218,91 +213,12 @@ Emailer::send (shared_ptr job) curl_easy_setopt (curl, CURLOPT_DEBUGFUNCTION, curl_debug_shim); curl_easy_setopt (curl, CURLOPT_DEBUGDATA, this); - curl_multi_add_handle (mcurl, curl); - - time_t start = time (0); - - int still_running = 1; - curl_multi_perform (mcurl, &still_running); - - while (still_running) { - - fd_set fdread; - fd_set fdwrite; - fd_set fdexcep; - - FD_ZERO (&fdread); - FD_ZERO (&fdwrite); - FD_ZERO (&fdexcep); - - struct timeval timeout; - timeout.tv_sec = 1; - timeout.tv_usec = 0; - - long curl_timeout = -1; - curl_multi_timeout (mcurl, &curl_timeout); - if (curl_timeout >= 0) { - timeout.tv_sec = curl_timeout / 1000; - if (timeout.tv_sec > 1) { - timeout.tv_sec = 1; - } else { - timeout.tv_usec = (curl_timeout % 1000) * 1000; - } - } - - int maxfd = -1; - CURLMcode mc = curl_multi_fdset (mcurl, &fdread, &fdwrite, &fdexcep, &maxfd); - - if (mc != CURLM_OK) { - throw KDMError (String::compose ("Failed to send KDM email to %1", address_list (_to))); - } - - int rc; - if (maxfd == -1) { -#ifdef DCPOMATIC_WINDOWS - Sleep (100); - rc = 0; -#else - struct timeval wait = { 0, 100 * 1000}; - rc = select (0, 0, 0, 0, &wait); -#endif - } else { - rc = select (maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); - } - - if (rc < 0) { - throw KDMError ("Failed to send KDM email"); - } - - mc = curl_multi_perform (mcurl, &still_running); - if (mc != CURLM_OK) { - throw KDMError (String::compose ("Failed to send KDM email (%1)", curl_multi_strerror (mc))); - } - - if (job) { - job->set_progress_unknown (); - } - - if ((time(0) - start) > 10) { - throw KDMError (_("Failed to send KDM email (timed out)")); - } + CURLcode const r = curl_easy_perform (curl); + if (r != CURLE_OK) { + throw KDMError (String::compose (_("Failed to send KDM email (%1)"), curl_easy_strerror (r))); } - int messages; - do { - CURLMsg* m = curl_multi_info_read (mcurl, &messages); - if (m && m->data.result != CURLE_OK) { - throw KDMError (String::compose ("Failed to send KDM email (%1)", curl_easy_strerror (m->data.result))); - } - } while (messages > 0); - - /* XXX: we should do this stuff when an exception is thrown, but curl_multi_remove_handle - seems to hang if we try that. - */ - curl_slist_free_all (recipients); - curl_multi_remove_handle (mcurl, curl); - curl_multi_cleanup (mcurl); curl_easy_cleanup (curl); curl_global_cleanup (); }