Delphi DLL
Delphi DLL
Set or Clear a Flag on a MessageSet
See more IMAP Examples
Demonstrates the Chilkat Imap.SetFlags method, which sets or clears a flag on every message in a MessageSet. The first argument is the MessageSet, the second is the flag name, and the third is the value (1 to set the flag, 0 to clear it). This example marks all unseen messages as Seen.
Background: IMAP flags are per-message keywords the server stores and shares across all clients. The standard system flags are
Seen, Answered, Flagged, Deleted, Draft, and Recent. Give the flag name without the leading backslash here (use "Seen", not "\Seen"). SetFlags applies the change to the whole set in one round trip, which is how a client implements "mark all as read."Chilkat Delphi DLL Downloads
var
success: Boolean;
imap: HCkImap;
msgSet: HCkMessageSet;
begin
success := False;
// Demonstrates the Imap.SetFlags method, which sets or clears a flag on every message in a
// MessageSet. The 1st argument is the MessageSet, the 2nd is the flag name, and the 3rd is
// the value (1 to set the flag, 0 to clear it).
imap := CkImap_Create();
CkImap_putSsl(imap,True);
CkImap_putPort(imap,993);
success := CkImap_Connect(imap,'imap.example.com');
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
success := CkImap_Login(imap,'user@example.com','myPassword');
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
success := CkImap_SelectMailbox(imap,'Inbox');
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
// Find the messages to flag (here, all unseen messages, by UID).
msgSet := CkMessageSet_Create();
success := CkImap_QueryMbx(imap,'UNSEEN',True,msgSet);
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
// Mark all of them as seen. A value of 1 sets the flag; 0 would clear it.
success := CkImap_SetFlags(imap,msgSet,'Seen',1);
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
Memo1.Lines.Add('Marked ' + IntToStr(CkMessageSet_getCount(msgSet)) + ' messages as Seen.');
success := CkImap_Disconnect(imap);
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
CkImap_Dispose(imap);
CkMessageSet_Dispose(msgSet);