source: examples/owlconf.vtformat @ 7dcef03

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 7dcef03 was d7cc50b, checked in by Anders Kaseorg <andersk@mit.edu>, 15 years ago
Death to more RCS keywords. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Property mode set to 100644
File size: 3.9 KB
Line 
1### The owlconf config file   -*- perl -*- 
2###
3### This file is interpreted by the perl interpreter.
4### If you wish to execute an owl command use the
5### function owl::command().  i.e.
6###
7###      owl::command("set zsigproc /mit/kretch/bin/getzsig");
8###
9### will set the owl variable zsigproc.  Subroutines created with
10### the names below will be executed at the specified times:
11###
12###     subroutine name    properties
13###     ---------------    ----------
14###     owl::startup()     run when owl first starts
15###     owl::shutdown()    run when owl exits
16###     owl::format_msg()  run when a new message arrives, the return
17###                           value is used to display the message on the
18###                           screen
19###
20### The following variables will be set each time a message is recevied:
21###
22###     $owl::class, $owl::instance, $owl::recipient,
23###     $owl::sender, $owl::opcode, $owl::zsig,
24###     $owl::msg, $owl::time, $owl::host, @owl::fields
25###   
26
27# classes will be appreviated this way
28my %class_abbrev = (
29                   "message"         => "",
30                   "spleen"          => "sp",
31                   "ccare"           => "cc",
32                   "implied-consent" => "ic",
33                   "syseng"          => "se",
34                   "install"         => "i",
35                   );
36
37sub owl::startup {
38    owl::command("set logging off");
39    #owl::command("set zsigproc /home/nygren/bin/owlzsigs");
40    owl::command("set startuplogin off");
41    owl::command("set shutdownlogout off");
42    #owl::command("set personalbell on");
43    owl::command("set rxping on");
44    owl::command("set typewinsize 5");
45}
46
47sub owl::shutdown {
48#    system("/mit/kretch/bin/zkill > /dev/null 2> /dev/null");
49}
50
51sub owl::format_msg {
52    my ($out, $tmp);
53
54    $owl::sender=~s/\@ATHENA\.MIT\.EDU$//;
55    $owl::sender=~s/\@local-realm$//;
56
57    if (uc($owl::opcode) eq "PING") {
58        return("\@bold(PING) from \@bold($owl::sender)\n");
59    } elsif (uc($owl::class) eq "LOGIN") {
60        if (uc($owl::opcode) eq "USER_LOGIN") {
61            $out="\@bold(LOGIN)";
62        } elsif (uc($owl::opcode) eq "USER_LOGOUT") {
63            $out="\@bold(LOGOUT)";
64        } else {
65            $out="\@bold(UNKNOWN)";
66        }
67        $out.=" for \@bold($owl::sender) at $fields[0] on $fields[2]\n";
68        return($out);
69    } elsif (uc($owl::class) eq "MAIL") {
70        $out = "\@bold(MAIL) ";
71        if ($owl::msg =~ /^From:\s+(.+)\s*$/m) { $out .= "From $1 "; }
72        if ($owl::msg =~ /^To:\s+(.+)\s*$/m) { $out .= "To $1 "; }
73        if ($owl::msg =~ /^Subject:\s+(.+)\s*$/m) { $out .= "Subject $1 "; }
74        return($out."\n");
75    }
76
77    my $channel = $owl::class;
78    if (defined $class_abbrev{lc($owl::class)}) {
79        $channel = $class_abbrev{lc($owl::class)};
80    }
81    if (lc($owl::class) ne "message" and lc($owl::instance) eq "personal") {
82        $owl::instance = "";
83    }
84    $channel .= "[".$owl::instance."]";
85    $channel = substr($channel,0,13);
86
87    $header = sprintf "%-8s %-13s ", lc($owl::sender), lc($channel);
88
89    if ($owl::msg =~ /=/) {
90        # indent it
91        $tmp=$owl::msg;
92        $tmp=~s/^/    /g;
93        $tmp=~s/\n/\n    /g;
94        $out.=$header."\n".$tmp;
95    } else {
96        # fill it
97        my $pagewidth = 74;
98        $out .= $header;
99        $out .= fill_text($owl::msg, $pagewidth, 22, 1);
100    }
101
102    # note: no zsig added in this version
103
104    # make personal messages bold
105    if (uc($owl::class) eq "MESSAGE" &&
106        uc($owl::instance) eq "PERSONAL") {
107        $out="\@bold{".$out."}\n";
108    }
109
110    return($out);
111}
112
113
114
115sub fill_text {
116    my ($in, $width, $indent, $unindent_first) = @_;
117    $indent = 0 if (@_ < 3);
118    my $unindent = $indent if ($unindent_first);
119    my @words = split " ", $in;
120    my $out = "";
121    my $outline = "";
122    if (!$unindent_first) {
123        my $outline = " "x$indent;
124    }
125    for my $w (@words) {
126        if (($outline ne "") 
127            && (length($outline)+length($w) > $width-$unindent)) {
128            $out .= $outline."\n";
129            $outline = " "x$indent;
130            $unindent = 0;
131        }
132        if ($outline =~ /.*\.$/) {
133            $outline .= "  ";
134        } elsif ($outline ne "") {
135            $outline .= " ";
136        }
137        $outline .= $w;
138    }
139    $out .= $outline . "\n";   
140}
Note: See TracBrowser for help on using the repository browser.