Пример #1
0
        private static OriginalMessage transformHeader(EmailHeaderItem header, IEnumerable <EmailHeaderItem> headerItems, IEnumerable <IItem> emailItems)
        {
            var headerString = "";

            if (header.Text == null && header.Title == null)
            {
                headerString = header.Raw;
            }
            else
            {
                headerString = header.Text;

                // add the EmailHeaderItem to the EmailHeaderItems
                headerItems = headerItems == null ? new[] { header } : new[] { header }.Concat(headerItems);
            }

            var emailHeaderItems = headerItems as EmailHeaderItem[] ?? headerItems.ToArray();

            if (headerItems == null || !emailHeaderItems.Any())
            {
                // no EmailHeaderItems found
                return(new OriginalMessage
                {
                    Header = headerString,
                    Items = emailItems
                });
            }

            var items = emailItems as IItem[] ?? emailItems.ToArray();

            if (emailItems != null && items.Any() && items.First().GetType().CanBeCastTo <EmailHeader>())
            {
                // combine EmailHeaders found in emailItems with emailHeaderItems
                var eHeader = items.First() as EmailHeader;
                var headers = emailHeaderItems.Concat(eHeader.Headers);
                eHeader.Headers = headers;

                emailItems = items.Except(new[] { eHeader as IItem });
                emailItems = new[] { eHeader }.Concat(emailItems);
            }
            else
            {
                // only use the EmailHeaderItem found
                emailItems = new[] { new EmailHeader {
                                         Headers = emailHeaderItems, IsLogHeader = true
                                     } }.Concat(items);
            }

            return(new OriginalMessage
            {
                Header = headerString,
                Items = emailItems
            });
        }
        private static OriginalMessage transformHeader(EmailHeaderItem header, IEnumerable<EmailHeaderItem> headerItems, IEnumerable<IItem> emailItems)
        {
            var headerString = "";

            if (header.Text == null && header.Title == null)
            {
                headerString = header.Raw;
            }
            else
            {
                headerString = header.Text;

                // add the EmailHeaderItem to the EmailHeaderItems
                headerItems = headerItems == null ? new[] { header } : new[] { header }.Concat(headerItems);
            }

            var emailHeaderItems = headerItems as EmailHeaderItem[] ?? headerItems.ToArray();
            if (headerItems == null || !emailHeaderItems.Any())
            {
                // no EmailHeaderItems found
                return new OriginalMessage
                {
                    Header = headerString,
                    Items = emailItems
                };
            }

            var items = emailItems as IItem[] ?? emailItems.ToArray();
            if (emailItems != null && items.Any() && items.First().GetType().CanBeCastTo<EmailHeader>())
            {
                // combine EmailHeaders found in emailItems with emailHeaderItems
                var eHeader = items.First() as EmailHeader;
                var headers = emailHeaderItems.Concat(eHeader.Headers);
                eHeader.Headers = headers;

                emailItems = items.Except(new[] { eHeader as IItem });
                emailItems = new[] { eHeader }.Concat(emailItems);
            }
            else
            {
                // only use the EmailHeaderItem found
                emailItems = new[] { new EmailHeader { Headers = emailHeaderItems, IsLogHeader = true } }.Concat(items);
            }

            return new OriginalMessage
            {
                Header = headerString,
                Items = emailItems
            };
        }