Added mime type detection
Signed-off-by: Tyrolyean <tyrolyean@tyrolyean.net>
This commit is contained in:
parent
b1ef07c103
commit
5e12445ac7
|
@ -23,6 +23,11 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
struct type_file_info_t{
|
||||||
|
char* name;
|
||||||
|
char* mime_type;
|
||||||
|
};
|
||||||
|
|
||||||
struct email_t{
|
struct email_t{
|
||||||
char* message;
|
char* message;
|
||||||
/* From the below values you can say pretty much anything about the
|
/* From the below values you can say pretty much anything about the
|
||||||
|
@ -58,8 +63,11 @@ struct email_t{
|
||||||
struct email_t** submes;
|
struct email_t** submes;
|
||||||
struct email_t* parent;
|
struct email_t* parent;
|
||||||
bool base64_encoded;
|
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_header(struct email_t* mail, const char* key, const char* value);
|
||||||
int append_to_header(struct email_t* mail, const char* pair);
|
int append_to_header(struct email_t* mail, const char* pair);
|
||||||
|
|
||||||
|
@ -69,8 +77,7 @@ void propagate_insert_delete(struct email_t* mail, char* change_p,
|
||||||
ssize_t change);
|
ssize_t change);
|
||||||
void propagate_root_pointer(struct email_t* mail, char* change_p, char* old_p);
|
void propagate_root_pointer(struct email_t* mail, char* change_p, char* old_p);
|
||||||
|
|
||||||
struct type_file_info_t{
|
struct type_file_info_t get_mime_file_info(struct email_t* mail);
|
||||||
};
|
|
||||||
|
|
||||||
#define MULTIPART_MIME "multipart/"
|
#define MULTIPART_MIME "multipart/"
|
||||||
#define BASE64_ENC "base64"
|
#define BASE64_ENC "base64"
|
||||||
|
|
17
src/attach.c
17
src/attach.c
|
@ -98,6 +98,8 @@ struct email_t* mail_from_text(char* message, size_t length,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mail->base64_encoded = detect_base64(mail);
|
mail->base64_encoded = detect_base64(mail);
|
||||||
|
|
||||||
|
mail->file_info = get_mime_file_info(mail);
|
||||||
|
|
||||||
return mail;
|
return mail;
|
||||||
}
|
}
|
||||||
|
@ -237,9 +239,18 @@ void print_mail_structure(struct email_t *email, unsigned int level){
|
||||||
print_mail_structure(email->submes[i], level+1);
|
print_mail_structure(email->submes[i], level+1);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
printf("final message with length %lu and type [%.*s] \n",
|
if( email->file_info.mime_type == NULL){
|
||||||
email->message_length, (int)email->ct_len,
|
|
||||||
email->content_type);
|
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;
|
return;
|
||||||
|
|
31
src/mail.c
31
src/mail.c
|
@ -168,5 +168,36 @@ void propagate_root_pointer(struct email_t* mail, char* change_p, char* old_p){
|
||||||
|
|
||||||
return;
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue