IMAPFetchParser::BodyPart IMAPFetchParser::_ParseBODY(const String &sString) { BodyPart oPart; // Set the description. String sNewName = sString; sNewName.ReplaceNoCase(_T("BODY.PEEK["), _T("BODY[")); oPart.SetDescription(sNewName); // Locate the start of the peek-part. long lBodyStart = sNewName.Find(_T("[")) + 1; // Locate the end of the part. long lBodyEnd = sNewName.Find(_T("]"), lBodyStart) - 1; if (sNewName.Find(_T("<"), lBodyEnd) == lBodyEnd +2) { int iStart = lBodyEnd+3; int iEnd = sNewName.Find(_T(">"), iStart); String sPartial = sNewName.Mid(iStart, iEnd - iStart); int iDotPos = sPartial.Find(_T(".")); oPart.m_iOctetStart = _ttoi(sPartial.Mid(0, iDotPos)); oPart.m_iOctetCount = _ttoi(sPartial.Mid(iDotPos+1)); // Remove the octets part from the description. String sBefore = sNewName.Mid(0, iStart - 1); String sAfter = sNewName.Mid(iEnd + 1); String sDescWithoutOctets = sBefore + sAfter; oPart.SetDescription(sDescWithoutOctets); } // Extract the body part. long lBodyLen = lBodyEnd - lBodyStart +1 ; String sBody = sNewName.Mid(lBodyStart, lBodyLen); if (sBody.IsEmpty()) { oPart.SetShowBodyFull(true); m_bSetSeen = true; } else { // Determine what to look at. long lTemp = 0; // Should we show all header fields except for... lTemp = sBody.FindNoCase(_T("HEADER.FIELDS.NOT")); if (lTemp >= 0) { int lStart = sBody.Find(_T("("), lTemp) + 1; int lEnd = sBody.Find(_T(")"), lStart) ; int lLength = lEnd - lStart; String sFields = sBody.Mid(lStart, lLength); oPart.GetHeaderFieldsNOT() = StringParser::SplitString(sFields, " "); oPart.SetShowBodyHeaderFieldsNOT(true); // Strip away the header fields part from the Body. // If we don't do this, we will parse the same string // as header.fields below. String sBefore = sBody.Mid(0, lTemp); String sAfter = sBody.Mid(lEnd + 2); sBody = sBefore + sAfter; } // Should we show header fields? lTemp = sBody.FindNoCase(_T("HEADER.FIELDS")); if (lTemp >= 0) { int lStart = sBody.Find(_T("("), lTemp) + 1; int lEnd = sBody.Find(_T(")"), lStart) ; int lLength = lEnd - lStart; String sFields = sBody.Mid(lStart, lLength); oPart.GetHeaderFields() = StringParser::SplitString(sFields, " "); oPart.SetShowBodyHeaderFields(true); // Strip away the header fields part from the Body. String sBefore = sBody.Mid(0, lTemp); String sAfter = sBody.Mid(lEnd + 2); sBody = sBefore + sAfter; } lTemp = sBody.FindNoCase(_T("HEADER")); if (lTemp >= 0) { oPart.SetShowBodyHeader(true); String sBefore = sBody.Mid(0, lTemp); String sAfter = sBody.Mid(lTemp + 7); sBody = sBefore + sAfter; } lTemp = sBody.FindNoCase(_T("MIME")); if (lTemp >= 0) { oPart.SetShowBodyHeader(true); String sBefore = sBody.Mid(0, lTemp); String sAfter = sBody.Mid(lTemp + 7); sBody = sBefore + sAfter; } lTemp = sBody.FindNoCase(_T("TEXT")); if (lTemp >= 0) { oPart.SetShowBodyText(true); String sBefore = sBody.Mid(0, lTemp); String sAfter = sBody.Mid(lTemp + 5); sBody = sBefore + sAfter; m_bSetSeen = true; } if (!oPart.GetShowBodyText() && !oPart.GetShowBodyHeader() && !oPart.GetShowBodyHeaderFields() && !oPart.GetShowBodyHeaderFieldsNOT()) { oPart.SetShowBodyText(true); m_bSetSeen = true; } sBody = sBody.TrimLeft(_T(".")); sBody = sBody.TrimRight(_T(".")); oPart.SetName(sBody); } return oPart; }