internal static SharingMessage GetSharingMessage(MessageItem item)
        {
            StreamAttachment sharingMessageAttachment = SharingMessageAttachment.GetSharingMessageAttachment(item);

            if (sharingMessageAttachment != null)
            {
                using (sharingMessageAttachment)
                {
                    using (Stream stream = sharingMessageAttachment.TryGetContentStream(PropertyOpenMode.ReadOnly))
                    {
                        SharingMessage sharingMessage = null;
                        try
                        {
                            sharingMessage = SharingMessage.DeserializeFromStream(stream);
                        }
                        catch (InvalidOperationException)
                        {
                        }
                        if (sharingMessage != null)
                        {
                            ValidationResults validationResults = sharingMessage.Validate();
                            if (validationResults.Result == ValidationResult.Success)
                            {
                                return(sharingMessage);
                            }
                        }
                    }
                }
            }
            return(null);
        }
        private static StreamAttachment GetOrCreateSharingMessageAttachment(MessageItem item)
        {
            StreamAttachment streamAttachment = SharingMessageAttachment.GetSharingMessageAttachment(item);

            if (streamAttachment == null)
            {
                streamAttachment = (StreamAttachment)item.AttachmentCollection.Create(AttachmentType.Stream);
            }
            return(streamAttachment);
        }
 internal static void SetSharingMessage(MessageItem item, SharingMessage sharingMessage)
 {
     using (StreamAttachment orCreateSharingMessageAttachment = SharingMessageAttachment.GetOrCreateSharingMessageAttachment(item))
     {
         orCreateSharingMessageAttachment.PropertyBag[AttachmentSchema.AttachMimeTag]      = "application/x-sharing-metadata-xml";
         orCreateSharingMessageAttachment.PropertyBag[AttachmentSchema.AttachLongFileName] = "sharing_metadata.xml";
         using (Stream contentStream = orCreateSharingMessageAttachment.GetContentStream(PropertyOpenMode.Create))
         {
             sharingMessage.SerializeToStream(contentStream);
             contentStream.Flush();
         }
         orCreateSharingMessageAttachment.Save();
     }
 }
Exemple #4
0
        internal bool ReadFromMetadataXml(MessageItem messageItem)
        {
            SharingMessage sharingMessage = SharingMessageAttachment.GetSharingMessage(messageItem);

            if (sharingMessage == null)
            {
                ExTraceGlobals.SharingTracer.TraceDebug <string>((long)this.GetHashCode(), "{0}: The sharing_metadata.xml is invalid", messageItem.Session.UserLegacyDN);
                return(false);
            }
            if (sharingMessage.Validate().Result != ValidationResult.Success)
            {
                ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: The sharing_metadata.xml is invalid", messageItem.Session.UserLegacyDN);
                throw new InvalidSharingMessageException("SharingMetadata");
            }
            SharingDataType sharingDataType = SharingDataType.FromExternalName(sharingMessage.DataType);

            if (sharingDataType == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: Unknown sharing data type: {1}", messageItem.Session.UserLegacyDN, sharingMessage.DataType);
                throw new InvalidSharingMessageException("DataType");
            }
            this.context.FolderClass = sharingDataType.ContainerClass;
            if (!SmtpAddress.IsValidSmtpAddress(sharingMessage.Initiator.SmtpAddress))
            {
                ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: Initiator's smtp address is invalid: {1}", messageItem.Session.UserLegacyDN, sharingMessage.Initiator.SmtpAddress);
                throw new InvalidSharingMessageException("InitiatorSmtpAddress");
            }
            this.context.InitiatorName        = sharingMessage.Initiator.Name;
            this.context.InitiatorSmtpAddress = sharingMessage.Initiator.SmtpAddress;
            this.context.InitiatorEntryId     = HexConverter.HexStringToByteArray(sharingMessage.Initiator.EntryId);
            this.context.AvailableSharingProviders.Clear();
            if (sharingMessage.Invitation != null)
            {
                this.ReadActionFromMetadataXml(sharingMessage.Invitation);
            }
            else if (sharingMessage.AcceptOfRequest != null)
            {
                this.ReadActionFromMetadataXml(sharingMessage.AcceptOfRequest);
            }
            else if (sharingMessage.Request != null)
            {
                this.ReadActionFromMetadataXml(sharingMessage.Request);
            }
            else if (sharingMessage.DenyOfRequest != null)
            {
                this.ReadActionFromMetadataXml(sharingMessage.DenyOfRequest);
            }
            if (this.context.AvailableSharingProviders.Count == 0)
            {
                ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: No known sharing provider is found in message.", messageItem.Session.UserLegacyDN);
                throw new NotSupportedSharingMessageException();
            }
            if (this.context.IsPrimary)
            {
                this.context.FolderName = sharingDataType.DisplayName.ToString(messageItem.Session.InternalPreferedCulture);
            }
            this.context.SetDefaultCapabilities();
            SharingMessageType sharingMessageType = SharingContextSerializer.CalculateSharingMessageType(sharingMessage);

            if (sharingMessageType == SharingMessageType.Unknown)
            {
                ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingMessageType is unknown", messageItem.Session.UserLegacyDN);
                throw new InvalidSharingMessageException("SharingMessageType");
            }
            this.context.SharingMessageType = sharingMessageType;
            return(true);
        }
Exemple #5
0
        internal void SaveIntoMetadataXml(MessageItem messageItem)
        {
            SharingMessage sharingMessage = this.CreateSharingMessage();

            SharingMessageAttachment.SetSharingMessage(messageItem, sharingMessage);
        }