diff --git a/Documentation/SOGoInstallationGuide.asciidoc b/Documentation/SOGoInstallationGuide.asciidoc index bd626c881..da6867977 100644 --- a/Documentation/SOGoInstallationGuide.asciidoc +++ b/Documentation/SOGoInstallationGuide.asciidoc @@ -394,6 +394,11 @@ attachment size being uploaded to SOGo when composing a mail. The value is in kilobyte. By default, the value is 0, or disabled so no limit will be set. +|S |SOGoMaximumMessageSizeLimit +|Parameter used to set the maximum allowed email message size when +composing a mail. The value is in kilobyte. By default, the value is 0, +or disabled so no limit will be set. + |S |SxVMemLimit |Parameter used to set the maximum amount of memory (in megabytes) that a child can use. Reaching that value will force children diff --git a/SoObjects/Mailer/SOGoDraftObject.m b/SoObjects/Mailer/SOGoDraftObject.m index 8b518620f..daafa17e2 100644 --- a/SoObjects/Mailer/SOGoDraftObject.m +++ b/SoObjects/Mailer/SOGoDraftObject.m @@ -55,6 +55,8 @@ #import #import #import +#import +#import #import @@ -641,6 +643,12 @@ static NSString *userAgent = nil; error = nil; message = [self mimeMessageAsData]; + if (!message) + { + error = [NSException exceptionWithHTTPStatus: 500 /* Server Error */ + reason: @"message too big"]; + } + client = [[self imap4Connection] client]; if (![imap4 doesMailboxExistAtURL: [container imap4URL]]) @@ -1368,18 +1376,27 @@ static NSString *userAgent = nil; } // -// +// returns nil on error // - (NSArray *) bodyPartsForAllAttachments { - /* returns nil on error */ - NSArray *attrs; - unsigned i, count; NGMimeBodyPart *bodyPart; NSMutableArray *bodyParts; + NSArray *attrs; + unsigned i, count, size, limit; attrs = [self fetchAttachmentAttrs]; count = [attrs count]; + size = 0; + + // We first check if we don't go over our message size limit + limit = [[SOGoSystemDefaults sharedSystemDefaults] maximumMessageSizeLimit] * 1024; + for (i = 0; i < count; i++) + size += [[[attrs objectAtIndex: i] objectForKey: @"size"] intValue]; + + if (limit && size > limit) + return nil; + bodyParts = [NSMutableArray arrayWithCapacity: count]; for (i = 0; i < count; i++) @@ -1437,13 +1454,9 @@ static NSString *userAgent = nil; mBody = [[NGMimeMultipartBody alloc] initWithPart: message]; if (!isHTML) - { - part = [self bodyPartForText]; - } + part = [self bodyPartForText]; else - { - part = [self mimeMultipartAlternative]; - } + part = [self mimeMultipartAlternative]; [mBody addBodyPart: part]; @@ -1644,8 +1657,10 @@ static NSString *userAgent = nil; { NSMutableArray *bodyParts; NGMimeMessage *message; + NSArray *allBodyParts; NGMutableHashMap *map; NSString *newText; + BOOL has_inline_images; message = nil; @@ -1667,9 +1682,13 @@ static NSString *userAgent = nil; if (map) { //[self debugWithFormat: @"MIME Envelope: %@", map]; + allBodyParts = [self bodyPartsForAllAttachments]; - [bodyParts addObjectsFromArray: [self bodyPartsForAllAttachments]]; + if (!allBodyParts) + return nil; + [bodyParts addObjectsFromArray: allBodyParts]; + //[self debugWithFormat: @"attachments: %@", bodyParts]; if ([bodyParts count] == 0) @@ -1709,10 +1728,19 @@ static NSString *userAgent = nil; - (NSData *) mimeMessageAsData { NGMimeMessageGenerator *generator; + NGMimeMessage *mimeMessage; NSData *message; generator = [NGMimeMessageGenerator new]; - message = [generator generateMimeFromPart: [self mimeMessageWithHeaders: nil excluding: nil extractingImages: NO]]; + mimeMessage = [self mimeMessageWithHeaders: nil excluding: nil extractingImages: NO]; + + if (!mimeMessage) + { + [generator release]; + return nil; + } + + message = [generator generateMimeFromPart: mimeMessage]; [generator release]; return message; diff --git a/SoObjects/SOGo/SOGoSystemDefaults.h b/SoObjects/SOGo/SOGoSystemDefaults.h index 00a38d0ac..b705c61c1 100644 --- a/SoObjects/SOGo/SOGoSystemDefaults.h +++ b/SoObjects/SOGo/SOGoSystemDefaults.h @@ -94,6 +94,8 @@ - (int) maximumFailedLoginInterval; - (int) failedLoginBlockInterval; +- (int) maximumMessageSizeLimit; + - (int) maximumMessageSubmissionCount; - (int) maximumRecipientCount; - (int) maximumSubmissionInterval; diff --git a/SoObjects/SOGo/SOGoSystemDefaults.m b/SoObjects/SOGo/SOGoSystemDefaults.m index 4ac596dd6..b197238cb 100644 --- a/SoObjects/SOGo/SOGoSystemDefaults.m +++ b/SoObjects/SOGo/SOGoSystemDefaults.m @@ -578,6 +578,14 @@ _injectConfigurationFromFile (NSMutableDictionary *defaultsDict, return v; } +// +// +// +- (int) maximumMessageSizeLimit +{ + return [self integerForKey: @"SOGoMaximumMessageSizeLimit"]; +} + // // //