예제 #1
0
        private void InternalAttachDiscoveryLogFiles()
        {
            if (!string.IsNullOrEmpty(this.exportRecordAttachmentId))
            {
                this.ewsClient.DeleteAttachments(this.PrimarySmtpAddress, new string[]
                {
                    this.exportRecordAttachmentId
                });
            }
            if (this.exportRecordAttachmentLog == null)
            {
                this.exportRecordAttachmentLog = new AttachmentLog(this.exportRecordLogFileName, Strings.SearchLogHeader);
            }
            FileAttachmentType fileAttachmentType = new FileAttachmentType
            {
                Name    = Path.ChangeExtension(this.exportRecordLogFileName, ".zip"),
                Content = this.exportRecordAttachmentLog.GetCompressedLogData()
            };
            List <AttachmentType> list = this.ewsClient.CreateAttachments(this.PrimarySmtpAddress, this.logItemId, new AttachmentType[]
            {
                fileAttachmentType
            });

            if (list != null && list.Count > 0)
            {
                this.exportRecordAttachmentId = list[0].AttachmentId.Id;
            }
        }
예제 #2
0
        // Token: 0x0600199D RID: 6557 RVA: 0x0005A534 File Offset: 0x00058734
        internal static AttachmentIdType CreateAttachmentAndSendPendingGetNotification(UserContext userContext, string itemId, byte[] bytes, string name, CreateAttachmentNotificationPayload result, IdConverter idConverter, string channelId)
        {
            AttachmentIdType result2 = null;

            if (!userContext.IsDisposed)
            {
                AttachmentBuilder attachmentBuilder = null;
                try
                {
                    userContext.LockAndReconnectMailboxSession();
                    if (result.ResultCode == AttachmentResultCode.Success)
                    {
                        IdAndSession       idAndSession       = new IdAndSession(StoreId.EwsIdToStoreObjectId(itemId), userContext.MailboxSession);
                        FileAttachmentType fileAttachmentType = new FileAttachmentType
                        {
                            Content  = bytes,
                            IsInline = false,
                            Name     = name,
                            Size     = bytes.Length
                        };
                        AttachmentHierarchy attachmentHierarchy = new AttachmentHierarchy(idAndSession, true, true);
                        attachmentBuilder = new AttachmentBuilder(attachmentHierarchy, new AttachmentType[]
                        {
                            fileAttachmentType
                        }, idConverter, true);
                        ServiceError serviceError;
                        using (Attachment attachment = attachmentBuilder.CreateAttachment(fileAttachmentType, out serviceError))
                        {
                            if (serviceError == null)
                            {
                                attachmentHierarchy.SaveAll();
                            }
                            result.Response = CreateAttachmentHelper.CreateAttachmentResponse(attachmentHierarchy, attachment, fileAttachmentType, idAndSession, serviceError);
                        }
                        if (result.Response.ResponseMessages.Items != null && result.Response.ResponseMessages.Items.Length > 0 && result.Response.ResponseMessages.Items[0].ResponseCode == ResponseCodeType.NoError)
                        {
                            ((AttachmentInfoResponseMessage)result.Response.ResponseMessages.Items[0]).Attachments[0].Size = fileAttachmentType.Size;
                            result2 = CreateAttachmentHelper.GetAttachmentIdFromCreateAttachmentResponse(result.Response);
                        }
                    }
                    CreateAttachmentHelper.SendPendingGetNotification(userContext, result, channelId);
                }
                finally
                {
                    userContext.UnlockAndDisconnectMailboxSession();
                    if (attachmentBuilder != null)
                    {
                        attachmentBuilder.Dispose();
                    }
                }
            }
            return(result2);
        }
예제 #3
0
        // Token: 0x0600199B RID: 6555 RVA: 0x0005A370 File Offset: 0x00058570
        internal static CreateAttachmentResponse CreateAttachmentResponse(AttachmentHierarchy attachmentHierarchy, Attachment attachment, AttachmentType attachmentType, IdAndSession parentIdAndSession, ServiceError warning)
        {
            IdAndSession idAndSession = parentIdAndSession.Clone();

            attachment.Load();
            idAndSession.AttachmentIds.Add(attachment.Id);
            AttachmentType attachmentType2;

            if (attachment is StreamAttachment)
            {
                attachmentType2 = new FileAttachmentType();
            }
            else if (attachment is ReferenceAttachment)
            {
                attachmentType2 = new ReferenceAttachmentType();
                ((ReferenceAttachmentType)attachmentType2).AttachLongPathName  = (string)attachment.TryGetProperty(AttachmentSchema.AttachLongPathName);
                ((ReferenceAttachmentType)attachmentType2).ProviderType        = (string)attachment.TryGetProperty(AttachmentSchema.AttachmentProviderType);
                ((ReferenceAttachmentType)attachmentType2).ProviderEndpointUrl = (string)attachment.TryGetProperty(AttachmentSchema.AttachmentProviderEndpointUrl);
                object obj = attachment.TryGetProperty(AttachmentSchema.AttachContentId);
                if (!(obj is PropertyError))
                {
                    ((ReferenceAttachmentType)attachmentType2).ContentId = (string)obj;
                }
                attachmentType2.Name = attachmentType.Name;
            }
            else
            {
                attachmentType2 = new ItemAttachmentType();
            }
            attachmentType2.AttachmentId = new AttachmentIdType(idAndSession.GetConcatenatedId().Id);
            if (attachmentType is ItemIdAttachmentType || attachmentType is ReferenceAttachmentType)
            {
                attachmentType2.Size = ((attachment.Size > 2147483647L) ? int.MaxValue : ((int)attachment.Size));
            }
            CreateAttachmentResponse       createAttachmentResponse = new CreateAttachmentResponse();
            ServiceResult <AttachmentType> serviceResult            = (warning == null) ? new ServiceResult <AttachmentType>(attachmentType2) : new ServiceResult <AttachmentType>(attachmentType2, warning);

            attachmentHierarchy.RootItem.Load();
            if (serviceResult.Value != null)
            {
                ConcatenatedIdAndChangeKey concatenatedId = IdConverter.GetConcatenatedId(attachmentHierarchy.RootItem.Id, parentIdAndSession, null);
                serviceResult.Value.AttachmentId.RootItemId        = concatenatedId.Id;
                serviceResult.Value.AttachmentId.RootItemChangeKey = concatenatedId.ChangeKey;
            }
            createAttachmentResponse.AddResponses(new ServiceResult <AttachmentType>[]
            {
                serviceResult
            });
            return(createAttachmentResponse);
        }
        public Guid SaveFileAttach(Stream fileStream, string fileName, FileAttachmentType attachmentType, Guid?relatedId = null, string path = null)
        {
            var uploadPath = AppSetting.Get <string>("FileUploadPath");

            if (!Directory.Exists(uploadPath))
            {
                throw new DirectoryNotFoundException(uploadPath);
            }
            if (!string.IsNullOrWhiteSpace(path))
            {
                uploadPath = Path.Combine(uploadPath, path);
            }

            var id           = Guid.NewGuid();
            var fileExt      = Path.GetExtension(fileName);
            var physicalName = id.ToString() + fileExt;

            if (!Directory.Exists(uploadPath))
            {
                Directory.CreateDirectory(uploadPath);
            }
            var filePath = Path.Combine(uploadPath, physicalName);

            using (var saveStream = System.IO.File.Create(filePath))
            {
                fileStream.Seek(0, SeekOrigin.Begin);
                fileStream.CopyTo(saveStream);
            }
            var file = new FileAttachment();

            file.Id             = id;
            file.FileName       = fileName;
            file.PhysicalName   = physicalName;
            file.Extension      = fileExt;
            file.Path           = path;
            file.RelatedId      = relatedId;
            file.AttachmentType = attachmentType;
            fileAttachmentRepository.Add(file);
            unitOfWork.SaveChanges();
            return(file.Id);
        }
예제 #5
0
        // Token: 0x06001998 RID: 6552 RVA: 0x0005A258 File Offset: 0x00058458
        internal static CreateAttachmentRequest CreateAttachmentRequest(ItemId parentItemId, string fileName, int size, string contentType, byte[] content, bool isInline, string cancellationId)
        {
            CreateAttachmentRequest createAttachmentRequest = new CreateAttachmentRequest();
            FileAttachmentType      fileAttachmentType      = new FileAttachmentType();

            fileAttachmentType.Name              = fileName;
            fileAttachmentType.Size              = size;
            fileAttachmentType.ContentType       = contentType;
            fileAttachmentType.Content           = content;
            fileAttachmentType.IsInline          = isInline;
            createAttachmentRequest.ParentItemId = parentItemId;
            createAttachmentRequest.Attachments  = new AttachmentType[]
            {
                fileAttachmentType
            };
            createAttachmentRequest.RequireImageType           = fileAttachmentType.IsInline;
            createAttachmentRequest.IncludeContentIdInResponse = fileAttachmentType.IsInline;
            createAttachmentRequest.ClientSupportsIrm          = true;
            createAttachmentRequest.CancellationId             = cancellationId;
            return(createAttachmentRequest);
        }
예제 #6
0
        /// <summary>
        /// Saves all attachments belonging to a specific message. This method can only be called after the message
        /// has been saved in exchange.
        /// </summary>
        /// <param name="messageId"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public IEnumerable <ItemIdType> SaveAttachments(ItemIdType messageId, ChannelMessage message)
        {
            var binding = ChannelHelper.BuildChannel(hostname, username, password);

            // Create add attachment request.
            var attachementRequest = new CreateAttachmentType();

            attachementRequest.ParentItemId = messageId;
            attachementRequest.Attachments  = new AttachmentType[message.Attachments.Count];

            for (int i = 0; i < message.Attachments.Count; i++)
            {
                var channelAttachment = message.Attachments[i];
                var exchAttachment    = new FileAttachmentType();

                exchAttachment.Name        = channelAttachment.Filename;
                exchAttachment.ContentType = MimeHelper.GetMimeType(channelAttachment.Filename);
                exchAttachment.Content     = channelAttachment.ContentStream.GetBytes();

                attachementRequest.Attachments[i] = exchAttachment;

                var saveAttachmentResponse = binding.CreateAttachment(attachementRequest);

                // Determine whether the request was a success.
                if (saveAttachmentResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
                {
                    throw new Exception(saveAttachmentResponse.ResponseMessages.Items[0].MessageText);
                }

                AttachmentIdType attachmentId = ((AttachmentInfoResponseMessageType)saveAttachmentResponse.ResponseMessages.Items[0]).Attachments[0].AttachmentId;

                yield return(new ItemIdType {
                    ChangeKey = attachmentId.RootItemChangeKey, Id = attachmentId.RootItemId
                });
            }
        }
예제 #7
0
        private static void PopulateAttachmentProperties(IdAndSession idAndSession, Item item, Attachment attachment, ModernAttachment outAttachment)
        {
            if (outAttachment == null || attachment == null || item == null)
            {
                return;
            }
            outAttachment.Data = new ModernAttachment.AttachmentData();
            outAttachment.Data.AttachmentEx = new AttachmentTypeEx();
            switch (attachment.AttachmentType)
            {
            case AttachmentType.NoAttachment:
                break;

            case AttachmentType.Stream:
            {
                StreamAttachment streamAttachment = attachment as StreamAttachment;
                if (streamAttachment != null)
                {
                    FileAttachmentType fileAttachmentType = new FileAttachmentType();
                    outAttachment.Data.Attachment     = fileAttachmentType;
                    fileAttachmentType.IsContactPhoto = streamAttachment.IsContactPhoto;
                }
                break;
            }

            case AttachmentType.EmbeddedMessage:
            {
                ItemAttachment itemAttachment = attachment as ItemAttachment;
                if (itemAttachment != null)
                {
                    outAttachment.Data.Attachment = new ItemAttachmentType();
                }
                break;
            }

            case AttachmentType.Ole:
            {
                OleAttachment oleAttachment = attachment as OleAttachment;
                if (oleAttachment != null)
                {
                    FileAttachmentType fileAttachmentType2 = new FileAttachmentType();
                    outAttachment.Data.Attachment      = fileAttachmentType2;
                    fileAttachmentType2.IsContactPhoto = oleAttachment.IsContactPhoto;
                }
                break;
            }

            case AttachmentType.Reference:
            {
                ReferenceAttachment referenceAttachment = attachment as ReferenceAttachment;
                if (referenceAttachment != null)
                {
                    UserContext userContext = UserContextManager.GetUserContext(HttpContext.Current);
                    if (userContext != null && userContext.FeaturesManager != null && userContext.FeaturesManager.ClientServerSettings.AttachmentsFilePicker.Enabled)
                    {
                        ReferenceAttachmentType referenceAttachmentType = new ReferenceAttachmentType();
                        outAttachment.Data.Attachment = referenceAttachmentType;
                        referenceAttachmentType.AttachLongPathName  = referenceAttachment.AttachLongPathName;
                        referenceAttachmentType.ProviderEndpointUrl = referenceAttachment.ProviderEndpointUrl;
                        referenceAttachmentType.ProviderType        = referenceAttachment.ProviderType;
                    }
                    else
                    {
                        outAttachment.Data.Attachment = new FileAttachmentType();
                    }
                }
                break;
            }

            default:
                return;
            }
            if (outAttachment.Data.Attachment == null)
            {
                outAttachment.Data.Attachment = new AttachmentType();
            }
            IdAndSession idAndSession2;

            if (idAndSession == null)
            {
                idAndSession2 = new IdAndSession(item.Id, item.Session);
            }
            else
            {
                idAndSession2 = idAndSession.Clone();
            }
            idAndSession2.AttachmentIds.Add(attachment.Id);
            outAttachment.Data.Attachment.AttachmentId     = new AttachmentIdType(idAndSession2.GetConcatenatedId().Id);
            outAttachment.Data.Attachment.ContentId        = (string.IsNullOrEmpty(attachment.ContentId) ? null : attachment.ContentId);
            outAttachment.Data.Attachment.ContentLocation  = ((attachment.ContentLocation == null) ? null : attachment.ContentLocation.PathAndQuery);
            outAttachment.Data.Attachment.ContentType      = attachment.ContentType;
            outAttachment.Data.Attachment.IsInline         = attachment.IsInline;
            outAttachment.Data.Attachment.LastModifiedTime = GetModernAttachmentsCommand.Utilities.FormatExDateTime(attachment.LastModifiedTime);
            outAttachment.Data.Attachment.Name             = attachment.DisplayName;
            outAttachment.Data.Attachment.Size             = (int)attachment.Size;
        }
예제 #8
0
        /// <summary>
        /// Creates an item or file attachment on an item.
        /// </summary>
        /// <param name="parentItemId">Identifies the parent item in the server store that contains the attachment.</param>
        /// <param name="attachmentsType">Attachment type.</param>
        /// <returns>A response message for "CreateAttachment" operation.</returns>
        protected CreateAttachmentResponseType CallCreateAttachmentOperation(string parentItemId, params AttachmentTypeValue[] attachmentsType)
        {
            // Configure attachments.
            int attachmentCount = attachmentsType.Length;

            this.Attachments = new AttachmentType[attachmentCount];
            for (int attachmentIndex = 0; attachmentIndex < attachmentCount; attachmentIndex++)
            {
                AttachmentType attachment = null;

                if (attachmentsType[attachmentIndex] == AttachmentTypeValue.FileAttachment)
                {
                    FileAttachmentType fileAttachment = new FileAttachmentType()
                    {
                        ContentLocation = @"http://www.contoso.com/xyz.abc",
                        Name            = "attach.jpg",

                        // Ensure content id is unique.
                        ContentId   = Guid.NewGuid().ToString(),
                        ContentType = "image/jpeg",
                        Content     = Convert.FromBase64String("/9j/4AAQSkZJRgABAQEAYABgAAD/7AARRHVja3kAAQAEAAAARgAA/9sAQwACAQECAQECAgICAgICAgMFAwMDAwMGBAQDBQcGBwcHBgcHCAkLCQgICggHBwoNCgoLDAwMDAcJDg8NDA4LDAwM/9sAQwECAgIDAwMGAwMGDAgHCAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM/8AAEQgADAAUAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A5j9hnXPH/gy003RdI+KejWVjciO7muPF86y2GiWFu3nahceUJUyEtfOcKroplMZeSJAxH1j+2p8f9L8TfBTw1qvwo8YSSWGr6FB4p1bStWsLi01TVPDl4ZLe21CwkeOJ9yXf2cSQlCfKukdjDvhM34beLf2n/G3wz+B2g+ItA1qbS9Y0bxBm1uIlDFA9vPG6kNkFWQlSp4welZfxG/4K1fHj9ozQj4T8V+N73U9J1u7e7uxLmWU+YYWaGJ5Cxt7fzLeF/s8Hlxbox8mABXNQjVjQnQlVk+zurrRbWSXnbbuedTyvD0ISoQvZ333WnyPqLxp8PG8feIrjU5dG8O60ZWMYuDeW1tjyyUKeWzALtZWGFG3Oe+aK/OP4ja3c+CfiZ4m07TJTbWdvq90iIQJSAsrKMs+WJwo6miuFZRbT2svvX+QoZTQirXf4f5H/2Q==")
                    };

                    attachment = fileAttachment;
                }
                else if (attachmentsType[attachmentIndex] == AttachmentTypeValue.ReferenceAttachment)
                {
                    ReferenceAttachmentType referenceAttachment = new ReferenceAttachmentType()
                    {
                        AttachLongPathName     = @"http://www.contoso.com/xyz.abc",
                        ProviderType           = "abc",
                        ProviderEndpointUrl    = @"http://www.contoso.com",
                        AttachmentPreviewUrl   = @"http://www.contoso.com/Preview.abc",
                        AttachmentThumbnailUrl = @"http://www.contoso.com/Thumbnail.abc",
                        ContentLocation        = @"http://www.contoso.com/xyz.abc",
                        Name        = "RefAttachment",
                        ContentId   = Guid.NewGuid().ToString(),
                        ContentType = "image/jpeg",
                    };

                    attachment = referenceAttachment;
                }
                else
                {
                    ItemAttachmentType itemAttachment = new ItemAttachmentType()
                    {
                        ContentLocation = @"http://www.contoso.com/xyz.abc",
                        Name            = "ItemName",

                        // Ensure content id is unique.
                        ContentId   = Guid.NewGuid().ToString(),
                        ContentType = "image/jpeg",
                    };

                    switch (attachmentsType[attachmentIndex])
                    {
                    case AttachmentTypeValue.ItemAttachment:
                        itemAttachment.Item = new ItemType();
                        break;

                    case AttachmentTypeValue.MessageAttachment:
                        itemAttachment.Item = new MessageType()
                        {
                            Body = new BodyType()
                            {
                                BodyType1 = BodyTypeType.HTML,
                                Value     = "<html><body><b>Bold</b><script>alert('Alert!');</script></body></html>"
                            },
                        };
                        break;

                    case AttachmentTypeValue.CalendarAttachment:
                        itemAttachment.Item = new CalendarItemType()
                        {
                            StartSpecified = true,
                            EndSpecified   = true
                        };
                        break;

                    case AttachmentTypeValue.ContactAttachment:
                        itemAttachment.Item = new ContactItemType();
                        break;

                    case AttachmentTypeValue.PostAttachment:
                        itemAttachment.Item = new PostItemType();
                        break;

                    case AttachmentTypeValue.TaskAttachment:
                        itemAttachment.Item = new TaskType();
                        break;

                    case AttachmentTypeValue.MeetingMessageAttachemnt:
                        itemAttachment.Item = new MeetingMessageType();
                        break;

                    case AttachmentTypeValue.MeetingRequestAttachment:
                        itemAttachment.Item = new MeetingRequestMessageType();
                        break;

                    case AttachmentTypeValue.MeetingResponseAttachment:
                        itemAttachment.Item = new MeetingResponseMessageType();
                        break;

                    case AttachmentTypeValue.MeetingCancellationAttachment:
                        itemAttachment.Item = new MeetingCancellationMessageType();
                        break;

                    case AttachmentTypeValue.PersonAttachment:
                        itemAttachment.Item = new AbchPersonItemType()
                        {
                            AntiLinkInfo   = "",
                            PersonId       = Guid.NewGuid().ToString(),
                            ContactHandles = new AbchPersonContactHandle[] {
                                new AbchPersonContactHandle(),
                            },
                            ContactCategories = new string[] {
                                "test category"
                            },
                        };
                        break;
                    }

                    attachment = itemAttachment;
                }

                this.Attachments[attachmentIndex] = attachment;
            }

            CreateAttachmentType createAttachmentRequest = new CreateAttachmentType()
            {
                ParentItemId = new ItemIdType()
                {
                    Id = parentItemId
                },
                Attachments = this.Attachments
            };

            return(this.ATTAdapter.CreateAttachment(createAttachmentRequest));
        }