public void SearchMessage(string [] asSearchData, bool bExactMatch, ArrayList asSearchResult)
{
if (!m_bIsLoggedIn)
{
try
{
Restore(true);
}
catch (ImapException e)
{
if (e.Type != ImapException.ImapErrorEnum.IMAP_ERR_INSUFFICIENT_DATA)
throw e;
throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_NOTCONNECTED);
}
}
if (!m_bIsFolderSelected && !m_bIsFolderExamined)
{
throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_NOTSELECTED);
}
int nCount = asSearchData.Length;
if (nCount == 0)
{
throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_INVALIDPARAM);
}
//--------------------------
// PREPARE SEARCH KEY/VALUE
string sCommandSuffix = "";
foreach (string sLine in asSearchData)
{
if (sLine.Length == 0)
{
throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_INVALIDPARAM);;
}
// convert to lower case once for all
sLine.ToLower();
if (sCommandSuffix.Length > 0)
sCommandSuffix += " ";
sCommandSuffix += sLine;
}
ImapResponseEnum eImapResponse = ImapResponseEnum.IMAP_SUCCESS_RESPONSE;
string sCommandString = IMAP_SEARCH_COMMAND + " " + sCommandSuffix;
sCommandString += IMAP_COMMAND_EOL;
ArrayList asResultArray = new ArrayList();
try
{
//-----------------------
// SEND SEARCH REQUEST
eImapResponse = SendAndReceive(sCommandString, ref asResultArray);
if (eImapResponse == ImapResponseEnum.IMAP_SUCCESS_RESPONSE)
{
//-------------------------
// PARSE RESPONSE
nCount = asResultArray.Count;
bool bResult = false;
string sPrefix = IMAP_UNTAGGED_RESPONSE_PREFIX + " ";
sPrefix += IMAP_SEARCH_RESPONSE;
foreach (string sLine in asResultArray)
{
int nPos = sLine.IndexOf(sPrefix );
if (nPos != -1)
{
nPos += sPrefix.Length ;
string sSuffix = sLine.Substring(nPos);
sSuffix.Trim();
string [] asSearchRes = sSuffix.Split(' ');
foreach (string sResultLine in asSearchRes)
{
asSearchResult.Add(sResultLine);
}
bResult = true;
break;
}
}
if (!bResult)
{
throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_SEARCH, sCommandSuffix);
}
}
else
throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_SEARCH, asResultArray[0].ToString());
}
catch (ImapException e)
{
LogOut();
throw e;
}
}