| 1 |
### The owlconf config file -*- perl -*- |
| 2 |
### |
| 3 |
### !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! |
| 4 |
### This is an example file intended to demonstrate how to use |
| 5 |
### various features of owl. Some of the key bindings, in particular, |
| 6 |
### are more for examples than things you may actually want to use. |
| 7 |
### Make sure to read through it first and understand it before just using it. |
| 8 |
### Don't blame me if anything in here ends up vaporizing your dog. |
| 9 |
### !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! |
| 10 |
### |
| 11 |
### |
| 12 |
### This file is interpreted by the perl interpreter. |
| 13 |
### If you wish to execute an owl command use the |
| 14 |
### function owl::command(). i.e. |
| 15 |
### |
| 16 |
### owl::command("set zsigproc /mit/kretch/bin/getzsig"); |
| 17 |
### |
| 18 |
### will set the owl variable zsigproc. Subroutines created with |
| 19 |
### the names below will be executed at the specified times: |
| 20 |
### |
| 21 |
### subroutine name properties |
| 22 |
### --------------- ---------- |
| 23 |
### owl::startup() run when owl first starts |
| 24 |
### owl::shutdown() run when owl exits |
| 25 |
### owl::format_msg() formats messages that are passed to it |
| 26 |
### owl::receive_msg() run when a message is received, and after |
| 27 |
### it has been added to the message list |
| 28 |
### |
| 29 |
### The format_msg and receive_msg functions are passed owl::Message objects. |
| 30 |
### The message attributes may be dereferenced with $m->attribute |
| 31 |
### |
| 32 |
### |
| 33 |
|
| 34 |
# tokens for sepbar are: |
| 35 |
# .username = ping |
| 36 |
# >username = login |
| 37 |
# <username = logout |
| 38 |
# :username = personal message |
| 39 |
# M = mail received |
| 40 |
my @sepbartokens = (); |
| 41 |
|
| 42 |
# Map for mail messages from msg id to pop msg id |
| 43 |
my %mail_id_map = (); |
| 44 |
|
| 45 |
# (originally from jdaniel) |
| 46 |
sub mail_add_message ($) { |
| 47 |
my ($m) = @_; |
| 48 |
my $from = `from -t`; |
| 49 |
# example value: |
| 50 |
# You have 188 messages (667593 bytes) on PO11.MIT.EDU. |
| 51 |
my ($msg_num) = $from =~ m/(\d+)/; |
| 52 |
$mail_id_map{$m->id} = $msg_num; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
sub mail_pop_curmsg () { |
| 57 |
my $m = owl::getcurmsg(); |
| 58 |
if (!$m->is_mail || !defined $mail_id_map{$m->id}) { |
| 59 |
&owl::command("pop-message"); |
| 60 |
} else { |
| 61 |
&owl::command(sprintf 'pexec pop -request c -request "retr %d" -request q', |
| 62 |
$mail_id_map{$m->id}); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
sub zlocatesender { |
| 67 |
my $m = owl::getcurmsg(); |
| 68 |
if ($m->{"type"} eq "zephyr") { |
| 69 |
my $sender = $m->{"sender"}; |
| 70 |
owl::command("zlocate $sender"); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
# adds a sepbartoken and also updates the appendtosepbar variable |
| 75 |
sub sepbartokens_add { |
| 76 |
my ($token) = @_; |
| 77 |
$token =~ s/"//g; # " |
| 78 |
unshift @sepbartokens, $token; |
| 79 |
pop @sepbartokens if (@sepbartokens > 80); |
| 80 |
sepbartokens_set(); |
| 81 |
} |
| 82 |
|
| 83 |
# trims a sepbartoken from the list also updates the appendtosepbar variable |
| 84 |
sub sepbartokens_trim { |
| 85 |
my ($token) = @_; |
| 86 |
@sepbartokens = map { if ($_ ne $token) { $_; } else { (); } } @sepbartokens; |
| 87 |
sepbartokens_set(); |
| 88 |
} |
| 89 |
|
| 90 |
my $loopctr=0; |
| 91 |
|
| 92 |
# trims a sepbartoken from the list also updates the appendtosepbar variable |
| 93 |
sub sepbartokens_set { |
| 94 |
owl::command(sprintf "set -q appendtosepbar \"%s %s %s\"", (scalar localtime), (join " ", @sepbartokens)); |
| 95 |
} |
| 96 |
|
| 97 |
my $restoreview = undef; |
| 98 |
sub swapview { |
| 99 |
my $curview = owl::command("getview"); |
| 100 |
if ($restoreview) { |
| 101 |
owl::command("view $restoreview"); |
| 102 |
$restoreview = undef; |
| 103 |
} else { |
| 104 |
$restoreview = $curview; |
| 105 |
owl::command("smartnarrow"); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
my $lastcolored = undef; |
| 110 |
sub colorthread { |
| 111 |
if ($lastcolored) { |
| 112 |
owl::command("filter $lastcolored -c default"); |
| 113 |
} |
| 114 |
my $smartfilt = owl::command("smartfilter"); |
| 115 |
if (!$smartfilt or $smartfilt eq $lastcolored) { |
| 116 |
owl::command("filter $lastcolored -c default"); |
| 117 |
$lastcolored = undef; |
| 118 |
} else { |
| 119 |
owl::command("filter $smartfilt -c green"); |
| 120 |
$lastcolored = $smartfilt; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
# Load in things which don't belong in an owlconf |
| 125 |
# that people might use as an example... |
| 126 |
sub personal_startup { |
| 127 |
my $personalconf = $ENV{"HOME"}."/.owl/personalconf"; |
| 128 |
if (-f $personalconf) { |
| 129 |
my $b = ""; |
| 130 |
open INB, $personalconf; |
| 131 |
for (<INB>) { $b .= $_; } |
| 132 |
close INB; |
| 133 |
eval $b; |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
sub owl::startup { |
| 138 |
owl::command("set -q logging on"); |
| 139 |
owl::command("set -q logpath ~/.zlog/owl/personal"); |
| 140 |
owl::command("set -q classlogpath ~/.zlog/owl/class"); |
| 141 |
owl::command("set -q logging on"); |
| 142 |
owl::command("set -q startuplogin off"); |
| 143 |
owl::command("set -q shutdownlogout off"); |
| 144 |
#owl::command("set personalbell on"); |
| 145 |
owl::command("set -q _burningears on"); |
| 146 |
owl::command("set -q rxping on"); |
| 147 |
owl::command("set -q typewinsize 5"); |
| 148 |
owl::command("filter me recipient %me% or ( sender %me% and class message and instance personal ) or class mail or type aim"); |
| 149 |
owl::command("filter owl instance ^owl.*"); |
| 150 |
|
| 151 |
owl::command(q(alias finger pperl $x=owl::getcurmsg()->hostname; `finger \@$x`;)); |
| 152 |
owl::command("bindkey recv f command finger"); |
| 153 |
|
| 154 |
owl::command("alias z zwrite"); |
| 155 |
owl::command("alias zw zwrite"); |
| 156 |
owl::command("alias v view"); |
| 157 |
|
| 158 |
owl::command("alias popmail perl mail_pop_curmsg();"); |
| 159 |
|
| 160 |
# toggle between a view and a smartnarrow with TAB |
| 161 |
owl::command("alias swapview perl swapview();"); |
| 162 |
owl::command("bindkey recv C-i command swapview"); |
| 163 |
|
| 164 |
# color the current thread |
| 165 |
owl::command("alias colorthread perl colorthread();"); |
| 166 |
owl::command("bindkey recv M-c command colorthread"); |
| 167 |
|
| 168 |
# zlocate current sender |
| 169 |
owl::command("bindkey recv L command perl zlocatesender();"); |
| 170 |
|
| 171 |
# Declare styles |
| 172 |
&owl::command("style vt perl format_msg_vt"); |
| 173 |
&owl::command("style brief perl format_msg_brief"); |
| 174 |
&owl::command("style custom perl format_msg_custom"); |
| 175 |
&owl::command("style debug perl format_msg_debug"); |
| 176 |
&owl::command("set -q default_style custom"); |
| 177 |
|
| 178 |
# Change to different view styles |
| 179 |
owl::command("bindkey recv \"C-s v\" command view -s vt"); |
| 180 |
owl::command("bindkey recv \"C-s c\" command view -s custom"); |
| 181 |
owl::command("bindkey recv \"C-s b\" command view -s brief"); |
| 182 |
owl::command("bindkey recv \"C-s d\" command view -s debug"); |
| 183 |
owl::command("bindkey recv \"C-s o\" command view -s standard"); |
| 184 |
|
| 185 |
# For fast-reading of zephyrs |
| 186 |
owl::command("bindkey recv M-k command ( smartnarrow ; delete view )"); |
| 187 |
owl::command("bindkey recv M-l command ( expunge ; view all )"); |
| 188 |
owl::command("bindkey recv M-K command ( smartnarrow ; delete view ; expunge ; view all )"); |
| 189 |
|
| 190 |
# Support for scroll mice |
| 191 |
&owl::command("bindkey recv \"M-[ A\" command recv:prev"); |
| 192 |
&owl::command("bindkey recv \"M-[ B\" command recv:next"); |
| 193 |
|
| 194 |
# This overrides the default "M" keybinding |
| 195 |
owl::command("bindkey recv M command popmail"); |
| 196 |
|
| 197 |
sepbartokens_add("..."); |
| 198 |
|
| 199 |
personal_startup(); |
| 200 |
} |
| 201 |
|
| 202 |
sub owl::shutdown { |
| 203 |
# not doing anything at the moment... |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
# run when a message is received, and after |
| 208 |
# it has been added to the message list. |
| 209 |
sub owl::receive_msg { |
| 210 |
my ($m) = @_; |
| 211 |
my ($out, $tmp); |
| 212 |
|
| 213 |
if ($m->is_admin && !$m->is_outgoing) { |
| 214 |
$m->delete(); |
| 215 |
return 1; |
| 216 |
} |
| 217 |
|
| 218 |
return 0 if (!$m->is_zephyr && !$m->is_aim); |
| 219 |
|
| 220 |
my $sender = $m->pretty_sender; |
| 221 |
|
| 222 |
if ($m->is_ping) { |
| 223 |
sepbartokens_add(".$sender"); |
| 224 |
$m->delete(); |
| 225 |
} elsif ($m->is_loginout) { |
| 226 |
$m->delete(); |
| 227 |
if ($m->is_login) { |
| 228 |
sepbartokens_add(">$sender"); |
| 229 |
sepbartokens_trim("<$sender"); |
| 230 |
} elsif ($m->is_logout) { |
| 231 |
sepbartokens_add("<$sender"); |
| 232 |
sepbartokens_trim(">$sender"); |
| 233 |
} |
| 234 |
} elsif ($m->is_mail) { |
| 235 |
mail_add_message($m); |
| 236 |
$m->delete(); |
| 237 |
sepbartokens_add("M"); |
| 238 |
} |
| 239 |
|
| 240 |
if ($m->is_personal) { |
| 241 |
sepbartokens_trim(".$sender"); |
| 242 |
sepbartokens_add(":$sender"); |
| 243 |
} |
| 244 |
|
| 245 |
return 1; |
| 246 |
} |
| 247 |
|
| 248 |
sub indent4 { |
| 249 |
my ($b) = @_; |
| 250 |
$b=~s/^/ /g; |
| 251 |
$b=~s/\n/\n /g; |
| 252 |
return $b; |
| 253 |
} |
| 254 |
|
| 255 |
# run to format a message |
| 256 |
sub format_msg_custom { |
| 257 |
my ($m) = @_; |
| 258 |
my ($out, $tmp); |
| 259 |
|
| 260 |
if ($m->is_admin) { |
| 261 |
$out = "\@bold([owl admin]) ".$m->header."\n"; |
| 262 |
$out.=indent4($m->body); |
| 263 |
return $out."\n"; |
| 264 |
} |
| 265 |
|
| 266 |
my $sender=$m->pretty_sender; |
| 267 |
|
| 268 |
if (($m->is_aim or $m->is_zephyr) && $m->is_loginout) { |
| 269 |
|
| 270 |
if ($m->is_login) { |
| 271 |
$out="\@bold(LOGIN)"; |
| 272 |
} elsif ($m->is_logout) { |
| 273 |
$out="\@bold(LOGOUT)"; |
| 274 |
} else { |
| 275 |
$out="\@bold(UNKNOWN)"; |
| 276 |
} |
| 277 |
$out.=" for \@bold($sender) on ".$m->type; |
| 278 |
if ($m->is_zephyr) { |
| 279 |
$out.=" at ".($m->login_host)." on ".($m->login_tty); |
| 280 |
} |
| 281 |
return("$out\n"); |
| 282 |
} |
| 283 |
|
| 284 |
if (!$m->is_zephyr && !$m->is_aim) { |
| 285 |
return "Unknown message type: ".$m->type."\n"; |
| 286 |
} |
| 287 |
|
| 288 |
if ($m->is_outgoing) { |
| 289 |
my $target = $m->recipient; |
| 290 |
if ($m->is_zephyr) { |
| 291 |
$target = $m->zwriteline; |
| 292 |
$target =~ s/^zwrite //; |
| 293 |
} |
| 294 |
$out = sprintf "\@bold([outgoing %s to %s]) / %s\n", $m->type, $target, $m->time; |
| 295 |
$out.=indent4($m->body); |
| 296 |
return "$out\n"; |
| 297 |
} |
| 298 |
|
| 299 |
if ($m->is_zephyr && $m->is_ping) { |
| 300 |
return("\@bold(PING) from \@bold($sender)\n"); |
| 301 |
} elsif ($m->is_zephyr && $m->is_mail) { |
| 302 |
$out = "\@bold(MAIL) "; |
| 303 |
if ($m->body =~ /^From:\s+(.+)\s*$/m) { $out .= "From $1 "; } |
| 304 |
if ($m->body =~ /^To:\s+(.+)\s*$/m) { $out .= "To $1 "; } |
| 305 |
if ($m->body =~ /^Subject:\s+(.+)\s*$/m) { $out .= "Subject $1 "; } |
| 306 |
return("$out\n"); |
| 307 |
} |
| 308 |
|
| 309 |
if ($m->is_zephyr) { |
| 310 |
$out = sprintf "[mit,%s,%s] / %s / %s", lc($m->class), |
| 311 |
lc($m->instance), $m->time, lc($m->host); |
| 312 |
if ($m->opcode ne "") {$out.=" op:".$m->opcode;} |
| 313 |
$out.="\n"; |
| 314 |
$out.= " \@bold($sender)> "; |
| 315 |
if ($m->zsig ne "") { |
| 316 |
my $zsig = $m->zsig; |
| 317 |
$zsig =~ s/(\n.*)+$/ [...]/; |
| 318 |
if (length($zsig)+5+length($sender) > 70) { |
| 319 |
$out.="# ..."; |
| 320 |
} else { |
| 321 |
$out.="# $zsig"; |
| 322 |
} |
| 323 |
} |
| 324 |
$out.="\n"; |
| 325 |
} else { |
| 326 |
$out = sprintf "[%s] / %s\n", lc($m->type), $m->time; |
| 327 |
$out.= " \@bold($sender)> "; |
| 328 |
$out.="\n"; |
| 329 |
} |
| 330 |
|
| 331 |
$out.=indent4($m->body); |
| 332 |
|
| 333 |
# make personal messages bold |
| 334 |
if ($m->is_personal) { |
| 335 |
$out="\@bold{".$out."}"; |
| 336 |
} |
| 337 |
|
| 338 |
return($out."\n"); |
| 339 |
} |
| 340 |
|
| 341 |
sub format_msg_debug { |
| 342 |
my ($m) = @_; |
| 343 |
return "\@bold(-------------MESSAGE-------------)\n".($m->serialize).".\n"; |
| 344 |
} |
| 345 |
|
| 346 |
sub format_msg_brief { |
| 347 |
my ($m) = @_; |
| 348 |
my $out = format_msg_vt($m); |
| 349 |
$out =~ s/\n/ /g; |
| 350 |
$out =~ s/ / /g; |
| 351 |
return($out."\n"); |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
sub format_msg_vt { |
| 356 |
my ($m) = @_; |
| 357 |
my ($out, $tmp); |
| 358 |
|
| 359 |
if ($m->is_admin) { |
| 360 |
$out = sprintf "%-29s \@i(%s)", "\@bold(OWL ADMIN)", $m->header; |
| 361 |
$tmp=$m->body; |
| 362 |
$tmp=~s/^/ /g; |
| 363 |
$tmp=~s/\n/\n /g; |
| 364 |
$out.="\n".$tmp; |
| 365 |
return $out; |
| 366 |
} |
| 367 |
|
| 368 |
my $sender=$m->pretty_sender; |
| 369 |
|
| 370 |
if ($m->is_outgoing) { |
| 371 |
my $target = $m->recipient; |
| 372 |
if ($m->is_zephyr) { |
| 373 |
$target = $m->zwriteline; |
| 374 |
$target =~ s/^zwrite //; |
| 375 |
} |
| 376 |
$out = sprintf "%-15s %-13s", "\@bold(OUTGOING)", "to $target via ".$m->type.": "; |
| 377 |
my $pagewidth = owl::getnumcols()-6; |
| 378 |
$out .= fill_text($m->body, $pagewidth, 22, 1); |
| 379 |
return $out; |
| 380 |
} |
| 381 |
|
| 382 |
if (!$m->is_zephyr && !$m->is_aim) { |
| 383 |
return "Unknown message type: ".$m->type."\n"; |
| 384 |
} |
| 385 |
|
| 386 |
if ($m->is_zephyr && $m->is_ping) { |
| 387 |
return (sprintf "%-15s %-13s\n", "\@bold(PING)", $sender); |
| 388 |
} elsif ($m->is_loginout) { |
| 389 |
my $state; |
| 390 |
if ($m->is_login) { |
| 391 |
$state="\@bold(LOGIN)"; |
| 392 |
} elsif ($m->is_logout) { |
| 393 |
$state="\@bold(LOGOUT)"; |
| 394 |
} else { |
| 395 |
$state="\@bold(UNKNOWN)"; |
| 396 |
} |
| 397 |
my $out = sprintf "%-15s %-13s ", $state, $sender; |
| 398 |
if ($m->is_zephyr) { |
| 399 |
$out .= sprintf "via %s on %s at %s", $m->type, $m->login_host, $m->login_tty; |
| 400 |
} else { |
| 401 |
$out .= sprintf "via %s", $m->type; |
| 402 |
} |
| 403 |
return "$out\n"; |
| 404 |
|
| 405 |
} elsif ($m->is_zephyr && $m->is_mail) { |
| 406 |
my $body = $m->body; |
| 407 |
$out = sprintf "%-15s %-13s ", "\@bold(MAIL)", ""; |
| 408 |
if ($body =~ /^From:\s+(.+)\s*$/m) { $out .= "From $1 "; } |
| 409 |
if ($body =~ /^To:\s+(.+)\s*$/m) { $out .= "To $1 "; } |
| 410 |
if ($body =~ /^Subject:\s+(.+)\s*$/m) { $out .= "Subject $1 "; } |
| 411 |
return($out."\n"); |
| 412 |
} |
| 413 |
|
| 414 |
my $channel = ""; |
| 415 |
my $body = $m->body; |
| 416 |
|
| 417 |
if ($m->is_zephyr) { |
| 418 |
my $inst = $m->instance; |
| 419 |
$channel = $m->class; |
| 420 |
if (lc($m->class) ne "message" and lc($m->instance) eq "personal") { |
| 421 |
$inst = ""; |
| 422 |
} |
| 423 |
$channel .= "[".$inst."]"; |
| 424 |
$channel = substr($channel,0,13); |
| 425 |
} else { |
| 426 |
$channel = "[".$m->type."]"; |
| 427 |
} |
| 428 |
|
| 429 |
$header = sprintf "%-8s %-13s ", lc($sender), lc($channel); |
| 430 |
|
| 431 |
if ($body =~ /=/) { |
| 432 |
# indent it |
| 433 |
$out.=$header."\n".indent4($body); |
| 434 |
} else { |
| 435 |
# fill it |
| 436 |
my $pagewidth = owl::getnumcols()-6; |
| 437 |
$out .= $header; |
| 438 |
$out .= fill_text($body, $pagewidth, 22, 1); |
| 439 |
} |
| 440 |
|
| 441 |
# note: no zsig added in this version |
| 442 |
|
| 443 |
# make personal messages bold |
| 444 |
if ($m->is_personal) { |
| 445 |
$out="\@bold{".$out."}"; |
| 446 |
} |
| 447 |
return($out); |
| 448 |
} |
| 449 |
|
| 450 |
sub fill_text { |
| 451 |
my ($in, $width, $indent, $unindent_first) = @_; |
| 452 |
$indent = 0 if (@_ < 3); |
| 453 |
my $unindent = $indent if ($unindent_first); |
| 454 |
my @words = split " ", $in; |
| 455 |
my $out = ""; |
| 456 |
my $outline = ""; |
| 457 |
if (!$unindent_first) { |
| 458 |
my $outline = " "x$indent; |
| 459 |
} |
| 460 |
for my $w (@words) { |
| 461 |
if (($outline ne "") |
| 462 |
&& (length($outline)+length($w) > $width-$unindent)) { |
| 463 |
$out .= $outline."\n"; |
| 464 |
$outline = " "x$indent; |
| 465 |
$unindent = 0; |
| 466 |
} |
| 467 |
if ($outline =~ /.*\.$/) { |
| 468 |
$outline .= " "; |
| 469 |
} elsif ($outline ne "") { |
| 470 |
$outline .= " "; |
| 471 |
} |
| 472 |
$outline .= $w; |
| 473 |
} |
| 474 |
$out .= $outline . "\n"; |
| 475 |
} |