Fix merge.
[dcpomatic.git] / src / lib / cinema_kdms.cc
index 37c9e1fb55cb5684aaba45612b8bdcc6c5ba2ba2..9fda6e2e9ca8132a711194580b785e6247f18054 100644 (file)
@@ -34,6 +34,7 @@
 using std::list;
 using std::cout;
 using std::string;
+using std::runtime_error;
 using boost::shared_ptr;
 
 void
@@ -56,16 +57,16 @@ CinemaKDMs::make_zip_file (string film_name, boost::filesystem::path zip_file) c
 
                struct zip_source* source = zip_source_buffer (zip, kdm->c_str(), kdm->length(), 0);
                if (!source) {
-                       throw StringError ("could not create ZIP source");
+                       throw runtime_error ("could not create ZIP source");
                }
 
                if (zip_add (zip, i.filename(film_name).c_str(), source) == -1) {
-                       throw StringError ("failed to add KDM to ZIP archive");
+                       throw runtime_error ("failed to add KDM to ZIP archive");
                }
        }
 
        if (zip_close (zip) == -1) {
-               throw StringError ("failed to close ZIP archive");
+               throw runtime_error ("failed to close ZIP archive");
        }
 }
 
@@ -118,11 +119,15 @@ CinemaKDMs::write_zip_files (string film_name, list<CinemaKDMs> cinema_kdms, boo
 /* XXX: should probably get from/to from the KDMs themselves */
 void
 CinemaKDMs::email (
-       string film_name, string cpl_name, list<CinemaKDMs> cinema_kdms, dcp::LocalTime from, dcp::LocalTime to, shared_ptr<Job> job, shared_ptr<Log> log
+       string film_name, string cpl_name, list<CinemaKDMs> cinema_kdms, dcp::LocalTime from, dcp::LocalTime to, shared_ptr<Log> log
        )
 {
        Config* config = Config::instance ();
 
+       if (config->mail_server().empty()) {
+               throw NetworkError (_("No mail server configured in preferences"));
+       }
+
        BOOST_FOREACH (CinemaKDMs const & i, cinema_kdms) {
 
                boost::filesystem::path zip_file = boost::filesystem::temp_directory_path ();
@@ -151,10 +156,10 @@ CinemaKDMs::email (
                }
                boost::algorithm::replace_all (body, "$SCREENS", screens.str().substr (0, screens.str().length() - 2));
 
-               Emailer email (config->kdm_from(), i.cinema->email, subject, body);
+               Emailer email (config->kdm_from(), i.cinema->emails, subject, body);
 
-               if (!config->kdm_cc().empty ()) {
-                       email.add_cc (config->kdm_cc ());
+               BOOST_FOREACH (string i, config->kdm_cc()) {
+                       email.add_cc (i);
                }
                if (!config->kdm_bcc().empty ()) {
                        email.add_bcc (config->kdm_bcc ());
@@ -162,7 +167,9 @@ CinemaKDMs::email (
 
                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);
+
+               Config* c = Config::instance ();
+               email.send (c->mail_server(), c->mail_port(), c->mail_user(), c->mail_password());
 
                if (log) {
                        log->log (email.notes(), LogEntry::TYPE_DEBUG_EMAIL);