From b1ef07c1032ae48e3794278e1671ae8a7ae4d2f8 Mon Sep 17 00:00:00 2001 From: Tyrolyean Date: Wed, 29 Apr 2020 20:18:10 +0200 Subject: [PATCH] Base 64 detection improvement Signed-off-by: Tyrolyean --- include/mail.h | 8 ++++++++ include/tools.h | 4 ++-- src/attach.c | 5 +++-- src/mail.c | 2 ++ src/tools.c | 6 +++--- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/include/mail.h b/include/mail.h index 702f010..34767b7 100644 --- a/include/mail.h +++ b/include/mail.h @@ -49,6 +49,11 @@ struct email_t{ size_t ct_len; char* content_type; + /* NOTICE: the boundary, content_type and message fields may be updated + * when the message of the root object is modified. See the + * propagate_root_pointer function for further information + */ + size_t submes_cnt; struct email_t** submes; struct email_t* parent; @@ -64,6 +69,9 @@ void propagate_insert_delete(struct email_t* mail, char* change_p, ssize_t change); void propagate_root_pointer(struct email_t* mail, char* change_p, char* old_p); +struct type_file_info_t{ +}; + #define MULTIPART_MIME "multipart/" #define BASE64_ENC "base64" diff --git a/include/tools.h b/include/tools.h index 2fe6e1e..42a7f01 100644 --- a/include/tools.h +++ b/include/tools.h @@ -29,8 +29,8 @@ char* search_header_key(const struct email_t* mail, const char* key); char* get_value_from_key(size_t* val_len, size_t key_offset, const struct email_t* mail); -char* get_multipart_boundary(char* content_type, size_t content_len, - size_t* boundary_len); +char* get_value_equals(char* content_type, size_t content_len, + size_t* boundary_len, char* key); const char* get_next_line(const char* message, size_t len); const char* get_prev_line(const char* message, size_t len_neg); diff --git a/src/attach.c b/src/attach.c index 289438b..bd58195 100644 --- a/src/attach.c +++ b/src/attach.c @@ -77,8 +77,9 @@ struct email_t* mail_from_text(char* message, size_t length, */ mail->is_multipart = true; size_t bd_len = 0; - char* bd = get_multipart_boundary( - mime_type, value_length, &bd_len); + char* bd = get_value_equals( + mime_type, value_length, &bd_len, + "boundary"); if(bd != NULL){ mail->boundary = bd; diff --git a/src/mail.c b/src/mail.c index 184854c..88dda2b 100644 --- a/src/mail.c +++ b/src/mail.c @@ -168,3 +168,5 @@ void propagate_root_pointer(struct email_t* mail, char* change_p, char* old_p){ return; } + + diff --git a/src/tools.c b/src/tools.c index 9a8a88b..4e23663 100644 --- a/src/tools.c +++ b/src/tools.c @@ -119,14 +119,14 @@ char* get_value_from_key(size_t* val_len, size_t key_offset, return val; } -char* get_multipart_boundary(char* content_type, size_t content_len, - size_t* boundary_len){ +char* get_value_equals(char* content_type, size_t content_len, + size_t* boundary_len, char* key){ if(content_type == NULL || boundary_len == NULL){ return NULL; } - char* bd = "boundary"; + char* bd = key; char* boundary_begin = NULL; size_t bd_len = strlen(bd); long boundary_offset = -1;