indy get unreademails lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- eldonfsr · 2023-11-10 14:46 Hello i tried to get unreademails from idmap4 , i can get the list of emails but when i tried to get message don't let me get it, i don't know what i doing wrong some body can help me please..   SetLength(SearchInfo, 1);   SearchInfo[0].SearchKey := skUnseen;   IDIMAP.UIDSearchMailBox(SearchInfo);   lParts := TIdImapMessageParts.Create(nil);  this containg list of emails  High(IDIMAP.MailBox.SearchResult) how i can get  message from here...? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TFormMain.getunreademails(Sender: TObject);Var  lj,i,id:Integer;    CurrUId:String;    msg: TIdMessage;    lParts:TIdImapMessageParts;    SearchInfo: array of TIdIMAP4SearchRec;beginprocedure TFormMain.getunreademails(Sender: TObject);Var  lj,i,id:Integer;    CurrUId:String;    msg: TIdMessage;    lParts:TIdImapMessageParts;    SearchInfo: array of TIdIMAP4SearchRec;begin  SetLength(SearchInfo, 1);  SearchInfo[0].SearchKey := skUnseen;  IDIMAP.UIDSearchMailBox(SearchInfo);  lParts := TIdImapMessageParts.Create(nil);       for i := 0 to High(IDIMAP.MailBox.SearchResult) do begin        MSG := TIdMessage.Create(nil);        Id:=IDIMAP.MailBox.SearchResult[i]; //     try              if(  IDIMAP.GetUID( id , currUID )) then begin; // never get uid of message i need get msg to see what contain..              IDIMAP.UIDRetrieve( currUID, msg );                IDImap.UIDRetrieveStructure(Inttostr(IDIMAP.MailBox.SearchResult[i]), lParts);                for lj := 0 to msg.MessageParts.Count - 1  do begin                   if msg.MessageParts.Items[lj] is TIdAttachment then  begin                       if( lParts[lJ].FileName <>'') then begin                          IDImap.UidRetrievePartToFile(Inttostr(IDIMAP.MailBox.SearchResult[i]), lParts[lJ].ImapPartNumber, i , Path+'emails\attach\'+lParts[lJ].FileName, lParts[lJ].ContentTransferEncoding);                       end;                  end;                end; //               fileName_MailSource := TmpFolder  + Inttostr(IDIMAP.MailBox.SearchResult[i])+ '.eml';                BDEmails.Append;                BDEmails.FieldByName('Account').AsString  := BDAcct.FieldByName('emailAcc').AsString;                BDEmails.FieldByName('ID').AsInteger      := IDIMAP.MailBox.SearchResult[i];                BDEmails.FieldByName('UID').AsString      := Inttostr(IDIMAP.MailBox.SearchResult[i]) ;                BDEmails.FieldByName('Date').AsDateTime   := msg.Date;                BDEmails.FieldByName('subject').AsString  := msg.Subject;              BDEmails.FieldByName('fromaddr').AsString := msg.From.Address;              BDEmails.post;            end;//        finally          MSG.Free;//        end;     end;     BDEmails.First;  end;       for i := 0 to High(IDIMAP.MailBox.SearchResult) do begin        MSG := TIdMessage.Create(nil);        Id:=IDIMAP.MailBox.SearchResult[i]; //     try //         if IDIMAP.Retrieve(IDIMAP.MailBox.SearchResult[i], MSG) then begin              if(  IDIMAP.GetUID( id , currUID )) then begin;                IDIMAP.UIDRetrieve( currUID, msg );              IDImap.UIDRetrieveStructure(Inttostr(IDIMAP.MailBox.SearchResult[i]), lParts);                for lj := 0 to msg.MessageParts.Count - 1  do begin                   if msg.MessageParts.Items[lj] is TIdAttachment then  begin                       if( lParts[lJ].FileName <>'') then begin                          IDImap.UidRetrievePartToFile(Inttostr(IDIMAP.MailBox.SearchResult[i]), lParts[lJ].ImapPartNumber, i , Path+'emails\attach\'+lParts[lJ].FileName, lParts[lJ].ContentTransferEncoding);                       end;                  end;                end;                BDEmails.Append;              BDEmails.FieldByName('Account').AsString  := BDAcct.FieldByName('emailAcc').AsString;                BDEmails.FieldByName('ID').AsInteger      := IDIMAP.MailBox.SearchResult[i];                BDEmails.FieldByName('UID').AsString      := Inttostr(IDIMAP.MailBox.SearchResult[i]) ;                BDEmails.FieldByName('Date').AsDateTime   := msg.Date;                BDEmails.FieldByName('subject').AsString  := msg.Subject;              BDEmails.FieldByName('fromaddr').AsString := msg.From.Address;              BDEmails.post;            end;//        finally          MSG.Free;//        end;     end;     BDEmails.First;  end; ---------------------------------------------------------------------- Remy Lebeau · 2023-11-10 17:58 Quote from: eldonfsr on November 10, 2023, 03:46:04 pmHello i tried to get unreademails from idmap4 , i can get the list of emails but when i tried to get message don't let me get it, i don't know what i doing wrong some body can help me please.. You are searching for unseen UIDs, but then you are calling GetUID() to retrieve a UID from a UID that you already have.  GetUID() takes a message number as input, not a UID.  So, simply remove the call to GetUID(), you don't need it. The UIDRetrieve...() methods take in a UID as a string, but UIDSearchMailBox() returns the found UIDs as UInt32s instead.  Just convert them back to strings using IntToStr().