diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-05-06 00:55:18 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-06-03 22:26:16 +0200 |
| commit | cacb0750b9e6efbefa5ffa33a0df9552db5483db (patch) | |
| tree | 98deb6fb61004f9c1dadca65bf3f74c3a15929ad /src/lib | |
| parent | 2bdee4f8e7712c50125b296a50c967101e619f94 (diff) | |
Allow sending KDMs to more emails (#2244).
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/kdm_cli.cc | 4 | ||||
| -rw-r--r-- | src/lib/kdm_with_metadata.cc | 38 | ||||
| -rw-r--r-- | src/lib/kdm_with_metadata.h | 3 | ||||
| -rw-r--r-- | src/lib/send_kdm_email_job.cc | 17 | ||||
| -rw-r--r-- | src/lib/send_kdm_email_job.h | 8 |
5 files changed, 49 insertions, 21 deletions
diff --git a/src/lib/kdm_cli.cc b/src/lib/kdm_cli.cc index e89da6e37..4c1a55d7d 100644 --- a/src/lib/kdm_cli.cc +++ b/src/lib/kdm_cli.cc @@ -250,7 +250,7 @@ from_film ( } write_files (kdms, zip, output, container_name_format, filename_format, verbose, out); if (email) { - send_emails ({kdms}, container_name_format, filename_format, film->dcp_name()); + send_emails ({kdms}, container_name_format, filename_format, film->dcp_name(), {}); } } catch (FileError& e) { throw KDMCLIError (String::compose("%1 (%2)", e.what(), e.file().string())); @@ -383,7 +383,7 @@ from_dkdm ( } write_files (kdms, zip, output, container_name_format, filename_format, verbose, out); if (email) { - send_emails ({kdms}, container_name_format, filename_format, dkdm.annotation_text().get_value_or("")); + send_emails ({kdms}, container_name_format, filename_format, dkdm.annotation_text().get_value_or(""), {}); } } catch (FileError& e) { throw KDMCLIError (String::compose("%1 (%2)", e.what(), e.file().string())); diff --git a/src/lib/kdm_with_metadata.cc b/src/lib/kdm_with_metadata.cc index a826327ca..5c1ab0aa6 100644 --- a/src/lib/kdm_with_metadata.cc +++ b/src/lib/kdm_with_metadata.cc @@ -38,6 +38,7 @@ using std::function; using std::list; using std::shared_ptr; using std::string; +using std::vector; using boost::optional; @@ -201,7 +202,8 @@ send_emails ( list<list<KDMWithMetadataPtr>> kdms, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, - string cpl_name + string cpl_name, + vector<string> extra_addresses ) { auto config = Config::instance (); @@ -255,22 +257,38 @@ send_emails ( email.add_attachment (zip_file, container_name_format.get(first->name_values(), ".zip"), "application/zip"); + auto log_details = [](Emailer& 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); + dcpomatic_log->log(email.notes(), LogEntry::TYPE_DEBUG_EMAIL); + }; + try { email.send (config->mail_server(), config->mail_port(), config->mail_protocol(), config->mail_user(), config->mail_password()); } catch (...) { boost::filesystem::remove (zip_file); - 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); - dcpomatic_log->log (email.notes(), LogEntry::TYPE_DEBUG_EMAIL); + log_details (email); throw; } - boost::filesystem::remove (zip_file); + log_details (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); - dcpomatic_log->log (email.notes(), LogEntry::TYPE_DEBUG_EMAIL); + for (auto extra: extra_addresses) { + Emailer email (config->kdm_from(), { extra }, subject, body); + email.add_attachment (zip_file, container_name_format.get(first->name_values(), ".zip"), "application/zip"); + + try { + email.send (config->mail_server(), config->mail_port(), config->mail_protocol(), config->mail_user(), config->mail_password()); + } catch (...) { + boost::filesystem::remove (zip_file); + log_details (email); + throw; + } + + log_details (email); + } + + boost::filesystem::remove (zip_file); } } diff --git a/src/lib/kdm_with_metadata.h b/src/lib/kdm_with_metadata.h index 6c961768a..df9f04125 100644 --- a/src/lib/kdm_with_metadata.h +++ b/src/lib/kdm_with_metadata.h @@ -107,7 +107,8 @@ void send_emails ( std::list<std::list<KDMWithMetadataPtr>> kdms, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, - std::string cpl_name + std::string cpl_name, + std::vector<std::string> extra_addresses ); #endif diff --git a/src/lib/send_kdm_email_job.cc b/src/lib/send_kdm_email_job.cc index d4d13fa48..bffdc9e58 100644 --- a/src/lib/send_kdm_email_job.cc +++ b/src/lib/send_kdm_email_job.cc @@ -19,18 +19,19 @@ */ -#include "send_kdm_email_job.h" #include "compose.hpp" -#include "kdm_with_metadata.h" #include "film.h" +#include "kdm_with_metadata.h" +#include "send_kdm_email_job.h" #include <list> #include "i18n.h" -using std::string; using std::list; using std::shared_ptr; +using std::string; +using std::vector; using boost::optional; @@ -38,12 +39,14 @@ SendKDMEmailJob::SendKDMEmailJob ( list<KDMWithMetadataPtr> kdms, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, - string cpl_name + string cpl_name, + vector<string> extra_addresses ) : Job (shared_ptr<Film>()) , _container_name_format (container_name_format) , _filename_format (filename_format) , _cpl_name (cpl_name) + , _extra_addresses (extra_addresses) { for (auto i: kdms) { list<KDMWithMetadataPtr> s; @@ -63,13 +66,15 @@ SendKDMEmailJob::SendKDMEmailJob ( list<list<KDMWithMetadataPtr> > kdms, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, - string cpl_name + string cpl_name, + vector<string> extra_addresses ) : Job (shared_ptr<Film>()) , _container_name_format (container_name_format) , _filename_format (filename_format) , _cpl_name (cpl_name) , _kdms (kdms) + , _extra_addresses (extra_addresses) { } @@ -104,7 +109,7 @@ void SendKDMEmailJob::run () { set_progress_unknown (); - send_emails (_kdms, _container_name_format, _filename_format, _cpl_name); + send_emails (_kdms, _container_name_format, _filename_format, _cpl_name, _extra_addresses); set_progress (1); set_state (FINISHED_OK); } diff --git a/src/lib/send_kdm_email_job.h b/src/lib/send_kdm_email_job.h index 76fb72b8a..621254e0f 100644 --- a/src/lib/send_kdm_email_job.h +++ b/src/lib/send_kdm_email_job.h @@ -24,6 +24,7 @@ #include <dcp/types.h> #include <dcp/name_format.h> #include <boost/filesystem.hpp> +#include <vector> namespace dcpomatic { @@ -41,14 +42,16 @@ public: std::list<KDMWithMetadataPtr> kdms, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, - std::string cpl_name + std::string cpl_name, + std::vector<std::string> extra_addresses ); SendKDMEmailJob ( std::list<std::list<KDMWithMetadataPtr>> kdms, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, - std::string cpl_name + std::string cpl_name, + std::vector<std::string> extra_addresses ); ~SendKDMEmailJob (); @@ -62,4 +65,5 @@ private: dcp::NameFormat _filename_format; std::string _cpl_name; std::list<std::list<KDMWithMetadataPtr>> _kdms; + std::vector<std::string> _extra_addresses; }; |
