mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-03 09:49:15 +02:00
Merge pull request #526 from deltachat/quotes
crop ">" only for other muas
This commit is contained in:
commit
2fd1d2b727
4 changed files with 28 additions and 16 deletions
|
@ -170,22 +170,22 @@ void stress_functions(dc_context_t* context)
|
|||
dc_simplify_t* simplify = dc_simplify_new();
|
||||
|
||||
const char* html = "\r\r\nline1<br>\r\n\r\n\r\rline2\n\r"; /* check, that `<br>\ntext` does not result in `\n text` */
|
||||
char* plain = dc_simplify_simplify(simplify, html, strlen(html), 1);
|
||||
char* plain = dc_simplify_simplify(simplify, html, strlen(html), 1, 0);
|
||||
assert( strcmp(plain, "line1\nline2")==0 );
|
||||
free(plain);
|
||||
|
||||
html = "<a href=url>text</a"; /* check unquoted attribute and unclosed end-tag */
|
||||
plain = dc_simplify_simplify(simplify, html, strlen(html), 1);
|
||||
plain = dc_simplify_simplify(simplify, html, strlen(html), 1, 0);
|
||||
assert( strcmp(plain, "[text](url)")==0 );
|
||||
free(plain);
|
||||
|
||||
html = "<!DOCTYPE name [<!DOCTYPE ...>]><!-- comment -->text <b><?php echo ... ?>bold</b><![CDATA[<>]]>";
|
||||
plain = dc_simplify_simplify(simplify, html, strlen(html), 1);
|
||||
plain = dc_simplify_simplify(simplify, html, strlen(html), 1, 0);
|
||||
assert( strcmp(plain, "text *bold*<>")==0 );
|
||||
free(plain);
|
||||
|
||||
html = "<>"'& äÄöÖüÜß fooÆçÇ ♦&noent;‎‏‌‍";
|
||||
plain = dc_simplify_simplify(simplify, html, strlen(html), 1);
|
||||
plain = dc_simplify_simplify(simplify, html, strlen(html), 1, 0);
|
||||
assert( strcmp(plain, "<>\"'& äÄöÖüÜß fooÆçÇ ♦&noent;")==0 );
|
||||
free(plain);
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include "dc_simplify.h"
|
||||
|
||||
|
||||
static void hash_header(dc_hash_t* out, const struct mailimf_fields* in, dc_context_t* context);
|
||||
|
||||
|
||||
// deprecated: flag to switch generation of compound messages on and off.
|
||||
static int s_generate_compound_msgs = 1;
|
||||
|
@ -1064,7 +1066,13 @@ static int dc_mimeparser_add_single_part_if_known(dc_mimeparser_t* mimeparser, s
|
|||
}
|
||||
}
|
||||
|
||||
char* simplified_txt = dc_simplify_simplify(simplifier, decoded_data, decoded_data_bytes, mime_type==DC_MIMETYPE_TEXT_HTML? 1 : 0);
|
||||
/* check header directly as is_send_by_messenger is not yet set up */
|
||||
int is_msgrmsg = dc_mimeparser_lookup_optional_field(mimeparser, "Chat-Version")!=NULL;
|
||||
|
||||
char* simplified_txt = dc_simplify_simplify(simplifier,
|
||||
decoded_data, decoded_data_bytes,
|
||||
mime_type==DC_MIMETYPE_TEXT_HTML? 1 : 0,
|
||||
is_msgrmsg);
|
||||
if (simplified_txt && simplified_txt[0])
|
||||
{
|
||||
part = dc_mimepart_new();
|
||||
|
@ -1204,6 +1212,9 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc
|
|||
|| mimeparser->header_protected==NULL) {
|
||||
dc_log_warning(mimeparser->context, 0, "Protected headers parsing error.");
|
||||
}
|
||||
else {
|
||||
hash_header(&mimeparser->header, mimeparser->header_protected, mimeparser->context);
|
||||
}
|
||||
}
|
||||
else {
|
||||
dc_log_info(mimeparser->context, 0, "Protected headers found in MIME header: Will be ignored as we already found an outer one.");
|
||||
|
@ -1348,6 +1359,7 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc
|
|||
if (mimeparser->header_root==NULL)
|
||||
{
|
||||
mimeparser->header_root = mime->mm_data.mm_message.mm_fields;
|
||||
hash_header(&mimeparser->header, mimeparser->header_root, mimeparser->context);
|
||||
}
|
||||
|
||||
if (mime->mm_data.mm_message.mm_msg_mime)
|
||||
|
@ -1459,10 +1471,6 @@ void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_termi
|
|||
/* recursively check, whats parsed, this also sets up header_old */
|
||||
dc_mimeparser_parse_mime_recursive(mimeparser, mimeparser->mimeroot);
|
||||
|
||||
/* setup header */
|
||||
hash_header(&mimeparser->header, mimeparser->header_root, mimeparser->context);
|
||||
hash_header(&mimeparser->header, mimeparser->header_protected, mimeparser->context); /* overwrite the original header with the protected one */
|
||||
|
||||
/* set some basic data */
|
||||
{
|
||||
struct mailimf_field* field = dc_mimeparser_lookup_field(mimeparser, "Subject");
|
||||
|
|
|
@ -90,7 +90,9 @@ void dc_simplify_unref(dc_simplify_t* simplify)
|
|||
******************************************************************************/
|
||||
|
||||
|
||||
static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char* buf_terminated)
|
||||
static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify,
|
||||
const char* buf_terminated,
|
||||
int is_msgrmsg)
|
||||
{
|
||||
/* This function ...
|
||||
... removes all text after the line `-- ` (footer mark)
|
||||
|
@ -98,9 +100,6 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char
|
|||
these are all lines starting with the character `>`
|
||||
... remove a non-empty line before the removed quote (contains sth. like "On 2.9.2016, Bjoern wrote:" in different formats and lanugages) */
|
||||
|
||||
/* we could skip some of this stuff if we know that the mail is from another messenger,
|
||||
however, this adds some additional complexity and seems not to be needed currently */
|
||||
|
||||
/* split the given buffer into lines */
|
||||
carray* lines = dc_split_into_lines(buf_terminated);
|
||||
int l = 0;
|
||||
|
@ -168,6 +167,7 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char
|
|||
}
|
||||
|
||||
/* remove full quotes at the end of the text */
|
||||
if (!is_msgrmsg)
|
||||
{
|
||||
int l_lastQuotedLine = -1;
|
||||
|
||||
|
@ -202,6 +202,7 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char
|
|||
}
|
||||
|
||||
/* remove full quotes at the beginning of the text */
|
||||
if (!is_msgrmsg)
|
||||
{
|
||||
int l_lastQuotedLine = -1;
|
||||
int hasQuotedHeadline = 0;
|
||||
|
@ -280,7 +281,8 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char
|
|||
******************************************************************************/
|
||||
|
||||
|
||||
char* dc_simplify_simplify(dc_simplify_t* simplify, const char* in_unterminated, int in_bytes, int is_html)
|
||||
char* dc_simplify_simplify(dc_simplify_t* simplify, const char* in_unterminated,
|
||||
int in_bytes, int is_html, int is_msgrmsg)
|
||||
{
|
||||
/* create a copy of the given buffer */
|
||||
char* out = NULL;
|
||||
|
@ -309,7 +311,7 @@ char* dc_simplify_simplify(dc_simplify_t* simplify, const char* in_unterminated,
|
|||
|
||||
/* simplify the text in the buffer (characters to remove may be marked by `\r`) */
|
||||
dc_remove_cr_chars(out); /* make comparisons easier, eg. for line `-- ` */
|
||||
if ((temp = dc_simplify_simplify_plain_text(simplify, out)) != NULL) {
|
||||
if ((temp = dc_simplify_simplify_plain_text(simplify, out, is_msgrmsg)) != NULL) {
|
||||
free(out);
|
||||
out = temp;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,9 @@ void dc_simplify_unref (dc_simplify_t*);
|
|||
/* Simplify and normalise text: Remove quotes, signatures, unnecessary
|
||||
lineends etc.
|
||||
The data returned from Simplify() must be free()'d when no longer used, private */
|
||||
char* dc_simplify_simplify (dc_simplify_t*, const char* txt_unterminated, int txt_bytes, int is_html);
|
||||
char* dc_simplify_simplify (dc_simplify_t*,
|
||||
const char* txt_unterminated, int txt_bytes,
|
||||
int is_html, int is_msgrmsg);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue