| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #ifndef GUARD_MSG_ENTITY_HH |
|---|
| 21 | #define GUARD_MSG_ENTITY_HH |
|---|
| 22 | |
|---|
| 23 | #include "entity_header.hh" |
|---|
| 24 | |
|---|
| 25 | #define DEFAULT_CT "text/plain; charset=\"US-ASCII\"" |
|---|
| 26 | |
|---|
| 27 | namespace tlate { class value; } |
|---|
| 28 | |
|---|
| 29 | namespace msg |
|---|
| 30 | { |
|---|
| 31 | class content_type; |
|---|
| 32 | class multipart; |
|---|
| 33 | |
|---|
| 34 | class entity |
|---|
| 35 | { |
|---|
| 36 | public: |
|---|
| 37 | typedef boost::shared_ptr<entity> ptr; |
|---|
| 38 | typedef boost::shared_ptr<const entity> const_ptr; |
|---|
| 39 | typedef entity_header::field_iterator field_iterator; |
|---|
| 40 | |
|---|
| 41 | static ptr mk(std::string msgstr, |
|---|
| 42 | bool validate, |
|---|
| 43 | std::string default_ct = DEFAULT_CT); |
|---|
| 44 | |
|---|
| 45 | virtual ~entity() {} |
|---|
| 46 | |
|---|
| 47 | virtual ptr clone() const = 0; |
|---|
| 48 | |
|---|
| 49 | virtual boost::shared_ptr<multipart> clone_as_multipart() const; |
|---|
| 50 | |
|---|
| 51 | virtual boost::shared_ptr<tlate::value> |
|---|
| 52 | get_tlate_value(bool hide_addreses) const = 0; |
|---|
| 53 | |
|---|
| 54 | boost::posix_time::ptime parsed_date() const { |
|---|
| 55 | return hdr->parsed_date(); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | field_iterator fields_begin() const { |
|---|
| 59 | return hdr->fields_begin(); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | field_iterator fields_end() const { return hdr->fields_end(); } |
|---|
| 63 | |
|---|
| 64 | std::string get_header() const { return hdr->get_header(); } |
|---|
| 65 | virtual std::string get_body() const = 0; |
|---|
| 66 | virtual std::string get_decoded_body() const { |
|---|
| 67 | return get_body(); |
|---|
| 68 | } |
|---|
| 69 | std::string get_entity() const { |
|---|
| 70 | return get_header() + "\r\n" + get_body(); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | bool has_field(std::string s) const{ return hdr->has_field(s); } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | std::string get_field(std::string s, bool full) const { |
|---|
| 77 | return hdr->get_field(s, full); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | size_t get_size() const; |
|---|
| 81 | size_t get_body_lines() const; |
|---|
| 82 | |
|---|
| 83 | void replace_field(std::string name, std::string body) { |
|---|
| 84 | return hdr->replace_field(name, body); |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | content_type get_content_type() const { |
|---|
| 88 | return hdr->get_content_type(); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | protected: |
|---|
| 92 | entity(entity_header::ptr hdr) |
|---|
| 93 | : hdr(hdr) |
|---|
| 94 | {} |
|---|
| 95 | entity(const entity &ent) |
|---|
| 96 | : hdr(new entity_header(*ent.hdr)) |
|---|
| 97 | {} |
|---|
| 98 | |
|---|
| 99 | private: |
|---|
| 100 | entity_header::ptr hdr; |
|---|
| 101 | |
|---|
| 102 | entity &operator=(const entity &); |
|---|
| 103 | }; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | #endif |
|---|