Tcl
Tcl
Append MIME from a StringBuilder with Flags
See more IMAP Examples
Demonstrates the Chilkat Imap.AppendMimeWithFlagsSb method, which uploads MIME contained in a StringBuilder and sets its initial system flags. The first argument is the mailbox, the second is the StringBuilder, and the third through sixth set \Seen, \Flagged, \Answered, and \Draft. This example uploads to Drafts with the draft flag set.
Background: This is the
StringBuilder form of AppendMimeWithFlags. Passing the MIME as a StringBuilder avoids copying a large message into an intermediate string and is convenient when you already built or loaded the message into a StringBuilder (for example with LoadFile).Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Demonstrates the Imap.AppendMimeWithFlagsSb method, which uploads MIME contained in a
# StringBuilder and sets its initial system flags. The 1st argument is the mailbox, the 2nd
# is the StringBuilder, and the 3rd through 6th set \Seen, \Flagged, \Answered, and \Draft.
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
}
# Load the MIME into a StringBuilder. (A StringBuilder can also be filled via LoadFile.)
set sbMime [new_CkStringBuilder]
CkStringBuilder_Append $sbMime $mimeText
# Choose the initial flags. Named variables make each argument's meaning clear at the call.
set seen 0
set flagged 0
set answered 0
set draft 1
# Upload to "Drafts" with the \Draft flag set.
set success [CkImap_AppendMimeWithFlagsSb $imap "Drafts" $sbMime $seen $flagged $answered $draft]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
delete_CkEmail $email
delete_CkStringBuilder $sbMime
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
delete_CkStringBuilder $sbMime
exit
}
delete_CkImap $imap
delete_CkEmail $email
delete_CkStringBuilder $sbMime