| 1 |
# -*- tcl -*- |
| 2 |
# This file is part of Mailutils testsuite. |
| 3 |
# Copyright (C) 2002-2025 Free Software Foundation, Inc. |
| 4 |
# |
| 5 |
# GNU Mailutils is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# GNU Mailutils is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
source $top_srcdir/testsuite/lib/mailutils.exp |
| 19 |
|
| 20 |
mu_init --nosum --norc |
| 21 |
|
| 22 |
#FIXME: this doesn't work with remote testing |
| 23 |
set env(MAILRC) $MU_RC_DIR/mail.rc |
| 24 |
set env(MBOX) "$MU_SPOOL_DIR/mbox" |
| 25 |
|
| 26 |
# The variable mail_prompt is a regexp which matches the mail prompt. |
| 27 |
global mail_prompt |
| 28 |
if ![info exists mail_prompt] then { |
| 29 |
set mail_prompt "\\? " |
| 30 |
} |
| 31 |
|
| 32 |
### Only procedures should come after this point. |
| 33 |
|
| 34 |
proc mail_version {} { |
| 35 |
mu_version |
| 36 |
} |
| 37 |
|
| 38 |
proc default_mail_start {args} { |
| 39 |
global verbose |
| 40 |
global MU_TOOL |
| 41 |
global MU_TOOL_FLAGS |
| 42 |
global mail_prompt |
| 43 |
global expect_out |
| 44 |
global mail_spawn_id |
| 45 |
|
| 46 |
mu_version |
| 47 |
|
| 48 |
set sw [join $args " "] |
| 49 |
append sw " " |
| 50 |
if [info exists MU_TOOL_FLAGS] { |
| 51 |
append sw $MU_TOOL_FLAGS |
| 52 |
} |
| 53 |
|
| 54 |
append sw " --set mailbox.mailbox-type=mbox" |
| 55 |
|
| 56 |
if [info exists host_board] { |
| 57 |
if [board_info $host_board exists top_srcdir] { |
| 58 |
append sw " --set \"mailbox.mail-spool='[board_info $host_board top_srcdir]/mail/testsuite/spool'\"" |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
set mail_cmd "$MU_TOOL $sw" |
| 63 |
verbose "Spawning $mail_cmd" |
| 64 |
|
| 65 |
set mail_spawn_id [remote_spawn host $mail_cmd] |
| 66 |
if { $mail_spawn_id < 0 || $mail_spawn_id == "" } { |
| 67 |
perror "Spawning $mail_cmd failed." |
| 68 |
return 1; |
| 69 |
} |
| 70 |
|
| 71 |
mu_expect 360 { |
| 72 |
-re "\[\r\n\]?${mail_prompt}$" { |
| 73 |
verbose "mail initialized." |
| 74 |
} |
| 75 |
default { |
| 76 |
perror "mail not initialized" |
| 77 |
return 1 |
| 78 |
} |
| 79 |
} |
| 80 |
return 0 |
| 81 |
} |
| 82 |
|
| 83 |
proc default_mail_stop {} { |
| 84 |
verbose "Stopping mail" |
| 85 |
mail_command "exit" |
| 86 |
remote_close host |
| 87 |
} |
| 88 |
|
| 89 |
proc mail_start {args} { |
| 90 |
verbose "Starting mail" |
| 91 |
|
| 92 |
set reuse_spool 0 |
| 93 |
for {set i 0} {$i < [llength $args]} {incr i} { |
| 94 |
set a [lindex $args $i] |
| 95 |
if {"$a" == "-reuse-spool"} { |
| 96 |
set reuse_spool 1 |
| 97 |
} else { |
| 98 |
break; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
if {$reuse_spool == 0} { |
| 103 |
mu_prepare_spools |
| 104 |
} |
| 105 |
return [default_mail_start [lrange $args $i end]] |
| 106 |
} |
| 107 |
|
| 108 |
proc mail_stop {} { |
| 109 |
global mail_spawn_id |
| 110 |
if {[info exists mail_spawn_id] && $mail_spawn_id > 0} { |
| 111 |
default_mail_stop |
| 112 |
unset mail_spawn_id |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
## |
| 117 |
|
| 118 |
proc mail_send { string } { |
| 119 |
return [mu_send "$string"] |
| 120 |
} |
| 121 |
|
| 122 |
proc mail_command { cmd } { |
| 123 |
return [mu_command $cmd] |
| 124 |
} |
| 125 |
|
| 126 |
proc mail_exit {} { |
| 127 |
mail_stop |
| 128 |
} |
| 129 |
|
| 130 |
# mail_test [-message MESSAGE][-default (FAIL|XFAIL)][-noprompt] |
| 131 |
# COMMAND PATTERN [PATTERN...] |
| 132 |
# COMMAND - Command to send to mail. |
| 133 |
# PATTERN - Sequence to expect in return. |
| 134 |
# MESSAGE - [optional] message to output |
| 135 |
proc mail_test { args } { |
| 136 |
global verbose |
| 137 |
global mail_prompt |
| 138 |
global suppress_flag; |
| 139 |
upvar timeout timeout |
| 140 |
|
| 141 |
set default "" |
| 142 |
set message "" |
| 143 |
set wait_for_prompt 1 |
| 144 |
for {set i 0} {$i < [llength $args]} {incr i} { |
| 145 |
set a [lindex $args $i] |
| 146 |
if {"$a" == "-default"} { |
| 147 |
set default [lindex $args [expr $i + 1]] |
| 148 |
incr i |
| 149 |
} elseif {"$a" == "-message"} { |
| 150 |
set message [lindex $args [expr $i + 1]] |
| 151 |
incr i |
| 152 |
} elseif {"$a" == "-noprompt"} { |
| 153 |
set wait_for_prompt 0 |
| 154 |
} else { |
| 155 |
set args [lrange $args $i end] |
| 156 |
break |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
if {"$message" == ""} { |
| 161 |
set message [lindex $args 0] |
| 162 |
} |
| 163 |
|
| 164 |
if $verbose>2 then { |
| 165 |
send_user "Message is \"$message\"\n" |
| 166 |
} |
| 167 |
set command [lindex $args 0] |
| 168 |
set pattern [lrange $args 1 end] |
| 169 |
set result [mu_test $command $pattern] |
| 170 |
if {$wait_for_prompt} { |
| 171 |
mu_expect 30 { |
| 172 |
-re "\[\r\n\]?${mail_prompt}$" {} |
| 173 |
default { |
| 174 |
perror "mail not initialized" |
| 175 |
return 1 |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
if {$result == 0} { |
| 181 |
pass "$message" |
| 182 |
} elseif {$result == 1} { |
| 183 |
if { "$default" == "" || "$default" != "FAIL" } { |
| 184 |
fail "$message" |
| 185 |
} else { |
| 186 |
xfail "$message" |
| 187 |
set result 0 |
| 188 |
} |
| 189 |
} elseif {$result == -2} { |
| 190 |
fail "$message (timeout)" |
| 191 |
} elseif {$result == -3} { |
| 192 |
fail "$message (eof)" |
| 193 |
} else { |
| 194 |
fail "$message" |
| 195 |
} |
| 196 |
return $result |
| 197 |
} |
| 198 |
|
| 199 |
|