aboutsummaryrefslogtreecommitdiff
path: root/libbutl/sendmail.mxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-09-22 23:32:28 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-09-22 23:32:28 +0200
commitc09cd7512491cee1e82c1ad8128ce9fd4bc3f79b (patch)
treea659ed768d849130ab5780a11b7f791a463a1a91 /libbutl/sendmail.mxx
parent2a00871f07067f8f9e2de08bb9c8f50e1bf6a650 (diff)
Initial modularization with both Clang and VC hacks
Note: gave up on VC about half way though.
Diffstat (limited to 'libbutl/sendmail.mxx')
-rw-r--r--libbutl/sendmail.mxx138
1 files changed, 138 insertions, 0 deletions
diff --git a/libbutl/sendmail.mxx b/libbutl/sendmail.mxx
new file mode 100644
index 0000000..778ff05
--- /dev/null
+++ b/libbutl/sendmail.mxx
@@ -0,0 +1,138 @@
+// file : libbutl/sendmail.mxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef __cpp_modules
+#pragma once
+#endif
+
+// C includes.
+
+#ifndef __cpp_lib_modules
+#include <string>
+
+#include <cstddef> // size_t
+#include <utility> // move(), forward()
+#endif
+
+// Other includes.
+
+#ifdef __cpp_modules
+export module butl.sendmail;
+#ifdef __cpp_lib_modules
+import std.core;
+#endif
+import butl.process;
+import butl.fdstream;
+import butl.small_vector;
+#else
+#include <libbutl/process.mxx>
+#include <libbutl/fdstream.mxx>
+#include <libbutl/small-vector.mxx>
+#endif
+
+#include <libbutl/export.hxx>
+
+LIBBUTL_MODEXPORT namespace butl
+{
+ // Send email using the sendmail(1) program.
+ //
+ // Write the body of the email to out. Note that you must explicitly close
+ // it before calling wait(). Throw process_error and io_error (both derive
+ // from system_error) in case of errors.
+ //
+ // Typical usage:
+ //
+ // try
+ // {
+ // sendmail sm (2, // Diagnostics to stderr.
+ // "", // Default From: address.
+ // "Test subject",
+ // {"test@example.com"});
+ //
+ // sm.out << "Test body" << endl;
+ //
+ // sm.out.close ();
+ //
+ // if (!sm.wait ())
+ // ... // sendmail returned non-zero status.
+ // }
+ // catch (const std::system_error& e)
+ // {
+ // cerr << "sendmail error: " << e << endl;
+ // }
+ //
+ class LIBBUTL_SYMEXPORT sendmail: public process
+ {
+ public:
+ ofdstream out;
+
+ // Notes:
+ //
+ // - If from is empty then the process user's address is used.
+ //
+ // - The to/cc/bcc addressed should already be quoted if required.
+ //
+ using recipients_type = small_vector<std::string, 1>;
+
+ template <typename E>
+ sendmail (E&& err,
+ const std::string& from,
+ const std::string& subject,
+ const recipients_type& to);
+
+ template <typename E>
+ sendmail (E&& err,
+ const std::string& from,
+ const std::string& subject,
+ const recipients_type& to,
+ const recipients_type& cc);
+
+ template <typename E, typename... O>
+ sendmail (E&& err,
+ const std::string& from,
+ const std::string& subject,
+ const recipients_type& to,
+ const recipients_type& cc,
+ const recipients_type& bcc,
+ O&&... options);
+
+ // Version with the command line callback (see process_run_callback() for
+ // details).
+ //
+ template <typename C, typename E>
+ sendmail (const C&,
+ E&& err,
+ const std::string& from,
+ const std::string& subject,
+ const recipients_type& to);
+
+ template <typename C, typename E>
+ sendmail (const C&,
+ E&& err,
+ const std::string& from,
+ const std::string& subject,
+ const recipients_type& to,
+ const recipients_type& cc);
+
+ template <typename C, typename E, typename... O>
+ sendmail (const C&,
+ E&& err,
+ const std::string& from,
+ const std::string& subject,
+ const recipients_type& to,
+ const recipients_type& cc,
+ const recipients_type& bcc,
+ O&&... options);
+
+ private:
+ void
+ headers (const std::string& from,
+ const std::string& subj,
+ const recipients_type& to,
+ const recipients_type& cc,
+ const recipients_type& bcc);
+ };
+}
+
+#include <libbutl/sendmail.ixx>