| Description: |
Since version 1.7.2. of the mime package as included in tcllib 2.0 if we create a mail message that contains carriage returns/linefeeds, the mail message we send using the smtp package will have double spaced format, because the mime::buildmessageaux function calls the mime::copymessageaux function with a the channel set to a translation of crlf.
On loading the message text in the mime::initialize procedure, the \r\n characters are preserved in the state(string).
In the copymessageaux procedure the statement
puts -nonewline $channel $state(string)
will have the \n characters translated to \r\n as instructed by the translation, causing the \r\n to be translated into \r\r\n.
All this of course only if the bug in the mime::encodingasciiP procedure is fixed.
This example code demonstrates this:
######################################################################
# Name: mime_test
# Purpose: Test mime package.
#
# History:
# 29-07-2026 E.R. Schreurs
# 1.0 (Initial Version)
#
proc mime_test { args } {
package require mime
package require smtp
# SMTP Config
set mailserver "smtp.dummy.com"
set sender "[email protected]"
set username ""
set password ""
set SimpleLine "Simple line\r"
set result [mime::encodingasciiP $SimpleLine]
puts "encodingasciiP for \"Simple line\\r\\n\" is $result"
set body "Simple line\r\nAnotherline\r\n"
set recipient "[email protected]"
#
# Create a complete MIME encoded message
#
set header [list From [email protected]]
append mailmsg "Subject: Test mime package\n"
append mailmsg "To: [email protected]\n"
append mailmsg "From: [email protected]\n"
append mailmsg "Sender: [email protected]\n"
append mailmsg "MIME-Version: 1.0\n"
append mailmsg "Content-Type: text/plain; charset=Cp1252\n"
append mailmsg "\n"; # blank line is the end of the header
append mailmsg $body
puts stdout "Mail message: $mailmsg"
set token [mime::initialize -string $mailmsg]
# puts stdout "Subject [mime::getheader $token Subject]"
smtp::sendmessage $token \
-recipients $recipient \
-debug $debug \
-header $header \
-originator $sender \
-username [lindex $username 0] \
-password [lindex $password 0] \
-servers $mailserver
mime::finalize $token -subordinates all
return
}
|