Copyright © 2024 IMIBO. Privacy Statement
Extended MAPI in DELPHI
Experimental # 6
What is the Best Body?
In the beginning, when the e-mail revolution was conceived – it was easy – the body of the messages was only as „simple“ text.
Over time, a consumer wants to see the important things in messages in different ways, to have pictures, embedded objects …
And of course, IT companies are responding to their wishes.
But this led to a situation in which messages contain „Plain“, „Rich“, „HTML“ version of the body.
And this entire – for compatibility.
Currently, many developers ask:
„How to get the best format for the message body?“
PR_BODY, PR_RTF_COMPRESSED, PR_HTML?
What is the „Best“?
This example application is trying to answer all these questions.
More over:
– There is not any third-party components for displaying HTML messages.
– Pure virtual list – no need to downloads the entire list of received messages, it is not necessary to use auxiliary structures – let’s MAPI to work for us – the fastest and most elegant way for the visualization of large lists – so that your Inbox may contain as few hundred or thousands of messages.
– Quickly and elegantly sorting by Subject, Sender, Date, Size, etc …
procedure TfrmMain.RenderBody(ItemId: Integer); var Rows: PSRowSet; PropValue: PSPropValue; MAPIMessage: IMessage; hr: HRESULT; ObjType: ULONG; MsgBody: String; BodyType: TMsgBodyType; CodePage: Integer; OurCursor: TCursor; begin Rows := GetRow(ListView.Selected.Index, ListView.Items.Count); if not Assigned(Rows) then exit; PropValue := PpropFindProp(Rows.aRow[0].lpProps, Rows.aRow[0].cValues, PR_ENTRYID); try if not Assigned(PropValue) or not Assigned(FInboxFolder) then exit; hr := FInboxFolder.OpenEntry(PropValue.Value.bin.cb, PENTRYID(PropValue.Value.bin.lpb), @IID_IMessage, MAPI_BEST_ACCESS, ObjType, IUnknown(MAPIMessage)); if failed(hr) then raise EMapiError.CreateMAPI(FInboxFolder, hr); MsgBody := GetBestBody(MAPIMessage, BodyType); case BodyType of aPlain: lbBB.Caption := 'Best Body Format: Plain Text'; aRTF: lbBB.Caption := 'Best Body Format: RTF'; aHTML: lbBB.Caption := 'Best Body Format: HTML'; aRtfToHml: lbBB.Caption := 'Best Body Format: HTML From RTF'; else // aUndefined lbBB.Caption := 'Best Body Format: Unknown'; end; if BodyType in [aHTML .. aRtfToHml] then begin CodePage := 0; OurCursor := Cursor; Cursor := crHourGlass; try if FPropExists(MAPIMessage, PR_INTERNET_CPID) then CodePage := CheckCP(GetPropLong(MAPIMessage, PR_INTERNET_CPID)); PageControl.ActivePage := TabSheetIE; if AnsiContainsText(MsgBody, 'src="cid:') or AnsiContainsText(MsgBody, 'src=cid:') or AnsiContainsText(MsgBody, 'src=''cid:') then CreateMimeMessage(MAPIMessage, MsgBody, WebBrowser, CodePage) else begin LoadDocFromString(WebBrowser, MsgBody, CodePage); end; finally Cursor := OurCursor; end; end else begin PageControl.ActivePage := TabSheetRichEdit; RichEdit.PlainText := False; RichEdit.Lines.LoadFromStream(TStringStream.Create(MsgBody)); end; finally if Assigned(Rows) then FreePRows(Rows); MAPIMessage := nil; end; Self.ActiveControl := ListView; if Assigned(ListView.Selected) then SelectedItemIndex := ListView.Selected.Index; end;