Added boundary retrieval
Signed-off-by: tyrolyean <tyrolyean@tyrolyean.net>
This commit is contained in:
parent
80e3efe078
commit
13b32a48b1
5 changed files with 65 additions and 3 deletions
|
@ -25,7 +25,8 @@
|
|||
|
||||
struct email_t mail_from_text(char* message, size_t length);
|
||||
void redetect_body_head(struct email_t* mail);
|
||||
|
||||
void unravel_multipart_mail(struct email_t* mail, char* boundary,
|
||||
size_t boundary_len);
|
||||
|
||||
char* attach_files(char* message, size_t len);
|
||||
|
||||
|
|
|
@ -39,4 +39,6 @@ struct email_t{
|
|||
int append_header(struct email_t* mail, const char* key, const char* value);
|
||||
int append_to_header(struct email_t* mail, const char* pair);
|
||||
|
||||
#define MULTIPART_MIME "multipart/"
|
||||
|
||||
#endif /* MAIL_H */
|
||||
|
|
|
@ -29,4 +29,6 @@ char* search_header_key(struct email_t* mail, const char* key);
|
|||
char* get_value_from_key(size_t* val_len, size_t key_offset,
|
||||
struct email_t* mail);
|
||||
|
||||
char* get_multipart_boundary(char* content_type, size_t content_len,
|
||||
size_t* boundary_len);
|
||||
#endif /* TOOLS_H */
|
||||
|
|
24
src/attach.c
24
src/attach.c
|
@ -48,8 +48,21 @@ struct email_t mail_from_text(char* message, size_t length){
|
|||
char * mime_type = get_value_from_key(&value_length,
|
||||
cont_type - mail.message, &mail);
|
||||
if(mime_type != NULL){
|
||||
printf("Found message mime type: [%.*s]\n",
|
||||
(int)value_length, mime_type);
|
||||
if(strncasecmp(mime_type, MULTIPART_MIME,
|
||||
strlen(MULTIPART_MIME)) == 0){
|
||||
/* We have multiple messages cramped inside this
|
||||
* one. Let's unravel em!
|
||||
*/
|
||||
size_t bd_len = 0;
|
||||
char* bd = get_multipart_boundary(
|
||||
mime_type, value_length, &bd_len);
|
||||
if(bd != NULL){
|
||||
printf("Received boundary: [%.*s]\n",
|
||||
(int)bd_len, bd);
|
||||
}
|
||||
unravel_multipart_mail(&mail, bd, bd_len);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,6 +106,13 @@ void redetect_body_head(struct email_t* mail){
|
|||
|
||||
}
|
||||
|
||||
void unravel_multipart_mail(struct email_t* mail, char* boundary,
|
||||
size_t boundary_len){
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/* Message is required to be a null terminated string, length is the mail body.
|
||||
* One may leave something behind the body. len is without the '\0'
|
||||
* Attempts to replace files inside the email with links to it on a webserver
|
||||
|
|
37
src/tools.c
37
src/tools.c
|
@ -113,3 +113,40 @@ char* get_value_from_key(size_t* val_len, size_t key_offset,
|
|||
|
||||
return val;
|
||||
}
|
||||
|
||||
char* get_multipart_boundary(char* content_type, size_t content_len,
|
||||
size_t* boundary_len){
|
||||
|
||||
if(content_type == NULL || boundary_len == NULL){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* bd = "boundary";
|
||||
char* boundary_begin = NULL;
|
||||
size_t bd_len = strlen(bd);
|
||||
long boundary_offset = -1;
|
||||
|
||||
for(size_t i = 0; i < (content_len - bd_len);i++){
|
||||
if(strncasecmp(&content_type[i], bd, bd_len) == 0){
|
||||
boundary_offset = i+bd_len;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(boundary_offset < 0){
|
||||
*boundary_len = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for(size_t i = boundary_offset; i < content_len;i++){
|
||||
if(content_type[i] == '"' && boundary_begin == NULL){
|
||||
boundary_begin = &content_type[i+1];
|
||||
}else if(content_type[i] == '"'){
|
||||
*boundary_len = &content_type[i] - boundary_begin ;
|
||||
return boundary_begin;
|
||||
}
|
||||
}
|
||||
|
||||
*boundary_len = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue