-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmutt-ph-query.pl.old
More file actions
executable file
·129 lines (87 loc) · 2.45 KB
/
Copy pathmutt-ph-query.pl.old
File metadata and controls
executable file
·129 lines (87 loc) · 2.45 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/perl -w
# mutt-ph-query.pl v0.1
#
# Mutt external query program for ph/qi
#
# Jay Kreibich, Research Programmer, CCSO, UIUC.
# jak@uiuc.edu
require 5.002;
use strict;
use Socket;
my( $remote, $port, $iaddr, $paddr );
my( $query, $line, $code, $line_num, $email_domain );
my( $current, $c_email, $c_name, $c_title, $c_division, $c_department );
$remote = 'wisc.edu';
$port = 105;
$email_domain = 'wisc.edu';
sub PrintEntry
{
my( $email, $name, $title, $division, $department ) = @_;
my( @name, $name_part, $lname );
$name =~ tr/A-Z/a-z/;
@name = split(' ', $name );
$name = '';
$lname = shift @name;
foreach $name_part ( @name ) {
$name .= "\u$name_part ";
}
$name .= "\u$lname";
if( not $email ) {
$email = "--no-email-address--";
} else {
$email =~ tr/A-Z/a-z/;
}
if( not $title ) {
$title = "Student";
} else {
$title = "$division, $department";
}
print STDOUT "$email\t$name\t$title\n";
}
if( @ARGV == 0 ) { die "Usage: $0 <alias>\n"; }
$query = $ARGV[0];
$iaddr = inet_aton( $remote ) or die "Could not lookup host: $remote";
$paddr = sockaddr_in( $port, $iaddr );
socket( SOCK, PF_INET, SOCK_STREAM, 0) or die "socket: $!";
connect( SOCK, $paddr ) or die "connect: $!";
select (SOCK); $| = 1; select(STDOUT);
print SOCK "query $query return email name title division department\r\n";
$line = <SOCK>;
( $code, $current ) = split(':', $line);
print STDOUT $current;
if( $code >= 200 ) { exit; }
$current = 1;
$c_email = '';
$c_name = '';
$c_title = '';
$c_division = '';
$c_department = '';
while( $line = <SOCK> )
{
# print $line;
chomp $line;
( $code, $line_num ) = split(':', $line);
last if( $code >= 200 );
next if( $code != -200 );
if( $line_num != $current )
{
PrintEntry $c_email, $c_name, $c_title, $c_division, $c_department;
$current = $line_num;
$c_email = '';
$c_name = '';
$c_title = '';
$c_division = '';
$c_department = '';
}
$c_email = $line if( $line =~ s/-200:.*\bemail: // );
$c_name = $line if( $line =~ s/-200:.*\bname: // );
$c_name = $line if( $line =~ s/-200:.*\bpretty_name: // );
$c_title = $line if( $line =~ s/-200:.*\btitle: // );
$c_division = $line if( $line =~ s/-200:.*\bdivision: // );
$c_department = $line if( $line =~ s/-200:.*\bdepartment: // );
}
if( $code == 200 )
{ PrintEntry $c_email, $c_name, $c_title, $c_division, $c_department; }
print SOCK "quit\r\n";
close( SOCK );
exit;