(feat) added new SOGoMaximumMessageSizeLimit config parameter (fixes #3510)

Conflicts:

	SoObjects/Mailer/SOGoDraftObject.m
pull/232/head
Ludovic Marcotte 2016-12-28 10:18:10 -05:00
parent 7c7440c988
commit 2cebee42b7
4 changed files with 55 additions and 12 deletions

View File

@ -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 value is in kilobyte. By default, the value is 0, or disabled so no
limit will be set. 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 |S |SxVMemLimit
|Parameter used to set the maximum amount of memory (in |Parameter used to set the maximum amount of memory (in
megabytes) that a child can use. Reaching that value will force children megabytes) that a child can use. Reaching that value will force children

View File

@ -55,6 +55,8 @@
#import <SOGo/SOGoMailer.h> #import <SOGo/SOGoMailer.h>
#import <SOGo/SOGoUser.h> #import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserFolder.h> #import <SOGo/SOGoUserFolder.h>
#import <SOGo/SOGoUserDefaults.h>
#import <SOGo/SOGoSystemDefaults.h>
#import <NGCards/NGVCard.h> #import <NGCards/NGVCard.h>
@ -641,6 +643,12 @@ static NSString *userAgent = nil;
error = nil; error = nil;
message = [self mimeMessageAsData]; message = [self mimeMessageAsData];
if (!message)
{
error = [NSException exceptionWithHTTPStatus: 500 /* Server Error */
reason: @"message too big"];
}
client = [[self imap4Connection] client]; client = [[self imap4Connection] client];
if (![imap4 doesMailboxExistAtURL: [container imap4URL]]) if (![imap4 doesMailboxExistAtURL: [container imap4URL]])
@ -1368,18 +1376,27 @@ static NSString *userAgent = nil;
} }
// //
// // returns nil on error
// //
- (NSArray *) bodyPartsForAllAttachments - (NSArray *) bodyPartsForAllAttachments
{ {
/* returns nil on error */
NSArray *attrs;
unsigned i, count;
NGMimeBodyPart *bodyPart; NGMimeBodyPart *bodyPart;
NSMutableArray *bodyParts; NSMutableArray *bodyParts;
NSArray *attrs;
unsigned i, count, size, limit;
attrs = [self fetchAttachmentAttrs]; attrs = [self fetchAttachmentAttrs];
count = [attrs count]; 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]; bodyParts = [NSMutableArray arrayWithCapacity: count];
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
@ -1437,13 +1454,9 @@ static NSString *userAgent = nil;
mBody = [[NGMimeMultipartBody alloc] initWithPart: message]; mBody = [[NGMimeMultipartBody alloc] initWithPart: message];
if (!isHTML) if (!isHTML)
{ part = [self bodyPartForText];
part = [self bodyPartForText];
}
else else
{ part = [self mimeMultipartAlternative];
part = [self mimeMultipartAlternative];
}
[mBody addBodyPart: part]; [mBody addBodyPart: part];
@ -1644,8 +1657,10 @@ static NSString *userAgent = nil;
{ {
NSMutableArray *bodyParts; NSMutableArray *bodyParts;
NGMimeMessage *message; NGMimeMessage *message;
NSArray *allBodyParts;
NGMutableHashMap *map; NGMutableHashMap *map;
NSString *newText; NSString *newText;
BOOL has_inline_images; BOOL has_inline_images;
message = nil; message = nil;
@ -1667,9 +1682,13 @@ static NSString *userAgent = nil;
if (map) if (map)
{ {
//[self debugWithFormat: @"MIME Envelope: %@", map]; //[self debugWithFormat: @"MIME Envelope: %@", map];
allBodyParts = [self bodyPartsForAllAttachments];
[bodyParts addObjectsFromArray: [self bodyPartsForAllAttachments]]; if (!allBodyParts)
return nil;
[bodyParts addObjectsFromArray: allBodyParts];
//[self debugWithFormat: @"attachments: %@", bodyParts]; //[self debugWithFormat: @"attachments: %@", bodyParts];
if ([bodyParts count] == 0) if ([bodyParts count] == 0)
@ -1709,10 +1728,19 @@ static NSString *userAgent = nil;
- (NSData *) mimeMessageAsData - (NSData *) mimeMessageAsData
{ {
NGMimeMessageGenerator *generator; NGMimeMessageGenerator *generator;
NGMimeMessage *mimeMessage;
NSData *message; NSData *message;
generator = [NGMimeMessageGenerator new]; 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]; [generator release];
return message; return message;

View File

@ -94,6 +94,8 @@
- (int) maximumFailedLoginInterval; - (int) maximumFailedLoginInterval;
- (int) failedLoginBlockInterval; - (int) failedLoginBlockInterval;
- (int) maximumMessageSizeLimit;
- (int) maximumMessageSubmissionCount; - (int) maximumMessageSubmissionCount;
- (int) maximumRecipientCount; - (int) maximumRecipientCount;
- (int) maximumSubmissionInterval; - (int) maximumSubmissionInterval;

View File

@ -578,6 +578,14 @@ _injectConfigurationFromFile (NSMutableDictionary *defaultsDict,
return v; return v;
} }
//
//
//
- (int) maximumMessageSizeLimit
{
return [self integerForKey: @"SOGoMaximumMessageSizeLimit"];
}
// //
// //
// //