safe
[ghsmtp.git] / MessageStore.hpp
blob0e57c6c5783766add866d61c09c2cd924ad7ea3b
1 #ifndef MESSAGESTORE_DOT_HPP
2 #define MESSAGESTORE_DOT_HPP
4 #include <fstream>
5 #include <string_view>
7 #include <boost/iostreams/device/mapped_file.hpp>
9 #include "Now.hpp"
10 #include "Pill.hpp"
12 #include "fs.hpp"
14 class MessageStore {
15 public:
16 void open(std::string_view fqdn,
17 std::streamsize max_size,
18 std::string_view folder);
20 Pill const& id() const { return s_; }
21 Now const& when() const { return then_; }
23 std::ostream& write(char const* s, std::streamsize count);
24 std::ostream& write(std::string_view s)
26 return write(s.data(), s.length());
29 void deliver();
30 void close();
31 void trash() { close(); }
33 std::string_view freeze();
35 bool size_error() const { return size_error_; }
36 std::streamsize size() const { return size_; }
37 std::streamsize max_size() const { return max_size_; }
38 std::streamsize size_left() const { return max_size() - size(); }
40 private:
41 Pill s_;
42 Now then_;
44 std::ofstream ofs_;
45 std::streamsize size_{0};
46 std::streamsize max_size_{0};
48 fs::path newfn_;
49 fs::path tmpfn_;
50 fs::path tmp2fn_;
52 bool size_error_{false};
54 boost::iostreams::mapped_file_source mapping_;
56 void try_close_();
59 #endif // MESSAGESTORE_DOT_HPP