private void ParseAlternativeView(ref EMailBodyAlternateView AlternateView, string[] ViewLines) { int headerEndPos = FindHeaderEnd(ViewLines); ParseAlternateViewHeaders(ref AlternateView, GetHeaderLines(ViewLines, headerEndPos)); ParseAlternateViewContent(ref AlternateView, GetBodyLines(ViewLines, headerEndPos)); }
private void ParseMultipartAlternativeViews(string[] ViewsCollectionLines, int[] BoundaryPositions, ref EMailBodyAlternateView[] Views, ref EMailAttachment[] Attachments) { EMailBodyAlternateView[] parsedViews = null; EMailAttachment[] parsedAttachments = null; if (BoundaryPositions != null && BoundaryPositions.Length > 2) { for (int i = 0; i < BoundaryPositions.Length - 1;) { string[] viewLines = GetStringArrayPart(ViewsCollectionLines, BoundaryPositions[i] + 1, BoundaryPositions[++i] - 1); ParseNestedContent(viewLines, ref parsedViews, ref parsedAttachments); } } if (Views == null) { Views = new EMailBodyAlternateView[0]; } if (Attachments == null) { Attachments = new EMailAttachment[0]; } if (parsedViews == null) { parsedViews = new EMailBodyAlternateView[0]; } if (parsedAttachments == null) { parsedAttachments = new EMailAttachment[0]; } EMailBodyAlternateView[] newViewsCollection = new EMailBodyAlternateView[Views.Length + parsedViews.Length]; Array.Copy(Views, newViewsCollection, Views.Length); Array.Copy(parsedViews, 0, newViewsCollection, Views.Length, parsedViews.Length); EMailAttachment[] newAttachmentsCollection = new EMailAttachment[Attachments.Length + parsedAttachments.Length]; Array.Copy(Attachments, newAttachmentsCollection, Attachments.Length); Array.Copy(parsedAttachments, 0, newAttachmentsCollection, Attachments.Length, parsedAttachments.Length); Views = newViewsCollection; Attachments = newAttachmentsCollection; return; }
private void ParseNestedContent(string[] NestedCollectionLines, ref EMailBodyAlternateView[] Views, ref EMailAttachment[] Attachments) { string boundary = string.Empty; int[] boundariesPos = null; string[] nestedContent = null; string messageLine = string.Empty; int headerEndLine = FindHeaderEnd(NestedCollectionLines); string contentType = ParseNestedContentHeaders(GetHeaderLines(NestedCollectionLines, headerEndLine), out boundary); if (boundary != null && boundary != string.Empty) { boundariesPos = FindBoundariesPositions(NestedCollectionLines, boundary, headerEndLine); } EMailBodyAlternateView[] parsedViews = null; EMailAttachment[] parsedAttachments = null; switch (contentType) { case "multipart/alternative": ParseMultipartAlternativeViews(GetBodyLines(NestedCollectionLines, headerEndLine), boundary, ref parsedViews, ref parsedAttachments); break; case "multipart/mixed": case "multipart/related": for (int i = 0; i < boundariesPos.Length - 1;) { nestedContent = GetStringArrayPart(GetBodyLines(NestedCollectionLines, headerEndLine), boundariesPos[i], boundariesPos[++i]); ParseNestedContent(nestedContent, ref Views, ref Attachments); } break; case "text/plain": case "text/html": case "text/htm": case "": parsedViews = new EMailBodyAlternateView[] { new EMailBodyAlternateView() }; ParseAlternativeView(ref parsedViews[0], NestedCollectionLines); break; default: parsedAttachments = new EMailAttachment[] { new EMailAttachment() }; ParseAttachment(ref parsedAttachments[0], NestedCollectionLines); break; } if (Views == null) { Views = new EMailBodyAlternateView[0]; } if (Attachments == null) { Attachments = new EMailAttachment[0]; } if (parsedViews == null) { parsedViews = new EMailBodyAlternateView[0]; } if (parsedAttachments == null) { parsedAttachments = new EMailAttachment[0]; } EMailBodyAlternateView[] newViewsCollection = new EMailBodyAlternateView[Views.Length + parsedViews.Length]; Array.Copy(Views, newViewsCollection, Views.Length); Array.Copy(parsedViews, 0, newViewsCollection, Views.Length, parsedViews.Length); EMailAttachment[] newAttachmentsCollection = new EMailAttachment[Attachments.Length + parsedAttachments.Length]; Array.Copy(Attachments, newAttachmentsCollection, Attachments.Length); Array.Copy(parsedAttachments, 0, newAttachmentsCollection, Attachments.Length, parsedAttachments.Length); Views = newViewsCollection; Attachments = newAttachmentsCollection; return; }
private void ParseAlternateViewContent(ref EMailBodyAlternateView AlternateView, string[] ViewContentLines) { AlternateView.ContentStream = ConcatenateStringArray(ViewContentLines); }
private void ParseAlternateViewHeaders(ref EMailBodyAlternateView AlternateView, string[] ViewHeaderLines) { Regex validHeaderLineRegEx = new Regex(VALIDHEADERPATTERN); Match validHeaderLineMatch; ArrayList linkedRes = new ArrayList(); string[] fixedMessageHeaderLines = SplitMultiValueLines(ViewHeaderLines); bool continuesFromPrevious = false; string lastHeaderProcessed = string.Empty; string headerName = string.Empty; string headerValue = string.Empty; foreach (string line in fixedMessageHeaderLines) { continuesFromPrevious = (line.StartsWith("\t") || line.StartsWith(" ")); validHeaderLineMatch = validHeaderLineRegEx.Match(line); validHeaderLineMatch = validHeaderLineRegEx.Match(line); if (validHeaderLineMatch.Groups.Count < 3) { continue; } if (continuesFromPrevious && CheckValidDateString(line)) { headerName = lastHeaderProcessed; headerValue = line.Trim(); } else { headerName = validHeaderLineMatch.Groups[1].Value.Trim().ToLower(); headerValue = validHeaderLineMatch.Groups[2].Value.Trim(); } switch (headerName) { case "content-type": AlternateView.ContentType = GetCleanValue(headerValue); break; case "content-transfer-encoding": AlternateView.ContentTransferEncoding = GetCleanValue(headerValue); break; case "charset": AlternateView.Charset = GetCleanValue(headerValue); break; case "base-uri": AlternateView.BaseUri = GetCleanValue(headerValue); break; case "id": AlternateView.Id = GetCleanValue(headerValue); break; case "linked-resources": linkedRes.Add(GetCleanValue(headerValue)); break; } } if (linkedRes.Count > 0) { AlternateView.LinkedResources = new string[linkedRes.Count]; linkedRes.CopyTo(AlternateView.LinkedResources); } }