| 2530 | } |
| 2531 | |
| 2532 | ParseResult |
| 2533 | mime_parser_parse(MIMEParser *parser, HdrHeap *heap, MIMEHdrImpl *mh, const char **real_s, const char *real_e, |
| 2534 | bool must_copy_strings, bool eof, bool remove_ws_from_field_name, size_t max_hdr_field_size) |
| 2535 | { |
| 2536 | ParseResult err; |
| 2537 | bool line_is_real; |
| 2538 | |
| 2539 | MIMEScanner *scanner = &parser->m_scanner; |
| 2540 | |
| 2541 | while (true) { |
| 2542 | //////////////////////////////////////////////////////////////////////////// |
| 2543 | // get a name:value line, with all continuation lines glued into one line // |
| 2544 | //////////////////////////////////////////////////////////////////////////// |
| 2545 | |
| 2546 | TextView text{*real_s, real_e}; |
| 2547 | TextView parsed; |
| 2548 | err = scanner->get(text, parsed, line_is_real, eof, MIMEScanner::FIELD); |
| 2549 | *real_s = text.data(); |
| 2550 | if (err != PARSE_RESULT_OK) { |
| 2551 | return err; |
| 2552 | } |
| 2553 | |
| 2554 | ////////////////////////////////////////////////// |
| 2555 | // if got a LF or CR on its own, end the header // |
| 2556 | ////////////////////////////////////////////////// |
| 2557 | |
| 2558 | if ((parsed.size() >= 2) && (parsed[0] == ParseRules::CHAR_CR) && (parsed[1] == ParseRules::CHAR_LF)) { |
| 2559 | return PARSE_RESULT_DONE; |
| 2560 | } |
| 2561 | |
| 2562 | if ((parsed.size() >= 1) && (parsed[0] == ParseRules::CHAR_LF)) { |
| 2563 | return PARSE_RESULT_DONE; |
| 2564 | } |
| 2565 | |
| 2566 | ///////////////////////////////////////////// |
| 2567 | // find pointers into the name:value field // |
| 2568 | ///////////////////////////////////////////// |
| 2569 | |
| 2570 | /** |
| 2571 | * Fix for INKqa09141. The is_token function fails for '@' character. |
| 2572 | * Header names starting with '@' signs are valid headers. Hence we |
| 2573 | * have to add one more check to see if the first parameter is '@' |
| 2574 | * character then, the header name is valid. |
| 2575 | **/ |
| 2576 | if ((!ParseRules::is_token(*parsed)) && (*parsed != '@')) { |
| 2577 | continue; // toss away garbage line |
| 2578 | } |
| 2579 | |
| 2580 | // find name last |
| 2581 | auto field_value = parsed; // need parsed as is later on. |
| 2582 | auto field_name = field_value.split_prefix_at(':'); |
| 2583 | if (field_name.empty()) { |
| 2584 | continue; // toss away garbage line |
| 2585 | } |
| 2586 | |
| 2587 | // RFC7230 section 3.2.4: |
| 2588 | // No whitespace is allowed between the header field-name and colon. In |
| 2589 | // the past, differences in the handling of such whitespace have led to |
no test coverage detected