示例#1
0
        public static void CreateForwardReplyHeader(ReplyForwardConfiguration configuration, Item item, ForwardReplyHeaderOptions headerOptions = null)
        {
            if (!(item is MessageItem) && !(item is CalendarItemBase) && !(item is PostItem))
            {
                throw new ArgumentException("HTML reply forward headers can only be created for MessageItem, CalendarItemBase and PostItem");
            }
            if (headerOptions == null)
            {
                headerOptions = new ForwardReplyHeaderOptions();
            }
            CultureInfo cultureInfo = configuration.Culture ?? item.Session.InternalCulture;

            if (item is PostItem)
            {
                ReplyForwardHeader.CreatePostReplyForwardHeader(configuration, item, headerOptions, cultureInfo);
            }
            IList <IRecipientBase> toRecipients = null;
            IList <IRecipientBase> ccRecipients = null;
            string from          = string.Empty;
            string sender        = null;
            string fromLabel     = ClientStrings.FromColon.ToString(cultureInfo);
            string toLabel       = ClientStrings.ToColon.ToString(cultureInfo);
            string ccLabel       = ClientStrings.CcColon.ToString(cultureInfo);
            bool   isMeetingItem = ObjectClass.IsMeetingMessage(item.ClassName);

            if (item is MessageItem)
            {
                MessageItem messageItem = (MessageItem)item;
                if (messageItem.From != null)
                {
                    from = messageItem.From.DisplayName;
                }
                if (messageItem.Sender != null)
                {
                    sender = messageItem.Sender.DisplayName;
                }
                toRecipients = ReplyForwardHeader.GetMessageRecipientCollection(RecipientItemType.To, messageItem);
                ccRecipients = ReplyForwardHeader.GetMessageRecipientCollection(RecipientItemType.Cc, messageItem);
            }
            else if (item is CalendarItemBase)
            {
                CalendarItemBase calendarItemBase = (CalendarItemBase)item;
                if (calendarItemBase.Organizer != null)
                {
                    from = calendarItemBase.Organizer.DisplayName;
                }
                toRecipients = ReplyForwardHeader.GetCalendarItemRecipientCollection(AttendeeType.Required, calendarItemBase);
                ccRecipients = ReplyForwardHeader.GetCalendarItemRecipientCollection(AttendeeType.Optional, calendarItemBase);
            }
            BodyInjectionFormat bodyPrefixFormat;
            string bodyPrefix;

            switch (configuration.TargetFormat)
            {
            case BodyFormat.TextPlain:
                bodyPrefixFormat = BodyInjectionFormat.Text;
                bodyPrefix       = ReplyForwardHeader.CreateTextReplyForwardHeader(item, headerOptions, fromLabel, from, sender, toLabel, ccLabel, toRecipients, ccRecipients, isMeetingItem, cultureInfo, configuration.TimeZone);
                break;

            case BodyFormat.TextHtml:
            case BodyFormat.ApplicationRtf:
                bodyPrefixFormat = BodyInjectionFormat.Html;
                bodyPrefix       = ReplyForwardHeader.CreateHtmlReplyForwardHeader(item, headerOptions, fromLabel, from, sender, toLabel, ccLabel, toRecipients, ccRecipients, isMeetingItem, cultureInfo, configuration.TimeZone);
                break;

            default:
                throw new ArgumentException("Unsupported body format");
            }
            configuration.AddBodyPrefix(bodyPrefix, bodyPrefixFormat);
        }