aboutsummaryrefslogtreecommitdiff
path: root/libbutl/sendmail.cxx
blob: 5fec1a6538ca492553c96a83f3ca6dc69bc018c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// file      : libbutl/sendmail.cxx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

#include <libbutl/sendmail.hxx>

using namespace std;

namespace butl
{
  void sendmail::
  headers (const std::string& from,
           const std::string& subj,
           const recipients_type& to,
           const recipients_type& cc,
           const recipients_type& bcc)
  {
    if (!from.empty ())
      out << "From: " << from << endl;

    auto rcp = [this] (const char* h, const recipients_type& rs)
    {
      if (!rs.empty ())
      {
        bool f (true);
        out << h << ": ";
        for (const string& r: rs)
          out << (f ? (f = false, "") : ", ") << r;
        out << endl;
      }
    };

    rcp ("To",  to);
    rcp ("Cc",  cc);
    rcp ("Bcc", bcc);

    out << "Subject: " << subj << endl
        << endl; // Header/body separator.
  }
}