Added conditional directory creation
Signed-off-by: Tyrolyean <tyrolyean@tyrolyean.net>
This commit is contained in:
parent
8c5cbe50e9
commit
fa6027c437
4 changed files with 25 additions and 16 deletions
|
@ -32,6 +32,6 @@ void free_submails(struct email_t* mail);
|
|||
|
||||
char* attach_files(char* message, size_t len);
|
||||
|
||||
int replace_base64_files(struct email_t* mail, const char* dirname);
|
||||
int replace_files(struct email_t* mail, const char* dirname, bool* created);
|
||||
|
||||
#endif /* ATTACH_H */
|
||||
|
|
35
src/attach.c
35
src/attach.c
|
@ -297,12 +297,8 @@ char* attach_files(char* message, size_t len){
|
|||
printf("Storing mail messages into directory [%s]\n",
|
||||
storage_dir);
|
||||
}
|
||||
if(mkdir(storage_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0){
|
||||
perror("Failed to create storage directory!");
|
||||
goto finish;
|
||||
|
||||
}
|
||||
if(replace_base64_files(email, storage_dir) < 0){
|
||||
bool dir_cre = false;
|
||||
if(replace_files(email, storage_dir, &dir_cre) < 0){
|
||||
fprintf(stderr, "Failed to store base64 messages!\n");
|
||||
goto finish;
|
||||
}
|
||||
|
@ -325,14 +321,17 @@ finish:
|
|||
/* 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
|
||||
* base64 files, or only one when you want to replace only one.
|
||||
* base64 files, or only one when you want to replace only one. Created is a
|
||||
* boolean wether the directory to store files has already been created.
|
||||
*/
|
||||
int replace_base64_files(struct email_t* mail, const char* dirname){
|
||||
int replace_files(struct email_t* mail, const char* dirname, bool* created){
|
||||
|
||||
if(mail->is_multipart){
|
||||
|
||||
for(size_t i = 0; i < mail->submes_cnt; i++){
|
||||
if(replace_base64_files(mail->submes[i], dirname) < 0){
|
||||
if(replace_files(mail->submes[i], dirname, created)
|
||||
< 0){
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -346,7 +345,17 @@ int replace_base64_files(struct email_t* mail, const char* dirname){
|
|||
min_filesize ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!*created){
|
||||
*created = true;
|
||||
if(mkdir(directory, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
|
||||
< 0){
|
||||
|
||||
perror("Failed to create storage directory!");
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if(mail->base64_encoded){
|
||||
if(base64_decode_file(dirname, mail) < 0){
|
||||
fprintf(stderr, "Failed to decode base64 file\n!");
|
||||
|
@ -362,7 +371,7 @@ int replace_base64_files(struct email_t* mail, const char* dirname){
|
|||
}
|
||||
|
||||
}
|
||||
/* Replace the mail message with some html text TODO */
|
||||
/* Insert a message telling you what has happened to the attachment */
|
||||
|
||||
/* Delete old attachment */
|
||||
if(mail->parent != NULL){
|
||||
|
@ -371,6 +380,10 @@ int replace_base64_files(struct email_t* mail, const char* dirname){
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
free_submails(mail);
|
||||
free(mail);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,5 +27,4 @@ int verbose = false;
|
|||
char* directory = NULL;
|
||||
char* url_base = NULL;
|
||||
|
||||
|
||||
long min_filesize= 1024*512;
|
||||
|
|
|
@ -150,9 +150,6 @@ int remove_mail(struct email_t* mail){
|
|||
|
||||
propagate_insert_delete(root, root->message+remove_offset, -remove_len);
|
||||
|
||||
|
||||
free_submails(mail);
|
||||
free(mail);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue