File: inc.expect

package info (click to toggle)
exmh 1:2.9.0-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 4,216 kB
  • sloc: tcl: 38,046; perl: 1,647; makefile: 130; sh: 101; exp: 75; csh: 9; sed: 2
file content (79 lines) | stat: -rwxr-xr-x 1,760 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
# \
exec /usr/bin/expect -f "$0" -- ${1+"$@"}
#
# Script to run inc and provide a password.
#
# When there is mail to incorporate, echo back only the message headers
# for the FTOC.  Otherwise, send back all text, for debug logging

set timeout 60
gets stdin password

# turn off echo so that password doesn't get echoed by tty driver
set stty_init -echo
eval spawn -noecho $argv
log_user 0

# When .netrc exists, inc doesn't prompt for a password.  After getting
# a password one way or another, inc prints one of
#    Incorporating new mail into inbox...\r\n\r\n
#    inc: no mail to incorporate
#
# For the case of mail available, we want to drain the informational
# line "Incorporating new mail" here, so it doesn't get sent back
# as output and get stuck in the FTOC window, and proceed to the while
# loop, below.
#
# If there's no mail, the informational message sent back, with exit 1,
# so the message gets put into the debug log.
#

expect {
    -re "Password (.*):" {
        exp_send -- $password\n
	lappend incout $expect_out(buffer) $password\n

	expect {
	    -re ".* new mail .*\n" {}
	    eof {
		send_user $expect_out(buffer)
		exit 1
	    }
	    timeout { send_user "timeout"; exit 1 }
	}
    }

    -re ".* new mail .*\n" {}

    eof {
        send_user $expect_out(buffer)
	exit 1
    }

    timeout { send_user "timeout"; exit 1 }
}

# drain any empty line
# echo back msg header for FTOC
# if exit status of inc is non-zero (e.g., 1 for no mail), 
# echo back all accumulated text 

while {1} {
    expect {
	-re "^\[ \r\n]+$" {}
        -re ".*\n" {
	    send_user $expect_out(buffer)
        }

        eof {
	    if { [lindex [wait] 3] == 0 } {
		exit 0
	    } else {
		send_user $incout
		exit 1
	    }
        }
    }
}