Example #1
0
        protected void DemoteAttachments()
        {
            if (this.item.AttachmentCollection == null || this.item.AttachmentCollection.Count == 0)
            {
                return;
            }
            ICollection <PropertyDefinition> collection = new List <PropertyDefinition>(1);

            collection.Add(AttachmentSchema.AttachContentId);
            foreach (AttachmentHandle handle in this.item.AttachmentCollection)
            {
                using (Attachment attachment = this.item.AttachmentCollection.Open(handle, collection))
                {
                    string attachmentContentId = ItemToMimeConverter.GetAttachmentContentId(attachment, base.OutboundContext.AttachmentLinks);
                    if (attachmentContentId == null || attachmentContentId.Trim().Length == 0)
                    {
                        ExTraceGlobals.ICalTracer.TraceError <string>((long)this.GetHashCode(), "VItemBase::DemoteAttachments. Incomplete attachment content id. Item:{0}", this.item.Id.ToString());
                        base.Context.AddError(ServerStrings.InvalidICalElement("Attachment.ContentId"));
                    }
                    else
                    {
                        this.calendarWriter.StartProperty(PropertyId.Attachment);
                        this.calendarWriter.WritePropertyValue("CID:" + attachmentContentId);
                    }
                }
            }
        }
Example #2
0
 public ImapItemConverter(Item itemIn, OutboundConversionOptions options)
 {
     StorageGlobals.ContextTraceInformation(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::ctor.");
     using (DisposeGuard disposeGuard = this.Guard())
     {
         Util.ThrowOnNullArgument(itemIn, "itemIn");
         Util.ThrowOnNullArgument(options, "options");
         Util.ThrowOnNullOrEmptyArgument(options.ImceaEncapsulationDomain, "options.ImceaEncapsulationDomain");
         if (!ItemConversion.IsItemClassConvertibleToMime(itemIn.ClassName))
         {
             StorageGlobals.ContextTraceError <string>(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::CheckItemType: wrong item type, {0}", itemIn.ClassName);
             throw new WrongObjectTypeException(ServerStrings.ConversionInvalidItemType(itemIn.ClassName));
         }
         this.itemIn  = itemIn;
         this.options = options;
         using (StorageGlobals.SetTraceContext(this.options))
         {
             using (StorageGlobals.SetTraceContext(this.itemIn))
             {
                 if (this.options.GenerateMimeSkeleton)
                 {
                     PropertyError propertyError = this.itemIn.TryGetProperty(InternalSchema.MimeSkeleton) as PropertyError;
                     if (propertyError != null && propertyError.PropertyErrorCode == PropertyErrorCode.NotFound)
                     {
                         if (this.itemIn.IsReadOnly)
                         {
                             this.itemIn.OpenAsReadWrite();
                         }
                         this.itemNeedsSave = true;
                         using (Stream stream = this.itemIn.OpenPropertyStream(InternalSchema.MimeSkeleton, PropertyOpenMode.Create))
                         {
                             using (Stream stream2 = new MimeStreamWriter.MimeTextStream(null))
                             {
                                 using (ItemToMimeConverter itemToMimeConverter = new ItemToMimeConverter(itemIn, options, ConverterFlags.GenerateSkeleton))
                                 {
                                     using (MimeStreamWriter mimeStreamWriter = new MimeStreamWriter(stream2, stream, itemToMimeConverter.GetItemMimeEncodingOptions(this.options), MimeStreamWriter.Flags.ForceMime))
                                     {
                                         ConversionLimitsTracker limits = new ConversionLimitsTracker(this.options.Limits);
                                         itemToMimeConverter.ConvertItemToMime(mimeStreamWriter, limits);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 ItemToMimeConverter itemToMimeConverter2 = new ItemToMimeConverter(itemIn, options, ConverterFlags.None);
                 this.mimeProvider        = IImapMimeProvider.CreateInstance(itemToMimeConverter2);
                 this.itemEncodingOptions = itemToMimeConverter2.GetItemMimeEncodingOptions(this.options);
             }
         }
         disposeGuard.Success();
     }
 }
Example #3
0
            private void WriteParticipant(ContactWriter writer, Participant addr, OutboundConversionOptions options)
            {
                if (addr == null)
                {
                    return;
                }
                string participantSmtpAddress = ItemToMimeConverter.GetParticipantSmtpAddress(addr, options);

                if (!string.IsNullOrEmpty(participantSmtpAddress))
                {
                    writer.StartProperty(PropertyId.EMail);
                    writer.WriteParameter(ParameterId.Type, "INTERNET");
                    writer.WritePropertyValue(participantSmtpAddress);
                }
            }
 internal MsgToRpMsgConverter(MessageItem envelopeMessage, Participant conversationOwner, OrganizationId orgId, RmsTemplate restriction, OutboundConversionOptions options)
 {
     MsgToRpMsgConverter < > 4__this = this;
     using (DisposeGuard disposeGuard = this.Guard())
     {
         this.options   = options;
         this.orgId     = orgId;
         this.charset   = ConvertUtils.GetItemMimeCharset(envelopeMessage.CoreItem.PropertyBag);
         this.messageId = envelopeMessage.InternetMessageId;
         MsgToRpMsgConverter.RpMsgConversionAddressCache rpMsgConversionAddressCache = new MsgToRpMsgConverter.RpMsgConversionAddressCache(this.options);
         rpMsgConversionAddressCache.CopyRecipientsFromItem(envelopeMessage);
         rpMsgConversionAddressCache.Sender = conversationOwner;
         if (envelopeMessage.From != null)
         {
             rpMsgConversionAddressCache.From = envelopeMessage.From;
         }
         rpMsgConversionAddressCache.Resolve();
         string senderAddress = ItemToMimeConverter.TryGetParticipantSmtpAddress(rpMsgConversionAddressCache.Sender ?? conversationOwner);
         if (string.IsNullOrEmpty(senderAddress))
         {
             ExTraceGlobals.StorageTracer.TraceError <string>(0L, "Message sender must have SMTP address to protect the message: {0}", conversationOwner.DisplayName);
             throw new CorruptDataException(ServerStrings.CannotProtectMessageForNonSmtpSender);
         }
         List <string> recipientAddresses = new List <string>(envelopeMessage.Recipients.Count);
         for (int i = 0; i < envelopeMessage.Recipients.Count; i++)
         {
             string text = ItemToMimeConverter.TryGetParticipantSmtpAddress(rpMsgConversionAddressCache.GetRecipient(i) ?? envelopeMessage.Recipients[i].Participant);
             if (!string.IsNullOrEmpty(text))
             {
                 recipientAddresses.Add(text);
             }
             else
             {
                 ExTraceGlobals.StorageTracer.TraceError <string>(0L, "Message recipient must have SMTP address to be included in the IRM message license: {0}", envelopeMessage.Recipients[i].Participant.DisplayName);
             }
         }
         string fromAddress = string.Empty;
         if (rpMsgConversionAddressCache.From != null)
         {
             fromAddress = ItemToMimeConverter.TryGetParticipantSmtpAddress(rpMsgConversionAddressCache.From);
             if (string.IsNullOrEmpty(fromAddress))
             {
                 ExTraceGlobals.StorageTracer.TraceError <string>(0L, "Message from participant must have SMTP address to be included in the IRM message license: {0}", rpMsgConversionAddressCache.From.DisplayName);
             }
         }
         this.InitTenantLicenses();
         MsgToRpMsgConverter.CallRM(delegate
         {
Example #5
0
        private IImapMimeProvider GetAttachedItemConverter(ref MimePartInfo part, ref Item item, ref EncodingOptions itemEncodingOptions, List <IDisposable> disposeList)
        {
            if (part.ContentType != MimePartContentType.ItemAttachment)
            {
                return(null);
            }
            IImapMimeProvider imapMimeProvider;

            if (part.SmimePart == null)
            {
                Attachment attachment = item.AttachmentCollection.Open(part.AttachmentId, InternalSchema.ContentConversionProperties);
                disposeList.Add(attachment);
                ItemAttachment itemAttachment = attachment as ItemAttachment;
                if (itemAttachment == null)
                {
                    StorageGlobals.ContextTraceError(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::GetAttachedItemConverter: attachment is not an item.");
                    ExAssert.RetailAssert(false, "ImapItemConverter::GetAttachedItemConverter: attachment is not an item.");
                    return(null);
                }
                item = ConvertUtils.OpenAttachedItem(itemAttachment);
                if (item == null)
                {
                    return(null);
                }
                disposeList.Add(item);
                ItemToMimeConverter itemToMimeConverter = new ItemToMimeConverter(item, this.options, ConverterFlags.IsEmbeddedMessage);
                imapMimeProvider = IImapMimeProvider.CreateInstance(itemToMimeConverter);
                disposeList.Add(imapMimeProvider);
                itemEncodingOptions = itemToMimeConverter.GetItemMimeEncodingOptions(this.options);
                if (part.AttachedItemStructure != null)
                {
                    itemToMimeConverter.SetSkeletonAndSmimeDoc(part.AttachedItemStructure.Skeleton, part.AttachedItemStructure.SmimeDocument);
                }
            }
            else
            {
                imapMimeProvider = IImapMimeProvider.CreateInstance((MimePart)part.SmimePart.FirstChild, part.SmimeDocument);
                disposeList.Add(imapMimeProvider);
                itemEncodingOptions = this.itemEncodingOptions;
            }
            if (part.AttachedItemStructure == null)
            {
                part.AttachedItemStructure = imapMimeProvider.CalculateMimeStructure(Charset.GetCharset(itemEncodingOptions.CharsetName));
            }
            part = part.AttachedItemStructure;
            return(imapMimeProvider);
        }
Example #6
0
 internal static IImapMimeProvider CreateInstance(ItemToMimeConverter itemConverter)
 {
     return(new ImapItemMimeProvider(itemConverter));
 }
 internal ImapItemMimeProvider(ItemToMimeConverter itemConverter)
 {
     this.itemConverter = itemConverter;
 }