Re: Question TidPOP3Server component

Giganews Newsgroups
Subject: Re: Question TidPOP3Server component
Posted by:  Remy Lebeau (TeamB) (gambit47.no.spam@no.spam.yahoo.com)
Date: Thu, 27 Nov 2003

"Marcello Scala" <msca…@email.it> wrote in message
news:FCECE3021A88E240msca…@email.it...

> How can i directly send to the Client,  a TIdMessage Class?
> Or what is the best way to send a TidMessage Class?

TIdPOP3Server has no concept of TIdMessage at all, nor should it.  Message
storage is server-specific.  You could choose to use a TIdMessage, but then
you could use a file or a database instead.  It is your responsibility to
store the message data when you receive it, and then send it to the client
when requested.  How you choose to store it in between is up to you.  In the
OnCommandRETR and OnCommandTOP event handlers, you can choose to use a
TIdMessage to load up the stored message if you choose, but you will have to
encode it to raw data first before you can send it to the client.  Either
way, your best bet is probably to load the stored message data into a
TStrings and then use the TIdTCPConnection::WriteRFCStrings() method to send
it to the client, ie:

    void __fastcall TForm1::IdPOP3Server1CommandRETR(TIdPeerThread *AThread,
int AMessageNum)
    {
        if( AMessageNum exists )
        {
            if( AMessageNum is not deleted )
            {
                TStringList *FMsg = new TStringList;
                try
                {
                    // load the entire requested message into the
TStringList

                    AThread->Connection->WriteLn('+OK');
                    AThread->Connection->WriteRFCStrings(FMsg);
                }
                __finally {
                    delete FMsg;
                }
            }
            else
                AThread->Connection->WriteLn('-ERR message is deleted');
        }
        else
            AThread->Connection->WriteLn('-ERR no such message');
    }

    void __fastcall TForm1::IdPOP3Server1CommandTOP(TIdPeerThread *AThread,
int AMessageNum, int ANumLines)
    {
        if( AMessageNum exists )
        {
            if( AMessageNum is not deleted )
            {
                TStringList *FMsg = new TStringList;
                try
                {
                    // load the requested message into the TStringList
                    // if ANumLines is 0, load just the headers
                    // otherwise load the headers followed by a blank line
                    // followed by the requested number if lines from the
                    //message content

                    AThread->Connection->WriteLn('+OK');
                    AThread->Connection->WriteRFCStrings(FMsg);
                }
                __finally {
                    delete FMsg;
                }
            }
            else
                AThread->Connection->WriteLn('-ERR message is deleted');
        }
        else
            AThread->Connection->WriteLn('-ERR no such message');
    }

Gambit

Replies

None

In response to

Question TidPOP3Server component posted by Marcello Scala on Thu, 27 Nov 2003