fix(mail): Clean temporary files when mail is sent

This commit is contained in:
smizrahi
2023-11-01 15:40:33 +01:00
parent 9c0948518b
commit f35a37bbdd
5 changed files with 120 additions and 4 deletions
+1
View File
@@ -64,6 +64,7 @@
BOOL isHTML;
BOOL sign;
BOOL encrypt;
NSMutableArray *tmpFiles;
// Used during S/MIME encryption
NSMutableDictionary *certificates;
+51 -4
View File
@@ -67,6 +67,7 @@
#import <SOGo/SOGoUserFolder.h>
#import <SOGo/SOGoUserDefaults.h>
#import <SOGo/SOGoSystemDefaults.h>
#import <SOGo/NGMimeFileData+SOGo.h>
#import <NGCards/NGVCard.h>
@@ -142,6 +143,7 @@ static NSString *userAgent = nil;
isHTML = NO;
sign = NO;
encrypt = NO;
tmpFiles = [[NSMutableArray alloc] init];
}
return self;
@@ -157,6 +159,7 @@ static NSString *userAgent = nil;
[sourceFlag release];
[inReplyTo release];
[references release];
[tmpFiles release];
[super dealloc];
}
@@ -1921,8 +1924,10 @@ static NSString *userAgent = nil;
if (_extractImages)
{
newText = [text htmlByExtractingImages: extractedBodyParts];
if ([extractedBodyParts count])
if ([extractedBodyParts count]) {
[self setText: newText];
[self addTmpFiles: extractedBodyParts];
}
}
@@ -1934,8 +1939,11 @@ static NSString *userAgent = nil;
//[self debugWithFormat: @"MIME Envelope: %@", map];
allBodyParts = [self bodyPartsForAllAttachments];
if (!allBodyParts)
return nil;
if (!allBodyParts) {
return nil;
} else {
[self addTmpFiles: allBodyParts];
}
//[self debugWithFormat: @"attachments: %@", bodyParts];
@@ -2225,6 +2233,41 @@ static NSString *userAgent = nil;
return [self sendMailAndCopyToSent: YES];
}
// Extract tmp files in NGMimeBuildMimeTempDirectory from NSArray and store locally
// The tmp files will be deleted once the message sent
- (void) addTmpFiles:(NSArray *) parts {
NGMimeBodyPart *part;
for (part in parts) {
NGMimeFileData *body;
NSString *path;
body = [part body];
if (body) {
path = [body path];
if (path) {
[tmpFiles addObject: path];
}
}
}
}
// Clean temporary files
- (void) cleanTmpFiles {
NSString *path;
NSFileManager *fm;
fm = [NSFileManager defaultManager];
for (path in tmpFiles) {
if ([fm fileExistsAtPath: path])
[fm removeFileAtPath: path handler: nil];
}
// Clean tmp files
[tmpFiles removeAllObjects];
}
//
//
//
@@ -2270,8 +2313,10 @@ static NSString *userAgent = nil;
inContext: context
systemMessage: NO];
if (error)
if (error) {
[self cleanTmpFiles];
return error;
}
}
// If the current user isn't part of the recipient list for encrypted emails
@@ -2330,6 +2375,8 @@ static NSString *userAgent = nil;
[imap4 doesMailboxExistAtURL: [container imap4URL]])
[(SOGoDraftsFolder *) container expunge];
[self cleanTmpFiles];
return error;
}
+2
View File
@@ -94,6 +94,7 @@ SOGo_HEADER_FILES = \
JWT.h \
\
NGMimeBodyPart+SOGo.h \
NGMimeFileData+SOGo.h \
\
SOGoMobileProvision.h
@@ -183,6 +184,7 @@ SOGo_OBJC_FILES = \
JWT.m \
\
NGMimeBodyPart+SOGo.m \
NGMimeFileData+SOGo.m \
\
SOGoMobileProvision.m
+34
View File
@@ -0,0 +1,34 @@
/* NGMimeFileData+SOGo.h - this file is part of SOGo
*
* Copyright (C) 2023 Alinto
*
* Author: Sébastien Mizrahi <smizrahi@alinto.eu>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef NGMIMEFILEDATA_SOGO_H
#define NGMIMEFILEDATA_SOGO_H
#import <NGMime/NGMimeFileData.h>
@interface NGMimeFileData (SOGoExtensions)
- (NSString *) path;
@end
#endif /* NGMIMEFILEDATA_SOGO_H */
+32
View File
@@ -0,0 +1,32 @@
/* NGMimeFileData+SOGo.m - this file is part of SOGo
*
* Copyright (C) 2023 Alinto
*
* Author: Sébastien Mizrahi <smizrahi@alinto.eu>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#import "NGMimeFileData+SOGo.h"
@implementation NGMimeFileData (SOGoExtensions)
- (NSString *) path {
return path;
}
@end