From 2852855f19fadb6d7e43282e545a0bcaedc1a3f7 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 7 Oct 2015 23:31:07 +0100 Subject: [PATCH] Tweak naming of KDM emails and attachments. --- src/lib/cinema_kdms.cc | 20 ++++++++------------ src/lib/cinema_kdms.h | 6 +++--- src/lib/emailer.cc | 16 ++++++++++------ src/lib/emailer.h | 11 +++++++++-- src/lib/screen_kdm.cc | 9 ++++----- src/lib/screen_kdm.h | 4 ++-- src/tools/dcpomatic_kdm.cc | 7 ++++++- 7 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/lib/cinema_kdms.cc b/src/lib/cinema_kdms.cc index 9b839a354..9584a3f23 100644 --- a/src/lib/cinema_kdms.cc +++ b/src/lib/cinema_kdms.cc @@ -35,11 +35,8 @@ using std::cout; using std::string; using boost::shared_ptr; -/** @param filename_first_part First part of name of KDM files inside the zip file - * (perhaps the name of the film). - */ void -CinemaKDMs::make_zip_file (string filename_first_part, boost::filesystem::path zip_file) const +CinemaKDMs::make_zip_file (string film_name, boost::filesystem::path zip_file) const { int error; struct zip* zip = zip_open (zip_file.string().c_str(), ZIP_CREATE | ZIP_EXCL, &error); @@ -61,7 +58,7 @@ CinemaKDMs::make_zip_file (string filename_first_part, boost::filesystem::path z throw StringError ("could not create ZIP source"); } - if (zip_add (zip, i.filename(filename_first_part).c_str(), source) == -1) { + if (zip_add (zip, i.filename(film_name).c_str(), source) == -1) { throw StringError ("failed to add KDM to ZIP archive"); } } @@ -107,18 +104,18 @@ CinemaKDMs::collect (list screen_kdms) } void -CinemaKDMs::write_zip_files (string filename_first_part, list cinema_kdms, boost::filesystem::path directory) +CinemaKDMs::write_zip_files (string film_name, list cinema_kdms, boost::filesystem::path directory) { BOOST_FOREACH (CinemaKDMs const & i, cinema_kdms) { boost::filesystem::path path = directory; path /= tidy_for_filename (i.cinema->name) + ".zip"; - i.make_zip_file (filename_first_part, path); + i.make_zip_file (film_name, path); } } /* XXX: should probably get from/to from the KDMs themselves */ void -CinemaKDMs::email (string filename_first_part, string cpl_name, list cinema_kdms, dcp::LocalTime from, dcp::LocalTime to, shared_ptr job) +CinemaKDMs::email (string film_name, string cpl_name, list cinema_kdms, dcp::LocalTime from, dcp::LocalTime to, shared_ptr job) { Config* config = Config::instance (); @@ -126,9 +123,7 @@ CinemaKDMs::email (string filename_first_part, string cpl_name, list boost::filesystem::path zip_file = boost::filesystem::temp_directory_path (); zip_file /= boost::filesystem::unique_path().string() + ".zip"; - i.make_zip_file (filename_first_part, zip_file); - - /* Send email */ + i.make_zip_file (film_name, zip_file); string subject = config->kdm_subject(); SafeStringStream start; @@ -161,7 +156,8 @@ CinemaKDMs::email (string filename_first_part, string cpl_name, list email.add_bcc (config->kdm_bcc ()); } - email.add_attachment (zip_file, "application/zip"); + string const name = tidy_for_filename(i.cinema->name) + "_" + tidy_for_filename(film_name) + ".zip"; + email.add_attachment (zip_file, name, "application/zip"); email.send (job); } } diff --git a/src/lib/cinema_kdms.h b/src/lib/cinema_kdms.h index ecff32ff4..49f29cc42 100644 --- a/src/lib/cinema_kdms.h +++ b/src/lib/cinema_kdms.h @@ -25,12 +25,12 @@ class Job; class CinemaKDMs { public: - void make_zip_file (std::string name_first_part, boost::filesystem::path zip_file) const; + void make_zip_file (std::string film_name, boost::filesystem::path zip_file) const; static std::list collect (std::list kdms); - static void write_zip_files (std::string filename_first_part, std::list cinema_kdms, boost::filesystem::path directory); + static void write_zip_files (std::string film_name, std::list cinema_kdms, boost::filesystem::path directory); static void email ( - std::string filename_first_part, + std::string film_name, std::string cpl_name, std::list cinema_kdms, dcp::LocalTime from, diff --git a/src/lib/emailer.cc b/src/lib/emailer.cc index 0febb56ab..0193f3605 100644 --- a/src/lib/emailer.cc +++ b/src/lib/emailer.cc @@ -61,9 +61,13 @@ Emailer::add_bcc (string bcc) } void -Emailer::add_attachment (boost::filesystem::path attachment, string mime_type) +Emailer::add_attachment (boost::filesystem::path file, string name, string mime_type) { - _attachments.push_back (make_pair (attachment, mime_type)); + Attachment a; + a.file = file; + a.name = name; + a.mime_type = mime_type; + _attachments.push_back (a); } static size_t @@ -129,18 +133,18 @@ Emailer::send (shared_ptr job) email << _body; - for (list >::const_iterator i = _attachments.begin(); i != _attachments.end(); ++i) { + BOOST_FOREACH (Attachment i, _attachments) { email << "\r\n\r\n--" << boundary << "\r\n" - << "Content-Type: " << i->second << "; name=" << i->first.leaf() << "\r\n" + << "Content-Type: " << i.mime_type << "; name=" << i.name << "\r\n" << "Content-Transfer-Encoding: Base64\r\n" - << "Content-Disposition: attachment; filename=" << i->first.leaf() << "\r\n\r\n"; + << "Content-Disposition: attachment; filename=" << i.name << "\r\n\r\n"; BIO* b64 = BIO_new (BIO_f_base64()); BIO* bio = BIO_new (BIO_s_mem()); bio = BIO_push (b64, bio); - Data data (i->first); + Data data (i.file); BIO_write (bio, data.data().get(), data.size()); (void) BIO_flush (bio); diff --git a/src/lib/emailer.h b/src/lib/emailer.h index 4b4d1f6f7..9e6fca5b0 100644 --- a/src/lib/emailer.h +++ b/src/lib/emailer.h @@ -27,7 +27,7 @@ public: void add_cc (std::string cc); void add_bcc (std::string bcc); - void add_attachment (boost::filesystem::path attachment, std::string); + void add_attachment (boost::filesystem::path file, std::string name, std::string mime_type); void send (boost::shared_ptr job); @@ -44,7 +44,14 @@ private: std::string _body; std::list _cc; std::list _bcc; - std::list > _attachments; + + struct Attachment { + boost::filesystem::path file; + std::string name; + std::string mime_type; + }; + + std::list _attachments; std::string _email; size_t _offset; boost::scoped_array _notes_buffer; diff --git a/src/lib/screen_kdm.cc b/src/lib/screen_kdm.cc index 60a81399d..bbe539801 100644 --- a/src/lib/screen_kdm.cc +++ b/src/lib/screen_kdm.cc @@ -33,19 +33,18 @@ operator== (ScreenKDM const & a, ScreenKDM const & b) return a.screen == b.screen && a.kdm == b.kdm; } -/** @param first_part first part of the filename (perhaps the name of the film) */ string -ScreenKDM::filename (string first_part) const +ScreenKDM::filename (string film_name) const { - return tidy_for_filename (first_part) + "_" + tidy_for_filename (screen->cinema->name) + "_" + tidy_for_filename (screen->name) + ".kdm.xml"; + return tidy_for_filename (film_name) + "_" + tidy_for_filename (screen->cinema->name) + "_" + tidy_for_filename (screen->name) + ".kdm.xml"; } void -ScreenKDM::write_files (string name_first_part, list screen_kdms, boost::filesystem::path directory) +ScreenKDM::write_files (string film_name, list screen_kdms, boost::filesystem::path directory) { /* Write KDMs to the specified directory */ BOOST_FOREACH (ScreenKDM const & i, screen_kdms) { - boost::filesystem::path out = directory / i.filename(name_first_part); + boost::filesystem::path out = directory / i.filename(film_name); i.kdm.as_xml (out); } } diff --git a/src/lib/screen_kdm.h b/src/lib/screen_kdm.h index e2a16d3b7..6230ea091 100644 --- a/src/lib/screen_kdm.h +++ b/src/lib/screen_kdm.h @@ -34,9 +34,9 @@ public: , kdm (k) {} - std::string filename (std::string first_part) const; + std::string filename (std::string film_name) const; - static void write_files (std::string name_first_part, std::list screen_kdms, boost::filesystem::path directory); + static void write_files (std::string film_name, std::list screen_kdms, boost::filesystem::path directory); boost::shared_ptr screen; dcp::EncryptedKDM kdm; diff --git a/src/tools/dcpomatic_kdm.cc b/src/tools/dcpomatic_kdm.cc index bc58be914..351c61750 100644 --- a/src/tools/dcpomatic_kdm.cc +++ b/src/tools/dcpomatic_kdm.cc @@ -50,6 +50,7 @@ using std::exception; using std::list; +using std::string; using boost::shared_ptr; using boost::bind; @@ -273,8 +274,12 @@ private: wxString::Format (s, int(screen_kdms.size()), std_to_wx(_output->directory().string()).data()) ); } else { + string film_name = decrypted.annotation_text (); + if (film_name.empty ()) { + film_name = decrypted.content_title_text (); + } shared_ptr job (new SendKDMEmailJob ( - decrypted.annotation_text(), + film_name, decrypted.content_title_text(), _timing->from(), _timing->until(), CinemaKDMs::collect (screen_kdms) -- 2.30.2