diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-09-25 12:20:26 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-09-25 12:20:26 +0100 |
| commit | 5909b9672821c1d5ea974761316dc0f3df558349 (patch) | |
| tree | f1eaa4603f26663f1facb9246f852f6c7f4a5bb8 /src/lib | |
| parent | 13d924ad844ca6b642880910e21c5e322dbc4408 (diff) | |
Part of work to add emailing of KDMs.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/config.cc | 5 | ||||
| -rw-r--r-- | src/lib/config.h | 9 | ||||
| -rw-r--r-- | src/lib/util.cc | 50 | ||||
| -rw-r--r-- | src/lib/wscript | 1 |
4 files changed, 65 insertions, 0 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc index 3a3a87faa..e53e15a81 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -58,6 +58,9 @@ Config::Config () , _default_container (Ratio::from_id ("185")) , _default_dcp_content_type (DCPContentType::from_dci_name ("TST")) , _default_j2k_bandwidth (200000000) + , _kdm_email ( + "Dear Projectionist\n\nPlease find attached KDMs for $CPL_NAME.\n\nBest regards,\nDCP-o-matic" + ) { _allowed_dcp_frame_rates.push_back (24); _allowed_dcp_frame_rates.push_back (25); @@ -142,6 +145,7 @@ Config::read () _mail_server = f.string_child ("MailServer"); _kdm_from = f.string_child ("KDMFrom"); + _kdm_email = f.string_child ("KDMEmail"); } void @@ -300,6 +304,7 @@ Config::write () const root->add_child("MailServer")->add_child_text (_mail_server); root->add_child("KDMFrom")->add_child_text (_kdm_from); + root->add_child("KDMEmail")->add_child_text (_kdm_email); doc.write_to_file_formatted (file(false).string ()); } diff --git a/src/lib/config.h b/src/lib/config.h index 8dcb513a5..7dd5abd17 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -142,6 +142,10 @@ public: return _kdm_from; } + std::string kdm_email () const { + return _kdm_email; + } + /** @param n New number of local encoding threads */ void set_num_local_encoding_threads (int n) { _num_local_encoding_threads = n; @@ -244,6 +248,10 @@ public: void set_kdm_from (std::string f) { _kdm_from = f; } + + void set_kdm_email (std::string e) { + _kdm_email = e; + } void write () const; @@ -294,6 +302,7 @@ private: std::list<boost::shared_ptr<Cinema> > _cinemas; std::string _mail_server; std::string _kdm_from; + std::string _kdm_email; /** Singleton instance, or 0 */ static Config* _instance; diff --git a/src/lib/util.cc b/src/lib/util.cc index baa37ae7c..739a327d6 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -54,6 +54,7 @@ extern "C" { #include <libpostproc/postprocess.h> #include <libavutil/pixfmt.h> } +#include <curl/curl.h> #include "util.h" #include "exceptions.h" #include "scaler.h" @@ -816,4 +817,53 @@ tidy_for_filename (string f) return t; } + +struct EmailState +{ + string message; + int done; +}; + +static size_t +send_email_function (void* ptr, size_t size, size_t nmemb, void* userdata) +{ + EmailState* state = reinterpret_cast<EmailState*> (userdata); + + int const now = min (size * nmemb, state->message.length() - state->done); + + memcpy (ptr, state->message.c_str() + state->done, now); + state->done += now; + + return now; +} +bool +send_email (string from, string to, string message) +{ + CURL* curl = curl_easy_init (); + if (!curl) { + return true; + } + + string const url = "smtp://" + Config::instance()->mail_server(); + + curl_easy_setopt (curl, CURLOPT_URL, url.c_str ()); + curl_easy_setopt (curl, CURLOPT_MAIL_FROM, from.c_str ()); + struct curl_slist* recipients = 0; + recipients = curl_slist_append (recipients, to.c_str ()); + curl_easy_setopt (curl, CURLOPT_READFUNCTION, send_email_function); + + EmailState state; + state.message = message; + state.done = 0; + curl_easy_setopt (curl, CURLOPT_READDATA, &state); + + if (curl_easy_perform (curl) != CURLE_OK) { + return true; + } + + curl_slist_free_all (recipients); + curl_easy_cleanup (curl); + + return false; +} diff --git a/src/lib/wscript b/src/lib/wscript index e91666f7f..8c02ff158 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -74,6 +74,7 @@ def build(bld): AVCODEC AVUTIL AVFORMAT AVFILTER SWSCALE SWRESAMPLE BOOST_FILESYSTEM BOOST_THREAD BOOST_DATETIME BOOST_SIGNALS2 SNDFILE OPENJPEG POSTPROC TIFF MAGICK SSH DCP CXML GLIB LZMA XML++ + CURL """ obj.source = sources + ' version.cc' |
