Use in-tree libquickmail; send metadata.xml too; fix basic build errors with quickmail.
[dcpomatic.git] / src / lib / send_problem_report_job.cc
1 /*
2     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "send_problem_report_job.h"
21 #include "compose.hpp"
22 #include "film.h"
23 #include "cross.h"
24 #include "film.h"
25 #include "log.h"
26 #include "quickmail.h"
27
28 #include "i18n.h"
29
30 using std::string;
31 using std::list;
32 using boost::shared_ptr;
33
34 SendProblemReportJob::SendProblemReportJob (
35         shared_ptr<const Film> film,
36         string from,
37         string summary
38         )
39         : Job (film)
40         , _from (from)
41         , _summary (summary)
42 {
43
44 }
45
46 string
47 SendProblemReportJob::name () const
48 {
49         return String::compose (_("Email problem report for %1"), _film->name());
50 }
51
52 void
53 SendProblemReportJob::run ()
54 {
55         set_progress_unknown ();
56         
57         quickmail mail = quickmail_create (_from.c_str(), "DCP-o-matic problem report");
58         
59         quickmail_add_to (mail, "carl@dcpomatic.com");
60         
61         string body = _summary + "\n\n";
62         
63         body += "log head and tail:\n";
64         body += "---<8----\n";
65         body += _film->log()->head_and_tail ();
66         body += "---<8----\n\n";
67
68         add_file (body, "ffprobe.log");
69         add_file (body, "metadata.xml");
70
71         quickmail_set_body (mail, body.c_str());
72         
73         char const* error = quickmail_send (mail, "main.carlh.net", 2525, 0, 0);
74         
75         if (error) {
76                 set_state (FINISHED_ERROR);
77                 set_error (error, "");
78         } else {
79                 set_state (FINISHED_OK);
80         }
81         
82         quickmail_destroy (mail);
83
84         set_progress (1);
85 }
86
87 void
88 SendProblemReportJob::add_file (string& body, boost::filesystem::path file) const
89 {
90         FILE* f = fopen_boost (_film->file (file), "r");
91         if (!f) {
92                 return;
93         }
94         
95         body += file.string() + ":\n";
96         body += "---<8----\n";
97         uintmax_t const size = boost::filesystem::file_size (_film->file (file));
98         char* buffer = new char[size + 1];
99         int const N = fread (buffer, 1, size, f);
100         buffer[N] = '\0';
101         body += buffer;
102         delete[] buffer;
103         body += "---<8----\n\n";
104         fclose (f);
105 }