Compare commits

..

No commits in common. "fdc2ddf53b0e27a4169c80d21a7924e4eb4a91e6" and "13125100749877b9555558fa9f7af213ebdf7911" have entirely different histories.

11 changed files with 13 additions and 154 deletions

View file

@ -21,7 +21,15 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "mail.h" struct email_t{
char* message;
/* From the below values you can say pretty much anything about the
* message. The line delimiting body and header is left out. The header
* len includes the last \r\n of the header. If header len is zero,
* there was no clear distinction between header and body...
*/
size_t header_len, body_offset, message_length;
};
struct email_t mail_from_text(char* message, size_t length); struct email_t mail_from_text(char* message, size_t length);
void redetect_body_head(struct email_t* mail); void redetect_body_head(struct email_t* mail);

View file

@ -26,6 +26,4 @@ extern uint16_t listen_port, forward_port;
extern int abort_on_pgp, abort_on_dkim; extern int abort_on_pgp, abort_on_dkim;
extern char* instance_id;
#endif /* CONFIG_H */ #endif /* CONFIG_H */

View file

@ -1,37 +0,0 @@
/*
* mail.h - Mail editing toolset
* The author licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef MAIL_H
#define MAIL_H
#include <stdint.h>
#include <stddef.h>
struct email_t{
char* message;
/* From the below values you can say pretty much anything about the
* message. The line delimiting body and header is left out. The header
* len includes the last \r\n of the header. If header len is zero,
* there was no clear distinction between header and body...
*/
size_t header_len, body_offset, message_length;
};
int append_header(struct email_t* mail, const char* key, const char* value);
int append_to_header(struct email_t* mail, const char* pair);
#endif /* MAIL_H */

View file

@ -20,7 +20,7 @@
#include <stddef.h> #include <stddef.h>
char* insert_string(char * destination, const char* source, const char* insert_string(char * destination, const char* source,
size_t dest_orig_len, size_t offset); size_t dest_orig_len, size_t offset);

View file

@ -19,7 +19,6 @@
#include "attach.h" #include "attach.h"
#include "detect.h" #include "detect.h"
#include "config.h" #include "config.h"
#include "mail.h"
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -95,10 +94,6 @@ char* attach_files(char* message, size_t len){
return email.message; return email.message;
} }
/* Now we can start the real work! */
/* Announce our presence via header */
append_header(&email,"X-Mailattached", instance_id);
return email.message; return email.message;
} }

View file

@ -14,11 +14,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
#include "config.h" #include "config.h"
#include <stddef.h>
uint16_t listen_port = 4269, forward_port = 4270; uint16_t listen_port = 4269, forward_port = 4270;
int abort_on_pgp = true, abort_on_dkim = true; int abort_on_pgp = true, abort_on_dkim = true;
char* instance_id = NULL;

View file

@ -58,7 +58,6 @@ bool detect_dkim(struct email_t* mail){
if(strcasestr(mail->message, dkim_signatures[i]) != NULL if(strcasestr(mail->message, dkim_signatures[i]) != NULL
&& strcasestr(mail->message, dkim_signatures[i]) && strcasestr(mail->message, dkim_signatures[i])
<= (mail->message+mail->header_len)){ <= (mail->message+mail->header_len)){
/* DKIM only happens inside the header, not the body! */
points++; points++;
} }

View file

@ -1,77 +0,0 @@
/*
* mail.c - Mail editing toolset
* The author licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "mail.h"
#include "tools.h"
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
int append_header(struct email_t* mail, const char* key, const char* value){
if(mail == NULL || key == NULL || value == NULL){
return -1;
}
const char* in_between = ": ";
size_t len = strlen(key) + strlen(value) + strlen(in_between) + 1;
char* buffer = malloc(len);
if(buffer == NULL){
return -1;
}
memset(buffer, 0, len);
strcat(buffer, key);
strcat(buffer, in_between);
strcat(buffer, value);
if(append_to_header(mail, buffer) < 0){
free(buffer);
return -1;
}
free(buffer);
return 0;
}
int append_to_header(struct email_t* mail, const char* pair){
if(pair == NULL || mail == NULL){
return -1;
}
char *buffer = malloc(strlen(pair) + 3);
if(buffer == NULL){
return -1;
}
memset(buffer, 0, strlen(pair) + 3);
buffer[0] = '\r';
buffer[1] = '\n';
strcat(buffer, pair);
mail->message=insert_string(mail->message, buffer, strlen(buffer),
mail->header_len);
free(buffer);
return 0;
}

View file

@ -7,9 +7,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <getopt.h> #include <getopt.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include "network.h" #include "network.h"
#include "config.h" #include "config.h"
@ -30,13 +27,12 @@ int main(int argc, char* argv[]){
{"noabort-dkim",no_argument, &abort_on_dkim,0}, {"noabort-dkim",no_argument, &abort_on_dkim,0},
{"in-port", required_argument, 0, 'i'}, {"in-port", required_argument, 0, 'i'},
{"out-port", required_argument, 0, 'o'}, {"out-port", required_argument, 0, 'o'},
{"instance-id", required_argument, 0, 'n'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
/* getopt_long stores the option index here. */ /* getopt_long stores the option index here. */
int option_index = 0; int option_index = 0;
c = getopt_long (argc, argv, "n:i:o:pd", c = getopt_long (argc, argv, "i:o:pd",
long_options, &option_index); long_options, &option_index);
/* Detect the end of the options. */ /* Detect the end of the options. */
@ -55,10 +51,6 @@ int main(int argc, char* argv[]){
forward_port = atoi(optarg); forward_port = atoi(optarg);
break; break;
case 'n':
instance_id = optarg;
break;
case '?': case '?':
/* getopt_long already printed an error message. */ /* getopt_long already printed an error message. */
return EXIT_FAILURE; return EXIT_FAILURE;
@ -69,17 +61,6 @@ int main(int argc, char* argv[]){
} }
} }
/* If not already specified, populate the instance ID with the sytem
* hostname.
*/
if(instance_id == NULL){
instance_id = malloc(HOST_NAME_MAX + 1);
memset(instance_id, 0, HOST_NAME_MAX + 1);
if(gethostname(instance_id, HOST_NAME_MAX) < 0){
perror("gethostname failed! set instance id manually");
}
}
printf("Incoming port: %u outgoing port: %u on loopback interface\n", printf("Incoming port: %u outgoing port: %u on loopback interface\n",
listen_port, forward_port); listen_port, forward_port);
@ -89,9 +70,6 @@ int main(int argc, char* argv[]){
printf("Ignoring DKIM signed messages: %s\n", printf("Ignoring DKIM signed messages: %s\n",
abort_on_dkim ? "true" : "false"); abort_on_dkim ? "true" : "false");
printf("Instance id for messages: %s\n",
instance_id);
if(init_net() < 0){ if(init_net() < 0){
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View file

@ -249,7 +249,6 @@ int init_net(){
if (bind(parentfd, (struct sockaddr *) &serveraddr, if (bind(parentfd, (struct sockaddr *) &serveraddr,
sizeof(serveraddr)) < 0) { sizeof(serveraddr)) < 0) {
perror("ERROR on binding"); perror("ERROR on binding");
return -1; return -1;
} }

View file

@ -24,7 +24,7 @@
/* Takes a string destination and inserts at the given point offset the string /* Takes a string destination and inserts at the given point offset the string
* in source. Really more like a stringcat with shifting the end. * in source. Really more like a stringcat with shifting the end.
* dest_orig_len is without '\0'*/ * dest_orig_len is without '\0'*/
char* insert_string(char * destination, const char* source, const char* insert_string(char * destination, const char* source,
size_t dest_orig_len, size_t offset){ size_t dest_orig_len, size_t offset){
if(source == NULL|| dest_orig_len < offset){ if(source == NULL|| dest_orig_len < offset){