support 2nd RCPT TO and PRDR
[ghsmtp.git] / esc-test.cpp
blob639a532652d0559ba56499dd44a275cc3cde78fc
1 #include "esc.hpp"
2 #include "fs.hpp"
3 #include "imemstream.hpp"
5 #include <iostream>
6 #include <string>
8 #include <glog/logging.h>
10 #include <boost/iostreams/device/mapped_file.hpp>
12 int main(int argc, char* argv[])
14 auto const s0 = "\a\xa0\b\t\n\v\f\r\\";
15 CHECK_EQ(esc(s0), "\\a\\xa0\\b\\t\\n\\v\\f\\r\\\\");
17 auto const s1 = "no characters to escape";
18 CHECK_EQ(esc(s1), s1);
20 for (auto arg{1}; arg < argc; ++arg) {
21 fs::path const path{argv[arg]};
23 auto const body_sz{fs::file_size(path)};
24 if (!body_sz)
25 continue;
27 boost::iostreams::mapped_file_source file_source{};
28 file_source.open(path);
30 imemstream isfile{file_source.data(), file_source.size()};
31 std::string line;
32 while (std::getline(isfile, line)) {
33 if (!isfile.eof())
34 line += '\n'; // since getline strips the newline
35 std::cout << esc(line, esc_line_option::multi) << '\n';