From f611b9d729767b9273cbdade1c689ca5e8f697ee Mon Sep 17 00:00:00 2001 From: Tyrolyean Date: Sat, 25 Apr 2020 01:50:44 +0200 Subject: [PATCH] Reverted behaviour back to file due to timing change Signed-off-by: Tyrolyean --- include/attach.h | 4 ++-- src/attach.c | 17 ++++++++++++----- src/main.c | 29 ++++++++++++++++++----------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/include/attach.h b/include/attach.h index 513b71e..78bdcf2 100644 --- a/include/attach.h +++ b/include/attach.h @@ -19,8 +19,8 @@ #define ATTACH_H #include +#include -char* attach_files(const unsigned char* original_message, - size_t original_length); +char* attach_files(FILE* buffer); #endif /* ATTACH_H */ diff --git a/src/attach.c b/src/attach.c index cd23083..13cd661 100644 --- a/src/attach.c +++ b/src/attach.c @@ -16,17 +16,24 @@ * under the License. */ +#include "attach.h" #include #include -char* attach_files(const unsigned char* original_message, - size_t original_length){ +char* attach_files(FILE* buffer){ + fseek(buffer, 0, SEEK_END); + size_t len = ftell(buffer); - const char* new_body = malloc(original_length + 1); + char* new_body = malloc(len + 1); if(new_body == NULL){ return NULL; } - memset(new_body,0, original_length + 1); - + memset(new_body,0, len + 1); + if(fread(new_body, 1, len, buffer) <= 0){ + perror("Failed to read file buffer"); + free(new_body); + } + + return new_body; } diff --git a/src/main.c b/src/main.c index 15690ae..f49be34 100644 --- a/src/main.c +++ b/src/main.c @@ -49,6 +49,24 @@ sfsistat mlfi_cleanup(SMFICTX* ctx, bool ok) { /* add a header to the message announcing our presence */ smfi_addheader(ctx, "X-Mail-Attached", VERSION); + + /* replace body if attachements have been found */ + char* new_body = attach_files(priv->mlfi_fp); + if(new_body != NULL){ + + size_t new_bodylen = strlen(new_body)+1; + unsigned char * replacement = malloc(new_bodylen+1); + memset(replacement, 0, new_bodylen+1); + memcpy(replacement, replacement, new_bodylen+1); + free(new_body); + printf("Replacing body of mail message\n"); + if(smfi_replacebody(ctx, replacement, new_bodylen) == + MI_FAILURE){ + printf("Failed to replace body of message...\n" + ); + free(replacement); + } + } } /* In any case release the temporary data storage file */ @@ -126,17 +144,6 @@ sfsistat mlfi_body(SMFICTX* ctx, unsigned char * bodyp, size_t bodylen) { (void) mlfi_cleanup(ctx, false); return SMFIS_TEMPFAIL; } - char* new_body = attach_files(bodyp, bodylen); - if(new_body != NULL){ - - size_t new_bodylen = strlen(new_body)+1; - unsigned char * replacement = malloc(new_bodylen+1); - memset(replacement, 0, new_bodylen+1); - memcpy(replacement, replacement, new_bodylen+1); - free(new_body); - printf("Replacing body of mail message\n"); - smfi_replacebody(ctx, replacement, new_bodylen); - } /* continue processing */ return SMFIS_CONTINUE; }