From abbb859d9eefa62a5cc774bd08020bf30ad77c26 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 13 Apr 2017 10:47:47 +0200 Subject: Implement sendmail process --- butl/sendmail.ixx | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 butl/sendmail.ixx (limited to 'butl/sendmail.ixx') diff --git a/butl/sendmail.ixx b/butl/sendmail.ixx new file mode 100644 index 0000000..3f6597d --- /dev/null +++ b/butl/sendmail.ixx @@ -0,0 +1,65 @@ +// file : butl/sendmail.ixx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include // move(), forward() + +namespace butl +{ + template + inline sendmail:: + sendmail (E&& err, + const std::string& from, + const std::string& subj, + const recipients_type& to, + const recipients_type& cc, + const recipients_type& bcc, + O&&... options) + : sendmail ([] (const char* [], std::size_t) {}, + std::forward (err), + from, + subj, + to, + cc, + bcc, + std::forward (options)...) + { + } + + template + inline sendmail:: + sendmail (const C& cmdc, + E&& err, + const std::string& from, + const std::string& subj, + const recipients_type& to, + const recipients_type& cc, + const recipients_type& bcc, + O&&... options) + { + { + fdpipe pipe (fdopen_pipe ()); // Text mode seems appropriate. + + process& p (*this); + p = process_start (cmdc, + pipe.in, + 2, // No output expected so redirect to stderr. + std::forward (err), + dir_path (), + "sendmail", + "-i", // Don't treat '.' as the end of input. + "-t", // Read recipients from headers. + std::forward (options)...); + + out.open (std::move (pipe.out)); + } // Close pipe.in. + + // Write headers. + // + // Note that if this throws, then the ofdstream will be closed first + // (which should signal to the process we are done). Then the process's + // destructor will wait for its termination ignoring any errors. + // + headers (from, subj, to, cc, bcc); + } +} -- cgit v1.1