void GetBodyStructure(string sMessageUID, XmlTextWriter oXmlWriter, bool bFetchBody)
{
ImapResponseEnum eImapResponse = ImapResponseEnum.IMAP_SUCCESS_RESPONSE;
string sCommandSuffix = sMessageUID + " " + "BODYSTRUCTURE";
string sCommandString = IMAP_UIDFETCH_COMMAND + " " + sCommandSuffix + IMAP_COMMAND_EOL ;
try
{
//-----------------------
// SEND SEARCH REQUEST
ArrayList asResultArray = new ArrayList();
eImapResponse = SendAndReceive(sCommandString, ref asResultArray);
if (eImapResponse == ImapResponseEnum.IMAP_SUCCESS_RESPONSE)
{
string sLastLine = IMAP_SERVER_RESPONSE_OK;
string sBodyStruct = "";
bool bResult = false;
int nStart = -1;
foreach (string sLine in asResultArray)
{
nStart = sLine.IndexOf(IMAP_BODYSTRUCTURE_COMMAND);
if (sLine.StartsWith(IMAP_UNTAGGED_RESPONSE_PREFIX) &&
(nStart != -1))
{
sBodyStruct = sLine;
}
else if (sLine.StartsWith(sLastLine))
{
bResult = true;
break;
}
}
if (!bResult)
{
throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_FETCHBODYSTRUCT);
}
else if (sBodyStruct.Length == 0)
{
Log(LogTypeEnum.INFO, "Bodystructure is empty");
return;
}
nStart = sBodyStruct.IndexOf(IMAP_BODYSTRUCTURE_COMMAND);
sBodyStruct = sBodyStruct.Substring(nStart + IMAP_BODYSTRUCTURE_COMMAND.Length);
int nEnd = sBodyStruct.LastIndexOf(")");
if (nEnd == -1)
{
throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_FETCHBODYSTRUCT);
}
sBodyStruct = sBodyStruct.Substring(0, nEnd);
string sPartPrefix = "";
if (!ParseBodyStructure(sMessageUID, ref sBodyStruct, oXmlWriter, sPartPrefix, bFetchBody))
throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_FETCHBODYSTRUCT);
}
else
{
throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_FETCHMSG, sCommandSuffix );
}
}
catch (ImapException e)
{
LogOut();
throw e;
}
}