Changeset 99057e4d73dbb905f06f5ccc4ea49708b8aaa0a8

Show
Ignore:
Timestamp:
09/19/10 20:59:45 (20 months ago)
Author:
Antti-Juhani Kaijanaho <antti-juhani@…>
Children:
11cf105fe323361072281747558cb61752f33fa8
Parents:
81c6e32180ba6f1018c28ae75b7281fd38121812
git-committer:
Antti-Juhani Kaijanaho <antti-juhani@…> (09/19/10 20:59:45)
Message:

Rework entity handling

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

Files:
3 added
1 removed
22 modified

Legend:

Unmodified
Added
Removed
  • db/db.cc

    r1a970cd r99057e4  
    225225 
    226226                // commit 
    227                 ::msg::entity::ptr entity(new ::msg::entity(msgstr)); 
     227                ::msg::entity::ptr entity = ::msg::entity::mk(msgstr, false); 
    228228                msg::ptr message(new msg::msg(msgid,entity)); 
    229229                for (std::map<std::string, group::number>::const_iterator it =  
  • db/group.cc

    r1a970cd r99057e4  
    6969                if (recv.empty()) return rv; 
    7070 
    71                 ::msg::entity::ptr nm(new ::msg::entity(*m->get_entity())); 
     71                ::msg::entity::ptr nm = m->get_entity()->clone(); 
    7272                { 
    7373                        std::string subject = nm->get_field("subject", false); 
  • http/article_entry.cc

    r1a970cd r99057e4  
    6565        } 
    6666 
    67         boost::shared_ptr<const msg::mime_entity> 
     67        boost::shared_ptr<const msg::entity> 
    6868        article_entry::get_content() const 
    6969        { 
    7070                db::msg::const_ptr m = tn->get_article(); 
    71                 return m->get_entity()->get_mime_entity(); 
     71                return m->get_entity(); 
    7272        } 
    7373 
  • http/article_entry.hh

    r4c1c17d r99057e4  
    4242                std::string get_title() const; 
    4343                std::string get_author() const; 
    44                 boost::shared_ptr<const msg::mime_entity> get_content() const; 
     44                boost::shared_ptr<const msg::entity> get_content() const; 
    4545                std::string get_link() const; 
    4646                boost::posix_time::ptime get_date() const; 
  • http/compose.cc

    r1a970cd r99057e4  
    228228                try 
    229229                { 
    230                         msg::entity::ptr e(new msg::entity(os.str())); 
     230                        msg::entity::ptr e = msg::entity::mk(os.str(), false); 
    231231                        msg::complete_mime(e); 
    232232                        m = cb.dbase().file(e, req->get_peer(), usr, cb); 
     
    382382                body << from << " wrote: \n\n"; 
    383383 
    384                 msg::text_plain tp(*precursor->get_entity()); 
     384                msg::text_plain tp(precursor->get_entity()); 
    385385 
    386386                for (size_t i = 0; i < tp.num_paras(); i++) 
  • http/feed_resource.cc

    r4c1c17d r99057e4  
    2727#include "../logger/logline.hh" 
    2828#include "../html/util.hh" 
    29 #include "../msg/mime_entity.hh" 
     29#include "../msg/entity.hh" 
    3030 
    3131namespace 
     
    100100                     it != entries.end(); it++) 
    101101                { 
    102                         msg::mime_entity::const_ptr me = (*it)->get_content(); 
     102                        msg::entity::const_ptr me = (*it)->get_content(); 
    103103                        tlate::value::ptr tv = me->get_tlate_value(true); 
    104104                        tlate::data_model::ptr am(new tlate::data_model); 
  • http/feed_resource.hh

    r4c1c17d r99057e4  
    2929#include <list> 
    3030 
    31 namespace msg { class mime_entity; } 
     31namespace msg { class entity; } 
    3232 
    3333namespace http 
     
    6161                        virtual std::string get_title() const = 0; 
    6262                        virtual std::string get_author() const = 0; 
    63                         virtual boost::shared_ptr<const msg::mime_entity> 
     63                        virtual boost::shared_ptr<const msg::entity> 
    6464                        get_content() const = 0; 
    6565                        virtual std::string get_link() const = 0; 
  • local/connection.cc

    r1a970cd r99057e4  
    9999                                        util::streambuf_to_string(*sbp, n); 
    100100                                if (s.length() > n) s.resize(n); 
    101                                 ent.reset(new msg::entity(s)); 
     101                                ent = msg::entity::mk(s, false); 
    102102                        } 
    103103                        catch (msg::format_violation &fv) 
     
    113113                        } 
    114114 
    115                         msg::entity::ptr m(new msg::entity(ms)); 
     115                        msg::entity::ptr m(msg::entity::mk(ms, false)); 
    116116 
    117117                        // identify action 
  • msg/content_type.hh

    r868b365 r99057e4  
    11/*  This file is part of Alue, the multiprotocol Internet discussion daemon 
    22 
    3     Copyright © 2009 Antti-Juhani Kaijanaho 
     3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho 
    44 
    55    Alue is free software: you can redistribute it and/or modify it 
     
    5151                        return it->second; 
    5252                } 
     53                void set_param(std::string name, std::string value) { 
     54                        params[name] = value; 
     55                } 
    5356 
    5457                std::string to_string() const; 
  • msg/entity.cc

    r1a970cd r99057e4  
    2424#include "text_plain.hh" 
    2525#include "util.hh" 
     26#include "raw_entity.hh" 
    2627 
    2728#include "../util.hh" 
     
    3233#include "../assert.hh" 
    3334 
    34 namespace 
    35 { 
    36         // RFC 5322 ftext 
    37         inline bool is_ftext(char c) 
    38         { 
    39                 return  (33 <= c && c <=  57) || 
    40                         (59 <= c && c <= 126); 
    41         } 
    42  
    43         // RFC 5234 VCHAR 
    44         inline bool is_vchar(char c) 
    45         { 
    46                 return 0x21 <= c && c <= 0x7e; 
    47         } 
    48  
    49         // RFC 5234 WSP 
    50         inline bool is_wsp(char c) 
    51         { 
    52                 return c == ' ' || c == '\t'; 
    53         } 
    54  
    55 } 
    56  
    5735namespace msg 
    5836{ 
    59         entity::entity(const entity &ent) 
    60                 : default_ct(ent.default_ct) 
    61                 , field_content(ent.field_content) 
    62                 , body(ent.body) 
    63                 , the_date(boost::posix_time::not_a_date_time) 
    64         { 
    65                 for (std::list<std::string>::iterator it=field_content.begin(); 
    66                      it != field_content.end(); it++) 
    67                 { 
    68                         std::string fc = *it; 
    69                         size_t colon = fc.find(':'); 
    70                         assert(colon != std::string::npos); 
    71                         std::string fn = util::to_lower(fc.substr(0, colon)); 
    72                         fields[fn] = it; 
    73                 } 
    74         } 
    75  
    76         entity::entity(std::string msgstr, 
    77                        std::string default_ct) 
    78                 : default_ct(default_ct) 
    79                 , the_date(boost::posix_time::not_a_date_time) 
    80         { 
    81                 parse_headers(msgstr); 
    82         } 
    83  
    84         void entity::parse_headers(std::string msgstr) 
    85         { 
    86                 size_t inx = 0; 
    87                 size_t name_start = 0; 
    88                 size_t body_start = 0; 
    89                 std::string field_name; 
    90  
    91         FIELD_NAME: 
    92                 if (inx >= msgstr.length()) 
    93                 { 
    94                         errors += 
    95                                 "message ends in the middle of a header name\n"; 
    96                         goto HEADER_END; 
    97                 } 
    98  
    99                 if (is_ftext(msgstr[inx])) 
    100                 { 
    101                         inx++; 
    102                         goto FIELD_NAME; 
    103                 } 
    104                 if (msgstr[inx] != ':') 
    105                 { 
    106                         errors += boost::str(boost::format 
    107                                              ("invalid character (0x%02x) " 
    108                                               "in header field name\n") 
    109                                              % (unsigned)msgstr[inx]); 
    110                 } 
    111                 field_name = msgstr.substr(name_start, inx - name_start); 
    112                 inx++; 
    113                 if (inx >= msgstr.length() || msgstr[inx] != ' ') 
    114                 { 
    115                         errors += "header field '" + field_name + "' " 
    116                                 "is missing the mandatory space after colon\n"; 
    117                 } 
    118                 inx++; 
    119                 body_start = inx; 
    120                 goto FIELD_BODY; 
    121  
    122         FIELD_BODY: 
    123                 if (inx >= msgstr.length()) 
    124                 { 
    125                         errors += "header field '" + field_name + "' " 
    126                                 "terminates abruptly\n"; 
    127                         goto HEADER_END; 
    128                 } 
    129                 if (is_vchar(msgstr[inx]) || is_wsp(msgstr[inx])) 
    130                 { 
    131                         inx++; 
    132                         goto FIELD_BODY; 
    133                 } 
    134                 if (msgstr[inx] != '\r')  
    135                 { 
    136                         errors += "header field '" + field_name + "' " 
    137                                 "contains a character that is not allowed\n"; 
    138                 } 
    139                 inx++; 
    140                 if (inx >= msgstr.length() || msgstr[inx] != '\n')  
    141                 { 
    142                         errors += "header field '" + field_name + "' " 
    143                                 "contains a stray CR\n"; 
    144                 } 
    145                 assert(inx  < msgstr.length()); 
    146                 inx++; 
    147                 if (inx < msgstr.length() && is_wsp(msgstr[inx])) 
    148                 { 
    149                         // folded header field 
    150                         goto FIELD_BODY; 
    151                 } 
    152                 // header field ends 
    153                 field_content.push_back(msgstr.substr(name_start, 
    154                                                       inx - name_start)); 
    155                 boost::to_lower(field_name); 
    156                 fields[field_name] = boost::prior(field_content.end()); 
    157                 if (inx + 1 < msgstr.length() && 
    158                     msgstr[inx+0] == '\r' && msgstr[inx+1] == '\n') 
    159                 { 
    160                         inx += 2; 
    161                         goto HEADER_END; 
    162                 } 
    163                 name_start = inx; 
    164                 goto FIELD_NAME; 
    165  
    166         HEADER_END: 
    167                 body = msgstr.substr(inx); 
    168         } 
    169  
    170         boost::posix_time::ptime entity::parsed_date() const 
    171         { 
    172                 if (the_date == boost::posix_time::not_a_date_time) 
    173                         the_date = parse_date(get_field("Date", false)); 
    174                 return the_date; 
    175         } 
    176  
    177         std::string entity::get_header() const 
    178         { 
    179                 std::string rv; 
    180                 for (field_iterator it = fields_begin(); 
    181                      it != fields_end(); it++) 
    182                 { 
    183                         rv += *it; 
    184                 } 
    185                 return rv; 
    186         }         
    187  
    188         std::string entity::get_field(std::string name, bool full) const 
    189         { 
    190                 boost::to_lower(name); 
    191  
    192                 std::map<std::string, std::list<std::string>::iterator> 
    193                         ::const_iterator it = fields.find(name); 
    194                 if (it == fields.end()) return ""; 
    195                  
    196                 const std::string content = *it->second; 
    197                 if (full) {  
    198                         return content; 
    199                 } else { 
    200                         return content.substr(name.length() + 2); 
    201                 } 
    202         } 
    203  
    20437        size_t entity::get_size() const 
    20538        { 
     39                std::string body = get_body(); 
    20640                size_t n = 0; 
    20741                for (field_iterator it = fields_begin(); 
     
    21751        size_t entity::get_body_lines() const 
    21852        { 
     53                std::string body = get_body(); 
    21954                unsigned long lines = -1; 
    22055                size_t inx = std::string::npos; 
     
    22863        } 
    22964 
    230         void entity::replace_field(std::string name, std::string body) 
     65        entity::ptr entity::mk(std::string ms, bool validate, std::string dct) 
    23166        { 
    232                 std::string fld = name + ": " + body + "\r\n"; 
    233                 fld.reserve(fld.length()); 
    234                 // fold it 
    235                 const size_t line_maxlen = 998; 
    236                 size_t lb = 0; 
    237                 for (size_t i = line_maxlen; i < fld.length(); i += line_maxlen) 
    238                 { 
    239                         while (i > lb && fld[i] != ' ' && fld[i] != '\t') i--; 
    240                         if (i == lb) break; 
    241                         fld.insert(i, "\r\n"); 
    242                         i += 2; 
    243                 } 
    244                 boost::to_lower(name); 
    245                 std::map<std::string, std::list<std::string>::iterator> 
    246                         ::iterator it = fields.find(name); 
    247                 if (it == fields.end()) { 
    248                         field_content.push_front(fld); 
    249                         fields[name] = field_content.begin(); 
    250                 } else { 
    251                         *it->second = fld; 
    252                 } 
    253                 if (name == "date") 
    254                         the_date = boost::posix_time::not_a_date_time; 
    255         } 
     67                entity_header::ptr hdr(new entity_header(ms, validate, dct)); 
    25668 
    257         content_type entity::get_content_type() const 
    258         { 
    259                 return content_type(has_field("content-type") 
    260                                     ? get_field("content-type", false) 
    261                                     : default_ct); 
    262         } 
    263  
    264         boost::shared_ptr<mime_entity> entity::get_mime_entity() const 
    265         { 
    266                 boost::shared_ptr<mime_entity> rv; 
    267                 content_type ct = get_content_type(); 
     69                entity::ptr rv; 
     70                content_type ct = hdr->get_content_type(); 
    26871                switch (ct.get_type()) 
    26972                { 
    27073                case content_type::MESSAGE: 
    271                         rv.reset(new message_entity(*this)); 
     74                        rv.reset(new message_entity(hdr, ms)); 
    27275                        break; 
    27376                case content_type::MULTIPART: 
    274                         rv.reset(new multipart(*this)); 
     77                        rv.reset(new multipart(hdr, ms)); 
    27578                        break; 
    276                 case content_type::TEXT: default: 
    277                         rv.reset(new text_plain(*this)); 
     79                case content_type::TEXT: 
     80                        rv.reset(new text_plain(hdr, ms)); 
     81                        break; 
     82                default: 
     83                        rv.reset(new raw_entity(hdr, ms)); 
    27884                        break; 
    27985                } 
     
    28187        } 
    28288 
    283         std::string entity::get_decoded_body() const 
    284         { 
    285                 /* This here would decode content-transfer-encoding, 
    286                    but lacking realistic test cases I'm leaving this 
    287                    for later. */ 
    288                 return get_body(); 
    289         } 
    29089} 
  • msg/entity.hh

    r1a970cd r99057e4  
    2121#define GUARD_MSG_ENTITY_HH 
    2222 
    23 #include "format_violation.hh" 
    24 #include <boost/algorithm/string/case_conv.hpp> 
    25 #include <boost/date_time/posix_time/posix_time.hpp> 
    26 #include <boost/shared_ptr.hpp> 
    27 #include <list> 
    28 #include <map> 
    29 #include <string> 
     23#include "entity_header.hh" 
     24 
     25#define DEFAULT_CT "text/plain; charset=\"US-ASCII\"" 
     26 
     27namespace tlate { class value; } 
    3028 
    3129namespace msg 
     
    3634        class entity 
    3735        { 
    38                 std::string errors; 
    39  
    4036        public: 
    4137                typedef boost::shared_ptr<entity> ptr; 
    4238                typedef boost::shared_ptr<const entity> const_ptr; 
    43                 typedef std::list<std::string>::const_iterator field_iterator; 
     39                typedef entity_header::field_iterator field_iterator; 
    4440 
    45                 explicit entity(std::string msgstr, 
    46                                 std::string default_ct =  
    47                                 "text/plain; charset=\"US-ASCII\""); 
    48                 explicit entity(const entity &); 
     41                static ptr mk(std::string msgstr, 
     42                              bool validate, 
     43                              std::string default_ct = DEFAULT_CT); 
    4944 
    5045                virtual ~entity() {} 
    5146 
    52                 boost::posix_time::ptime parsed_date() const; 
     47                virtual ptr clone() const = 0; 
    5348 
    54                 void validate_format() const { 
    55                         if (!errors.empty()) throw format_violation(errors); 
     49                virtual boost::shared_ptr<tlate::value> 
     50                get_tlate_value(bool hide_addreses) const = 0; 
     51 
     52                boost::posix_time::ptime parsed_date() const { 
     53                        return hdr->parsed_date(); 
    5654                } 
    5755 
    5856                field_iterator fields_begin() const { 
    59                         return field_content.begin(); 
     57                        return hdr->fields_begin(); 
    6058                } 
    6159 
    62                 field_iterator fields_end() const { 
    63                         return field_content.end(); 
     60                field_iterator fields_end() const { return hdr->fields_end(); } 
     61 
     62                std::string get_header() const { return hdr->get_header(); }  
     63                virtual std::string get_body() const = 0; 
     64                virtual std::string get_decoded_body() const { 
     65                        return get_body(); 
    6466                } 
    65  
    66                 std::string get_header() const; 
    67                 std::string get_body() const { return body; } 
    68                 std::string get_decoded_body() const; 
    6967                std::string get_entity() const { 
    7068                        return get_header() + "\r\n" + get_body(); 
    7169                } 
    7270 
    73  
    74                 bool has_field(std::string s) const{ 
    75                         boost::to_lower(s); 
    76                         return fields.find(s) != fields.end(); 
    77                 } 
     71                bool has_field(std::string s) const{ return hdr->has_field(s); } 
    7872 
    7973                // returns the field unprocessed 
    80                 std::string get_field(std::string s, bool full) const; 
     74                std::string get_field(std::string s, bool full) const { 
     75                        return hdr->get_field(s, full); 
     76                } 
    8177 
    8278                size_t get_size() const; 
    8379                size_t get_body_lines() const; 
    8480 
    85                 virtual void replace_field(std::string name, std::string body); 
     81                void replace_field(std::string name, std::string body) { 
     82                        return hdr->replace_field(name, body); 
     83                } 
    8684 
    87                 void replace_body(std::string s) { body = s; } 
     85                content_type get_content_type() const { 
     86                        return hdr->get_content_type(); 
     87                } 
    8888 
    89                 content_type get_content_type() const; 
    90  
    91                 boost::shared_ptr<mime_entity> get_mime_entity() const; 
     89        protected: 
     90                entity(entity_header::ptr hdr) 
     91                        : hdr(hdr) 
     92                        {} 
     93                entity(const entity &ent) 
     94                        : hdr(new entity_header(*ent.hdr)) 
     95                        {} 
    9296 
    9397        private: 
    94                 std::string default_ct; 
    95                 // this split is to both provide a fast name lookup 
    96                 // and to preserve the field ordering 
    97                 std::list<std::string> field_content; // includes the names 
    98                 std::map<std::string, std::list<std::string>::iterator> fields; 
    99                 std::string body; 
    100                 mutable boost::posix_time::ptime the_date; 
    101  
    102                 void parse_headers(std::string); 
     98                entity_header::ptr hdr; 
    10399 
    104100                entity &operator=(const entity &); // DISABLED 
  • msg/message_entity.cc

    r1a970cd r99057e4  
    2828namespace msg 
    2929{ 
    30         message_entity::message_entity(const entity & ent) 
    31                 : mime_entity(ent) 
    32                 , m(new entity(get_body())) 
    33         { 
    34         } 
    3530 
    3631        boost::shared_ptr<tlate::value> 
     
    5651                           new tlate::date_value 
    5752                           (parse_date(m->get_field("Date", false)))); 
    58                 mime_entity::const_ptr bme = m->get_mime_entity(); 
    59                 am->insert("body", bme->get_tlate_value(munge)); 
     53                am->insert("body", m->get_tlate_value(munge)); 
    6054                return am; 
    6155        } 
  • msg/message_entity.hh

    re7bbf3c r99057e4  
    2121#define GUARD_MSG_MESSAGE_ENTITY_HH 
    2222 
    23 #include "mime_entity.hh" 
     23#include "entity.hh" 
    2424 
    2525namespace msg 
    2626{ 
    27         class message_entity : public mime_entity 
     27        class message_entity : public entity 
    2828        { 
    2929                entity::ptr m; 
     30 
    3031        public: 
    31                 explicit message_entity(const entity &); 
     32                message_entity(entity_header::ptr hdr, std::string body) 
     33                        : entity(hdr) 
     34                        , m(entity::mk(body, false)) 
     35                        {} 
     36 
     37                entity::ptr clone() const {  
     38                        entity::ptr rv(new message_entity(*this)); 
     39                        return rv; 
     40                } 
     41 
     42                std::string get_body() const { return m->get_entity(); } 
    3243 
    3344                boost::shared_ptr<tlate::value> get_tlate_value(bool) const; 
  • msg/multipart.cc

    rc504199 r99057e4  
    2525namespace msg 
    2626{ 
    27         multipart::multipart(const entity &ent) 
    28                 : mime_entity(ent) 
     27        multipart::multipart(entity_header::ptr hdr, std::string str) 
     28                : entity(hdr) 
    2929        { 
    3030                content_type ct = get_content_type(); 
     
    3232                        throw std::logic_error("not multipart"); 
    3333                std::string boundary = ct.get_param("boundary"); 
    34                 std::string str = get_body(); 
    3534                size_t bs = str.find("\r\n--"+boundary); 
     35                preamble = str.substr(0,bs); 
    3636                std::string default_ct = ct.get_subtype() == "digest" 
    3737                        ? "message/rfc822" 
     
    3939                while (bs != std::string::npos) 
    4040                { 
    41                         if (str.substr(bs + 4 + boundary.length(), 2) == "--") 
    42                                 break; 
    4341                        size_t be = str.find("\r\n", bs+2); 
    4442                        if (be == std::string::npos) be = str.length() - 2; 
     43                        if (str.substr(bs + 4 + boundary.length(), 2) == "--") 
     44                        { 
     45                                trailer = be + 2 < str.length() 
     46                                        ? str.substr(be+2) 
     47                                        : ""; 
     48                                break; 
     49                        } 
    4550                        size_t ns = str.find("\r\n--"+boundary, be); 
    4651                        std::string sub = str.substr(be+2, ns - be); 
    47                         entity::ptr sen(new entity(sub, default_ct)); 
     52                        entity::ptr sen(entity::mk(sub, false, default_ct)); 
    4853                        parts.push_back(sen); 
    4954                        bs = ns; 
     
    5762                for (size_t i = 0; i < parts.size(); i++) 
    5863                { 
    59                         mime_entity::ptr men = parts[i]->get_mime_entity(); 
    60                         li->push_back(men->get_tlate_value(hide_addresses)); 
     64                        entity::ptr en = parts[i]; 
     65                        li->push_back(en->get_tlate_value(hide_addresses)); 
    6166                } 
    6267                tlate::data_model::ptr am(new tlate::data_model); 
     
    6469                return am; 
    6570        } 
     71 
     72        std::string multipart::get_body() const 
     73        { 
     74                content_type ct = get_content_type(); 
     75                std::string boundary = ct.get_param("boundary"); 
     76                std::ostringstream os; 
     77                os << preamble; 
     78                for (size_t i = 0; i < parts.size(); i++) 
     79                { 
     80                        os << "\r\n--" << boundary << "\r\n"; 
     81                        os << parts[i]->get_entity(); 
     82                } 
     83                os << "\r\n--" << boundary << "--\r\n"; 
     84                os << trailer; 
     85                return os.str(); 
     86        } 
    6687} 
  • msg/multipart.hh

    rc504199 r99057e4  
    2121#define GUARD_MSG_MULTIPART_HH 
    2222 
    23 #include "mime_entity.hh" 
     23#include "entity.hh" 
    2424#include <vector> 
    2525 
    2626namespace msg 
    2727{ 
    28         class multipart : public mime_entity 
     28        class multipart : public entity 
    2929        { 
    3030                std::vector<entity::ptr> parts; 
     31                std::string preamble, trailer; 
    3132        public: 
    32                 explicit multipart(const entity &); 
     33                multipart(entity_header::ptr hdr, std::string body); 
     34 
     35                entity::ptr clone() const { 
     36                        entity::ptr rv(new multipart(*this)); 
     37                        return rv; 
     38                } 
     39 
     40                std::string get_body() const; 
    3341 
    3442                boost::shared_ptr<tlate::value> get_tlate_value(bool) const; 
  • msg/text_plain.cc

    r62231ec r99057e4  
    1919 
    2020#include "content_type.hh" 
     21#include "entity_header.hh" 
    2122#include "text_plain.hh" 
    2223 
     
    2627#include "../util.hh" 
    2728 
     29namespace 
     30{ 
     31        msg::entity_header::ptr ct_hdr(msg::content_type ct) 
     32        { 
     33                std::string str = 
     34                        std::string("Content-Type: ") + 
     35                        ct.to_string() + "\r\n" + 
     36                        "Content-Transfer-Encoding: 8bit\r\n" + 
     37                        "\r\n"; 
     38                msg::entity_header::ptr rv(new msg::entity_header(str, 
     39                                                                  false, 
     40                                                                  ct.to_string() 
     41                                                   ) 
     42                        ); 
     43                return rv; 
     44        } 
     45} 
     46 
    2847namespace msg 
    2948{ 
    30         text_plain::text_plain(const entity &ent) 
    31                 : mime_entity(ent) 
    32         { 
    33                 init(); 
    34         } 
    35  
    36         text_plain::text_plain(std::string text, content_type ct) 
    37                 : mime_entity(std::string("Content-Type: ") + 
    38                               ct.to_string() + "\r\n" + 
    39                               "Content-Transfer-Encoding: 8bit\r\n" + 
    40                               "\r\n" + 
    41                               text) 
    42         { 
    43                 init(); 
    44         } 
    45  
    46         void text_plain::init() 
    47         { 
    48                 std::string text = get_decoded_body(); 
     49        text_plain::text_plain(entity_header::ptr hdr, std::string body) 
     50                : entity(hdr) 
     51        { 
     52                init(body); 
     53        } 
     54 
     55        text_plain::text_plain(std::string body, content_type ct) 
     56                : entity(ct_hdr(ct)) 
     57        { 
     58                init(body); 
     59        } 
     60 
     61        text_plain::text_plain(entity::const_ptr e) 
     62                : entity(*e) 
     63        { 
     64                init(e->get_body()); 
     65        } 
     66 
     67        void text_plain::init(std::string text) 
     68        { 
     69                raw_body = text; 
    4970                content_type ct = get_content_type(); 
    5071                if (ct.get_type() != msg::content_type::TEXT || 
  • msg/text_plain.hh

    r868b365 r99057e4  
    11/*  This file is part of Alue, the multiprotocol Internet discussion daemon 
    22 
    3     Copyright © 2009 Antti-Juhani Kaijanaho 
     3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho 
    44 
    55    Alue is free software: you can redistribute it and/or modify it 
     
    2222 
    2323#include "content_type.hh" 
    24 #include "mime_entity.hh" 
     24#include "entity.hh" 
    2525 
    2626#include <string> 
     
    2929namespace msg 
    3030{ 
    31         class text_plain : public mime_entity 
     31        class text_plain : public entity 
    3232        { 
    3333        public: 
     
    4747 
    4848                explicit text_plain(std::string body, content_type); 
    49                 explicit text_plain(const entity &); 
     49                explicit text_plain(entity_header::ptr hdr, std::string body); 
     50                explicit text_plain(entity::const_ptr e); 
    5051 
    5152                size_t num_paras() const { return paras.size(); } 
     
    5455                boost::shared_ptr<tlate::value> 
    5556                get_tlate_value(bool hide_addreses) const; 
     57 
     58                std::string get_body() const { return raw_body; } 
     59 
     60                entity::ptr clone() const { 
     61                        entity::ptr rv(new text_plain(*this)); 
     62                        return rv; 
     63                } 
    5664        private: 
     65                std::string raw_body; 
    5766                std::vector<para> paras; 
    5867 
    59                 void init(); 
     68                void init(std::string body); 
    6069        }; 
    6170} 
  • msg/util.cc

    r1a970cd r99057e4  
    256256        void validate_imf(entity::const_ptr e)  
    257257        { 
    258                 e->validate_format(); 
    259258                check_present(e, "From");                 
    260259                check_present(e, "Date");                 
  • nntp/post.cc

    r1a970cd r99057e4  
    4242                try { 
    4343                        msg::entity::ptr e 
    44                                 (new msg::entity(msg::dot_destuff(data))); 
     44                                (msg::entity::mk(msg::dot_destuff(data), true)); 
    4545                        m = c.dbase().file(e, c.peer(), c.identity(), 
    4646                                           c.srv_cb()); 
  • smtp_client/smtp_client.cc

    r1a970cd r99057e4  
    4040                message = msg::crlf_canonize(message); 
    4141                msg::entity::ptr msg 
    42                         (new msg::entity(msg::dot_destuff(message))); 
     42                        (msg::entity::mk(msg::dot_destuff(message), true)); 
    4343                msg::complete_imf(msg); 
    4444                msg::complete_mime(msg); 
  • tlate/date_value.cc

    r1a970cd r99057e4  
    2929#include "../http/compose.hh" 
    3030#include "../msg/lexutils.hh" 
    31 #include "../msg/mime_entity.hh" 
    3231#include "../uri.hh" 
    3332 
  • tlate/msg_value.cc

    r1a970cd r99057e4  
    3333#include "../msg/entity.hh" 
    3434#include "../msg/lexutils.hh" 
    35 #include "../msg/mime_entity.hh" 
    3635#include "../uri.hh" 
    3736 
     
    174173                        rv.reset(new header_value(e,!u)); 
    175174                else if (rauthz && m && var == "body") 
    176                 { 
    177                         msg::mime_entity::const_ptr me = e->get_mime_entity(); 
    178                         rv = me->get_tlate_value(authn); 
    179                 } 
     175                        rv = e->get_tlate_value(authn); 
    180176                else if (rauthz && m && var == "xref") 
    181177                        rv.reset(new xref_seq(m, u));