Debugging repacebody

Signed-off-by: Tyrolyean <tyrolyean@tyrolyean.net>
This commit is contained in:
Tyrolyean 2020-04-25 17:48:13 +02:00
parent 449cb018c3
commit 561ed72add
No known key found for this signature in database
GPG key ID: 81EC9BAC5E9667C6
2 changed files with 27 additions and 10 deletions

View file

@ -18,4 +18,10 @@
#define VERSION "0.1" #define VERSION "0.1"
#ifndef bool
# define bool int
# define TRUE 1
# define FALSE 0
#endif /* ! bool */
#endif /* LICENSE_H */ #endif /* LICENSE_H */

View file

@ -11,7 +11,6 @@
#include <string.h> #include <string.h>
#include <sysexits.h> #include <sysexits.h>
#include <unistd.h> #include <unistd.h>
#include <stdbool.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <libmilter/mfapi.h> #include <libmilter/mfapi.h>
@ -49,20 +48,24 @@ sfsistat mlfi_cleanup(SMFICTX* ctx, bool ok) {
char* new_body = attach_files(priv->mlfi_fp); char* new_body = attach_files(priv->mlfi_fp);
if(new_body != NULL){ if(new_body != NULL){
const char* head = "REPLACED:";
size_t new_bodylen = strlen(new_body)+1; size_t new_bodylen = strlen(new_body)+10;
unsigned char * replacement = malloc(new_bodylen+1); unsigned char * replacement = malloc(new_bodylen+1);
memset(replacement, 0, new_bodylen+1); memset(replacement, 0, new_bodylen+1);
memcpy(replacement, replacement, new_bodylen+1); strcat(replacement, head);
strcat(replacement, new_body);
free(new_body); free(new_body);
printf("Replacing body of mail message\n"); printf("Replacing body of mail message with len %lu\n",
if(smfi_replacebody(ctx, replacement, new_bodylen) == strlen(replacement));
printf("Content: [%s]\n",replacement);
if(smfi_replacebody(ctx, replacement, strlen(replacement)) ==
MI_FAILURE){ MI_FAILURE){
printf("Failed to replace body of message...\n" printf("Failed to replace body of message...\n"
); );
free(replacement); free(replacement);
} }
} }
} }
/* close the archive file */ /* close the archive file */
if (priv->mlfi_fp != NULL && fclose(priv->mlfi_fp) == EOF){ if (priv->mlfi_fp != NULL && fclose(priv->mlfi_fp) == EOF){
@ -208,7 +211,7 @@ struct smfiDesc smfilter =
{ {
"mailattach", /* filter name */ "mailattach", /* filter name */
SMFI_VERSION, /* version code -- do not change */ SMFI_VERSION, /* version code -- do not change */
SMFIF_ADDHDRS | SMFIF_CHGBODY, /* flags */ SMFIF_ADDHDRS|SMFIF_CHGFROM|SMFIF_ADDRCPT|SMFIF_DELRCPT|SMFIF_CHGBODY, /* flags */
NULL, /* connection info filter */ NULL, /* connection info filter */
NULL, /* SMTP HELO command filter */ NULL, /* SMTP HELO command filter */
mlfi_envfrom, /* envelope sender filter */ mlfi_envfrom, /* envelope sender filter */
@ -229,11 +232,19 @@ struct smfiDesc smfilter =
int main(){ int main(){
printf("INIT\n"); printf("INIT\n");
const char* conn_prefix = "local:";
size_t conn_len = strlen(socket_location)+strlen(conn_prefix)+1;
char * conn_str = malloc(conn_len);
memset(conn_str, 0, conn_len);
strcat(conn_str, conn_prefix);
strcat(conn_str, socket_location);
printf("Using socket for milter communication at [%s]\n", printf("Using socket for milter communication at [%s]\n",
socket_location); conn_str);
smfi_setconn(conn_str);
smfi_setconn("local:/var/run/mailattach");
if (smfi_register(smfilter) == MI_FAILURE) if (smfi_register(smfilter) == MI_FAILURE)
{ {