better with obs forms
[ghsmtp.git] / arcverify.cpp
blobf779192a019eb9aed165210c56a3224c0730294b
1 #include "Mailbox.hpp"
2 #include "OpenARC.hpp"
3 #include "OpenDKIM.hpp"
4 #include "OpenDMARC.hpp"
5 #include "esc.hpp"
6 #include "fs.hpp"
7 #include "iequal.hpp"
8 #include "imemstream.hpp"
9 #include "message.hpp"
10 #include "osutil.hpp"
12 #include <cstring>
13 #include <map>
15 #include <fmt/format.h>
16 #include <fmt/ostream.h>
18 #include <boost/algorithm/string.hpp>
19 #include <boost/iostreams/device/mapped_file.hpp>
21 using namespace std::string_literals;
23 bool arc_verify(message::parsed& msg)
25 CHECK(!msg.headers.empty());
27 // ARC
29 OpenARC::verify arv;
30 for (auto const& header : msg.headers) {
31 arv.header(header.as_view());
33 arv.eoh();
34 arv.body(msg.body);
35 arv.eom();
37 LOG(INFO) << "ARC status == " << arv.chain_status_str();
38 LOG(INFO) << "ARC custody == " << arv.chain_custody_str();
40 return "fail"s != arv.chain_status_str();
43 int main(int argc, char* argv[])
45 google::ParseCommandLineFlags(&argc, &argv, true);
47 auto const server_identity = [] {
48 auto const id_from_env{getenv("GHSMTP_SERVER_ID")};
49 if (id_from_env)
50 return std::string{id_from_env};
52 auto const hostname{osutil::get_hostname()};
53 if (hostname.find('.') != std::string::npos)
54 return hostname;
56 LOG(FATAL) << "can't determine my server ID, set GHSMTP_SERVER_ID maybe";
57 return "(none)"s;
58 }();
60 auto const config_path = osutil::get_config_dir();
62 for (int a = 1; a < argc; ++a) {
63 if (!fs::exists(argv[a]))
64 LOG(FATAL) << "can't find mail file " << argv[a];
65 boost::iostreams::mapped_file_source file;
66 file.open(argv[a]);
67 message::parsed msg;
68 CHECK(msg.parse(std::string_view(file.data(), file.size())));
69 arc_verify(msg);
70 // std::cout << msg.as_string();