Tk Library Source Code

View Ticket
Login
Ticket UUID: 754920
Title: text/html file content causes socket error
Type: Bug Version: None
Submitter: royterry Created on: 2003-06-15 16:17:41
Subsystem: mime Assigned To: andreas_kupries
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2005-03-09 04:41:07
Resolution: Fixed Closed By: andreas_kupries
    Closed on: 2005-03-08 21:41:07
Description:
My original experimental code combined three MIME 
parts into a single message and used SMTP to send 
successfully. The parts where a plain text file, a binary 
file and an html file.

When I moved the html file to the beginning of the 
-parts list, I started getting 

400: error writing "sock248": invalid argument

out of mime::copymessageaux

On further trials, I've simplfied the issue and it seems 
related to the *contents* of a file.

The following script will trigger the error. (file is 
attached)

# 14Jun03RT - experimental mime/smtp coding
package require mime
package require smtp

proc mb {} {
    # Build a mime thingy
    set TO [email protected]
    set FROM [email protected]
    set SUBJ "Mime [clock format [clock seconds] -
format "%m%d-%T"]"

       set hfile mime-bad.htm

    # Start making mime parts
     # The error also occurs if "text/html" is used
    set hpart [mime::initialize -canonical text/plain  -file 
$hfile]

    # Put them all together
    # The error also occurs if 2 or 3 parts are combined 
as long as $hpart is the first in the list.
    set allparts [mime::initialize -canonical 
multipart/mixed \
        -parts [list $hpart ] ]


    # Send it!
    set sres [smtp::sendmessage $allparts      \
        -header [list From $FROM]    \
        -header [list To $TO]        \
        -header [list Subject $SUBJ] \
        -servers mail.earthlink.net ]

}
User Comments: andreas_kupries added on 2005-03-09 04:41:07:
Logged In: YES 
user_id=75003

I have, I believe, found the problem, and committed a change
to the CVS head that should fix it. I am closing this bug
now (state pending). Just reopen if I am mistaken.

Here what I wrote into the ChangeLog


* mime.tcl (::mime::copymessageaux): Removed usage of the
command
  'unstack'. Its presence is a bug ever since revision 1.3
(March
  9, 2000) of mime.tcl, when the converters (base64,
  quoted-printable) started to be used in immediate mode
instead
  of attaching them to the output channel. This also means
that we
  do not need the fallback implementation anymore either.

  Many thanks to Roy Terry <[email protected]> for
keeping up
  the nagging about [SF Tcllib Bug 754920] which
demonstrated the
  problem.

  What happened is that the unpaired 'unstack' removes the
outer
  .-transformation and a second call may close the channel. If
  that happens any further access to the channel errors
out, and
  the mail server gets and transfers an incomplete mail
message.
  It is a 'may' and not a 'will' because it seems that
sometimes
  the channel has a refcount > 0 and then 'unstack' does
  nothing. This part made the reproduction difficult. It was
  originally suspected to be a problem in Trf itself, but is
  actually a problem in how it is used by mime.

tkmiller3 added on 2005-02-25 11:27:35:
Logged In: YES 
user_id=1215370

I have recently encountered this same bug using Tcl 8.4.9 (from 
ActiveState) sending PDF attachments; package smtp 1.4, mime 1.4.  
Does anyone have a fix or workaround?  Thanks.

royterry added on 2003-07-11 06:58:53:
Logged In: YES 
user_id=146884

Still encountering this error. 
Very apparent that the other side is sometimes closing the 
socket early but why?  I ran it through sockspy and it never 
failed! Outside of sockspy it fails frequently. The failure point 
varies but always occurs on "puts $channel ..."

I would welcome suggestions for further debugging.

Another wrinkle. When I run the mime entities through a file 
and reload into separate process the problem is common. If I 
run smtp::sendmessage in my mine program then I don't see 
the error.

royterry added on 2003-06-15 23:36:28:
Logged In: YES 
user_id=146884

Here is the errorInfo
error writing "sock240": invalid argument
    while executing
"puts $channel [$converter -mode encode -- $X]"
    ("file" arm line 37)
    invoked from within
"switch -- $state(value) {
        file {
            set closeP 1
            if {[info exists state(root)]} {
# FRINK: nocheck
                vari..."
    (procedure "mime::copymessageaux" line 75)
    invoked from within
"mime::copymessageaux $token $channel "
    invoked from within
"mime::copymessage $part $channel"
    ("foreach" body line 3)
    invoked from within
"foreach part $state(parts) {
                        puts $channel "\n--$boundary"
                        mime::copymessage $part $channel
          ..."
    ("default" arm line 2)
    invoked from within
"switch -glob -- $state(content) {
                message/* {
                    puts $channel ""
                    foreach part $state(parts) {
  ..."
    ("parts" arm line 7)
    invoked from within
"switch -- $state(value) {
        file {
            set closeP 1
            if {[info exists state(root)]} {
# FRINK: nocheck
                vari..."
    (procedure "mime::copymessageaux" line 75)
    invoked from within
"mime::copymessageaux $token $channel "
    invoked from within
"mime::copymessage $part $state(sd) "
    invoked from within
"smtp::wtextaux $token $part "
    invoked from within
"smtp::sendmessage $allparts       -header [list From 
$FROM]     -header [list To $TO]         -header [list Subject 
$SUBJ]  -servers mail.earthlink.ne..."
    (procedure "mb" line 20)
    invoked from within
"mb"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 mb"
(time) 84 %

royterry added on 2003-06-15 23:22:33:
Logged In: YES 
user_id=146884

Forget to provide background info
(time) 79 % package require mime
1.3.2
(time) 80 % package require smtp
1.3.2
(time) 81 % info patchlevel
8.4.2
tcl_platform(byteOrder) = littleEndian
tcl_platform(machine)   = intel
tcl_platform(os)        = Windows NT
tcl_platform(osVersion) = 5.0
tcl_platform(platform)  = windows
tcl_platform(user)      = Administrator
tcl_platform(wordSize)  = 4

royterry added on 2003-06-15 23:17:41:

File Added - 53157: mime-bad.htm

Attachments: