source: examples/owlconf.erik @ 488ebf6

owl
Last change on this file since 488ebf6 was dab82f29, checked in by James M. Kretchmar <kretch@mit.edu>, 16 years ago
Don't crash on mobile device AIM messages [BZ 20] Don't crash when sending to someone not on AIM buddy list [BZ 94] Fix overflow vulerability in zwrite.c and zcrypt.c Add stack protector and -D_FORTIFY_SOURCE=2 where possible Fix hang [barnowl 4c46dfdebc294ca24fef59924f01688b8ee07dee] Fix segfault on missing subs [barnowl 99dabeed7de6d19acb50f1e73aa0bfe5f9469c02] Fix zcrypt bufffer size bug [barnowl 559076cd86edc3a8317819814dd5877b8bc7c3cb] Fix double free [barnowl e97c4a306ae2c9d2147d83da29fee59918198e70] Memory leak fix [barnowl c0a90c2c7ab97b9465c9873757faf312faa0021e] Memory leak fix [barnowl 95caa16b2e9ba10770d87d0955198c14c2d0e16a] Memory leak fix [barnowl 1716fed8c2650e46892cf6571555eac937266c6e] Add getstyle command [barnowl 216c73421653e3ef0e957aa9a9804e208a77c80e] Binary search for msgid [barnowl 0c8ab5eadbb6ecc97a120c91b9a824b33538c764] File-handle leak [barnowl e78397d6ac5da0de31a4e269c0ba7f3d691857a3] Fix delay in jump from top to bottom [barnowl 801b7ac63b962640debbcfd422cb9a60da5fea31] Load subs in chunks [barnowl 93e883d60051b80bf6d35391f9d76fd7dfd198e3] Load subs in chunks [barnowl f6050ee9b0a171a5031f84409eb181062afacd18] Better zsig logging [barnowl d857b667a5a9b108b1a2a26b4a5513bef2b53f80] free() -> owlfree() [barnowl d524c838ac7c115628424b8ac171c3489622ea3a] Escape AIM users in smartfilters [barnowl af9b92e3e7ccb7de276a94b5c7e5861b24e71eff] Better regex escape chars [barnowl 80e54a7631f091be8c9762adb9746bad38104738] Deal with quotes in smart filters [barnowl 4099cf83702763fa8d1efc4f1582a605431bdb77] Deal with 0 length zephyr fields [barnowl 128171aaf7cefa91a4bb1eada93a19d8fd0c355c] Deal with 0 length zephyr fields [barnowl 50e29e35c64d64e223d378d350a7bc4f038d78f5] Deal with 0 length zephyr fields [barnowl 804ab8af8b6d00bcd7e2402df892db8fbd61a3ec] Leave curmsg on screen after resize [barnowl c0f9e3009bc03e80a44de64cd5f2b4033290236e] Rip out brower stuff [barnowl 8e5935d11c699a7ce5a3e6e9a47799564c696d6a] Rip out browser stuff [barnowl 4f15e8e9ceada0d4b2cc969ebf43b0a1fb3709ea] No passwords in command history [barnowl 6e400cc71aa59e041dce677aadf50dc1f25228e2] Format NOC mssages [barnowl a1bb1980e4bca23b8329cc0e7c0bd5027055ea0a] Expand ~ in loadsubs [barnowl 27d8d835dc6d58c08fae10e75aae306c49215143] Expand ~ in source [barnowl 10d67d57cb29221f63a43a30643c697fc7b38911] Only use resizeterm() if it's available Debian backports Change license to GPLv3
  • Property mode set to 100644
File size: 12.8 KB
Line 
1### The owlconf config file   -*- perl -*- 
2###  $Id$
3###
4### !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!!
5### This is an example file intended to demonstrate how to use
6### various features of owl.  Some of the key bindings, in particular,
7### are more for examples than things you may actually want to use.
8### Make sure to read through it first and understand it before just using it.
9### Don't blame me if anything in here ends up vaporizing your dog.
10### !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!!
11###
12###
13### This file is interpreted by the perl interpreter.
14### If you wish to execute an owl command use the
15### function owl::command().  i.e.
16###
17###      owl::command("set zsigproc /mit/kretch/bin/getzsig");
18###
19### will set the owl variable zsigproc.  Subroutines created with
20### the names below will be executed at the specified times:
21###
22###     subroutine name    properties
23###     ---------------    ----------
24###     owl::startup()     run when owl first starts
25###     owl::shutdown()    run when owl exits
26###     owl::format_msg()  formats messages that are passed to it
27###     owl::receive_msg() run when a message is received, and after
28###                        it has been added to the message list
29###
30### The format_msg and receive_msg functions are passed owl::Message objects.
31### The message attributes may be dereferenced with $m->attribute
32###
33###   
34
35# tokens for sepbar are:
36#    .username = ping
37#    >username = login
38#    <username = logout
39#    :username = personal message
40#    M         = mail received
41my @sepbartokens = ();
42
43# Map for mail messages from msg id to pop msg id
44my %mail_id_map = ();
45
46# (originally from jdaniel)
47sub 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
57sub 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
67sub zlocatesender {
68    my $m = owl::getcurmsg();
69    if ($m->{"type"} eq "zephyr") {
70        my $sender = $m->{"sender"};
71        owl::command("zlocate $sender");
72    }
73}
74
75# adds a sepbartoken and also updates the appendtosepbar variable
76sub sepbartokens_add {
77    my ($token) = @_;
78    $token =~ s/"//g;  # "
79    unshift @sepbartokens, $token;
80    pop @sepbartokens if (@sepbartokens > 80);
81    sepbartokens_set();
82}
83
84# trims a sepbartoken from the list also updates the appendtosepbar variable
85sub sepbartokens_trim {
86    my ($token) = @_;
87    @sepbartokens = map { if ($_ ne $token) { $_; } else { (); } } @sepbartokens;
88    sepbartokens_set();
89}
90
91my $loopctr=0;
92
93# trims a sepbartoken from the list also updates the appendtosepbar variable
94sub sepbartokens_set {
95    owl::command(sprintf "set -q appendtosepbar \"%s %s %s\"", (scalar localtime), (join " ", @sepbartokens));
96}
97
98my $restoreview = undef;
99sub swapview {
100    my $curview = owl::command("getview");
101    if ($restoreview) {
102        owl::command("view $restoreview");
103        $restoreview = undef;
104    } else {
105        $restoreview = $curview;
106        owl::command("smartnarrow");
107    }
108}
109
110my $lastcolored = undef;
111sub colorthread {
112    if ($lastcolored) {
113        owl::command("filter $lastcolored -c default");
114    }
115    my $smartfilt = owl::command("smartfilter");
116    if (!$smartfilt or $smartfilt eq $lastcolored) {
117        owl::command("filter $lastcolored -c default");
118        $lastcolored = undef;
119    } else {
120        owl::command("filter $smartfilt -c green");
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...
127sub 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;
135    }
136}
137
138sub owl::startup {
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");
143    owl::command("set -q startuplogin off");
144    owl::command("set -q shutdownlogout off");
145    #owl::command("set personalbell on");
146    owl::command("set -q _burningears on");
147    owl::command("set -q rxping on");
148    owl::command("set -q typewinsize 5");
149    owl::command("filter me recipient %me% or ( sender %me% and class message and instance personal ) or class mail or type aim");
150    owl::command("filter owl instance ^owl.*");
151
152    owl::command(q(alias finger pperl $x=owl::getcurmsg()->hostname; `finger \@$x`;));
153    owl::command("bindkey recv f command finger");
154
155    owl::command("alias z zwrite");
156    owl::command("alias zw zwrite");
157    owl::command("alias v view");
158
159    owl::command("alias popmail perl mail_pop_curmsg();");
160
161    # toggle between a view and a smartnarrow with TAB
162    owl::command("alias swapview perl swapview();");
163    owl::command("bindkey recv C-i command swapview");
164
165    # color the current thread
166    owl::command("alias colorthread perl colorthread();");
167    owl::command("bindkey recv M-c command colorthread");
168
169    # zlocate current sender
170    owl::command("bindkey recv L command perl zlocatesender();");
171
172    # Declare styles
173    &owl::command("style vt     perl format_msg_vt");
174    &owl::command("style brief  perl format_msg_brief");
175    &owl::command("style custom perl format_msg_custom");
176    &owl::command("style debug  perl format_msg_debug");
177    &owl::command("set -q default_style custom");
178
179    # Change to different view styles
180    owl::command("bindkey recv \"C-s v\" command view -s vt");
181    owl::command("bindkey recv \"C-s c\" command view -s custom");
182    owl::command("bindkey recv \"C-s b\" command view -s brief");
183    owl::command("bindkey recv \"C-s d\" command view -s debug");
184    owl::command("bindkey recv \"C-s o\" command view -s standard");
185
186    # For fast-reading of zephyrs
187    owl::command("bindkey recv M-k command ( smartnarrow ; delete view )");
188    owl::command("bindkey recv M-l command ( expunge ; view all )");
189    owl::command("bindkey recv M-K command ( smartnarrow ; delete view ; expunge ; view all )");
190
191    # Support for scroll mice
192    &owl::command("bindkey recv \"M-[ A\" command recv:prev");
193    &owl::command("bindkey recv \"M-[ B\" command recv:next");
194
195    # This overrides the default "M" keybinding
196    owl::command("bindkey recv M command popmail");
197
198    sepbartokens_add("...");
199
200    personal_startup();
201}
202
203sub owl::shutdown {
204#    not doing anything at the moment...
205}
206
207
208# run when a message is received, and after
209# it has been added to the message list.
210sub owl::receive_msg {
211    my ($m) = @_;
212    my ($out, $tmp);
213
214    if ($m->is_admin && !$m->is_outgoing) {
215        $m->delete();
216        return 1;
217    }
218
219    return 0 if (!$m->is_zephyr && !$m->is_aim);
220
221    my $sender = $m->pretty_sender;
222
223    if ($m->is_ping) {
224        sepbartokens_add(".$sender");
225        $m->delete();
226    } elsif ($m->is_loginout) {
227        $m->delete();
228        if ($m->is_login) {
229            sepbartokens_add(">$sender");
230            sepbartokens_trim("<$sender");
231        } elsif ($m->is_logout) {
232            sepbartokens_add("<$sender");
233            sepbartokens_trim(">$sender");
234        } 
235    } elsif ($m->is_mail) {
236        mail_add_message($m);
237        $m->delete();
238        sepbartokens_add("M");
239    }
240
241    if ($m->is_personal) {
242        sepbartokens_trim(".$sender");
243        sepbartokens_add(":$sender");
244    }
245
246    return 1;
247}
248
249sub indent4 {
250    my ($b) = @_;
251    $b=~s/^/    /g;
252    $b=~s/\n/\n    /g;   
253    return $b;
254}
255
256# run to format a message
257sub format_msg_custom {
258    my ($m) = @_;
259    my ($out, $tmp);
260
261    if ($m->is_admin) {
262        $out = "\@bold([owl admin]) ".$m->header."\n";
263        $out.=indent4($m->body);
264        return $out."\n";
265    }
266
267    my $sender=$m->pretty_sender;
268
269    if (($m->is_aim or $m->is_zephyr) && $m->is_loginout) {
270
271        if ($m->is_login) {
272            $out="\@bold(LOGIN)";
273        } elsif ($m->is_logout) {
274            $out="\@bold(LOGOUT)";
275        } else {
276            $out="\@bold(UNKNOWN)";
277        }
278        $out.=" for \@bold($sender) on ".$m->type;
279        if ($m->is_zephyr) {
280            $out.=" at ".($m->login_host)." on ".($m->login_tty);
281        }
282        return("$out\n");
283    }
284
285    if (!$m->is_zephyr && !$m->is_aim) { 
286        return "Unknown message type: ".$m->type."\n";
287    }
288
289    if ($m->is_outgoing) {
290        my $target = $m->recipient;
291        if ($m->is_zephyr) {
292            $target = $m->zwriteline;
293            $target =~ s/^zwrite //;
294        }
295        $out = sprintf "\@bold([outgoing %s to %s]) / %s\n", $m->type, $target, $m->time;
296        $out.=indent4($m->body);
297        return "$out\n";
298    }
299
300    if ($m->is_zephyr && $m->is_ping) {
301        return("\@bold(PING) from \@bold($sender)\n");
302    } elsif ($m->is_zephyr && $m->is_mail) {
303        $out = "\@bold(MAIL) ";
304        if ($m->body =~ /^From:\s+(.+)\s*$/m) { $out .= "From $1 "; }
305        if ($m->body =~ /^To:\s+(.+)\s*$/m) { $out .= "To $1 "; }
306        if ($m->body =~ /^Subject:\s+(.+)\s*$/m) { $out .= "Subject $1 "; }
307        return("$out\n");
308    }
309
310    if ($m->is_zephyr) {
311        $out = sprintf "[mit,%s,%s] / %s / %s", lc($m->class), 
312        lc($m->instance), $m->time, lc($m->host);
313        if ($m->opcode ne "") {$out.=" op:".$m->opcode;}
314        $out.="\n";
315        $out.= "  \@bold($sender)> ";
316        if ($m->zsig ne "") {
317            my $zsig = $m->zsig;
318            $zsig =~ s/(\n.*)+$/ [...]/;
319            if (length($zsig)+5+length($sender) > 70) {
320                $out.="# ...";
321            } else {
322                $out.="# $zsig";
323            }
324        }
325        $out.="\n";             
326    } else {
327        $out = sprintf "[%s] / %s\n", lc($m->type), $m->time;
328        $out.= "  \@bold($sender)> ";
329        $out.="\n";             
330    }
331
332    $out.=indent4($m->body);
333
334    # make personal messages bold
335    if ($m->is_personal) {
336        $out="\@bold{".$out."}";
337    }
338
339    return($out."\n");
340}
341
342sub format_msg_debug {
343    my ($m) = @_;
344    return "\@bold(-------------MESSAGE-------------)\n".($m->serialize).".\n";
345}
346
347sub format_msg_brief {
348    my ($m) = @_;
349    my $out = format_msg_vt($m);
350    $out =~ s/\n/ /g;
351    $out =~ s/                        / /g;
352    return($out."\n");
353}
354
355
356sub format_msg_vt {
357    my ($m) = @_;
358    my ($out, $tmp);
359
360    if ($m->is_admin) {
361        $out = sprintf "%-29s \@i(%s)", "\@bold(OWL ADMIN)", $m->header;
362        $tmp=$m->body;
363        $tmp=~s/^/                       /g;
364        $tmp=~s/\n/\n                       /g;
365        $out.="\n".$tmp;
366        return $out;
367    }
368
369    my $sender=$m->pretty_sender;
370
371    if ($m->is_outgoing) {
372        my $target = $m->recipient;
373        if ($m->is_zephyr) {
374            $target = $m->zwriteline;
375            $target =~ s/^zwrite //;
376        }
377        $out = sprintf "%-15s %-13s", "\@bold(OUTGOING)", "to $target via ".$m->type.": ";
378        my $pagewidth = owl::getnumcols()-6;
379        $out .= fill_text($m->body, $pagewidth, 22, 1);
380        return $out;
381    }
382
383    if (!$m->is_zephyr && !$m->is_aim) { 
384        return "Unknown message type: ".$m->type."\n";
385    }
386
387    if ($m->is_zephyr && $m->is_ping) {
388        return (sprintf "%-15s %-13s\n", "\@bold(PING)", $sender);
389    } elsif ($m->is_loginout) {
390        my $state;
391        if ($m->is_login) {
392            $state="\@bold(LOGIN)";
393        } elsif ($m->is_logout) {
394            $state="\@bold(LOGOUT)";
395        } else {
396            $state="\@bold(UNKNOWN)";
397        }
398        my $out = sprintf "%-15s %-13s ", $state, $sender;
399        if ($m->is_zephyr) {
400            $out .= sprintf "via %s on %s at %s", $m->type, $m->login_host, $m->login_tty;
401        } else {
402            $out .= sprintf "via %s", $m->type;
403        }
404        return "$out\n";
405               
406    } elsif ($m->is_zephyr && $m->is_mail) {
407        my $body = $m->body;
408        $out = sprintf "%-15s %-13s ", "\@bold(MAIL)", "";
409        if ($body =~ /^From:\s+(.+)\s*$/m) { $out .= "From $1 "; }
410        if ($body =~ /^To:\s+(.+)\s*$/m) { $out .= "To $1 "; }
411        if ($body =~ /^Subject:\s+(.+)\s*$/m) { $out .= "Subject $1 "; }
412        return($out."\n");
413    }
414
415    my $channel = "";
416    my $body = $m->body;
417   
418    if ($m->is_zephyr) {
419        my $inst = $m->instance;
420        $channel = $m->class;
421        if (lc($m->class) ne "message" and lc($m->instance) eq "personal") {
422            $inst = "";
423        }
424        $channel .= "[".$inst."]";
425        $channel = substr($channel,0,13);
426    } else {
427        $channel = "[".$m->type."]";
428    }
429
430    $header = sprintf "%-8s %-13s ", lc($sender), lc($channel);
431
432    if ($body =~ /=/) {
433        # indent it
434        $out.=$header."\n".indent4($body);
435    } else {
436        # fill it
437        my $pagewidth = owl::getnumcols()-6;
438        $out .= $header;
439        $out .= fill_text($body, $pagewidth, 22, 1);
440    }
441
442    # note: no zsig added in this version
443
444    # make personal messages bold
445    if ($m->is_personal) {
446        $out="\@bold{".$out."}";
447    }
448    return($out);
449}
450
451sub fill_text {
452    my ($in, $width, $indent, $unindent_first) = @_;
453    $indent = 0 if (@_ < 3);
454    my $unindent = $indent if ($unindent_first);
455    my @words = split " ", $in;
456    my $out = "";
457    my $outline = "";
458    if (!$unindent_first) {
459        my $outline = " "x$indent;
460    }
461    for my $w (@words) {
462        if (($outline ne "") 
463            && (length($outline)+length($w) > $width-$unindent)) {
464            $out .= $outline."\n";
465            $outline = " "x$indent;
466            $unindent = 0;
467        }
468        if ($outline =~ /.*\.$/) {
469            $outline .= "  ";
470        } elsif ($outline ne "") {
471            $outline .= " ";
472        }
473        $outline .= $w;
474    }
475    $out .= $outline . "\n";   
476}
Note: See TracBrowser for help on using the repository browser.