@ -45,6 +45,14 @@ struct ParserBase
} ;
struct Discard : public ParserBase
{
virtual void assign ( message * msg , const std : : string & s ) override
{
// Do nothing, intentionally. So this header is discarded.
}
} ;
// Parser that assigns the result of the function to the message data member
template < class T >
struct TParser : public ParserBase
@ -130,6 +138,7 @@ const std::map<std::string, struct ParserBase*> parsers =
{ " In-Reply-To " , P < DS , stringlist_t * > ( & message : : in_reply_to , message_id_list , & create_stringlist ) } ,
{ " References " , P < std : : vector < std : : string > , stringlist_t * > ( & message : : references , message_id_list , & create_stringlist ) } ,
{ " Received " , new Discard } ,
} ;
// parses the header and fill the parts in msg
@ -143,9 +152,25 @@ void parse_header(message* msg, const HeaderSection& header)
const auto p = parsers . find ( h . name ) ;
if ( p = = parsers . end ( ) )
{
// unknown header with no special parser:
stringpair_list_add ( msg - > opt_fields , new_stringpair ( h . name . c_str ( ) , h . value . c_str ( ) ) ) ;
// unknown header with no special parser: just dump it in opt_fields
auto sp = new_stringpair ( h . name . c_str ( ) , h . value . c_str ( ) ) ;
auto f = stringpair_list_add ( msg - > opt_fields , sp ) ;
// the function above has a strange semantic:
// it adds the stringpair to the given list (if it is non-NULL) or returns it (if given list is NULL).
if ( f )
{
if ( msg - > opt_fields = = nullptr )
{
msg - > opt_fields = f ;
} else {
// do nothing. f is already added to the list. oO
}
} else { // stringpair_list_add() fails for whatever reason: avoid memory leak
free_stringpair ( sp ) ;
}
} else {
// do the "right thing" with this well-known header line:
p - > second - > assign ( msg , h . value ) ;
}
}