diff --git a/include/attach.h b/include/attach.h index e127ae4..599fceb 100644 --- a/include/attach.h +++ b/include/attach.h @@ -21,15 +21,7 @@ #include #include -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; -}; +#include "mail.h" struct email_t mail_from_text(char* message, size_t length); void redetect_body_head(struct email_t* mail); diff --git a/include/mail.h b/include/mail.h new file mode 100644 index 0000000..44272fc --- /dev/null +++ b/include/mail.h @@ -0,0 +1,37 @@ +/* + * 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 +#include + +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 */ diff --git a/include/tools.h b/include/tools.h index 48f7362..0f571f7 100644 --- a/include/tools.h +++ b/include/tools.h @@ -20,7 +20,7 @@ #include -const char* insert_string(char * destination, const char* source, +char* insert_string(char * destination, const char* source, size_t dest_orig_len, size_t offset); diff --git a/src/attach.c b/src/attach.c index 2ca2b5a..585c6b4 100644 --- a/src/attach.c +++ b/src/attach.c @@ -19,6 +19,7 @@ #include "attach.h" #include "detect.h" #include "config.h" +#include "mail.h" #include #include @@ -94,6 +95,10 @@ char* attach_files(char* message, size_t len){ 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; } diff --git a/src/mail.c b/src/mail.c new file mode 100644 index 0000000..463d499 --- /dev/null +++ b/src/mail.c @@ -0,0 +1,77 @@ +/* + * 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 +#include +#include +#include + +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; + +} + diff --git a/src/network.c b/src/network.c index e5d3e2f..5a0ee0d 100644 --- a/src/network.c +++ b/src/network.c @@ -248,7 +248,8 @@ int init_net(){ serveraddr.sin_port = htons((unsigned short)listen_port); if (bind(parentfd, (struct sockaddr *) &serveraddr, - sizeof(serveraddr)) < 0) { + sizeof(serveraddr)) < 0) { + perror("ERROR on binding"); return -1; } diff --git a/src/tools.c b/src/tools.c index 17b7d41..37054b3 100644 --- a/src/tools.c +++ b/src/tools.c @@ -24,7 +24,7 @@ /* Takes a string destination and inserts at the given point offset the string * in source. Really more like a stringcat with shifting the end. * dest_orig_len is without '\0'*/ -const char* insert_string(char * destination, const char* source, +char* insert_string(char * destination, const char* source, size_t dest_orig_len, size_t offset){ if(source == NULL|| dest_orig_len < offset){