// ----------------------- AddNewPart ------------------------------- public MimeMessagePart AddNewPart(MimePartCode InPartCode) { MimeMessagePart part = null; if (InPartCode == MimePartCode.Top) { part = new MimeTopPart( ); } else { part = new MimeMessagePart( ); } part.PartCode = InPartCode; base.Add(part); return(part); }
// -------------------------- MessagePartSplitter ----------------------- // input is an array holding the unfolded lines of the message. // Build and return a list of MimeMessagePart objects. Each part object holds the // lines of a part of the message. // ( a part is either the header part or the boundary string delimited content parts. public static InMail.MimeMessagePartList MessagePartSplitter(string[] InLines) { InMail.MimeMessagePartList parts = new InMail.MimeMessagePartList( ); int curPartBx = -1; int curPartCx = 0; MimePartCode curPartCode = MimePartCode.Top; bool currentlyBetweenParts = false; bool partIsJustStarting = true; StringStack bdryStack = new StringStack( ); for (int Ix = 0; Ix < InLines.Length; ++Ix) { string line = InLines[Ix]; MimeLineCode lc = MimeParser.CalcLineCode(line, bdryStack.GetTop( )); switch (lc) { case MimeLineCode.Property: { StringPair propPair = MimeParser.SplitPropertyLine(line); // the content-type property. Could have an boundary="xxxxx" element. // Boundary strings in a mime document have scope. That is, within one // boundary ( section ) of the document, there can be sub boundaries // ( sub sections ) if (propPair.a.ToLower( ) == "content-type") { PartProperty.ContentType ct = MimeParser.ParseContentType(propPair.b); if ((ct.Boundary != null) && (ct.Boundary != "")) { bdryStack.Push(ct.Boundary); } } break; } // part boundary line. load the lines of the current part and reset the line // counter of this new part. case MimeLineCode.PartBdry: if (curPartBx != -1) { parts.AddNewPart(curPartCode) .LoadLines(InLines, curPartBx, curPartCx); } curPartCx = 0; curPartBx = -1; curPartCode = MimePartCode.Content; currentlyBetweenParts = false; partIsJustStarting = true; break; case MimeLineCode.PartEndBdry: if (curPartBx != -1) { parts.AddNewPart(curPartCode) .LoadLines(InLines, curPartBx, curPartCx); } curPartCx = 0; curPartBx = -1; if (bdryStack.IsNotEmpty) { bdryStack.Pop( ); } currentlyBetweenParts = true; break; default: break; } // add to range of lines in the current part. if ((currentlyBetweenParts == false) && (lc != MimeLineCode.PartBdry)) { if ((partIsJustStarting == true) && (line == "")) { } else { ++curPartCx; if (curPartBx == -1) { curPartBx = Ix; } } partIsJustStarting = false; } } // load the lines of the final in progress part. if (curPartBx != -1) { parts.AddNewPart(curPartCode) .LoadLines(InLines, curPartBx, curPartCx); } return(parts); }
// ------------------------- SetPartCode ----------------------------- public MimeMessagePart SetPartCode(MimePartCode InPartCode) { mPartCode = InPartCode; return(this); }
public PartInProgress(MimePartCode InCode) { PartCode = InCode; }