diff --git a/SoObjects/Mailer/SOGoDraftObject.h b/SoObjects/Mailer/SOGoDraftObject.h index 05b7dd339..ae149b2b1 100644 --- a/SoObjects/Mailer/SOGoDraftObject.h +++ b/SoObjects/Mailer/SOGoDraftObject.h @@ -64,6 +64,7 @@ BOOL isHTML; BOOL sign; BOOL encrypt; + NSMutableArray *tmpFiles; // Used during S/MIME encryption NSMutableDictionary *certificates; diff --git a/SoObjects/Mailer/SOGoDraftObject.m b/SoObjects/Mailer/SOGoDraftObject.m index 02bfc08c4..e1b3540f4 100644 --- a/SoObjects/Mailer/SOGoDraftObject.m +++ b/SoObjects/Mailer/SOGoDraftObject.m @@ -67,6 +67,7 @@ #import #import #import +#import #import @@ -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; } diff --git a/SoObjects/SOGo/GNUmakefile b/SoObjects/SOGo/GNUmakefile index fcb78def3..aa9372062 100644 --- a/SoObjects/SOGo/GNUmakefile +++ b/SoObjects/SOGo/GNUmakefile @@ -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 diff --git a/SoObjects/SOGo/NGMimeFileData+SOGo.h b/SoObjects/SOGo/NGMimeFileData+SOGo.h new file mode 100644 index 000000000..1fba62207 --- /dev/null +++ b/SoObjects/SOGo/NGMimeFileData+SOGo.h @@ -0,0 +1,34 @@ +/* NGMimeFileData+SOGo.h - this file is part of SOGo + * + * Copyright (C) 2023 Alinto + * + * Author: Sébastien Mizrahi + * + * 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 + +@interface NGMimeFileData (SOGoExtensions) + +- (NSString *) path; + +@end + +#endif /* NGMIMEFILEDATA_SOGO_H */ diff --git a/SoObjects/SOGo/NGMimeFileData+SOGo.m b/SoObjects/SOGo/NGMimeFileData+SOGo.m new file mode 100644 index 000000000..bfdd36343 --- /dev/null +++ b/SoObjects/SOGo/NGMimeFileData+SOGo.m @@ -0,0 +1,32 @@ +/* NGMimeFileData+SOGo.m - this file is part of SOGo + * + * Copyright (C) 2023 Alinto + * + * Author: Sébastien Mizrahi + * + * 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