Skip to content

Commit

Permalink
(feat) added new SOGoMaximumMessageSizeLimit config parameter (fixes …
Browse files Browse the repository at this point in the history
…#3510)
  • Loading branch information
extrafu authored and cgx committed Jan 7, 2017
1 parent c4c1e87 commit 81df371
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
53 changes: 40 additions & 13 deletions SoObjects/Mailer/SOGoDraftObject.m
Expand Up @@ -65,6 +65,7 @@
#import <SOGo/SOGoMailer.h>
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserDefaults.h>
#import <SOGo/SOGoSystemDefaults.h>

#import <NGCards/NGVCard.h>

Expand Down Expand Up @@ -651,6 +652,12 @@ - (NSException *) save
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]])
Expand Down Expand Up @@ -1440,18 +1447,27 @@ - (NGMimeBodyPart *) bodyPartForAttachmentWithName: (NSString *) _name
}

//
//
// 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++)
Expand Down Expand Up @@ -1509,13 +1525,9 @@ - (NGMimeMessage *) mimeMultiPartMessageWithHeaderMap: (NGMutableHashMap *) map
mBody = [[NGMimeMultipartBody alloc] initWithPart: message];

if (!isHTML)
{
part = [self bodyPartForText];
}
part = [self bodyPartForText];
else
{
part = [self mimeMultipartAlternative];
}
part = [self mimeMultipartAlternative];

[mBody addBodyPart: part];

Expand Down Expand Up @@ -1717,8 +1729,10 @@ - (NGMimeMessage *) mimeMessageWithHeaders: (NSDictionary *) _headers
{
NSMutableArray *bodyParts;
NGMimeMessage *message;
NSArray *allBodyParts;
NGMutableHashMap *map;
NSString *newText;

BOOL has_inline_images;

message = nil;
Expand All @@ -1740,8 +1754,12 @@ - (NGMimeMessage *) mimeMessageWithHeaders: (NSDictionary *) _headers
if (map)
{
//[self debugWithFormat: @"MIME Envelope: %@", map];

[bodyParts addObjectsFromArray: [self bodyPartsForAllAttachments]];
allBodyParts = [self bodyPartsForAllAttachments];

if (!allBodyParts)
return nil;

[bodyParts addObjectsFromArray: allBodyParts];

//[self debugWithFormat: @"attachments: %@", bodyParts];

Expand Down Expand Up @@ -1782,10 +1800,19 @@ - (NGMimeMessage *) mimeMessage
- (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;
Expand Down
2 changes: 2 additions & 0 deletions SoObjects/SOGo/SOGoSystemDefaults.h
Expand Up @@ -92,6 +92,8 @@
- (int) maximumFailedLoginInterval;
- (int) failedLoginBlockInterval;

- (int) maximumMessageSizeLimit;

- (int) maximumMessageSubmissionCount;
- (int) maximumRecipientCount;
- (int) maximumSubmissionInterval;
Expand Down
8 changes: 8 additions & 0 deletions SoObjects/SOGo/SOGoSystemDefaults.m
Expand Up @@ -565,6 +565,14 @@ - (int) failedLoginBlockInterval
return v;
}

//
//
//
- (int) maximumMessageSizeLimit
{
return [self integerForKey: @"SOGoMaximumMessageSizeLimit"];
}

//
//
//
Expand Down

0 comments on commit 81df371

Please sign in to comment.