Fix the build for older macOS.
[dcpomatic.git] / src / lib / send_problem_report_job.cc
1 /*
2     Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 #include "send_problem_report_job.h"
23 #include "compose.hpp"
24 #include "film.h"
25 #include "cross.h"
26 #include "film.h"
27 #include "log.h"
28 #include "version.h"
29 #include "emailer.h"
30 #include "environment_info.h"
31 #include <libxml++/libxml++.h>
32
33 #include "i18n.h"
34
35
36 using std::list;
37 using std::shared_ptr;
38 using std::string;
39
40
41 /** @param film Film thta the problem is with, or 0.
42  *  @param from Email address to use for From:
43  *  @param summary Summary of the problem.
44  */
45 SendProblemReportJob::SendProblemReportJob (
46         shared_ptr<const Film> film,
47         string from,
48         string summary
49         )
50         : Job (film)
51         , _from (from)
52         , _summary (summary)
53 {
54
55 }
56
57
58 SendProblemReportJob::~SendProblemReportJob ()
59 {
60         stop_thread ();
61 }
62
63
64 string
65 SendProblemReportJob::name () const
66 {
67         if (!_film) {
68                 return _("Email problem report");
69         }
70
71         return String::compose (_("Email problem report for %1"), _film->name());
72 }
73
74
75 string
76 SendProblemReportJob::json_name () const
77 {
78         return N_("send_problem_report");
79 }
80
81
82 void
83 SendProblemReportJob::run ()
84 {
85         sub (_("Sending email"));
86         set_progress_unknown ();
87
88         string body = _summary + "\n\n";
89
90         body += "Version: " + string(dcpomatic_version) + " " + string(dcpomatic_git_commit) + "\n\n";
91
92         for (auto i: environment_info ()) {
93                 body += i + "\n";
94         }
95
96         body += "\n";
97
98         if (_film) {
99                 body += "log head and tail:\n";
100                 body += "---<8----\n";
101                 body += _film->log()->head_and_tail (4096);
102                 body += "---<8----\n\n";
103
104                 add_file (body, "ffprobe.log");
105
106                 body += "---<8----\n";
107                 body += _film->metadata()->write_to_string_formatted("UTF-8");
108                 body += "---<8----\n";
109         }
110
111         Emailer emailer (_from, {"carl@dcpomatic.com"}, "DCP-o-matic problem report", body);
112         emailer.send ("main.carlh.net", 2525, EmailProtocol::STARTTLS);
113
114         set_progress (1);
115         set_state (FINISHED_OK);
116 }
117
118
119 void
120 SendProblemReportJob::add_file (string& body, boost::filesystem::path file) const
121 {
122         body += file.string() + ":\n";
123         body += "---<8----\n";
124         body += dcp::file_to_string (_film->file(file));
125         body += "---<8----\n\n";
126 }