Store attachment contents in the Email object.
authorCarl Hetherington <cth@carlh.net>
Thu, 7 Mar 2024 15:40:03 +0000 (16:40 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 7 Mar 2024 15:40:03 +0000 (16:40 +0100)
src/lib/email.cc
src/lib/email.h
src/lib/kdm_with_metadata.cc

index 5017f4d28e41819bbda4d6dec78ecfef584872c0..8557b40e0c808cf06f2e10b3e5d32bebd4dd0261 100644 (file)
@@ -77,7 +77,7 @@ void
 Email::add_attachment(boost::filesystem::path file, string name, string mime_type)
 {
        Attachment a;
-       a.file = file;
+       a.file = dcp::ArrayData(file);
        a.name = name;
        a.mime_type = mime_type;
        _attachments.push_back (a);
@@ -171,8 +171,7 @@ Email::send(string server, int port, EmailProtocol protocol, string user, string
                }
                bio = BIO_push (b64, bio);
 
-               ArrayData data (i.file);
-               BIO_write (bio, data.data(), data.size());
+               BIO_write(bio, i.file.data(), i.file.size());
                (void) BIO_flush (bio);
 
                char* out;
index 3bcb8af4aa0ca4debff214ec22b9928e86317d71..36398bfd804984f5f5179be77bc5b1a8581279c7 100644 (file)
@@ -30,6 +30,7 @@ public:
 
        void add_cc (std::string cc);
        void add_bcc (std::string bcc);
+       /** Add attachment, copying the contents of the file into memory */
        void add_attachment (boost::filesystem::path file, std::string name, std::string mime_type);
 
        void send (std::string server, int port, EmailProtocol protocol, std::string user = "", std::string password = "");
@@ -61,7 +62,7 @@ private:
        std::vector<std::string> _bcc;
 
        struct Attachment {
-               boost::filesystem::path file;
+               dcp::ArrayData file;
                std::string name;
                std::string mime_type;
        };
index e7d9aa31c48a5965d1750ef4f8ce105e0633b96f..971eeac76f9a9b38b4efae314010691ac40b39fd 100644 (file)
@@ -268,6 +268,7 @@ send_emails (
                }
 
                email.add_attachment (zip_file, container_name_format.get(first->name_values(), ".zip"), "application/zip");
+               dcp::filesystem::remove(zip_file);
 
                auto log_details = [](Email& email) {
                        dcpomatic_log->log("Email content follows", LogEntry::TYPE_DEBUG_EMAIL);
@@ -279,13 +280,10 @@ send_emails (
                try {
                        email.send (config->mail_server(), config->mail_port(), config->mail_protocol(), config->mail_user(), config->mail_password());
                } catch (...) {
-                       dcp::filesystem::remove(zip_file);
                        log_details (email);
                        throw;
                }
 
                log_details (email);
-
-               dcp::filesystem::remove(zip_file);
        }
 }