private Stream GetItemAttachmentStream(Attachment attachment, OutboundConversionOptions outboundConversionOptions)
        {
            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 = ZipEntryAttachment.GetContentsReplacementStream(-1706159495);
                    text   = ".txt";
                }
            }
            if (text != null)
            {
                this.fileName             = this.GetConvertedItemFileName(this.fileName, text);
                this.encodedfileNameBytes = ZipEntryAttachment.GetEncodedString(this.fileName);
            }
            stream.Position = 0L;
            return(stream);
        }
 internal ZipEntryAttachment(string fileName, Attachment attachment, bool doNeedToFilterHtml, bool doNotSniff, bool isNotHtmlandNotXml)
 {
     this.fileName             = fileName;
     this.encodedfileNameBytes = ZipEntryAttachment.GetEncodedString(fileName);
     this.attachmentId         = attachment.Id;
     this.doNeedToFilterHtml   = doNeedToFilterHtml;
     this.doNotSniff           = doNotSniff;
     this.isNotHtmlandNotXml   = isNotHtmlandNotXml;
     if (this.NeedsCompression(attachment))
     {
         this.CompressionMethod     = 8;
         this.GeneralPurposeBitFlag = 2056;
     }
     else
     {
         this.CompressionMethod     = 0;
         this.GeneralPurposeBitFlag = 2048;
     }
     this.CurrentDateTime = this.CurrentDosDateTime();
 }
 private static Stream GetContentsReplacementStream(Strings.IDs resource)
 {
     byte[] encodedString = ZipEntryAttachment.GetEncodedString(Strings.GetLocalizedString(resource));
     return(new MemoryStream(encodedString, 0, encodedString.Length));
 }