internal static ReadOnlyCollection <AttachmentLink> MergeAttachmentLinks(IList <AttachmentLink> existingLinks, CoreAttachmentCollection attachments) { IList <AttachmentLink> list; if (attachments != null) { list = ((existingLinks == null) ? new List <AttachmentLink>(attachments.Count) : new List <AttachmentLink>(existingLinks)); ICollection <PropertyDefinition> preloadProperties = new PropertyDefinition[] { AttachmentSchema.AttachContentId }; using (IEnumerator <AttachmentHandle> enumerator = attachments.GetEnumerator()) { while (enumerator.MoveNext()) { AttachmentHandle handle = enumerator.Current; using (CoreAttachment coreAttachment = attachments.Open(handle, preloadProperties)) { using (Attachment attachment = AttachmentCollection.CreateTypedAttachment(coreAttachment, null)) { if (AttachmentLink.Find(attachment.Id, list) == null) { AttachmentLink item = new AttachmentLink(attachment); list.Add(item); } } } } goto IL_C5; } } list = ((existingLinks == null) ? new List <AttachmentLink>(0) : new List <AttachmentLink>(existingLinks)); IL_C5: return(new ReadOnlyCollection <AttachmentLink>(list)); }
private string GetOrGenerateAttachContentId(AttachmentLink link) { string text = link.ContentId; if (string.IsNullOrEmpty(text)) { text = AttachmentLink.CreateContentId(this.AttachmentCollection.ContainerItem, link.AttachmentId, this.contentIdDomain); link.ContentId = text; } return(text); }
public override bool ProcessImage(string imageUrl, int approximateRenderingPosition) { AttachmentLink attachmentLink = base.FindAttachmentByBodyReference(imageUrl); if (attachmentLink == null) { return(false); } attachmentLink.RenderingPosition = approximateRenderingPosition; attachmentLink.IsHidden = false; attachmentLink.MarkInline(true); return(true); }
internal static ReadOnlyCollection <AttachmentLink> ItemToICal(Item item, ReadOnlyCollection <AttachmentLink> existingAttachmentLinks, OutboundAddressCache addressCache, Stream stream, string charsetName, OutboundConversionOptions outboundConversionOptions) { ReadOnlyCollection <AttachmentLink> readOnlyCollection = AttachmentLink.MergeAttachmentLinks(existingAttachmentLinks, item.AttachmentCollection.CoreAttachmentCollection); foreach (AttachmentLink attachmentLink in readOnlyCollection) { if (string.IsNullOrEmpty(attachmentLink.ContentId)) { attachmentLink.ContentId = AttachmentLink.CreateContentId(item.CoreItem, attachmentLink.AttachmentId, outboundConversionOptions.ImceaEncapsulationDomain); } } return(CalendarDocument.InternalItemsToICal(null, new Item[] { item }, readOnlyCollection, addressCache, false, stream, new List <LocalizedString>(), charsetName, outboundConversionOptions)); }
internal AttachmentLink(Attachment attachment) { this.attachmentType = attachment.AttachmentType; this.attachmentId = attachment.Id; this.contentId = attachment.ContentId; this.contentBase = attachment.ContentBase; this.contentLocation = attachment.ContentLocation; this.filename = attachment.FileName; this.displayName = attachment.DisplayName; this.size = attachment.Size; this.originalIsInline = attachment.IsInline; this.markedInline = null; this.contentType = AttachmentLink.GetContentType(attachment); this.renderingPosition = attachment.GetValueOrDefault <int>(InternalSchema.RenderingPosition, -1); this.isHidden = attachment.GetValueOrDefault <bool>(InternalSchema.AttachCalendarHidden); this.isChanged = false; }
public override void ProcessTag(HtmlTagContext tagContext, HtmlWriter htmlWriter) { if (tagContext.TagId != HtmlTagId.Img) { tagContext.WriteTag(true); return; } AttachmentLink attachmentLink = null; string text = null; foreach (HtmlTagContextAttribute htmlTagContextAttribute in tagContext.Attributes) { if (htmlTagContextAttribute.Id == HtmlAttributeId.Src) { text = htmlTagContextAttribute.Value; break; } } if (!string.IsNullOrEmpty(text)) { attachmentLink = base.FindAttachmentByBodyReference(text); } if (attachmentLink == null) { if (!this.clearEmptyLinks || !DefaultHtmlCallbacks.IsEmptyLink(text)) { tagContext.WriteTag(true); } return; } string text2; string text3; if (attachmentLink.AttachmentType == AttachmentType.Ole) { text2 = "image/jpeg"; text3 = "jpg"; attachmentLink.ConvertToImage(); } else { text2 = attachmentLink.ContentType; text3 = attachmentLink.FileExtension; } bool flag = text.StartsWith("cid:Microsoft-Infopath-", StringComparison.OrdinalIgnoreCase) && string.IsNullOrEmpty(text3) && !string.IsNullOrEmpty(text2) && text2.Equals("application/octet-stream"); if (DefaultHtmlCallbacks.IsInlineImage(text2, text3) || flag) { tagContext.WriteTag(false); foreach (HtmlTagContextAttribute htmlTagContextAttribute2 in tagContext.Attributes) { if (htmlTagContextAttribute2.Id == HtmlAttributeId.Src) { string value = "cid:" + this.GetOrGenerateAttachContentId(attachmentLink); htmlWriter.WriteAttribute(HtmlAttributeId.Src, value); } else { htmlTagContextAttribute2.Write(); } } attachmentLink.MarkInline(true); return; } if (!this.RemoveLinksToNonImageAttachments) { string text4 = attachmentLink.Filename; if (text4 == null) { text4 = ServerStrings.DefaultHtmlAttachmentHrefText; } htmlWriter.WriteStartTag(HtmlTagId.A); htmlWriter.WriteAttribute(HtmlAttributeId.Href, "cid:" + this.GetOrGenerateAttachContentId(attachmentLink)); htmlWriter.WriteText(text4); htmlWriter.WriteEndTag(HtmlTagId.A); attachmentLink.MarkInline(false); } }
public ReadOnlyCollection <AttachmentLink> InitializeAttachmentLinks(IList <AttachmentLink> linksToMerge) { this.attachmentLinks = AttachmentLink.MergeAttachmentLinks(linksToMerge, this.AttachmentCollection); return(this.attachmentLinks); }
private AttachmentLink InternalFindByBodyReference(string bodyReference, Uri baseUri) { Uri uri; if (!Uri.TryCreate(bodyReference, UriKind.RelativeOrAbsolute, out uri)) { ExTraceGlobals.StorageTracer.TraceError <string>((long)this.GetHashCode(), "BodyConversionCallbacksBase.InternalFindId: bodyReference not a valid URI\r\n'{0}'", bodyReference); return(null); } if (!uri.IsWellFormedOriginalString()) { ExTraceGlobals.StorageTracer.TraceError <string>((long)this.GetHashCode(), "BodyConversionCallbacksBase.InternalFindId: bodyReference not a valid URI\r\n'{0}'", bodyReference); return(null); } if (uri.IsAbsoluteUri && uri.Scheme == "cid") { using (IEnumerator <AttachmentLink> enumerator = this.AttachmentLinks.GetEnumerator()) { while (enumerator.MoveNext()) { AttachmentLink attachmentLink = enumerator.Current; AttachmentId attachmentId = attachmentLink.AttachmentId; string text; if (string.Equals(uri.LocalPath, attachmentLink.ContentId, StringComparison.OrdinalIgnoreCase)) { text = attachmentLink.ContentId; } else if (string.Equals(uri.LocalPath, attachmentLink.Filename, StringComparison.OrdinalIgnoreCase)) { text = attachmentLink.Filename; } else { if (!string.Equals(uri.LocalPath, attachmentLink.DisplayName, StringComparison.OrdinalIgnoreCase)) { continue; } text = attachmentLink.DisplayName; } Uri contentLocation; if (!Uri.TryCreate("cid:" + text, UriKind.RelativeOrAbsolute, out contentLocation)) { ExTraceGlobals.StorageTracer.TraceError <string, AttachmentId>((long)this.GetHashCode(), "BodyConversionCallbacksBase.InternalFindId: attachmentContentKey[{1}] not a valid URI\r\n'{0}'", text, attachmentId); return(null); } if (!contentLocation.IsWellFormedOriginalString()) { ExTraceGlobals.StorageTracer.TraceError <string, AttachmentId>((long)this.GetHashCode(), "BodyConversionCallbacksBase.InternalFindId: attachmentContentKey[{1}] not a valid URI\r\n'{0}'", text, attachmentId); return(null); } return(attachmentLink); } goto IL_2A1; } } if (uri.IsAbsoluteUri && uri.Scheme == "objattph") { if (this.attachmentsByPositionEnumerator == null) { this.CreateAttachmentsByPositionEnumerator(); } if (this.attachmentsByPositionEnumerator.MoveNext()) { KeyValuePair <int, AttachmentLink> keyValuePair = this.attachmentsByPositionEnumerator.Current; return(keyValuePair.Value); } return(null); } else { Uri uri2; if (uri.IsAbsoluteUri) { uri2 = uri; } else if (baseUri != null) { if (!Uri.TryCreate(baseUri, uri, out uri2)) { ExTraceGlobals.StorageTracer.TraceError <Uri, Uri>((long)this.GetHashCode(), "AttachmentCollection.InternalFindId: can't build absolute URI from bodyReference and base\r\n'{0}'\r\n'{1}'", uri, baseUri); uri2 = uri; } } else { uri2 = uri; } foreach (AttachmentLink attachmentLink2 in this.AttachmentLinks) { AttachmentId attachmentId2 = attachmentLink2.AttachmentId; Uri contentLocation = attachmentLink2.ContentLocation; Uri contentBase = attachmentLink2.ContentBase; if (!(contentLocation == null)) { Uri obj; if (contentLocation.IsAbsoluteUri) { obj = contentLocation; } else if (contentBase != null) { if (!Uri.TryCreate(contentBase, contentLocation, out obj)) { ExTraceGlobals.StorageTracer.TraceError <Uri, AttachmentId>((long)this.GetHashCode(), "AttachmentCollection.InternalFindId: attachContentLocation[{1}] not a valid URI\r\n'{0}'", contentLocation, attachmentId2); obj = contentLocation; } } else { obj = contentLocation; } try { if (uri2.Equals(obj)) { return(attachmentLink2); } } catch (UriFormatException) { } } } } IL_2A1: return(null); }
public virtual bool SaveChanges() { if (this.AttachmentCollection == null) { throw new InvalidOperationException("Target item not specified; callback cannot invoke attachment-specific methods"); } bool result = false; if (this.attachmentLinks != null) { using (IEnumerator <AttachmentLink> enumerator = this.attachmentLinks.GetEnumerator()) { while (enumerator.MoveNext()) { AttachmentLink attachmentLink = enumerator.Current; using (CoreAttachment coreAttachment = this.AttachmentCollection.Open(attachmentLink.AttachmentId)) { using (Attachment attachment = Microsoft.Exchange.Data.Storage.AttachmentCollection.CreateTypedAttachment(coreAttachment, null)) { if (this.removeUnlinkedAttachments && !attachmentLink.IsInline(this.requireMarkInline) && attachment.IsInline) { attachment.Dispose(); this.AttachmentCollection.Remove(attachmentLink.AttachmentId); } else { if (attachmentLink.NeedsConversionToImage && attachment.AttachmentType == AttachmentType.Ole) { OleAttachment oleAttachment = attachment as OleAttachment; if (oleAttachment == null) { continue; } using (Attachment attachment2 = oleAttachment.ConvertToImageAttachment(this.AttachmentCollection, ImageFormat.Jpeg)) { result = true; attachmentLink.MakeAttachmentChanges(attachment2, this.requireMarkInline); attachment2.Save(); continue; } } if (attachmentLink.MakeAttachmentChanges(attachment, this.requireMarkInline)) { result = true; attachment.Save(); } } } } } return(result); } } if (this.requireMarkInline) { List <AttachmentId> list = null; foreach (AttachmentHandle handle in this.AttachmentCollection) { using (CoreAttachment coreAttachment2 = this.AttachmentCollection.Open(handle)) { if (coreAttachment2.IsInline) { if (this.removeUnlinkedAttachments) { if (list == null) { list = new List <AttachmentId>(); } list.Add(coreAttachment2.Id); } else { coreAttachment2.IsInline = false; result = true; coreAttachment2.Save(); } } } } if (list != null) { foreach (AttachmentId id in list) { this.AttachmentCollection.Remove(id); } } } return(result); }