期望将变量中的解释文本作为开关发送

时间:2015-12-03 18:48:54

标签: tcl expect

对于expect / Tcl,我是一个完整的新手。我试图使用expect来测试我的自定义邮件配置,但似乎它将我的行缓冲区的内容解释为当我希望它被视为文字文本时有额外的标志。我得到的错误是由MIME边界引起的。任何帮助将不胜感激(我发现了类似的问题,但没有答案)。

bad flag "--------------040802090700050105080302": must be -i, -h, -s, -null, -0, -raw, -break, or --
spawn telnet $server 25
expect "Connected"
expect "220 "
send "HELO <domain>\n"
expect "250 "
send "MAIL FROM: <sender>\n"
expect "250 "
send "RCPT TO: <recipient>\n"
expect "250 "
sleep 2
send "DATA\n"
expect "354" 
sleep 2
set fh [open mailtest.txt]   
while {[gets $fh read_line] != -1} {
        send $read_line      # This explodes when the line starts with --
        send "\n";
}
close $fh
send ".\n"
sleep 2   
send "QUIT\n"

部分输入示例(MIME分隔符导致爆炸):

... header ...
MIME-Version: 1.0
Content-Type: multipart/alternative;
        boundary=------------040802090700050105080302

This is a multi-part message in MIME format.
--------------040802090700050105080302   <-- bomb
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

... rest of MIME body ...

1 个答案:

答案 0 :(得分:2)

所以在搜索之后,我在几个不同的地方找到了答案。发送只需要一个( - )参数来表示没有其他标志,并且所有剩余文本都是文字文本:

while {[gets $fh read_line] != -1} {
        send -- $read_line
        send "\n";
}

Exploring Expect