SaveMessage() public method

public SaveMessage ( string output ) : string
output string
return string
Ejemplo n.º 1
0
        public async Task HandleReceivedAsync(
            [NotNull] byte[] messageData,
            [NotNull] string[] recipients)
        {
            if (messageData == null)
            {
                throw new ArgumentNullException(nameof(messageData));
            }
            if (recipients == null)
            {
                throw new ArgumentNullException(nameof(recipients));
            }

            string file;

            using (var ms = new MemoryStream(messageData))
            {
                var message = await MimeMessage.LoadAsync(ParserOptions.Default, ms, true);

                var lookup = recipients.ToHashSet(StringComparer.CurrentCultureIgnoreCase);

                // remove TO:
                lookup.ExceptWith(message.To.Mailboxes.Select(s => s.Address));

                // remove CC:
                lookup.ExceptWith(message.Cc.Mailboxes.Select(s => s.Address));

                if (lookup.Any())
                {
                    // Bcc is remaining, add to message
                    foreach (var r in lookup)
                    {
                        message.Bcc.Add(MailboxAddress.Parse(r));
                    }
                }

                file = _messageRepository.SaveMessage(message.Subject, fs => message.WriteTo(fs));
            }

            try
            {
                if (!string.IsNullOrWhiteSpace(file))
                {
                    await this._messageBus.PublishAsync(new NewMessageEvent(new MessageEntry(file)));
                }
            }
            catch (Exception ex)
            {
                _logger.Fatal(ex, "Unable to publish new message event for message file: {MessageFile}", file);
            }
        }
Ejemplo n.º 2
0
        public void HandleReceived(string messageData, [CanBeNull] IList <string> recipients)
        {
            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(messageData)))
            {
                var message = MimeMessage.Load(ParserOptions.Default, ms, true);

                var lookup = recipients.IfNullEmpty()
                             .ToDictionary(s => s, s => s, StringComparer.OrdinalIgnoreCase);

                // remove TO:
                lookup.RemoveRange(
                    message.To.Mailboxes.Select(s => s.ToString(FormatOptions.Default, false))
                    .Where(s => lookup.ContainsKey(s)));

                // remove CC:
                lookup.RemoveRange(
                    message.Cc.Mailboxes.Select(s => s.ToString(FormatOptions.Default, false))
                    .Where(s => lookup.ContainsKey(s)));

                if (lookup.Any())
                {
                    // Bcc is remaining, add to message
                    foreach (var r in lookup)
                    {
                        message.Bcc.Add(MailboxAddress.Parse(r.Key));
                    }

                    messageData = message.ToString();
                }
            }

            var file = _messageRepository.SaveMessage(messageData);

            try
            {
                if (!string.IsNullOrWhiteSpace(file))
                {
                    _publishEvent.Publish(new NewMessageEvent(new MessageEntry(file)));
                }
            }
            catch (Exception ex)
            {
                _logger.Fatal(ex, "Unable to publish new message event for message file: {MessageFile}", file);
            }
        }
Ejemplo n.º 3
0
        public void HandleReceived(string messageData, [CanBeNull] string[] recipients, Encoding connectionEncoding)
        {
            string file;

            using (var ms = new MemoryStream(connectionEncoding.GetBytes(messageData)))
            {
                var message = MimeMessage.Load(ParserOptions.Default, ms, true);

                var lookup = recipients.ToHashSet(StringComparer.CurrentCultureIgnoreCase);

                // remove TO:
                lookup.ExceptWith(message.To.Mailboxes.Select(s => s.Address));

                // remove CC:
                lookup.ExceptWith(message.Cc.Mailboxes.Select(s => s.Address));

                if (lookup.Any())
                {
                    // Bcc is remaining, add to message
                    foreach (var r in lookup)
                    {
                        message.Bcc.Add(MailboxAddress.Parse(r));
                    }
                }

                file = _messageRepository.SaveMessage(fs => message.WriteTo(fs));
            }

            try
            {
                if (!string.IsNullOrWhiteSpace(file))
                {
                    this._messageBus.Publish(new NewMessageEvent(new MessageEntry(file)));
                }
            }
            catch (Exception ex)
            {
                _logger.Fatal(ex, "Unable to publish new message event for message file: {MessageFile}", file);
            }
        }