Joshi.Utils.Imap.Imap.GetBodyStructure C# (CSharp) Method

GetBodyStructure() private method

Get the Body structure of the message. If message is single part then first part is 1 If message is multipart then first part is 0
private GetBodyStructure ( string sMessageUID, XmlTextWriter oXmlWriter, bool bFetchBody ) : void
sMessageUID string Message UID
oXmlWriter System.Xml.XmlTextWriter
bFetchBody bool
return void
        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;
            }
        }