| 1 |
#!/usr/local/bin/perl -w |
| 2 |
|
| 3 |
# ----------------------------------------------------------- |
| 4 |
# Perl UKC mailinfo host |
| 5 |
# |
| 6 |
# A perl script that mimmicks the behaviour of the UKC |
| 7 |
# mailinfo client. Supports all functions except the -C |
| 8 |
# option to change mailstore. |
| 9 |
# - T.D.Bishop@kent.ac.uk |
| 10 |
# |
| 11 |
# $Author: tdb $ |
| 12 |
# $Id: mailinfo.pl,v 1.6 2001/10/15 16:29:03 tdb Exp $ |
| 13 |
#------------------------------------------------------------ |
| 14 |
|
| 15 |
$| = 1; |
| 16 |
|
| 17 |
use strict; |
| 18 |
use IO::Socket; |
| 19 |
|
| 20 |
# default mailinfo server |
| 21 |
my($mailinfo_server) = "mercury.ukc.ac.uk"; |
| 22 |
my($mailinfo_port) = "912"; |
| 23 |
|
| 24 |
# default settings |
| 25 |
my($mailinfo_mode) = "mi_guess"; |
| 26 |
my($mailinfo_name) = ""; |
| 27 |
my($mailinfo_quick) = 0; |
| 28 |
|
| 29 |
# work out the switches |
| 30 |
my($mode_set) = 0; |
| 31 |
while(@ARGV) { |
| 32 |
my($opt) = shift; |
| 33 |
if($opt eq "-l" && $mode_set == 0) { |
| 34 |
$mailinfo_mode = "mi_login"; |
| 35 |
$mode_set = 1; |
| 36 |
} |
| 37 |
elsif($opt eq "-n" && $mode_set == 0) { |
| 38 |
$mailinfo_mode = "mi_name"; |
| 39 |
$mode_set = 1; |
| 40 |
} |
| 41 |
elsif($opt eq "-s" && $mode_set == 0) { |
| 42 |
$mailinfo_mode = "mi_soundex"; |
| 43 |
$mode_set = 1; |
| 44 |
} |
| 45 |
elsif($opt eq "-i" && $mode_set == 0) { |
| 46 |
$mailinfo_mode = "mi_sysid"; |
| 47 |
$mode_set = 1; |
| 48 |
} |
| 49 |
elsif($opt eq "-g" && $mode_set == 0) { |
| 50 |
$mailinfo_mode = "mi_guess"; |
| 51 |
$mode_set = 1; |
| 52 |
} |
| 53 |
elsif($opt eq "-q" && $mailinfo_quick == 0) { |
| 54 |
$mailinfo_quick = 1; |
| 55 |
} |
| 56 |
elsif($opt =~ /^-/) { |
| 57 |
&usage; |
| 58 |
} |
| 59 |
else { |
| 60 |
$mailinfo_name .= " $opt"; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
if($mailinfo_name eq "") { $mailinfo_name = getlogin; } |
| 65 |
|
| 66 |
# run mailinfo |
| 67 |
&mailinfo($mailinfo_server, $mailinfo_port, $mailinfo_mode, $mailinfo_name, $mailinfo_quick); |
| 68 |
|
| 69 |
exit(0); |
| 70 |
|
| 71 |
|
| 72 |
#----------------------------------------------------------------------- |
| 73 |
# mailinfo |
| 74 |
# Performs a mailinfo query to a specific server. |
| 75 |
# Parameters are: |
| 76 |
# $server = the IP or name of the port server |
| 77 |
# $port = the port of the mailinfo server |
| 78 |
# $mode = the lookup mode to use |
| 79 |
# $name = the name to lookup |
| 80 |
# $quick = whether to do a quick lookup or not (1 = quick) |
| 81 |
#----------------------------------------------------------------------- |
| 82 |
sub mailinfo() { |
| 83 |
my($server, $port, $mode, $name, $quick) = @_; |
| 84 |
|
| 85 |
# connect |
| 86 |
my($sock) = new IO::Socket::INET( |
| 87 |
PeerAddr => $server, |
| 88 |
PeerPort => $port, |
| 89 |
Proto => 'tcp' |
| 90 |
) or die "Connection to server broken\n"; |
| 91 |
|
| 92 |
if(!defined $sock) { |
| 93 |
print "Connection to server broken\n"; |
| 94 |
exit(1); |
| 95 |
} |
| 96 |
|
| 97 |
my($response) = ""; |
| 98 |
|
| 99 |
# set the sensible option if we want quick mode |
| 100 |
if($quick) { |
| 101 |
print $sock "sensible on\n"; |
| 102 |
$response = <$sock>; |
| 103 |
while($response ne ".\n") { |
| 104 |
$response = <$sock>; |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
# send the query |
| 109 |
print $sock "$mode $name\n"; |
| 110 |
$response = ""; |
| 111 |
|
| 112 |
# read and print the response |
| 113 |
while($response ne ".\n") { |
| 114 |
$response = <$sock>; |
| 115 |
if($response =~ s/^\?/mailinfo: /) { |
| 116 |
print $response; |
| 117 |
} |
| 118 |
else { |
| 119 |
print $response unless $response eq ".\n"; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
# quit and close |
| 124 |
print $sock "quit\n"; |
| 125 |
close($sock); |
| 126 |
return; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
#----------------------------------------------------------------------- |
| 131 |
# usage |
| 132 |
# Prints out usage information |
| 133 |
#----------------------------------------------------------------------- |
| 134 |
sub usage() { |
| 135 |
print <<EOF; |
| 136 |
Usage: mailinfo [mode] name ... |
| 137 |
where mode is: |
| 138 |
-l login search |
| 139 |
-n name search |
| 140 |
-s `sounds like' search |
| 141 |
-i sysid search |
| 142 |
-g guess search (default) |
| 143 |
-q quick mode (no mailbox info) |
| 144 |
-C change mailstore (unsupported) |
| 145 |
EOF |
| 146 |
exit(1); |
| 147 |
} |