/// <summary> /// Execute the command. /// </summary> /// <param name="context">The execution context to operate on.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A task which asynchronously performs the execution.</returns> public override async Task ExecuteAsync(ISmtpSessionContext context, CancellationToken cancellationToken) { using (var container = new DisposableContainer <IMailboxFilter>(_mailboxFilterFactory.CreateInstance(context))) { switch (await container.Instance.CanDeliverToAsync(context, _address, context.Transaction.From)) { case MailboxFilterResult.Yes: context.Transaction.To.Add(_address); await context.Text.ReplyAsync(SmtpResponse.Ok, cancellationToken); return; case MailboxFilterResult.NoTemporarily: await context.Text.ReplyAsync(SmtpResponse.MailboxUnavailable, cancellationToken); return; case MailboxFilterResult.NoPermanently: await context.Text.ReplyAsync(SmtpResponse.MailboxNameNotAllowed, cancellationToken); return; } } throw new NotSupportedException("The Acceptance state is not supported."); }
/// <summary> /// Execute the command. /// </summary> /// <param name="context">The execution context to operate on.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A task which asynchronously performs the execution.</returns> public override async Task ExecuteAsync(ISmtpSessionContext context, CancellationToken cancellationToken) { context.Transaction.Reset(); // check if a size has been defined var size = GetMessageSize(); // check against the server supplied maximum if (_maxMessageSize > 0 && size > _maxMessageSize) { await context.Text.ReplyAsync(SmtpResponse.SizeLimitExceeded, cancellationToken); return; } using (var container = new DisposableContainer <IMailboxFilter>(_mailboxFilterFactory.CreateInstance(context))) { switch (await container.Instance.CanAcceptFromAsync(context, Address, size)) { case MailboxFilterResult.Yes: context.Transaction.From = _address; await context.Text.ReplyAsync(SmtpResponse.Ok, cancellationToken); return; case MailboxFilterResult.NoTemporarily: await context.Text.ReplyAsync(SmtpResponse.MailboxUnavailable, cancellationToken); return; case MailboxFilterResult.NoPermanently: await context.Text.ReplyAsync(SmtpResponse.MailboxNameNotAllowed, cancellationToken); return; case MailboxFilterResult.SizeLimitExceeded: await context.Text.ReplyAsync(SmtpResponse.SizeLimitExceeded, cancellationToken); return; } } throw new NotSupportedException("The Acceptance state is not supported."); }