Compare commits
No commits in common. "5f898f4e492d5df78cd0014ce8c03acd3a7eac83" and "0431bcda913d0dfc995b4c952ab21d3ed143372a" have entirely different histories.
5f898f4e49
...
0431bcda91
3 changed files with 4 additions and 91 deletions
|
@ -71,7 +71,7 @@ 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);
|
||||
int append_to_body(struct email_t* mail, const char* text);
|
||||
|
||||
int remove_mail(struct email_t* mail);
|
||||
|
||||
struct email_t* get_root_mail(struct email_t* mail);
|
||||
|
|
55
src/attach.c
55
src/attach.c
|
@ -319,40 +319,6 @@ finish:
|
|||
return mess;
|
||||
}
|
||||
|
||||
/* This function returns the first message where it makes sense to append the
|
||||
* attachment message to. To differentiate between text and html the mime type
|
||||
* is sent along
|
||||
*/
|
||||
struct email_t* get_appendable_mail(struct email_t* mail,
|
||||
const char* mime_type){
|
||||
|
||||
if(mail->is_multipart){
|
||||
struct email_t* ret = NULL;
|
||||
for(size_t i = 0; i < mail->submes_cnt; i++){
|
||||
struct email_t* ret2 =
|
||||
get_appendable_mail(mail->submes[i], mime_type);
|
||||
if(ret2 != NULL){
|
||||
ret = ret2;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
if(mail->base64_encoded || mail->file_info.mime_type == NULL ||
|
||||
mail->file_info.name != NULL){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(strcasecmp(mail->file_info.mime_type, mime_type) == 0){
|
||||
return mail;
|
||||
}else{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* This function RECURSIVELY replaces ALL base 64 encoded messages above the
|
||||
* threshold set in the config file with links to that file in the HTML format.
|
||||
* Call this function with the mail ROOT object if you want to replace all
|
||||
|
@ -392,15 +358,6 @@ int replace_files(struct email_t* mail, const char* dirname, bool* created){
|
|||
}
|
||||
|
||||
}
|
||||
struct email_t* root = get_root_mail(mail);
|
||||
if(root == NULL){
|
||||
return -1;
|
||||
}
|
||||
struct email_t* txt_app = get_appendable_mail(root, "text/plain");
|
||||
struct email_t* html_app = get_appendable_mail(root, "text/html");
|
||||
if(txt_app == NULL && html_app == NULL){
|
||||
return -1;
|
||||
}
|
||||
char* chosen_filename = NULL;
|
||||
if(mail->base64_encoded){
|
||||
if(base64_decode_file(dirname, mail, &chosen_filename) < 0){
|
||||
|
@ -444,7 +401,7 @@ int replace_files(struct email_t* mail, const char* dirname, bool* created){
|
|||
mime_len = strlen(mail->file_info.mime_type);
|
||||
}
|
||||
|
||||
size_t html_buffer_len = strlen(html_filler_pref) + 2*url_len + 100 +
|
||||
size_t html_buffer_len = strlen(html_filler_pref) + 2*url_len + 50 +
|
||||
mime_len + 2*strlen(mail->file_info.name);
|
||||
|
||||
size_t text_buffer_len = strlen(html_filler_pref) + url_len + 50 +
|
||||
|
@ -467,14 +424,8 @@ int replace_files(struct email_t* mail, const char* dirname, bool* created){
|
|||
mail->file_info.mime_type,
|
||||
url_base, chosen_filename+directory_len);
|
||||
|
||||
|
||||
if(txt_app != NULL){
|
||||
append_to_body(txt_app, text_buffer);
|
||||
}
|
||||
if(html_app != NULL){
|
||||
append_to_body(html_app, html_buffer);
|
||||
|
||||
}
|
||||
printf(html_buffer);
|
||||
printf(text_buffer);
|
||||
|
||||
free(html_buffer);
|
||||
free(text_buffer);
|
||||
|
|
38
src/mail.c
38
src/mail.c
|
@ -79,44 +79,6 @@ int append_to_header(struct email_t* mail, const char* pair){
|
|||
}
|
||||
propagate_size_change(mail, strlen(buffer));
|
||||
|
||||
propagate_root_pointer(root, new_root, old_root);
|
||||
propagate_insert_delete(root, root->message+root_offset,
|
||||
strlen(buffer));
|
||||
|
||||
mail->header_len += strlen(buffer);
|
||||
mail->body_offset += strlen(buffer);
|
||||
|
||||
free(buffer);
|
||||
redetect_body_head(mail);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/* Append the string text DIRECTLY to the end of the body of the message mail*/
|
||||
int append_to_body(struct email_t* mail, const char* text){
|
||||
|
||||
if(text == NULL || mail == NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *buffer = malloc(strlen(text) + 3);
|
||||
memset(buffer, 0, strlen(text) + 3);
|
||||
buffer[0] = '\r';
|
||||
buffer[1] = '\n';
|
||||
strcat(buffer, text);
|
||||
struct email_t* root = get_root_mail(mail);
|
||||
size_t root_offset = mail->message_length +
|
||||
(mail->message - root->message);
|
||||
|
||||
char* old_root = root->message;
|
||||
char * new_root = insert_string(root->message, buffer,
|
||||
root->message_length, root_offset);
|
||||
if(new_root == NULL){
|
||||
return -1;
|
||||
}
|
||||
propagate_size_change(mail, strlen(buffer));
|
||||
|
||||
propagate_root_pointer(root, new_root, old_root);
|
||||
propagate_insert_delete(root, root->message+root_offset,
|
||||
strlen(buffer));
|
||||
|
|
Loading…
Reference in a new issue