Fix lack of email sending if there are no cinema addresses (only extra ones) (#2514).
authorCarl Hetherington <cth@carlh.net>
Thu, 20 Apr 2023 19:49:57 +0000 (21:49 +0200)
committerCarl Hetherington <cth@carlh.net>
Thu, 20 Apr 2023 19:49:57 +0000 (21:49 +0200)
src/lib/kdm_with_metadata.cc

index e4aea1be70d97524ef02c73f88de289d35a3c66f..5cbadc911a0dfba290dec7661f575688ad68e0c5 100644 (file)
@@ -220,10 +220,6 @@ send_emails (
 
                auto first = kdms_for_cinema.front();
 
-               if (first->emails().empty()) {
-                       continue;
-               }
-
                auto zip_file = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
                boost::filesystem::create_directories (zip_file);
                zip_file /= container_name_format.get(first->name_values(), ".zip");
@@ -251,6 +247,11 @@ send_emails (
                boost::algorithm::replace_all (body, "$SCREENS", screens.substr (0, screens.length() - 2));
 
                auto emails = first->emails();
+               std::copy(extra_addresses.begin(), extra_addresses.end(), std::back_inserter(emails));
+               if (emails.empty()) {
+                       continue;
+               }
+
                Emailer email (config->kdm_from(), { emails.front() }, subject, body);
 
                /* Use CC for the second and subsequent email addresses, so we seem less spammy (#2310) */
@@ -284,21 +285,6 @@ send_emails (
 
                log_details (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);
        }
 }