From 0e9980154dfed6b4b10eb5f2a732c178a008e642 Mon Sep 17 00:00:00 2001 From: Tyrolyean Date: Tue, 28 Apr 2020 20:00:11 +0200 Subject: [PATCH] Resized mail message body to allow resize Signed-off-by: Tyrolyean --- src/attach.c | 2 +- src/main.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/attach.c b/src/attach.c index 5fc3f86..144d7b0 100644 --- a/src/attach.c +++ b/src/attach.c @@ -66,7 +66,7 @@ void redetect_body_head(struct email_t* mail){ } mail->body_offset = body_start - mail->message; - mail->header_len = last_lf - mail->message; + mail->header_len = last_lf - mail->message - 1 /* for the CR */; return; diff --git a/src/main.c b/src/main.c index a9ba771..9956b29 100644 --- a/src/main.c +++ b/src/main.c @@ -92,6 +92,24 @@ void receive_mail(struct mail_recv_t* rec){ size_t body_len = rec->body_p- (rec->input_buffer+rec->body_offs); + /* Copy the after body message and reduce original + * pointer to mail size to allow reallocs */ + size_t abody_len = rec->in_len- + (rec->body_offs+body_len); + + void * abody = malloc(abody_len); + memcpy(abody, + rec->input_buffer+rec->body_offs+body_len, + abody_len); + + /* reduce the input buffer to the body */ + memmove(rec->input_buffer, + rec->input_buffer+rec->body_offs, body_len); + rec->input_buffer = realloc(rec->input_buffer, + body_len + 1); + rec->input_buffer[body_len+1] = 0; + rec->in_len = body_len; + char* new_body = attach_files( rec->input_buffer+rec->body_offs, body_len); @@ -112,8 +130,8 @@ void receive_mail(struct mail_recv_t* rec){ /* Rest of conversation after message */ write((rec->fds[1].fd), - rec->input_buffer+rec->body_offs+body_len, - rec->in_len-(rec->body_offs+body_len)); + abody, + abody_len); rec->after_body = true;