// Token: 0x06002914 RID: 10516 RVA: 0x000E8774 File Offset: 0x000E6974 protected void RenderMime() { OutboundConversionOptions outboundConversionOptions = Utilities.CreateOutboundConversionOptions(base.UserContext); outboundConversionOptions.AllowPartialStnefConversion = true; outboundConversionOptions.DemoteBcc = true; try { ItemConversion.ConvertItemToMime(base.Item, base.Response.OutputStream, outboundConversionOptions); } catch (NotSupportedException innerException) { throw new OwaInvalidRequestException("Conversion failed", innerException); } catch (NotImplementedException innerException2) { throw new OwaInvalidRequestException("Conversion failed", innerException2); } catch (StoragePermanentException innerException3) { throw new OwaInvalidRequestException("Conversion failed", innerException3); } catch (StorageTransientException innerException4) { throw new OwaInvalidRequestException("Conversion failed", innerException4); } }
// Token: 0x06001C33 RID: 7219 RVA: 0x0006FF24 File Offset: 0x0006E124 protected override string InternalExecute() { IdAndSession idAndSession = base.IdConverter.ConvertItemIdToIdAndSessionReadOnly(this.itemId); MessageItem messageItem = Item.BindAsMessage(idAndSession.Session, idAndSession.Id); messageItem.Load(StoreObjectSchema.ContentConversionProperties); OutboundConversionOptions outboundConversionOptions = new OutboundConversionOptions(base.CallContext.DefaultDomain.DomainName.ToString()); UserContext userContext = UserContextManager.GetUserContext(base.CallContext.HttpContext); outboundConversionOptions.UserADSession = UserContextUtilities.CreateADRecipientSession(base.CallContext.ClientCulture.LCID, true, ConsistencyMode.IgnoreInvalid, false, userContext, true, base.CallContext.Budget); outboundConversionOptions.LoadPerOrganizationCharsetDetectionOptions(userContext.ExchangePrincipal.MailboxInfo.OrganizationId); outboundConversionOptions.AllowPartialStnefConversion = true; outboundConversionOptions.DemoteBcc = true; string @string; using (MemoryStream memoryStream = new MemoryStream()) { ItemConversion.ConvertItemToMime(messageItem, memoryStream, outboundConversionOptions); memoryStream.Position = 0L; byte[] array = new byte[memoryStream.Length]; memoryStream.Read(array, 0, array.Length); @string = Encoding.ASCII.GetString(array); } return(@string); }
// Token: 0x06001988 RID: 6536 RVA: 0x000953D4 File Offset: 0x000935D4 internal Stream GetItemAttachmentStream(Attachment attachment, HttpContext httpContext) { OwaContext owaContext = OwaContext.Get(httpContext); UserContext userContext = owaContext.UserContext; OutboundConversionOptions outboundConversionOptions = Utilities.CreateOutboundConversionOptions(userContext); Stream stream = Streams.CreateTemporaryStorageStream(); string text = null; ItemAttachment itemAttachment = attachment as ItemAttachment; using (Item item = itemAttachment.GetItem(StoreObjectSchema.ContentConversionProperties)) { try { if (ItemConversion.IsItemClassConvertibleToMime(item.ClassName)) { ItemConversion.ConvertItemToMime(item, stream, outboundConversionOptions); text = ".eml"; } else if (ObjectClass.IsCalendarItemCalendarItemOccurrenceOrRecurrenceException(item.ClassName)) { (item as CalendarItemBase).ExportAsICAL(stream, "UTF-8", outboundConversionOptions); text = ".ics"; } else if (ObjectClass.IsContact(item.ClassName)) { Contact.ExportVCard(item as Contact, stream, outboundConversionOptions); text = ".vcf"; } else { ItemConversion.ConvertItemToMsgStorage(item, stream, outboundConversionOptions); } } catch (Exception) { stream = this.GetContentsReplacementStream(-1706159495); text = ".txt"; } } if (text != null) { this.fileName = this.GetConvertedItemFileName(this.fileName, text); this.encodedfileNameBytes = this.GetEncodedString(this.fileName); } stream.Position = 0L; return(stream); }
public static Stream ConvertItemToMime(StoreObject xsoItem) { Item item = xsoItem as Item; if (item == null) { throw new UnexpectedTypeException("Item", xsoItem); } OutboundConversionOptions outboundConversionOptions = AirSyncUtility.GetOutboundConversionOptions(); PolicyData policyData = ADNotificationManager.GetPolicyData(Command.CurrentCommand.User); if (policyData != null && !policyData.AttachmentsEnabled) { outboundConversionOptions.FilterAttachmentHandler = ((Item item1, Attachment attachment) => false); } item.Load(StoreObjectSchema.ContentConversionProperties); AirSyncStream airSyncStream = new AirSyncStream(); try { if (BodyConversionUtilities.IsMessageRestrictedAndDecoded(item)) { ItemConversion.ConvertItemToMime(((RightsManagedMessageItem)item).DecodedItem, airSyncStream, outboundConversionOptions); } else { ItemConversion.ConvertItemToMime(item, airSyncStream, outboundConversionOptions); } } catch (ConversionFailedException innerException) { throw new ConversionException(string.Format(CultureInfo.InvariantCulture, "MIME conversion failed for Item {0}", new object[] { item }), innerException); } return(airSyncStream); }
private byte[] GetMimeData(StoreObjectId itemId, out string[] recipients) { recipients = null; byte[] result; using (MessageItem messageItem = MessageItem.Bind(this.mailboxSession, itemId, StoreObjectSchema.ContentConversionProperties)) { List <string> list = new List <string>(messageItem.Recipients.Count); foreach (RecipientBase recipientBase in messageItem.Recipients) { Participant participant = recipientBase.Participant; if (participant != null) { string valueOrDefault = participant.GetValueOrDefault <string>(ParticipantSchema.SmtpAddress); list.Add(valueOrDefault); } } OutboundConversionOptions options = new OutboundConversionOptions(this.mailboxSession.GetADRecipientSession(true, ConsistencyMode.IgnoreInvalid), this.mailboxSession.ServerFullyQualifiedDomainName) { IsSenderTrusted = true, RecipientCache = null, ClearCategories = true, Limits = { MimeLimits = MimeLimits.Unlimited }, AllowPartialStnefConversion = true }; using (PooledMemoryStream pooledMemoryStream = new PooledMemoryStream(6)) { ItemConversion.ConvertItemToMime(messageItem, pooledMemoryStream, options); recipients = list.ToArray(); result = pooledMemoryStream.ToArray(); } } return(result); }
// Token: 0x06000107 RID: 263 RVA: 0x000041B0 File Offset: 0x000023B0 public Stream GetAttachmentStream(AttachmentHandler.IAttachmentRetriever attachmentRetriever, AttachmentHandler.IAttachmentPolicyChecker policyChecker, bool asDataUri) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug <string>((long)this.GetHashCode(), "AttachmentHandler.GetAttachmentStream: Getting attachment stream for id={0}", this.id); if (string.IsNullOrEmpty(this.id)) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug((long)this.GetHashCode(), "Attachment id is empty or null. returning null stream."); throw new FaultException("Id cannot be null or empty."); } Stream stream = null; ByteEncoder byteEncoder = null; Stream stream2 = null; Stream result; try { Attachment attachment = attachmentRetriever.Attachment; AttachmentPolicyLevel policy = policyChecker.GetPolicy(attachment, this.webOperationContext.IsPublicLogon); if (AudioFile.IsProtectedVoiceAttachment(attachment.FileName)) { attachment.ContentType = Utils.GetUnProtectedVoiceAttachmentContentType(attachment.FileName); stream = DRMUtils.OpenProtectedAttachment(attachment, this.callContext.AccessingADUser.OrganizationId); string fileName; if (AudioFile.TryGetNonDRMFileNameFromDRM(attachment.FileName, out fileName)) { attachment.FileName = fileName; } } string text = AttachmentUtilities.GetContentType(attachment); string fileExtension = attachment.FileExtension; OleAttachment oleAttachment = attachment as OleAttachment; if (oleAttachment != null) { stream = oleAttachment.ConvertToImage(ImageFormat.Jpeg); if (stream != null) { text = "image/jpeg"; } } if (this.IsBlocked(policy) && !attachment.IsInline && !this.IsImagePreview) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug <string>((long)this.GetHashCode(), "Attachment is blocked. Returning null stream. id is {0}", this.id); result = null; } else { this.WriteResponseHeaders(text, policy, attachment); if (stream == null) { StreamAttachment streamAttachment = attachment as StreamAttachment; if (streamAttachment != null) { if (string.Equals(text, "audio/mpeg", StringComparison.OrdinalIgnoreCase)) { stream = streamAttachment.GetContentStream(PropertyOpenMode.Modify); } else { stream = streamAttachment.GetContentStream(PropertyOpenMode.ReadOnly); } } else { ItemAttachment itemAttachment = attachment as ItemAttachment; if (itemAttachment != null) { using (Item item = itemAttachment.GetItem(StoreObjectSchema.ContentConversionProperties)) { IRecipientSession adrecipientSession = item.Session.GetADRecipientSession(true, ConsistencyMode.IgnoreInvalid); OutboundConversionOptions outboundConversionOptions = new OutboundConversionOptions(this.callContext.DefaultDomain.DomainName.Domain); outboundConversionOptions.ClearCategories = false; outboundConversionOptions.UserADSession = adrecipientSession; outboundConversionOptions.LoadPerOrganizationCharsetDetectionOptions(adrecipientSession.SessionSettings.CurrentOrganizationId); stream = new MemoryStream(); ItemConversion.ConvertItemToMime(item, stream, outboundConversionOptions); stream.Seek(0L, SeekOrigin.Begin); } } } } long num = 0L; long num2 = 0L; if (AttachmentUtilities.NeedToFilterHtml(text, fileExtension, policy, this.configurationContext)) { stream = AttachmentUtilities.GetFilteredStream(this.configurationContext, stream, attachment.TextCharset, attachmentRetriever.BlockStatus); } else if (this.NeedToSendPartialContent(stream, out num, out num2)) { string value = string.Format(CultureInfo.InvariantCulture, "bytes {0}-{1}/{2}", new object[] { num, num2, stream.Length }); this.webOperationContext.Headers["Accept-Ranges"] = "bytes"; this.webOperationContext.Headers["Content-Range"] = value; this.webOperationContext.ETag = this.id; this.webOperationContext.StatusCode = HttpStatusCode.PartialContent; long num3 = num2 - num + 1L; if (num3 < stream.Length) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug <long, long, long>((long)this.GetHashCode(), "RangeBytes:{0} - Seek:{1} - SetLength:{2}", num3, num, num2 + 1L); stream.Seek(num, SeekOrigin.Begin); return(new BoundedStream(stream, true, num, num2)); } } if (asDataUri) { byteEncoder = new Base64Encoder(); stream2 = new EncoderStream(stream, byteEncoder, EncoderStreamAccess.Read); stream = new DataUriStream(stream2, text); } result = stream; } } catch (Exception ex) { if (stream != null) { stream.Dispose(); } if (stream2 != null) { stream2.Dispose(); } if (byteEncoder != null) { byteEncoder.Dispose(); } string formatString = string.Empty; if (ex is ExchangeDataException) { formatString = "Fail to sanitize HTML getting attachment. id is {0}, Exception: {1}"; } else if (ex is StoragePermanentException) { formatString = "StoragePermanentException when getting attachment. id is {0}, Exception: {1}"; } else { if (!(ex is StorageTransientException)) { throw; } formatString = "StorageTransientException when getting attachment. id is {0}, Exception: {1}"; } ExTraceGlobals.AttachmentHandlingTracer.TraceError <string, Exception>((long)this.GetHashCode(), formatString, this.id, ex); throw new CannotOpenFileAttachmentException(ex); } return(result); }
private static string GetAttachmentItself(Attachment attachment, Stream outStream, int offset, int count, out int total) { string text = string.Empty; total = 0; StreamAttachmentBase streamAttachmentBase = attachment as StreamAttachmentBase; if (streamAttachmentBase != null) { OleAttachment oleAttachment = streamAttachmentBase as OleAttachment; Stream stream = null; try { if (oleAttachment != null) { stream = oleAttachment.TryConvertToImage(ImageFormat.Jpeg); if (stream != null) { text = "image/jpeg"; } } if (stream == null) { stream = streamAttachmentBase.GetContentStream(); } if (string.IsNullOrEmpty(text)) { text = attachment.ContentType; } if (string.IsNullOrEmpty(text)) { text = attachment.CalculatedContentType; } if (stream.Length > 0L) { if ((long)offset >= stream.Length) { throw new ArgumentOutOfRangeException("offset"); } int num = (count == -1) ? ((int)stream.Length) : count; if (num > GlobalSettings.MaxDocumentDataSize) { throw new DataTooLargeException(StatusCode.AttachmentIsTooLarge); } StreamHelper.CopyStream(stream, outStream, offset, num); total = (int)stream.Length; } } finally { if (stream != null) { stream.Dispose(); stream = null; } } return(text); } ItemAttachment itemAttachment = attachment as ItemAttachment; if (itemAttachment != null) { using (Item item = itemAttachment.GetItem(StoreObjectSchema.ContentConversionProperties)) { text = "message/rfc822"; OutboundConversionOptions outboundConversionOptions = AirSyncUtility.GetOutboundConversionOptions(); using (AirSyncStream airSyncStream = new AirSyncStream()) { try { ItemConversion.ConvertItemToMime(item, airSyncStream, outboundConversionOptions); } catch (ConversionFailedException innerException) { throw new FormatException(string.Format(CultureInfo.InvariantCulture, "MIME conversion failed for Attachment {0}!", new object[] { attachment }), innerException); } if (airSyncStream.Length > 0L) { if ((long)offset >= airSyncStream.Length) { throw new ArgumentOutOfRangeException("offset"); } int num2 = (count == -1) ? ((int)airSyncStream.Length) : count; if (num2 > GlobalSettings.MaxDocumentDataSize) { throw new DataTooLargeException(StatusCode.AttachmentIsTooLarge); } StreamHelper.CopyStream(airSyncStream, outStream, offset, num2); total = (int)airSyncStream.Length; } } } return(text); } throw new FormatException(string.Format(CultureInfo.InvariantCulture, "Attachment {0} is of invalid format!", new object[] { attachment })); }