Add methods to control size of in-memory queue os emails

This commit is contained in:
Richard Frith-Macdonald 2020-11-14 04:25:34 +00:00
parent 23d431234c
commit d4df4b6d87
2 changed files with 48 additions and 4 deletions

View file

@ -434,6 +434,10 @@ GS_GSMimeSMTPClient_IVARS;
*/
- (NSError*) lastError;
/** Returns the number of messages currently in the queue.
*/
- (NSUInteger) queueSize;
/** Add the message to the queue of emails to be sent by the receiver.
*/
- (void) send: (GSMimeDocument*)message;
@ -464,6 +468,13 @@ GS_GSMimeSMTPClient_IVARS;
*/
- (void) setIdentity: (NSString*)s;
/** Sets the maximum number of messages which may remain in the queue.
* If this is exceeded then any unsuccessful send attempt results in
* excess queued messages discarded as unsent.<br />
* The method returns the previous setting.
*/
- (NSUInteger) setMaximum: (NSUInteger)m;
/** Set the originator for any emails sent by the SMTP client.<br />
* This overrides the value in the 'from' header of an email.<br />
* If this is not set (or is set to nil) then the GSMimeSMTPClientOriginator

View file

@ -69,6 +69,7 @@
GSMimeDocument *current;\
GSMimeHeader *version;\
NSMutableArray *queue;\
NSUInteger maximum;\
NSMutableArray *pending;\
NSInputStream *istream;\
NSOutputStream *ostream;\
@ -8052,7 +8053,7 @@ GS_PRIVATE_INTERNAL(GSMimeSMTPClient)
@implementation GSMimeSMTPClient
/* Shuts the connection down, fails any message in progress, anbd discards all
/* Shuts the connection down, fails any message in progress, and discards all
* queued messages as 'unsent'
*/
- (void) abort
@ -8147,6 +8148,11 @@ GS_PRIVATE_INTERNAL(GSMimeSMTPClient)
return internal->lastError;
}
- (NSUInteger) queueSize
{
return [internal->queue count];
}
- (void) send: (GSMimeDocument*)message
{
[self send: message envelopeID: nil];
@ -8194,6 +8200,14 @@ GS_PRIVATE_INTERNAL(GSMimeSMTPClient)
ASSIGNCOPY(internal->identity, s);
}
- (NSUInteger) setMaximum: (NSUInteger)m
{
NSUInteger old = internal->maximum;
internal->maximum = m;
return old;
}
- (void) setOriginator: (NSString*)s
{
ASSIGNCOPY(internal->originator, s);
@ -8944,9 +8958,28 @@ GS_PRIVATE_INTERNAL(GSMimeSMTPClient)
[internal->pending removeAllObjects];
ASSIGN(internal->lastError, e);
if (internal->current != nil)
if (nil == internal->current)
{
GSMimeDocument *d = [internal->current retain];
while ([self queueSize] > internal->maximum)
{
GSMimeDocument *d = RETAIN([internal->queue objectAtIndex: 0]);
[internal->queue removeObjectAtIndex: 0];
if (nil == internal->delegate)
{
NSDebugMLLog(@"GSMime", @"-smtpClient:mimeUnsent: %@ %@",
self, d);
}
else
{
[internal->delegate smtpClient: self mimeUnsent: d];
}
RELEASE(d);
}
}
else
{
GSMimeDocument *d = RETAIN(internal->current);
[internal->queue removeObjectAtIndex: 0];
internal->current = nil;
@ -8958,7 +8991,7 @@ GS_PRIVATE_INTERNAL(GSMimeSMTPClient)
{
[internal->delegate smtpClient: self mimeFailed: d];
}
[d release];
RELEASE(d);
}
if ([internal->queue count] > 0)
{