From f610a8708f11d6052a995f31cd506bc93faafa1c Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 7 Mar 2024 16:12:22 +0100 Subject: Rename Emailer -> Email. --- src/lib/kdm_with_metadata.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/lib/kdm_with_metadata.cc') diff --git a/src/lib/kdm_with_metadata.cc b/src/lib/kdm_with_metadata.cc index 10054f01e..e7d9aa31c 100644 --- a/src/lib/kdm_with_metadata.cc +++ b/src/lib/kdm_with_metadata.cc @@ -23,7 +23,7 @@ #include "config.h" #include "cross.h" #include "dcpomatic_log.h" -#include "emailer.h" +#include "email.h" #include "kdm_with_metadata.h" #include "screen.h" #include "util.h" @@ -253,7 +253,7 @@ send_emails ( continue; } - Emailer email (config->kdm_from(), { emails.front() }, subject, body); + Email email(config->kdm_from(), { emails.front() }, subject, body); /* Use CC for the second and subsequent email addresses, so we seem less spammy (#2310) */ for (auto cc = std::next(emails.begin()); cc != emails.end(); ++cc) { @@ -269,7 +269,7 @@ send_emails ( email.add_attachment (zip_file, container_name_format.get(first->name_values(), ".zip"), "application/zip"); - auto log_details = [](Emailer& email) { + auto log_details = [](Email& email) { dcpomatic_log->log("Email content follows", LogEntry::TYPE_DEBUG_EMAIL); dcpomatic_log->log(email.email(), LogEntry::TYPE_DEBUG_EMAIL); dcpomatic_log->log("Email session follows", LogEntry::TYPE_DEBUG_EMAIL); -- cgit v1.2.3 From 0a93c0df8fd6a40b627cc53d51a249628db6b795 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 7 Mar 2024 16:40:03 +0100 Subject: Store attachment contents in the Email object. --- src/lib/email.cc | 5 ++--- src/lib/email.h | 3 ++- src/lib/kdm_with_metadata.cc | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) (limited to 'src/lib/kdm_with_metadata.cc') diff --git a/src/lib/email.cc b/src/lib/email.cc index 5017f4d28..8557b40e0 100644 --- a/src/lib/email.cc +++ b/src/lib/email.cc @@ -77,7 +77,7 @@ void Email::add_attachment(boost::filesystem::path file, string name, string mime_type) { Attachment a; - a.file = file; + a.file = dcp::ArrayData(file); a.name = name; a.mime_type = mime_type; _attachments.push_back (a); @@ -171,8 +171,7 @@ Email::send(string server, int port, EmailProtocol protocol, string user, string } bio = BIO_push (b64, bio); - ArrayData data (i.file); - BIO_write (bio, data.data(), data.size()); + BIO_write(bio, i.file.data(), i.file.size()); (void) BIO_flush (bio); char* out; diff --git a/src/lib/email.h b/src/lib/email.h index 3bcb8af4a..36398bfd8 100644 --- a/src/lib/email.h +++ b/src/lib/email.h @@ -30,6 +30,7 @@ public: void add_cc (std::string cc); void add_bcc (std::string bcc); + /** Add attachment, copying the contents of the file into memory */ void add_attachment (boost::filesystem::path file, std::string name, std::string mime_type); void send (std::string server, int port, EmailProtocol protocol, std::string user = "", std::string password = ""); @@ -61,7 +62,7 @@ private: std::vector _bcc; struct Attachment { - boost::filesystem::path file; + dcp::ArrayData file; std::string name; std::string mime_type; }; diff --git a/src/lib/kdm_with_metadata.cc b/src/lib/kdm_with_metadata.cc index e7d9aa31c..971eeac76 100644 --- a/src/lib/kdm_with_metadata.cc +++ b/src/lib/kdm_with_metadata.cc @@ -268,6 +268,7 @@ send_emails ( } email.add_attachment (zip_file, container_name_format.get(first->name_values(), ".zip"), "application/zip"); + dcp::filesystem::remove(zip_file); auto log_details = [](Email& email) { dcpomatic_log->log("Email content follows", LogEntry::TYPE_DEBUG_EMAIL); @@ -279,13 +280,10 @@ send_emails ( try { email.send (config->mail_server(), config->mail_port(), config->mail_protocol(), config->mail_user(), config->mail_password()); } catch (...) { - dcp::filesystem::remove(zip_file); log_details (email); throw; } log_details (email); - - dcp::filesystem::remove(zip_file); } } -- cgit v1.2.3 From 04b5957318df591f56e0a5d39720df143dc8230d Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 7 Mar 2024 23:33:03 +0100 Subject: Fix screen name order in KDM emails. --- src/lib/kdm_with_metadata.cc | 9 ++++----- src/lib/util.cc | 28 ++++++++++++++++++++++++++++ src/lib/util.h | 1 + test/util_test.cc | 11 +++++++++++ 4 files changed, 44 insertions(+), 5 deletions(-) (limited to 'src/lib/kdm_with_metadata.cc') diff --git a/src/lib/kdm_with_metadata.cc b/src/lib/kdm_with_metadata.cc index 971eeac76..f7ff84435 100644 --- a/src/lib/kdm_with_metadata.cc +++ b/src/lib/kdm_with_metadata.cc @@ -238,14 +238,13 @@ send_emails ( auto subject = substitute_variables(config->kdm_subject()); auto body = substitute_variables(config->kdm_email()); - string screens; + vector screens; for (auto kdm: kdms_for_cinema) { - auto screen_name = kdm->get('s'); - if (screen_name) { - screens += *screen_name + ", "; + if (auto screen_name = kdm->get('s')) { + screens.push_back(*screen_name); } } - boost::algorithm::replace_all (body, "$SCREENS", screens.substr (0, screens.length() - 2)); + boost::algorithm::replace_all(body, "$SCREENS", screen_names_to_string(screens)); auto emails = first->emails(); std::copy(extra_addresses.begin(), extra_addresses.end(), std::back_inserter(emails)); diff --git a/src/lib/util.cc b/src/lib/util.cc index 7f6e9da5a..fe6602de3 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1123,3 +1123,31 @@ word_wrap(string input, int columns) return output; } + +string +screen_names_to_string(vector names) +{ + if (names.empty()) { + return {}; + } + + auto number = [](string const& s) { + return s.find_first_not_of("0123456789") == string::npos; + }; + + if (std::find_if(names.begin(), names.end(), [number](string const& s) { return !number(s); }) == names.end()) { + std::sort(names.begin(), names.end(), [](string const& a, string const& b) { + return dcp::raw_convert(a) < dcp::raw_convert(b); + }); + } else { + std::sort(names.begin(), names.end()); + } + + string result; + for (auto const& name: names) { + result += name + ", "; + } + + return result.substr(0, result.length() - 2); +} + diff --git a/src/lib/util.h b/src/lib/util.h index b92869b25..fd6fd6164 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -97,5 +97,6 @@ extern std::string error_details(boost::system::error_code ec); extern bool contains_assetmap(boost::filesystem::path dir); extern std::string word_wrap(std::string input, int columns); extern void capture_ffmpeg_logs(); +extern std::string screen_names_to_string(std::vector names); #endif diff --git a/test/util_test.cc b/test/util_test.cc index 49d0b3bc2..afcc4cfc9 100644 --- a/test/util_test.cc +++ b/test/util_test.cc @@ -155,3 +155,14 @@ BOOST_AUTO_TEST_CASE(word_wrap_test) BOOST_CHECK(word_wrap("hello this is a longer bit of text and it should be word-wrapped", 31) == string{"hello this is a longer bit of \ntext and it should be word-\nwrapped\n"}); BOOST_CHECK_EQUAL(word_wrap("hellocan'twrapthissadly", 5), "hello\ncan't\nwrapt\nhissa\ndly\n"); } + + +BOOST_AUTO_TEST_CASE(screen_names_to_string_test) +{ + BOOST_CHECK_EQUAL(screen_names_to_string({"1", "2", "3"}), "1, 2, 3"); + BOOST_CHECK_EQUAL(screen_names_to_string({"3", "2", "1"}), "1, 2, 3"); + BOOST_CHECK_EQUAL(screen_names_to_string({"39", "3", "10", "1", "2"}), "1, 2, 3, 10, 39"); + BOOST_CHECK_EQUAL(screen_names_to_string({"Sheila", "Fred", "Jim"}), "Fred, Jim, Sheila"); + BOOST_CHECK_EQUAL(screen_names_to_string({"Sheila", "Fred", "Jim", "1"}), "1, Fred, Jim, Sheila"); +} + -- cgit v1.2.3