// Token: 0x06000D03 RID: 3331 RVA: 0x0003642C File Offset: 0x0003462C private void UploadSingleFile(string fileName, IAttachmentCollection attachmentCollection, Action abortFileOperation) { abortFileOperation(); string fileName2 = Path.GetFileName(fileName); using (IOCostStream iocostStream = new IOCostStream(new FileStream(fileName, FileMode.Open))) { using (new FileSystemPerformanceTracker("MailboxUpload", iocostStream, this.logger)) { using (HashAlgorithm hashAlgorithm = new SHA1CryptoServiceProvider()) { using (IStreamAttachment streamAttachment = (IStreamAttachment)attachmentCollection.CreateIAttachment(AttachmentType.Stream)) { using (new StorePerformanceTracker("MailboxUpload", this.logger)) { CopyStreamResult arg; using (IOCostStream iocostStream2 = new IOCostStream(streamAttachment.GetContentStream())) { arg = MailboxFileStore.streamCopier.CopyStream(iocostStream, iocostStream2, hashAlgorithm, abortFileOperation); iocostStream2.Flush(); } streamAttachment[AttachmentSchema.DisplayName] = fileName2; streamAttachment[AttachmentSchema.AttachLongFileName] = fileName2; streamAttachment[AttachmentSchema.AttachHash] = hashAlgorithm.Hash; streamAttachment.Save(); this.tracer.TraceDebug <string, CopyStreamResult>((long)this.GetHashCode(), "Uploaded file '{0}' to mailbox. {1}", fileName, arg); } } } } } }
internal static void CreateAttachment(IItem parentItem, Attachment16Data attachmentData) { AirSyncDiagnostics.TraceDebug <byte>(ExTraceGlobals.RequestsTracer, null, "CreateAttachment with AttachMethod:{0}", attachmentData.Method); if (attachmentData.Method == 1) { if (attachmentData.Content == null) { throw new ConversionException(string.Format(" Attachment content can not be null.", new object[0])); } IStreamAttachment streamAttachment = parentItem.IAttachmentCollection.CreateIAttachment(AttachmentType.Stream) as IStreamAttachment; AttachmentHelper.CopyCommonAttachmentProperties(streamAttachment, attachmentData); using (Stream contentStream = streamAttachment.GetContentStream()) { contentStream.Write(attachmentData.Content, 0, attachmentData.Content.Length); } streamAttachment.Save(); } else { if (attachmentData.Method != 5) { throw new ConversionException(string.Format("UnSupported Value '{0}' for Attachment Method. Only 1 & 5 is supported AttachemntType", attachmentData.Method)); } ItemAttachment itemAttachment = parentItem.IAttachmentCollection.CreateIAttachment(AttachmentType.EmbeddedMessage) as ItemAttachment; AttachmentHelper.CopyCommonAttachmentProperties(itemAttachment, attachmentData); using (Stream stream = new MemoryStream(attachmentData.Content)) { stream.Seek(0L, SeekOrigin.Begin); InboundConversionOptions inboundConversionOptions = AirSyncUtility.GetInboundConversionOptions(); inboundConversionOptions.ClearCategories = false; try { using (Item item = itemAttachment.GetItem()) { ItemConversion.ConvertAnyMimeToItem(item, stream, inboundConversionOptions); item.Save(SaveMode.NoConflictResolution); } } catch (ExchangeDataException innerException) { throw new AirSyncPermanentException(HttpStatusCode.BadRequest, StatusCode.InvalidMIME, innerException, false); } catch (ConversionFailedException innerException2) { throw new AirSyncPermanentException(HttpStatusCode.BadRequest, StatusCode.InvalidMIME, innerException2, false); } } itemAttachment.Save(); } AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.RequestsTracer, null, "AttachmentHelper:CreateAttachments:: AttachmentCreated successful. AttachmentCount:{0}", parentItem.IAttachmentCollection.Count); }