Lua
Lua
Get an IMAP Flag from a Downloaded Email
See more IMAP Examples
Demonstrates the Chilkat Imap.GetMailFlag method, which returns the state of a named flag for an Email object that was downloaded from the server. The first argument is the Email and the second is the flag name. The return value is 1 if the flag is set, 0 if not, and -1 if the flag is not present. This example iterates a bundle and reports which messages are read vs unread.
Background: When Chilkat downloads a message it records the flags the server reported at fetch time, so you can inspect them locally with
GetMailFlag without another round trip. This is the client-side view: it reflects the state as of the download, not necessarily the live state on the server, which other clients could have changed. Use RefetchMailFlags to update an Email object's flags to the current server values.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- Demonstrates the Imap.GetMailFlag method, which returns the state of a named flag for an
-- Email object that was downloaded from the server. The 1st argument is the Email and the
-- 2nd is the flag name. The return value is 1 if the flag is set, 0 if not, and -1 if the
-- flag is not present.
local imap = chilkat.Imap.new()
imap.ssl = true
imap.port = 993
local success = imap:connect("imap.example.com")
if not success then
print(imap.last_error_text)
return
end
success = imap:login("user@example.com", "myPassword")
if not success then
print(imap.last_error_text)
return
end
success = imap:select_mailbox("Inbox")
if not success then
print(imap.last_error_text)
return
end
local msgSet = chilkat.MessageSet.new()
success = imap:query_mbx("ALL", true, msgSet)
if not success then
print(imap.last_error_text)
return
end
local bundle = chilkat.EmailBundle.new()
success = imap:fetch_msg_set(true, msgSet, bundle)
if not success then
print(imap.last_error_text)
return
end
local email = chilkat.Email.new()
for i = 0, bundle.message_count - 1 do
success = bundle:email_at(i, email)
-- Check whether each message has been read (the "Seen" flag).
local seen = imap:get_mail_flag(email, "Seen")
if seen == 1 then
print(email.subject .. " -- already read")
end
ERROR: "}" expected
end