Compare commits
No commits in common. "5e12445ac7f53a60b1b208d0492ce252dda67312" and "c5257bbb6cca67595f44b01fcc0343423671b3d2" have entirely different histories.
5e12445ac7
...
c5257bbb6c
5 changed files with 10 additions and 70 deletions
|
@ -23,11 +23,6 @@
|
|||
#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
|
||||
|
@ -54,20 +49,12 @@ 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);
|
||||
|
||||
|
@ -77,8 +64,6 @@ 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_value_equals(char* content_type, size_t content_len,
|
||||
size_t* boundary_len, char* key);
|
||||
char* get_multipart_boundary(char* content_type, size_t content_len,
|
||||
size_t* boundary_len);
|
||||
|
||||
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,9 +77,8 @@ struct email_t* mail_from_text(char* message, size_t length,
|
|||
*/
|
||||
mail->is_multipart = true;
|
||||
size_t bd_len = 0;
|
||||
char* bd = get_value_equals(
|
||||
mime_type, value_length, &bd_len,
|
||||
"boundary");
|
||||
char* bd = get_multipart_boundary(
|
||||
mime_type, value_length, &bd_len);
|
||||
|
||||
if(bd != NULL){
|
||||
mail->boundary = bd;
|
||||
|
@ -99,8 +98,6 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -239,18 +236,9 @@ void print_mail_structure(struct email_t *email, unsigned int level){
|
|||
print_mail_structure(email->submes[i], level+1);
|
||||
}
|
||||
}else{
|
||||
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);
|
||||
|
||||
}
|
||||
printf("final message with length %lu and type [%.*s] \n",
|
||||
email->message_length, (int)email->ct_len,
|
||||
email->content_type);
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
33
src/mail.c
33
src/mail.c
|
@ -168,36 +168,3 @@ 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_value_equals(char* content_type, size_t content_len,
|
||||
size_t* boundary_len, char* key){
|
||||
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 = key;
|
||||
char* bd = "boundary";
|
||||
char* boundary_begin = NULL;
|
||||
size_t bd_len = strlen(bd);
|
||||
long boundary_offset = -1;
|
||||
|
|
Loading…
Reference in a new issue