Tweak naming of KDM emails and attachments.
authorCarl Hetherington <cth@carlh.net>
Wed, 7 Oct 2015 22:31:07 +0000 (23:31 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 9 Oct 2015 12:45:00 +0000 (13:45 +0100)
src/lib/cinema_kdms.cc
src/lib/cinema_kdms.h
src/lib/emailer.cc
src/lib/emailer.h
src/lib/screen_kdm.cc
src/lib/screen_kdm.h
src/tools/dcpomatic_kdm.cc

index 9b839a3545f4f8597f6bb2c1b65bf0ecf8133ef7..9584a3f236200a22bbabd576221de1784d9bdcce 100644 (file)
@@ -35,11 +35,8 @@ using std::cout;
 using std::string;
 using boost::shared_ptr;
 
-/** @param filename_first_part First part of name of KDM files inside the zip file
- *  (perhaps the name of the film).
- */
 void
-CinemaKDMs::make_zip_file (string filename_first_part, boost::filesystem::path zip_file) const
+CinemaKDMs::make_zip_file (string film_name, boost::filesystem::path zip_file) const
 {
        int error;
        struct zip* zip = zip_open (zip_file.string().c_str(), ZIP_CREATE | ZIP_EXCL, &error);
@@ -61,7 +58,7 @@ CinemaKDMs::make_zip_file (string filename_first_part, boost::filesystem::path z
                        throw StringError ("could not create ZIP source");
                }
 
-               if (zip_add (zip, i.filename(filename_first_part).c_str(), source) == -1) {
+               if (zip_add (zip, i.filename(film_name).c_str(), source) == -1) {
                        throw StringError ("failed to add KDM to ZIP archive");
                }
        }
@@ -107,18 +104,18 @@ CinemaKDMs::collect (list<ScreenKDM> screen_kdms)
 }
 
 void
-CinemaKDMs::write_zip_files (string filename_first_part, list<CinemaKDMs> cinema_kdms, boost::filesystem::path directory)
+CinemaKDMs::write_zip_files (string film_name, list<CinemaKDMs> cinema_kdms, boost::filesystem::path directory)
 {
        BOOST_FOREACH (CinemaKDMs const & i, cinema_kdms) {
                boost::filesystem::path path = directory;
                path /= tidy_for_filename (i.cinema->name) + ".zip";
-               i.make_zip_file (filename_first_part, path);
+               i.make_zip_file (film_name, path);
        }
 }
 
 /* XXX: should probably get from/to from the KDMs themselves */
 void
-CinemaKDMs::email (string filename_first_part, string cpl_name, list<CinemaKDMs> cinema_kdms, dcp::LocalTime from, dcp::LocalTime to, shared_ptr<Job> job)
+CinemaKDMs::email (string film_name, string cpl_name, list<CinemaKDMs> cinema_kdms, dcp::LocalTime from, dcp::LocalTime to, shared_ptr<Job> job)
 {
        Config* config = Config::instance ();
 
@@ -126,9 +123,7 @@ CinemaKDMs::email (string filename_first_part, string cpl_name, list<CinemaKDMs>
 
                boost::filesystem::path zip_file = boost::filesystem::temp_directory_path ();
                zip_file /= boost::filesystem::unique_path().string() + ".zip";
-               i.make_zip_file (filename_first_part, zip_file);
-
-               /* Send email */
+               i.make_zip_file (film_name, zip_file);
 
                string subject = config->kdm_subject();
                SafeStringStream start;
@@ -161,7 +156,8 @@ CinemaKDMs::email (string filename_first_part, string cpl_name, list<CinemaKDMs>
                        email.add_bcc (config->kdm_bcc ());
                }
 
-               email.add_attachment (zip_file, "application/zip");
+               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);
        }
 }
index ecff32ff42c521c24817ea5fcb1d1501c1896d3e..49f29cc42b05562927d001461b303b2899d37eac 100644 (file)
@@ -25,12 +25,12 @@ class Job;
 class CinemaKDMs
 {
 public:
-       void make_zip_file (std::string name_first_part, boost::filesystem::path zip_file) const;
+       void make_zip_file (std::string film_name, boost::filesystem::path zip_file) const;
 
        static std::list<CinemaKDMs> collect (std::list<ScreenKDM> kdms);
-       static void write_zip_files (std::string filename_first_part, std::list<CinemaKDMs> cinema_kdms, boost::filesystem::path directory);
+       static void write_zip_files (std::string film_name, std::list<CinemaKDMs> cinema_kdms, boost::filesystem::path directory);
        static void email (
-               std::string filename_first_part,
+               std::string film_name,
                std::string cpl_name,
                std::list<CinemaKDMs> cinema_kdms,
                dcp::LocalTime from,
index 0febb56ab6601ff3eec9350708ca0cbc291cce24..0193f36051c216724eeeaeb0cda6f9d443ad38da 100644 (file)
@@ -61,9 +61,13 @@ Emailer::add_bcc (string bcc)
 }
 
 void
-Emailer::add_attachment (boost::filesystem::path attachment, string mime_type)
+Emailer::add_attachment (boost::filesystem::path file, string name, string mime_type)
 {
-       _attachments.push_back (make_pair (attachment, mime_type));
+       Attachment a;
+       a.file = file;
+       a.name = name;
+       a.mime_type = mime_type;
+       _attachments.push_back (a);
 }
 
 static size_t
@@ -129,18 +133,18 @@ Emailer::send (shared_ptr<Job> job)
 
        email << _body;
 
-       for (list<pair<boost::filesystem::path, string> >::const_iterator i = _attachments.begin(); i != _attachments.end(); ++i) {
+       BOOST_FOREACH (Attachment i, _attachments) {
                email << "\r\n\r\n--" << boundary << "\r\n"
-                     << "Content-Type: " << i->second << "; name=" << i->first.leaf() << "\r\n"
+                     << "Content-Type: " << i.mime_type << "; name=" << i.name << "\r\n"
                      << "Content-Transfer-Encoding: Base64\r\n"
-                     << "Content-Disposition: attachment; filename=" << i->first.leaf() << "\r\n\r\n";
+                     << "Content-Disposition: attachment; filename=" << i.name << "\r\n\r\n";
 
                BIO* b64 = BIO_new (BIO_f_base64());
 
                BIO* bio = BIO_new (BIO_s_mem());
                bio = BIO_push (b64, bio);
 
-               Data data (i->first);
+               Data data (i.file);
                BIO_write (bio, data.data().get(), data.size());
                (void) BIO_flush (bio);
 
index 4b4d1f6f77d4013905d2609decbb2bd9ef430c57..9e6fca5b05f1665a8b34271991fa430e66d8ec21 100644 (file)
@@ -27,7 +27,7 @@ public:
 
        void add_cc (std::string cc);
        void add_bcc (std::string bcc);
-       void add_attachment (boost::filesystem::path attachment, std::string);
+       void add_attachment (boost::filesystem::path file, std::string name, std::string mime_type);
 
        void send (boost::shared_ptr<Job> job);
 
@@ -44,7 +44,14 @@ private:
        std::string _body;
        std::list<std::string> _cc;
        std::list<std::string> _bcc;
-       std::list<std::pair<boost::filesystem::path, std::string> > _attachments;
+
+       struct Attachment {
+               boost::filesystem::path file;
+               std::string name;
+               std::string mime_type;
+       };
+
+       std::list<Attachment> _attachments;
        std::string _email;
        size_t _offset;
        boost::scoped_array<char> _notes_buffer;
index 60a81399d3c79c0714e393230bbf0137ec07d845..bbe539801dbdb400ab0e15e57c79ac2d4c2dc5d0 100644 (file)
@@ -33,19 +33,18 @@ operator== (ScreenKDM const & a, ScreenKDM const & b)
        return a.screen == b.screen && a.kdm == b.kdm;
 }
 
-/** @param first_part first part of the filename (perhaps the name of the film) */
 string
-ScreenKDM::filename (string first_part) const
+ScreenKDM::filename (string film_name) const
 {
-       return tidy_for_filename (first_part) + "_" + tidy_for_filename (screen->cinema->name) + "_" + tidy_for_filename (screen->name) + ".kdm.xml";
+       return tidy_for_filename (film_name) + "_" + tidy_for_filename (screen->cinema->name) + "_" + tidy_for_filename (screen->name) + ".kdm.xml";
 }
 
 void
-ScreenKDM::write_files (string name_first_part, list<ScreenKDM> screen_kdms, boost::filesystem::path directory)
+ScreenKDM::write_files (string film_name, list<ScreenKDM> screen_kdms, boost::filesystem::path directory)
 {
        /* Write KDMs to the specified directory */
        BOOST_FOREACH (ScreenKDM const & i, screen_kdms) {
-               boost::filesystem::path out = directory / i.filename(name_first_part);
+               boost::filesystem::path out = directory / i.filename(film_name);
                i.kdm.as_xml (out);
        }
 }
index e2a16d3b726cc4501082909c5c71e044d0939743..6230ea091b3b7dfbeb3dbb6454e869d50eda5399 100644 (file)
@@ -34,9 +34,9 @@ public:
                , kdm (k)
        {}
 
-       std::string filename (std::string first_part) const;
+       std::string filename (std::string film_name) const;
 
-       static void write_files (std::string name_first_part, std::list<ScreenKDM> screen_kdms, boost::filesystem::path directory);
+       static void write_files (std::string film_name, std::list<ScreenKDM> screen_kdms, boost::filesystem::path directory);
 
        boost::shared_ptr<Screen> screen;
        dcp::EncryptedKDM kdm;
index bc58be914a93ae1c13ad243748a9f9f1b9004908..351c61750a37de9dbcf28ee978710abf9215d9e9 100644 (file)
@@ -50,6 +50,7 @@
 
 using std::exception;
 using std::list;
+using std::string;
 using boost::shared_ptr;
 using boost::bind;
 
@@ -273,8 +274,12 @@ private:
                                        wxString::Format (s, int(screen_kdms.size()), std_to_wx(_output->directory().string()).data())
                                        );
                        } else {
+                               string film_name = decrypted.annotation_text ();
+                               if (film_name.empty ()) {
+                                       film_name = decrypted.content_title_text ();
+                               }
                                shared_ptr<Job> job (new SendKDMEmailJob (
-                                                            decrypted.annotation_text(),
+                                                            film_name,
                                                             decrypted.content_title_text(),
                                                             _timing->from(), _timing->until(),
                                                             CinemaKDMs::collect (screen_kdms)