Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TIdIMAP4.SendCmd
#1
Dear All; here's an easy one:
trying to SearchMailBox like this:
Code:
TIdIMAP4SearchRec sr;
::ZeroMemory(&sr, sizeof(sr));
sr.Date = TDateTime::CurrentDate()-2;
sr.SearchKey = skSince;
if(IdIMAP4->SearchMailBox(&sr, 0)){
  //...
}
and this is what the log.file shows:
Code:
...
C4 OK [READ-ONLY] Inbox selected. (Success)<EOL>
C5 SEARCH SINCE  8-JUL-2018<EOL>
C5 BAD Could not parse command<EOL>
...
I bet I've seen similar topics back when Borland news groups were alive; so what's wrong with my code?
Should I use IdIMAP4->SendCmd() directly? I would if I knew its proper syntax. Thanks in advance.
Reply
#2
(07-11-2018, 04:22 AM)Boba TC Wrote:
Code:
C5 SEARCH SINCE  8-JUL-2018<EOL>
C5 BAD Could not parse command<EOL>

The date string has a space char instead of a '0' char in front of the '8', it should be like this instead:

Code:
C5 SEARCH SINCE 08-JUL-2018

You must be using a VERY old version of Indy, because that problem was fixed a LONG time ago (back around 2010). Please upgrade to a modern version of Indy.

If that is not an option for you, then yes, you will have to send the command manually (note that some of the needed functionality is not public), for example:

Code:
class TIdIMAP4Access : public TIdIMAP4
{
public:
    inline void CheckIfState(TIdIMAP4ConnectionState AState) { TIdIMAP4::CheckConnectionState(AState); }
    inline void ParseSearch(TIdMailBox *AMailBox, TStrings *ADetails) { TIdIMAP4::ParseSearchResult(AMailBox, ADetails); }
};

...

TDateTime dtDate = TDateTime::CurrentDate() - 2;

Word wYear, wMonth, wDay;
dtDate.DecodeDate(&wYear, &wMonth, &wDay);

String Cmd = _D("SEARCH SINCE ") + Format(_D("%.2d-%s-%.4d"), ARRAYOFCONST(( wDay, monthnames[wMonth-1].UpperCase(), wYear )) );

((TIdIMAP4Access*)IdIMAP4)->CheckIfState(csSelected);
if (IdIMAP4->SendCmd(Cmd, OPENARRAY(String, (_D("SEARCH"), _D("UID")))) == IMAP_OK)
{
    ((TIdIMAP4Access*)IdIMAP4)->ParseSearch(IdIMAP4->MailBox, IdIMAP4->LastCmdResult->Text);
    // use IdIMAP4->MailBox->SearchResults as needed...
}

Reply
#3
Thanks Remy. Yes, I believe this project is maintained by the very last compiler from Borland. Sorry for being late with reply. Boba.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)