Reverted behaviour back to file due to timing change
Signed-off-by: Tyrolyean <tyrolyean@tyrolyean.net>
This commit is contained in:
parent
d1c580e287
commit
f611b9d729
|
@ -19,8 +19,8 @@
|
||||||
#define ATTACH_H
|
#define ATTACH_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
char* attach_files(const unsigned char* original_message,
|
char* attach_files(FILE* buffer);
|
||||||
size_t original_length);
|
|
||||||
|
|
||||||
#endif /* ATTACH_H */
|
#endif /* ATTACH_H */
|
||||||
|
|
17
src/attach.c
17
src/attach.c
|
@ -16,17 +16,24 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "attach.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
char* attach_files(const unsigned char* original_message,
|
char* attach_files(FILE* buffer){
|
||||||
size_t original_length){
|
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){
|
if(new_body == NULL){
|
||||||
return 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
29
src/main.c
29
src/main.c
|
@ -49,6 +49,24 @@ sfsistat mlfi_cleanup(SMFICTX* ctx, bool ok) {
|
||||||
|
|
||||||
/* add a header to the message announcing our presence */
|
/* add a header to the message announcing our presence */
|
||||||
smfi_addheader(ctx, "X-Mail-Attached", VERSION);
|
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 */
|
/* 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);
|
(void) mlfi_cleanup(ctx, false);
|
||||||
return SMFIS_TEMPFAIL;
|
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 */
|
/* continue processing */
|
||||||
return SMFIS_CONTINUE;
|
return SMFIS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue