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