Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Feb : Re: Viewing text/attachments in a newsreader using Indy 10 TIdNNTP component

www.cryer.info
Managed Newsgroup Archive

Re: Viewing text/attachments in a newsreader using Indy 10 TIdNNTP component

Subject:Re: Viewing text/attachments in a newsreader using Indy 10 TIdNNTP component
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Tue, 20 Feb 2007 11:26:48

"John Mitson" <jrmit@hawaii.rr.com> wrote in message
news:45d9fafd$1@newsgroups.borland.com...

> However, messages without attachments do not display text.

That is because you are not looking in the right place for the text of
those messages.  When no attachments are present, the text is stored
in the TIdMessage.Body property instead and the MessageParts
collection is empty.

> I would have thought the "else" portion of the procedure would
> provide me with an output for text only messages.

No, because the MessageParts.Count will be 0, so your code is not even
reaching that far in the first place.

> However, if I use the code commented out at the bottom I
> can display text only messages.

As you should be, because that code is using the TIdMessage.Body
property when no attachments are present.

Try this code:

    procedure TForm1.ObtainArticle(Sender: TObject);
    var
        partIdx: Integer;
        part: TIdMessagePart;
        li: TListItem;
    begin
        li := ListView2.Selected;
        if li <> nil then
        begin
            ListView3.Clear;
            Memo1.Clear;
            IdMessage1.Clear;
            IdNNTP1.GetArticle(Integer(li.Data), IdMessage1);
            if IdMessage1.MessageParts.Count > 0 then
            begin
                for partIdx := 0 to IdMessage1.MessageParts.Count - 1
do
                begin
                    part := IdMessage1.MessageParts.Items[partIdx];
                    if part is TIdAttachment then
                    begin
                        li := ListView3.Items.Add;
                        li.ImageIndex := 8;
                        li.Caption :=
ExtractFileName(TIdAttachment(part).FileName);

TIdAttachment(part).SaveToFile(ExtractFilePath(GetModuleName(hInstance
)) + li.Caption);
                        li.SubItems.Add(part.ContentType);
                    end
                    else if part is TIdText then
                        Memo1.Lines.Assign(TIdText(part).Body);
                end;
            end else
                Memo1.Lines.Assign(IdMessage1.Body);
        end;
    end;


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive