Ejemplo n.º 1
0
        private Command.ExecutionState ForwardUsingXso(StoreObjectId smartId)
        {
            Item             smartItem        = base.GetSmartItem(smartId);
            MessageItem      messageItem      = null;
            VersionedId      versionedId      = null;
            MessageItem      messageItem2     = null;
            CalendarItemBase calendarItemBase = null;

            try
            {
                StoreObjectId defaultFolderId = base.MailboxSession.GetDefaultFolderId(DefaultFolderType.Drafts);
                messageItem = MessageItem.Create(base.MailboxSession, defaultFolderId);
                base.ParseMimeToMessage(messageItem);
                messageItem.Save(SaveMode.NoConflictResolution);
                messageItem.Load();
                versionedId = messageItem.Id;
                messageItem.Dispose();
                messageItem = MessageItem.Bind(base.MailboxSession, versionedId);
                RmsTemplate            rmsTemplate = null;
                SendMailBase.IrmAction irmAction   = base.GetIrmAction(delegate(RightsManagedMessageItem originalRightsManagedItem)
                {
                    if (originalRightsManagedItem == null)
                    {
                        throw new ArgumentNullException("originalRightsManagedItem");
                    }
                    if (!originalRightsManagedItem.UsageRights.IsUsageRightGranted(ContentRight.Forward))
                    {
                        throw new AirSyncPermanentException(StatusCode.IRM_OperationNotPermitted, false)
                        {
                            ErrorStringForProtocolLogger = "sfcEOperationNotPermitted"
                        };
                    }
                }, ref smartItem, out rmsTemplate);
                Microsoft.Exchange.Data.Storage.BodyFormat bodyFormat = messageItem.Body.Format;
                MeetingMessage meetingMessage = smartItem as MeetingMessage;
                string         text;
                if ((base.ReplaceMime || irmAction == SendMailBase.IrmAction.CreateNewPublishingLicenseAttachOriginalMessage) && meetingMessage != null && !meetingMessage.IsDelegated() && (meetingMessage is MeetingRequest || meetingMessage is MeetingCancellation))
                {
                    text = string.Empty;
                }
                else
                {
                    using (TextReader textReader = messageItem.Body.OpenTextReader(bodyFormat))
                    {
                        text = textReader.ReadToEnd();
                    }
                    Body body = (irmAction == SendMailBase.IrmAction.CreateNewPublishingLicenseInlineOriginalBody || irmAction == SendMailBase.IrmAction.ReusePublishingLicenseInlineOriginalBody) ? ((RightsManagedMessageItem)smartItem).ProtectedBody : smartItem.Body;
                    if (body.Format == Microsoft.Exchange.Data.Storage.BodyFormat.TextHtml)
                    {
                        if (bodyFormat == Microsoft.Exchange.Data.Storage.BodyFormat.TextPlain)
                        {
                            XmlDocument  xmlDocument  = new SafeXmlDocument();
                            XmlNode      xmlNode      = xmlDocument.CreateElement("PRE");
                            XmlAttribute xmlAttribute = xmlDocument.CreateAttribute("STYLE");
                            xmlAttribute.Value = "word-wrap:break-word; font-size:10.0pt; font-family:Tahoma; color:black";
                            xmlNode.Attributes.Append(xmlAttribute);
                            xmlNode.InnerText = text;
                            text = xmlNode.OuterXml;
                        }
                        bodyFormat = Microsoft.Exchange.Data.Storage.BodyFormat.TextHtml;
                    }
                }
                ReplyForwardConfiguration replyForwardConfiguration = new ReplyForwardConfiguration(bodyFormat);
                replyForwardConfiguration.ConversionOptionsForSmime = AirSyncUtility.GetInboundConversionOptions();
                replyForwardConfiguration.AddBodyPrefix(text);
                if (base.Version >= 120)
                {
                    if (smartItem is MessageItem)
                    {
                        messageItem2 = ((MessageItem)smartItem).CreateForward(defaultFolderId, replyForwardConfiguration);
                        if (irmAction == SendMailBase.IrmAction.CreateNewPublishingLicense || irmAction == SendMailBase.IrmAction.CreateNewPublishingLicenseInlineOriginalBody || irmAction == SendMailBase.IrmAction.CreateNewPublishingLicenseAttachOriginalMessage)
                        {
                            messageItem2 = base.GetRightsManagedReplyForward(messageItem2, irmAction, rmsTemplate);
                        }
                    }
                    else if (smartItem is CalendarItem)
                    {
                        CalendarItem calendarItem = (CalendarItem)smartItem;
                        calendarItemBase = base.GetCalendarItemBaseToReplyOrForward(calendarItem);
                        messageItem2     = calendarItemBase.CreateForward(defaultFolderId, replyForwardConfiguration);
                        if (!calendarItem.IsMeeting)
                        {
                            BodyConversionUtilities.CopyBody(messageItem, messageItem2);
                        }
                    }
                    if (messageItem2 == null)
                    {
                        base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ForwardFailed");
                        throw new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.MailSubmissionFailed, null, false);
                    }
                    if (base.ReplaceMime || irmAction == SendMailBase.IrmAction.CreateNewPublishingLicenseAttachOriginalMessage)
                    {
                        RightsManagedMessageItem rightsManagedMessageItem = messageItem2 as RightsManagedMessageItem;
                        if (rightsManagedMessageItem != null)
                        {
                            rightsManagedMessageItem.ProtectedAttachmentCollection.RemoveAll();
                        }
                        else
                        {
                            messageItem2.AttachmentCollection.RemoveAll();
                        }
                    }
                    base.CopyMessageContents(messageItem, messageItem2, false, (irmAction == SendMailBase.IrmAction.CreateNewPublishingLicenseAttachOriginalMessage) ? smartItem : null);
                    base.SendMessage(messageItem2);
                }
                else if (smartItem is MessageItem)
                {
                    using (ItemAttachment itemAttachment = messageItem.AttachmentCollection.AddExistingItem(smartItem))
                    {
                        MessageItem messageItem3 = (MessageItem)smartItem;
                        itemAttachment.FileName = messageItem3.Subject + itemAttachment.FileExtension;
                        itemAttachment.Save();
                    }
                    base.SendMessage(messageItem);
                }
                else if (smartItem is CalendarItem)
                {
                    CalendarItem calendarItem2 = (CalendarItem)smartItem;
                    messageItem2 = calendarItem2.CreateForward(defaultFolderId, replyForwardConfiguration);
                    if (messageItem2 == null)
                    {
                        base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ForwardFailed2");
                        throw new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.MailSubmissionFailed, null, false);
                    }
                    if (!calendarItem2.IsMeeting)
                    {
                        BodyConversionUtilities.CopyBody(messageItem, messageItem2);
                    }
                    base.CopyMessageContents(messageItem, messageItem2, false, null);
                    base.SendMessage(messageItem2);
                }
            }
            finally
            {
                if (messageItem != null)
                {
                    if (versionedId != null)
                    {
                        base.MailboxSession.Delete(DeleteItemFlags.HardDelete, new StoreId[]
                        {
                            versionedId
                        });
                    }
                    messageItem.Dispose();
                }
                if (smartItem != null)
                {
                    smartItem.Dispose();
                }
                if (messageItem2 != null)
                {
                    messageItem2.Dispose();
                }
                if (calendarItemBase != null)
                {
                    calendarItemBase.Dispose();
                }
            }
            return(Command.ExecutionState.Complete);
        }