X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fkdm.cc;h=f0ba8fb85022ac8080594767eb5b61cf127cc39d;hb=1858190cff2f960f3d1f0a5cc02c69da86088f5b;hp=108860594e2592144760965a02aeb1220f8cf02c;hpb=f4030653da8f5a0b3daebe640f485b3daf9ef091;p=dcpomatic.git diff --git a/src/lib/kdm.cc b/src/lib/kdm.cc index 108860594..f0ba8fb85 100644 --- a/src/lib/kdm.cc +++ b/src/lib/kdm.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington + Copyright (C) 2013-2015 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,19 +17,22 @@ */ -#include -#include -#include -#include -#include -#include #include "kdm.h" #include "cinema.h" +#include "screen.h" #include "exceptions.h" #include "util.h" #include "film.h" #include "config.h" #include "safe_stringstream.h" +#include "quickmail.h" +#include "compose.hpp" +#include +#include +#include +#include +#include +#include using std::list; using std::string; @@ -42,7 +45,7 @@ struct ScreenKDM : screen (s) , kdm (k) {} - + shared_ptr screen; dcp::EncryptedKDM kdm; }; @@ -68,23 +71,23 @@ struct CinemaKDMs } throw FileError ("could not create ZIP file", zip_file); } - + list > kdm_strings; - + for (list::const_iterator i = screen_kdms.begin(); i != screen_kdms.end(); ++i) { shared_ptr kdm (new string (i->kdm.as_xml ())); kdm_strings.push_back (kdm); - + struct zip_source* source = zip_source_buffer (zip, kdm->c_str(), kdm->length(), 0); if (!source) { throw StringError ("could not create ZIP source"); } - + if (zip_add (zip, kdm_filename (film, *i).c_str(), source) == -1) { throw StringError ("failed to add KDM to ZIP archive"); } } - + if (zip_close (zip) == -1) { throw StringError ("failed to close ZIP archive"); } @@ -111,9 +114,9 @@ make_screen_kdms ( ) { list kdms = film->make_kdms (screens, cpl, from, to, formulation); - + list screen_kdms; - + list >::iterator i = screens.begin (); list::iterator j = kdms.begin (); while (i != screens.end() && j != kdms.end ()) { @@ -139,18 +142,18 @@ make_cinema_kdms ( list cinema_kdms; while (!screen_kdms.empty ()) { - + /* Get all the screens from a single cinema */ CinemaKDMs ck; - + list::iterator i = screen_kdms.begin (); ck.cinema = i->screen->cinema; ck.screen_kdms.push_back (*i); list::iterator j = i; ++i; screen_kdms.remove (*j); - + while (i != screen_kdms.end ()) { if (i->screen->cinema == ck.cinema) { ck.screen_kdms.push_back (*i); @@ -225,27 +228,27 @@ email_kdms ( list cinema_kdms = make_cinema_kdms (film, screens, cpl, from, to, formulation); for (list::const_iterator i = cinema_kdms.begin(); i != cinema_kdms.end(); ++i) { - + boost::filesystem::path zip_file = boost::filesystem::temp_directory_path (); zip_file /= boost::filesystem::unique_path().string() + ".zip"; i->make_zip_file (film, zip_file); - + /* Send email */ - + quickmail_initialize (); SafeStringStream start; start << from.date() << " " << from.time_of_day(); SafeStringStream end; end << to.date() << " " << to.time_of_day(); - + string subject = Config::instance()->kdm_subject(); boost::algorithm::replace_all (subject, "$CPL_NAME", film->dcp_name ()); boost::algorithm::replace_all (subject, "$START_TIME", start.str ()); boost::algorithm::replace_all (subject, "$END_TIME", end.str ()); boost::algorithm::replace_all (subject, "$CINEMA_NAME", i->cinema->name); quickmail mail = quickmail_create (Config::instance()->kdm_from().c_str(), subject.c_str ()); - + quickmail_add_to (mail, i->cinema->email.c_str ()); if (!Config::instance()->kdm_cc().empty ()) { quickmail_add_cc (mail, Config::instance()->kdm_cc().c_str ()); @@ -253,13 +256,13 @@ email_kdms ( if (!Config::instance()->kdm_bcc().empty ()) { quickmail_add_bcc (mail, Config::instance()->kdm_bcc().c_str ()); } - + string body = Config::instance()->kdm_email().c_str(); boost::algorithm::replace_all (body, "$CPL_NAME", film->dcp_name ()); boost::algorithm::replace_all (body, "$START_TIME", start.str ()); boost::algorithm::replace_all (body, "$END_TIME", end.str ()); boost::algorithm::replace_all (body, "$CINEMA_NAME", i->cinema->name); - + SafeStringStream screens; for (list::const_iterator j = i->screen_kdms.begin(); j != i->screen_kdms.end(); ++j) { screens << j->screen->name << ", "; @@ -269,19 +272,23 @@ email_kdms ( quickmail_set_body (mail, body.c_str()); quickmail_add_attachment_file (mail, zip_file.string().c_str(), "application/zip"); - int const port = Config::instance()->mail_user().empty() ? 25 : 587; - char const* error = quickmail_send ( mail, Config::instance()->mail_server().c_str(), - port, + Config::instance()->mail_port(), Config::instance()->mail_user().c_str(), Config::instance()->mail_password().c_str() ); - + if (error) { quickmail_destroy (mail); - throw KDMError (String::compose ("Failed to send KDM email (%1)", error)); + throw KDMError ( + String::compose ( + "Failed to send KDM email to %1 (%2)", + Config::instance()->mail_server(), + error + ) + ); } quickmail_destroy (mail); }