示例#1
0
        private Task <IWritable[]> CreateDispatchesAsync(
            string mailId,
            IEnumerable <string> recipients,
            string sender,
            CancellationToken token)
        {
            string senderDomain = MailUtilities.GetDomainFromMailbox(sender);

            return(Task.WhenAll(
                       recipients
                       .GroupBy(MailUtilities.GetDomainFromMailbox)
                       .SelectMany(
                           g =>
            {
                if (_settings.Value.DomainName == g.Key)
                {
                    _log.Information($"{mailId} is local mail found");
                    return g.Select(r => _delivery.NewMailAsync(mailId, r, token).Cast <IMailboxItemWriteReference, IWritable>());
                }

                if (_settings.Value.RelayDomains.Any(d => string.Equals(d.Name, g.Key, StringComparison.OrdinalIgnoreCase)) ||
                    _settings.Value.DomainName == senderDomain)
                {
                    _log.Information($"{mailId} is related to {g.Key}");
                    return _transfer.NewMailAsync(mailId, sender, g.ToImmutableList(), token)
                    .Cast <IMailWriteReference, IWritable>()
                    .ToEnumerable();
                }

                _log.Error($"Invalid domain {g.Key}");
                return Enumerable.Empty <Task <IWritable> >();
            }
                           )
                       ));
        }
示例#2
0
 public static Task <IMailboxItemWriteReference> NewMailAsync(
     this IMailboxDeliveryStore store,
     string id,
     string mailbox,
     CancellationToken token)
 {
     return(store.NewMailAsync(id, mailbox, "inbox", token));
 }