Reverted behaviour back to file due to timing change

Signed-off-by: Tyrolyean <tyrolyean@tyrolyean.net>
This commit is contained in:
Tyrolyean 2020-04-25 01:50:44 +02:00
parent d1c580e287
commit f611b9d729
No known key found for this signature in database
GPG Key ID: 81EC9BAC5E9667C6
3 changed files with 32 additions and 18 deletions

View File

@ -19,8 +19,8 @@
#define ATTACH_H
#include <stdint.h>
#include <stdio.h>
char* attach_files(const unsigned char* original_message,
size_t original_length);
char* attach_files(FILE* buffer);
#endif /* ATTACH_H */

View File

@ -16,17 +16,24 @@
* under the License.
*/
#include "attach.h"
#include <string.h>
#include <stdlib.h>
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;
}

View File

@ -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;
}