Delphi ActiveX
Delphi ActiveX
Set an IMAP Flag Using an Email Object
See more IMAP Examples
Demonstrates the Chilkat Imap.SetMailFlag method, which sets or clears a flag on the server for the message represented by an Email object. The first argument is the Email, the second is the flag name, and the third is the value (1 to set, 0 to clear). This example flags each fetched message as Flagged on the server.
Background:
SetMailFlag is convenient when you already hold an Email from a fetch: Chilkat uses the UID it recorded on that object to target the right message on the server, so you do not have to track IDs yourself. It updates both the server and the local Email object, keeping the two in sync. Under the hood this is the same STORE operation as SetFlag — just addressed by object rather than by raw ID.Chilkat Delphi ActiveX Downloads
var
success: Integer;
imap: TChilkatImap;
msgSet: TMessageSet;
bundle: TChilkatEmailBundle;
email: TChilkatEmail;
i: Integer;
begin
success := 0;
// Demonstrates the Imap.SetMailFlag method, which sets or clears a flag on the server for the
// message represented by an Email object. The 1st argument is the Email, the 2nd is the flag
// name, and the 3rd is the value (1 to set, 0 to clear).
imap := TChilkatImap.Create(Self);
imap.Ssl := 1;
imap.Port := 993;
success := imap.Connect('imap.example.com');
if (success = 0) then
begin
Memo1.Lines.Add(imap.LastErrorText);
Exit;
end;
success := imap.Login('user@example.com','myPassword');
if (success = 0) then
begin
Memo1.Lines.Add(imap.LastErrorText);
Exit;
end;
success := imap.SelectMailbox('Inbox');
if (success = 0) then
begin
Memo1.Lines.Add(imap.LastErrorText);
Exit;
end;
msgSet := TMessageSet.Create(Self);
success := imap.QueryMbx('UNSEEN',1,msgSet.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(imap.LastErrorText);
Exit;
end;
bundle := TChilkatEmailBundle.Create(Self);
success := imap.FetchMsgSet(1,msgSet.ControlInterface,bundle.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(imap.LastErrorText);
Exit;
end;
email := TChilkatEmail.Create(Self);
for i := 0 to bundle.MessageCount - 1 do
begin
success := bundle.EmailAt(i,email.ControlInterface);
// Mark this message as Flagged on the server. A value of 1 sets the flag; 0 would clear it.
success := imap.SetMailFlag(email.ControlInterface,'Flagged',1);
if (success = 0) then
begin
Memo1.Lines.Add(imap.LastErrorText);
Exit;
end;
end;
Memo1.Lines.Add('Flagged ' + IntToStr(bundle.MessageCount) + ' messages.');
success := imap.Disconnect();
if (success = 0) then
begin
Memo1.Lines.Add(imap.LastErrorText);
Exit;
end;