Changeset c504199e7e127458fff243397776ee854e62b7a3

Show
Ignore:
Timestamp:
09/02/10 20:10:07 (21 months ago)
Author:
Antti-Juhani Kaijanaho <antti-juhani@…>
Children:
e7bbf3c6b857df8ad33c4d39396d693b48a48461
Parents:
62231ec0359b34f6a82b6688a7af97f2eb2ede10
git-committer:
Antti-Juhani Kaijanaho <antti-juhani@…> (09/02/10 20:10:07)
Message:

Support multipart entities

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

Location:
msg
Files:
2 added
2 modified

Legend:

Unmodified
Added
Removed
  • msg/entity.cc

    r62231ec rc504199  
    2121#include "entity.hh" 
    2222#include "format_violation.hh" 
     23#include "multipart.hh" 
    2324#include "text_plain.hh" 
    2425 
     
    5657{ 
    5758        entity::entity(const entity &ent) 
    58                 : field_content(ent.field_content) 
     59                : default_ct(ent.default_ct) 
     60                , field_content(ent.field_content) 
    5961                , body(ent.body) 
    6062        { 
     
    7072        } 
    7173 
    72         entity::entity(std::string msgstr) 
     74        entity::entity(std::string msgstr, 
     75                       std::string default_ct) 
     76                : default_ct(default_ct) 
    7377        { 
    7478                parse_headers(msgstr); 
     
    229233        content_type entity::get_content_type() const 
    230234        { 
    231                 return content_type(get_field("content-type", false)); 
     235                return content_type(has_field("content-type") 
     236                                    ? get_field("content-type", false) 
     237                                    : default_ct); 
    232238        } 
    233239 
     
    235241        { 
    236242                boost::shared_ptr<mime_entity> rv; 
    237                 // use text/plain as a fallback for now 
    238                 rv.reset(new text_plain(*this)); 
     243                content_type ct = get_content_type(); 
     244                switch (ct.get_type()) 
     245                { 
     246                case content_type::MULTIPART: 
     247                        rv.reset(new multipart(*this)); 
     248                        break; 
     249                case content_type::TEXT: default: 
     250                        rv.reset(new text_plain(*this)); 
     251                        break; 
     252                } 
    239253                return rv; 
    240254        } 
  • msg/entity.hh

    r62231ec rc504199  
    3939                typedef std::list<std::string>::const_iterator field_iterator; 
    4040 
    41                 explicit entity(std::string msgstr); 
     41                explicit entity(std::string msgstr, 
     42                                std::string default_ct =  
     43                                "text/plain; charset=\"US-ASCII\""); 
    4244 
    4345                virtual ~entity() {} 
     
    5961 
    6062 
    61                 bool has_field(std::string s) { 
     63                bool has_field(std::string s) const{ 
    6264                        boost::to_lower(s); 
    6365                        return fields.find(s) != fields.end(); 
     
    8284 
    8385        private: 
     86                std::string default_ct; 
    8487                // this split is to both provide a fast name lookup 
    8588                // and to preserve the field ordering