Compare commits
2 commits
c5257bbb6c
...
5e12445ac7
Author | SHA1 | Date | |
---|---|---|---|
5e12445ac7 | |||
b1ef07c103 |
5 changed files with 70 additions and 10 deletions
|
@ -23,6 +23,11 @@
|
|||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
struct type_file_info_t{
|
||||
char* name;
|
||||
char* mime_type;
|
||||
};
|
||||
|
||||
struct email_t{
|
||||
char* message;
|
||||
/* From the below values you can say pretty much anything about the
|
||||
|
@ -49,12 +54,20 @@ struct email_t{
|
|||
size_t ct_len;
|
||||
char* content_type;
|
||||
|
||||
/* NOTICE: the boundary, content_type and message fields may be updated
|
||||
* when the message of the root object is modified. See the
|
||||
* propagate_root_pointer function for further information
|
||||
*/
|
||||
|
||||
size_t submes_cnt;
|
||||
struct email_t** submes;
|
||||
struct email_t* parent;
|
||||
bool base64_encoded;
|
||||
struct type_file_info_t file_info;
|
||||
};
|
||||
|
||||
|
||||
|
||||
int append_header(struct email_t* mail, const char* key, const char* value);
|
||||
int append_to_header(struct email_t* mail, const char* pair);
|
||||
|
||||
|
@ -64,6 +77,8 @@ void propagate_insert_delete(struct email_t* mail, char* change_p,
|
|||
ssize_t change);
|
||||
void propagate_root_pointer(struct email_t* mail, char* change_p, char* old_p);
|
||||
|
||||
struct type_file_info_t get_mime_file_info(struct email_t* mail);
|
||||
|
||||
#define MULTIPART_MIME "multipart/"
|
||||
#define BASE64_ENC "base64"
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ char* search_header_key(const struct email_t* mail, const char* key);
|
|||
char* get_value_from_key(size_t* val_len, size_t key_offset,
|
||||
const struct email_t* mail);
|
||||
|
||||
char* get_multipart_boundary(char* content_type, size_t content_len,
|
||||
size_t* boundary_len);
|
||||
char* get_value_equals(char* content_type, size_t content_len,
|
||||
size_t* boundary_len, char* key);
|
||||
|
||||
const char* get_next_line(const char* message, size_t len);
|
||||
const char* get_prev_line(const char* message, size_t len_neg);
|
||||
|
|
22
src/attach.c
22
src/attach.c
|
@ -77,8 +77,9 @@ struct email_t* mail_from_text(char* message, size_t length,
|
|||
*/
|
||||
mail->is_multipart = true;
|
||||
size_t bd_len = 0;
|
||||
char* bd = get_multipart_boundary(
|
||||
mime_type, value_length, &bd_len);
|
||||
char* bd = get_value_equals(
|
||||
mime_type, value_length, &bd_len,
|
||||
"boundary");
|
||||
|
||||
if(bd != NULL){
|
||||
mail->boundary = bd;
|
||||
|
@ -97,6 +98,8 @@ struct email_t* mail_from_text(char* message, size_t length,
|
|||
}
|
||||
}
|
||||
mail->base64_encoded = detect_base64(mail);
|
||||
|
||||
mail->file_info = get_mime_file_info(mail);
|
||||
|
||||
return mail;
|
||||
}
|
||||
|
@ -236,9 +239,18 @@ void print_mail_structure(struct email_t *email, unsigned int level){
|
|||
print_mail_structure(email->submes[i], level+1);
|
||||
}
|
||||
}else{
|
||||
printf("final message with length %lu and type [%.*s] \n",
|
||||
email->message_length, (int)email->ct_len,
|
||||
email->content_type);
|
||||
if( email->file_info.mime_type == NULL){
|
||||
|
||||
printf("final message with length %lu and type "
|
||||
"[%.*s] \n",
|
||||
email->message_length, (int)email->ct_len,
|
||||
email->content_type);
|
||||
}else{
|
||||
printf("final message with length %lu and type [%s] \n",
|
||||
email->message_length,
|
||||
email->file_info.mime_type);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
33
src/mail.c
33
src/mail.c
|
@ -168,3 +168,36 @@ void propagate_root_pointer(struct email_t* mail, char* change_p, char* old_p){
|
|||
|
||||
return;
|
||||
}
|
||||
struct type_file_info_t get_mime_file_info(struct email_t* mail){
|
||||
|
||||
struct type_file_info_t fileinfo;
|
||||
fileinfo.name = NULL;
|
||||
fileinfo.mime_type = NULL;
|
||||
|
||||
if(mail->content_type == NULL){
|
||||
return fileinfo;
|
||||
}
|
||||
|
||||
char* semic = strchr(mail->content_type, ';');
|
||||
size_t mime_len = 0;
|
||||
if(semic > (mail->content_type + mail->ct_len)){
|
||||
mime_len = mail->ct_len;
|
||||
}else{
|
||||
mime_len = semic - mail->content_type;
|
||||
}
|
||||
|
||||
fileinfo.mime_type = malloc(mime_len + 1);
|
||||
memset(fileinfo.mime_type, 0, mime_len + 1);
|
||||
memcpy(fileinfo.mime_type, mail->content_type, mime_len);
|
||||
size_t filename_len = 0;
|
||||
char* filename = get_value_equals(mail->content_type, mail->ct_len,
|
||||
&filename_len, "name");
|
||||
|
||||
if(filename != NULL){
|
||||
fileinfo.name = malloc(filename_len + 1);
|
||||
memset(fileinfo.name, 0, filename_len + 1);
|
||||
memcpy(fileinfo.name, filename, filename_len);
|
||||
}
|
||||
|
||||
return fileinfo;
|
||||
}
|
||||
|
|
|
@ -119,14 +119,14 @@ 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){
|
||||
char* get_value_equals(char* content_type, size_t content_len,
|
||||
size_t* boundary_len, char* key){
|
||||
|
||||
if(content_type == NULL || boundary_len == NULL){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* bd = "boundary";
|
||||
char* bd = key;
|
||||
char* boundary_begin = NULL;
|
||||
size_t bd_len = strlen(bd);
|
||||
long boundary_offset = -1;
|
||||
|
|
Loading…
Reference in a new issue