Tcl
Tcl
Append MIME with Initial IMAP Flags
See more IMAP Examples
Demonstrates the Chilkat Imap.AppendMimeWithFlags method, which uploads a MIME message and sets its initial system flags. The first argument is the mailbox and the second is the MIME text. The third through sixth arguments control \Seen, \Flagged, \Answered, and \Draft respectively — pass true to set a flag. This example uploads a message that is already marked read.
Background: When importing or archiving mail you frequently want the uploaded message to arrive in a particular state — already read, pre-flagged, or marked as a draft. Setting the flags at append time is a single operation, avoiding a second
STORE round trip. These explicit arguments take precedence over the AppendSeen property.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Demonstrates the Imap.AppendMimeWithFlags method, which uploads a MIME message and sets its
# initial system flags. The 1st argument is the mailbox, the 2nd is the MIME text, and the
# 3rd through 6th arguments set the \Seen, \Flagged, \Answered, and \Draft flags.
set imap [new_CkImap]
CkImap_put_Ssl $imap 1
CkImap_put_Port $imap 993
set success [CkImap_Connect $imap "imap.example.com"]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
set success [CkImap_Login $imap "user@example.com" "myPassword"]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
# Build the email to be uploaded.
set email [new_CkEmail]
CkEmail_put_Subject $email "Meeting agenda"
CkEmail_put_From $email "Alice <alice@example.com>"
set success [CkEmail_AddTo $email "Bob" "bob@example.com"]
CkEmail_put_Body $email "Let's meet at 10am to review the agenda."
set mimeText [CkEmail_getMime $email]
if {[CkEmail_get_LastMethodSuccess $email] == 0} then {
puts [CkEmail_lastErrorText $email]
delete_CkImap $imap
delete_CkEmail $email
exit
}
# Choose the initial flags. Named variables make each argument's meaning clear at the call.
set seen 1
set flagged 0
set answered 0
set draft 0
# Upload to the Inbox already marked as read (\Seen), with the other flags unset.
set success [CkImap_AppendMimeWithFlags $imap "Inbox" $mimeText $seen $flagged $answered $draft]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
delete_CkEmail $email
exit
}
puts "Appended UID: [CkImap_get_AppendUid $imap]"
set success [CkImap_Disconnect $imap]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
delete_CkEmail $email
exit
}
delete_CkImap $imap
delete_CkEmail $email