1 | # $Id$ |
---|
2 | # |
---|
3 | # This is all linked into the binary and evaluated when perl starts up... |
---|
4 | # |
---|
5 | ##################################################################### |
---|
6 | ##################################################################### |
---|
7 | # XXX NOTE: This file is sourced before almost any barnowl |
---|
8 | # architecture is loaded. This means, for example, that it cannot |
---|
9 | # execute any owl commands. Any code that needs to do so, should |
---|
10 | # create a function wrapping it and push it onto @onStartSubs |
---|
11 | |
---|
12 | |
---|
13 | use strict; |
---|
14 | use warnings; |
---|
15 | |
---|
16 | package BarnOwl; |
---|
17 | |
---|
18 | |
---|
19 | BEGIN { |
---|
20 | # bootstrap in C bindings and glue |
---|
21 | *owl:: = \*BarnOwl::; |
---|
22 | bootstrap BarnOwl 1.2; |
---|
23 | }; |
---|
24 | |
---|
25 | use lib(get_data_dir()."/lib"); |
---|
26 | use lib($ENV{HOME}."/.owl/lib"); |
---|
27 | |
---|
28 | our $configfile; |
---|
29 | |
---|
30 | if(!$configfile && -f $ENV{HOME} . "/.barnowlconf") { |
---|
31 | $configfile = $ENV{HOME} . "/.barnowlconf"; |
---|
32 | } |
---|
33 | $configfile ||= $ENV{HOME}."/.owlconf"; |
---|
34 | |
---|
35 | # populate global variable space for legacy owlconf files |
---|
36 | sub _format_msg_legacy_wrap { |
---|
37 | my ($m) = @_; |
---|
38 | $m->legacy_populate_global(); |
---|
39 | return &BarnOwl::format_msg($m); |
---|
40 | } |
---|
41 | |
---|
42 | # populate global variable space for legacy owlconf files |
---|
43 | sub _receive_msg_legacy_wrap { |
---|
44 | my ($m) = @_; |
---|
45 | $m->legacy_populate_global(); |
---|
46 | return &BarnOwl::Hooks::receive_msg($m); |
---|
47 | } |
---|
48 | |
---|
49 | # make BarnOwl::<command>("foo") be aliases to BarnOwl::command("<command> foo"); |
---|
50 | sub AUTOLOAD { |
---|
51 | our $AUTOLOAD; |
---|
52 | my $called = $AUTOLOAD; |
---|
53 | $called =~ s/.*:://; |
---|
54 | $called =~ s/_/-/g; |
---|
55 | return &BarnOwl::command("$called ".join(" ",@_)); |
---|
56 | } |
---|
57 | |
---|
58 | =head2 new_command NAME FUNC [{ARGS}] |
---|
59 | |
---|
60 | Add a new owl command. When owl executes the command NAME, FUNC will |
---|
61 | be called with the arguments passed to the command, with NAME as the |
---|
62 | first argument. |
---|
63 | |
---|
64 | ARGS should be a hashref containing any or all of C<summary>, |
---|
65 | C<usage>, or C<description> keys. |
---|
66 | |
---|
67 | =cut |
---|
68 | |
---|
69 | sub new_command { |
---|
70 | my $name = shift; |
---|
71 | my $func = shift; |
---|
72 | my $args = shift || {}; |
---|
73 | my %args = ( |
---|
74 | summary => undef, |
---|
75 | usage => undef, |
---|
76 | description => undef, |
---|
77 | %{$args} |
---|
78 | ); |
---|
79 | |
---|
80 | no warnings 'uninitialized'; |
---|
81 | BarnOwl::new_command_internal($name, $func, $args{summary}, $args{usage}, $args{description}); |
---|
82 | } |
---|
83 | |
---|
84 | ##################################################################### |
---|
85 | ##################################################################### |
---|
86 | |
---|
87 | package BarnOwl::Message; |
---|
88 | |
---|
89 | sub new { |
---|
90 | my $class = shift; |
---|
91 | my %args = (@_); |
---|
92 | if($class eq __PACKAGE__ && $args{type}) { |
---|
93 | $class = "BarnOwl::Message::" . ucfirst $args{type}; |
---|
94 | } |
---|
95 | return bless {%args}, $class; |
---|
96 | } |
---|
97 | |
---|
98 | sub type { return shift->{"type"}; } |
---|
99 | sub direction { return shift->{"direction"}; } |
---|
100 | sub time { return shift->{"time"}; } |
---|
101 | sub id { return shift->{"id"}; } |
---|
102 | sub body { return shift->{"body"}; } |
---|
103 | sub sender { return shift->{"sender"}; } |
---|
104 | sub recipient { return shift->{"recipient"}; } |
---|
105 | sub login { return shift->{"login"}; } |
---|
106 | sub is_private { return shift->{"private"}; } |
---|
107 | |
---|
108 | sub is_login { return shift->login eq "login"; } |
---|
109 | sub is_logout { return shift->login eq "logout"; } |
---|
110 | sub is_loginout { my $m=shift; return ($m->is_login or $m->is_logout); } |
---|
111 | sub is_incoming { return (shift->{"direction"} eq "in"); } |
---|
112 | sub is_outgoing { return (shift->{"direction"} eq "out"); } |
---|
113 | |
---|
114 | sub is_deleted { return shift->{"deleted"}; } |
---|
115 | |
---|
116 | sub is_admin { return (shift->{"type"} eq "admin"); } |
---|
117 | sub is_generic { return (shift->{"type"} eq "generic"); } |
---|
118 | sub is_zephyr { return (shift->{"type"} eq "zephyr"); } |
---|
119 | sub is_aim { return (shift->{"type"} eq "AIM"); } |
---|
120 | sub is_jabber { return (shift->{"type"} eq "jabber"); } |
---|
121 | sub is_icq { return (shift->{"type"} eq "icq"); } |
---|
122 | sub is_yahoo { return (shift->{"type"} eq "yahoo"); } |
---|
123 | sub is_msn { return (shift->{"type"} eq "msn"); } |
---|
124 | sub is_loopback { return (shift->{"type"} eq "loopback"); } |
---|
125 | |
---|
126 | # These are overridden by appropriate message types |
---|
127 | sub is_ping { return 0; } |
---|
128 | sub is_mail { return 0; } |
---|
129 | sub is_personal { return shift->is_private; } |
---|
130 | sub class { return undef; } |
---|
131 | sub instance { return undef; } |
---|
132 | sub realm { return undef; } |
---|
133 | sub opcode { return undef; } |
---|
134 | sub header { return undef; } |
---|
135 | sub host { return undef; } |
---|
136 | sub hostname { return undef; } |
---|
137 | sub auth { return undef; } |
---|
138 | sub fields { return undef; } |
---|
139 | sub zsig { return undef; } |
---|
140 | sub zwriteline { return undef; } |
---|
141 | sub login_host { return undef; } |
---|
142 | sub login_tty { return undef; } |
---|
143 | |
---|
144 | sub pretty_sender { return shift->sender; } |
---|
145 | sub pretty_recipient { return shift->recipient; } |
---|
146 | |
---|
147 | sub delete { |
---|
148 | my ($m) = @_; |
---|
149 | &BarnOwl::command("delete --id ".$m->id); |
---|
150 | } |
---|
151 | |
---|
152 | sub undelete { |
---|
153 | my ($m) = @_; |
---|
154 | &BarnOwl::command("undelete --id ".$m->id); |
---|
155 | } |
---|
156 | |
---|
157 | # Serializes the message into something similar to the zwgc->vt format |
---|
158 | sub serialize { |
---|
159 | my ($this) = @_; |
---|
160 | my $s; |
---|
161 | for my $f (keys %$this) { |
---|
162 | my $val = $this->{$f}; |
---|
163 | if (ref($val) eq "ARRAY") { |
---|
164 | for my $i (0..@$val-1) { |
---|
165 | my $aval; |
---|
166 | $aval = $val->[$i]; |
---|
167 | $aval =~ s/\n/\n$f.$i: /g; |
---|
168 | $s .= "$f.$i: $aval\n"; |
---|
169 | } |
---|
170 | } else { |
---|
171 | $val =~ s/\n/\n$f: /g; |
---|
172 | $s .= "$f: $val\n"; |
---|
173 | } |
---|
174 | } |
---|
175 | return $s; |
---|
176 | } |
---|
177 | |
---|
178 | # Populate the annoying legacy global variables |
---|
179 | sub legacy_populate_global { |
---|
180 | my ($m) = @_; |
---|
181 | $BarnOwl::direction = $m->direction ; |
---|
182 | $BarnOwl::type = $m->type ; |
---|
183 | $BarnOwl::id = $m->id ; |
---|
184 | $BarnOwl::class = $m->class ; |
---|
185 | $BarnOwl::instance = $m->instance ; |
---|
186 | $BarnOwl::recipient = $m->recipient ; |
---|
187 | $BarnOwl::sender = $m->sender ; |
---|
188 | $BarnOwl::realm = $m->realm ; |
---|
189 | $BarnOwl::opcode = $m->opcode ; |
---|
190 | $BarnOwl::zsig = $m->zsig ; |
---|
191 | $BarnOwl::msg = $m->body ; |
---|
192 | $BarnOwl::time = $m->time ; |
---|
193 | $BarnOwl::host = $m->host ; |
---|
194 | $BarnOwl::login = $m->login ; |
---|
195 | $BarnOwl::auth = $m->auth ; |
---|
196 | if ($m->fields) { |
---|
197 | @BarnOwl::fields = @{$m->fields}; |
---|
198 | @main::fields = @{$m->fields}; |
---|
199 | } else { |
---|
200 | @BarnOwl::fields = undef; |
---|
201 | @main::fields = undef; |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | sub smartfilter { |
---|
206 | die("smartfilter not supported for this message"); |
---|
207 | } |
---|
208 | |
---|
209 | # Display fields -- overridden by subclasses when needed |
---|
210 | sub login_type {""} |
---|
211 | sub login_extra {""} |
---|
212 | sub long_sender {""} |
---|
213 | |
---|
214 | # The context in which a non-personal message was sent, e.g. a chat or |
---|
215 | # class |
---|
216 | sub context {""} |
---|
217 | |
---|
218 | # Some indicator of context *within* $self->context. e.g. the zephyr |
---|
219 | # instance |
---|
220 | sub subcontext {""} |
---|
221 | |
---|
222 | ##################################################################### |
---|
223 | ##################################################################### |
---|
224 | |
---|
225 | package BarnOwl::Message::Admin; |
---|
226 | |
---|
227 | use base qw( BarnOwl::Message ); |
---|
228 | |
---|
229 | sub header { return shift->{"header"}; } |
---|
230 | |
---|
231 | ##################################################################### |
---|
232 | ##################################################################### |
---|
233 | |
---|
234 | package BarnOwl::Message::Generic; |
---|
235 | |
---|
236 | use base qw( BarnOwl::Message ); |
---|
237 | |
---|
238 | ##################################################################### |
---|
239 | ##################################################################### |
---|
240 | |
---|
241 | package BarnOwl::Message::AIM; |
---|
242 | |
---|
243 | use base qw( BarnOwl::Message ); |
---|
244 | |
---|
245 | # all non-loginout AIM messages are personal for now... |
---|
246 | sub is_personal { |
---|
247 | return !(shift->is_loginout); |
---|
248 | } |
---|
249 | |
---|
250 | ##################################################################### |
---|
251 | ##################################################################### |
---|
252 | |
---|
253 | package BarnOwl::Message::Zephyr; |
---|
254 | |
---|
255 | use base qw( BarnOwl::Message ); |
---|
256 | |
---|
257 | sub login_type { |
---|
258 | return (shift->zsig eq "") ? "(PSEUDO)" : ""; |
---|
259 | } |
---|
260 | |
---|
261 | sub login_extra { |
---|
262 | my $m = shift; |
---|
263 | return undef if (!$m->is_loginout); |
---|
264 | my $s = lc($m->host); |
---|
265 | $s .= " " . $m->login_tty if defined $m->login_tty; |
---|
266 | return $s; |
---|
267 | } |
---|
268 | |
---|
269 | sub long_sender { |
---|
270 | my $m = shift; |
---|
271 | return $m->zsig; |
---|
272 | } |
---|
273 | |
---|
274 | sub context { |
---|
275 | return shift->class; |
---|
276 | } |
---|
277 | |
---|
278 | sub subcontext { |
---|
279 | return shift->instance; |
---|
280 | } |
---|
281 | |
---|
282 | sub login_tty { |
---|
283 | my ($m) = @_; |
---|
284 | return undef if (!$m->is_loginout); |
---|
285 | return $m->fields->[2]; |
---|
286 | } |
---|
287 | |
---|
288 | sub login_host { |
---|
289 | my ($m) = @_; |
---|
290 | return undef if (!$m->is_loginout); |
---|
291 | return $m->fields->[0]; |
---|
292 | } |
---|
293 | |
---|
294 | sub zwriteline { return shift->{"zwriteline"}; } |
---|
295 | |
---|
296 | sub is_ping { return (lc(shift->opcode) eq "ping"); } |
---|
297 | |
---|
298 | sub is_personal { |
---|
299 | my ($m) = @_; |
---|
300 | return ((lc($m->class) eq "message") |
---|
301 | && (lc($m->instance) eq "personal") |
---|
302 | && $m->is_private); |
---|
303 | } |
---|
304 | |
---|
305 | sub is_mail { |
---|
306 | my ($m) = @_; |
---|
307 | return ((lc($m->class) eq "mail") && $m->is_private); |
---|
308 | } |
---|
309 | |
---|
310 | sub pretty_sender { |
---|
311 | my ($m) = @_; |
---|
312 | my $sender = $m->sender; |
---|
313 | my $realm = BarnOwl::zephyr_getrealm(); |
---|
314 | $sender =~ s/\@$realm$//; |
---|
315 | return $sender; |
---|
316 | } |
---|
317 | |
---|
318 | sub pretty_recipient { |
---|
319 | my ($m) = @_; |
---|
320 | my $recip = $m->recipient; |
---|
321 | my $realm = BarnOwl::zephyr_getrealm(); |
---|
322 | $recip =~ s/\@$realm$//; |
---|
323 | return $recip; |
---|
324 | } |
---|
325 | |
---|
326 | # These are arguably zephyr-specific |
---|
327 | sub class { return shift->{"class"}; } |
---|
328 | sub instance { return shift->{"instance"}; } |
---|
329 | sub realm { return shift->{"realm"}; } |
---|
330 | sub opcode { return shift->{"opcode"}; } |
---|
331 | sub host { return shift->{"hostname"}; } |
---|
332 | sub hostname { return shift->{"hostname"}; } |
---|
333 | sub header { return shift->{"header"}; } |
---|
334 | sub auth { return shift->{"auth"}; } |
---|
335 | sub fields { return shift->{"fields"}; } |
---|
336 | sub zsig { return shift->{"zsig"}; } |
---|
337 | |
---|
338 | ##################################################################### |
---|
339 | ##################################################################### |
---|
340 | ################################################################################ |
---|
341 | package BarnOwl; |
---|
342 | |
---|
343 | ################################################################################ |
---|
344 | # Mainloop hook |
---|
345 | ################################################################################ |
---|
346 | |
---|
347 | our $shutdown; |
---|
348 | $shutdown = 0; |
---|
349 | our $reload; |
---|
350 | $reload = 0; |
---|
351 | |
---|
352 | #Run this on start and reload. Adds modules |
---|
353 | sub onStart |
---|
354 | { |
---|
355 | _load_owlconf(); |
---|
356 | reload_init(); |
---|
357 | loadModules(); |
---|
358 | } |
---|
359 | ################################################################################ |
---|
360 | # Reload Code, taken from /afs/sipb/user/jdaniel/project/owl/perl |
---|
361 | ################################################################################ |
---|
362 | sub reload_hook (@) |
---|
363 | { |
---|
364 | BarnOwl::Hooks::startup(); |
---|
365 | return 1; |
---|
366 | } |
---|
367 | |
---|
368 | sub reload |
---|
369 | { |
---|
370 | # Use $reload to tell modules that we're performing a reload. |
---|
371 | { |
---|
372 | local $reload = 1; |
---|
373 | BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE}; |
---|
374 | } |
---|
375 | |
---|
376 | @BarnOwl::Hooks::onMainLoop = (); |
---|
377 | @BarnOwl::Hooks::onStartSubs = (); |
---|
378 | |
---|
379 | # Do reload |
---|
380 | package main; |
---|
381 | if (-r $BarnOwl::configfile) { |
---|
382 | undef $@; |
---|
383 | do $BarnOwl::configfile; |
---|
384 | BarnOwl::error("Error reloading $BarnOwl::configfile: $@") if $@; |
---|
385 | } |
---|
386 | BarnOwl::reload_hook(@_); |
---|
387 | package BarnOwl; |
---|
388 | } |
---|
389 | |
---|
390 | sub reload_init () |
---|
391 | { |
---|
392 | BarnOwl::command('alias reload perl BarnOwl::reload()'); |
---|
393 | BarnOwl::command('bindkey global "C-x C-r" command reload'); |
---|
394 | } |
---|
395 | |
---|
396 | ################################################################################ |
---|
397 | # Loads modules from ~/.owl/modules and owl's data directory |
---|
398 | ################################################################################ |
---|
399 | |
---|
400 | sub loadModules () { |
---|
401 | my @modules; |
---|
402 | my $rv; |
---|
403 | foreach my $dir ( BarnOwl::get_data_dir() . "/modules", |
---|
404 | $ENV{HOME} . "/.owl/modules" ) |
---|
405 | { |
---|
406 | opendir( MODULES, $dir ); |
---|
407 | |
---|
408 | # source ./modules/*.pl |
---|
409 | @modules = sort grep( /\.pl$/, readdir(MODULES) ); |
---|
410 | |
---|
411 | foreach my $mod (@modules) { |
---|
412 | unless ($rv = do "$dir/$mod") { |
---|
413 | BarnOwl::error("Couldn't load $dir/$mod:\n $@") if $@; |
---|
414 | BarnOwl::error("Couldn't run $dir/$mod:\n $!") unless defined $rv; |
---|
415 | } |
---|
416 | } |
---|
417 | closedir(MODULES); |
---|
418 | } |
---|
419 | } |
---|
420 | |
---|
421 | sub _load_owlconf { |
---|
422 | # Only do this the first time |
---|
423 | return if $BarnOwl::reload; |
---|
424 | # load the config file |
---|
425 | if ( -r $BarnOwl::configfile ) { |
---|
426 | undef $@; |
---|
427 | package main; |
---|
428 | do $BarnOwl::configfile; |
---|
429 | die $@ if $@; |
---|
430 | package BarnOwl; |
---|
431 | } |
---|
432 | } |
---|
433 | |
---|
434 | package BarnOwl::Hooks; |
---|
435 | |
---|
436 | # Arrays of subrefs to be called at specific times. |
---|
437 | our @onStartSubs = (); |
---|
438 | our @onReceiveMsg = (); |
---|
439 | our @onMainLoop = (); |
---|
440 | our @onGetBuddyList = (); |
---|
441 | |
---|
442 | # Functions to call hook lists |
---|
443 | sub runHook($@) |
---|
444 | { |
---|
445 | my $hook = shift; |
---|
446 | my @args = @_; |
---|
447 | $_->(@args) for (@$hook); |
---|
448 | } |
---|
449 | |
---|
450 | sub runHook_accumulate($@) |
---|
451 | { |
---|
452 | my $hook = shift; |
---|
453 | my @args = @_; |
---|
454 | return join("\n", map {$_->(@args)} @$hook); |
---|
455 | } |
---|
456 | |
---|
457 | ################################################################################ |
---|
458 | # Startup and Shutdown code |
---|
459 | ################################################################################ |
---|
460 | sub startup |
---|
461 | { |
---|
462 | # Modern versions of owl provides a great place to have startup stuff. |
---|
463 | # Put things in ~/.owl/startup |
---|
464 | |
---|
465 | #So that the user's .owlconf can have startsubs, we don't clear |
---|
466 | #onStartSubs; reload does however |
---|
467 | @onReceiveMsg = (); |
---|
468 | @onMainLoop = (); |
---|
469 | @onGetBuddyList = (); |
---|
470 | |
---|
471 | BarnOwl::onStart(); |
---|
472 | |
---|
473 | runHook(\@onStartSubs); |
---|
474 | |
---|
475 | BarnOwl::startup() if *BarnOwl::startup{CODE}; |
---|
476 | } |
---|
477 | |
---|
478 | sub shutdown |
---|
479 | { |
---|
480 | # Modern versions of owl provides a great place to have shutdown stuff. |
---|
481 | # Put things in ~/.owl/shutdown |
---|
482 | |
---|
483 | # use $shutdown to tell modules that that's what we're doing. |
---|
484 | $BarnOwl::shutdown = 1; |
---|
485 | BarnOwl::mainloop_hook(); |
---|
486 | |
---|
487 | BarnOwl::shutdown() if *BarnOwl::shutdown{CODE}; |
---|
488 | } |
---|
489 | |
---|
490 | sub mainloop_hook |
---|
491 | { |
---|
492 | runHook(\@onMainLoop); |
---|
493 | BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE}; |
---|
494 | } |
---|
495 | |
---|
496 | ################################################################################ |
---|
497 | # Hooks into receive_msg() |
---|
498 | ################################################################################ |
---|
499 | |
---|
500 | sub receive_msg |
---|
501 | { |
---|
502 | my $m = shift; |
---|
503 | runHook(\@onReceiveMsg, $m); |
---|
504 | BarnOwl::receive_msg($m) if *BarnOwl::receive_msg{CODE}; |
---|
505 | } |
---|
506 | |
---|
507 | ################################################################################ |
---|
508 | # Hooks into get_blist() |
---|
509 | ################################################################################ |
---|
510 | |
---|
511 | sub get_blist |
---|
512 | { |
---|
513 | return runHook_accumulate(\@onGetBuddyList); |
---|
514 | } |
---|
515 | |
---|
516 | ################################################################################ |
---|
517 | # Built-in perl styles |
---|
518 | ################################################################################ |
---|
519 | package BarnOwl::Style::Default; |
---|
520 | ################################################################################ |
---|
521 | # Branching point for various formatting functions in this style. |
---|
522 | ################################################################################ |
---|
523 | sub format_message($) |
---|
524 | { |
---|
525 | my $m = shift; |
---|
526 | |
---|
527 | if ( $m->is_loginout) { |
---|
528 | return format_login($m); |
---|
529 | } elsif($m->is_ping) { |
---|
530 | return ( "\@b(PING) from \@b(" . $m->pretty_sender . ")\n" ); |
---|
531 | } elsif($m->is_admin) { |
---|
532 | return "\@bold(OWL ADMIN)\n" . indentBody($m); |
---|
533 | } else { |
---|
534 | return format_chat($m); |
---|
535 | } |
---|
536 | } |
---|
537 | |
---|
538 | BarnOwl::_create_style("default", "BarnOwl::Style::Default::format_message", "Default style"); |
---|
539 | |
---|
540 | ################################################################################ |
---|
541 | |
---|
542 | sub time_hhmm { |
---|
543 | my $m = shift; |
---|
544 | my ($time) = $m->time =~ /(\d\d:\d\d)/; |
---|
545 | return $time; |
---|
546 | } |
---|
547 | |
---|
548 | sub format_login($) { |
---|
549 | my $m = shift; |
---|
550 | return sprintf( |
---|
551 | '@b<%s%s> for @b(%s) (%s) %s', |
---|
552 | uc( $m->login ), |
---|
553 | $m->login_type, |
---|
554 | $m->pretty_sender, |
---|
555 | $m->login_extra, |
---|
556 | time_hhmm($m) |
---|
557 | ); |
---|
558 | } |
---|
559 | |
---|
560 | sub format_chat($) { |
---|
561 | my $m = shift; |
---|
562 | my $header; |
---|
563 | if ( $m->is_personal ) { |
---|
564 | if ( $m->direction eq "out" ) { |
---|
565 | $header = ucfirst $m->type . " sent to " . $m->pretty_recipient; |
---|
566 | } else { |
---|
567 | $header = ucfirst $m->type . " from " . $m->pretty_sender; |
---|
568 | } |
---|
569 | } else { |
---|
570 | $header = $m->context; |
---|
571 | if($m->subcontext) { |
---|
572 | $header .= ' / ' . $m->subcontext; |
---|
573 | } |
---|
574 | $header .= ' / @b{' . $m->pretty_sender . '}'; |
---|
575 | } |
---|
576 | |
---|
577 | $header .= " " . time_hhmm($m); |
---|
578 | my $sender = $m->long_sender; |
---|
579 | $sender =~ s/\n.*$//s; |
---|
580 | $header .= "\t(" . $sender . ")"; |
---|
581 | my $message = $header . "\n". indentBody($m); |
---|
582 | if($m->is_private && $m->direction eq "in") { |
---|
583 | $message = BarnOwl::Style::boldify($message); |
---|
584 | } |
---|
585 | return $message; |
---|
586 | } |
---|
587 | |
---|
588 | sub indentBody($) |
---|
589 | { |
---|
590 | my $m = shift; |
---|
591 | |
---|
592 | my $body = $m->body; |
---|
593 | # replace newline followed by anything with |
---|
594 | # newline plus four spaces and that thing. |
---|
595 | $body =~ s/\n(.)/\n $1/g; |
---|
596 | |
---|
597 | return " ".$body; |
---|
598 | } |
---|
599 | |
---|
600 | |
---|
601 | package BarnOwl::Style; |
---|
602 | |
---|
603 | # This takes a zephyr to be displayed and modifies it to be displayed |
---|
604 | # entirely in bold. |
---|
605 | sub boldify($) |
---|
606 | { |
---|
607 | local $_ = shift; |
---|
608 | if ( !(/\)/) ) { |
---|
609 | return '@b(' . $_ . ')'; |
---|
610 | } elsif ( !(/\>/) ) { |
---|
611 | return '@b<' . $_ . '>'; |
---|
612 | } elsif ( !(/\}/) ) { |
---|
613 | return '@b{' . $_ . '}'; |
---|
614 | } elsif ( !(/\]/) ) { |
---|
615 | return '@b[' . $_ . ']'; |
---|
616 | } else { |
---|
617 | my $txt = "\@b($_"; |
---|
618 | $txt =~ s/\)/\)\@b\[\)\]\@b\(/g; |
---|
619 | return $txt . ')'; |
---|
620 | } |
---|
621 | } |
---|
622 | |
---|
623 | |
---|
624 | # switch to package main when we're done |
---|
625 | package main; |
---|
626 | # alias the hooks |
---|
627 | { |
---|
628 | no strict 'refs'; |
---|
629 | foreach my $hook qw (onStartSubs |
---|
630 | onReceiveMsg |
---|
631 | onMainLoop |
---|
632 | onGetBuddyList ) { |
---|
633 | *{"main::".$hook} = \*{"BarnOwl::Hooks::".$hook}; |
---|
634 | *{"owl::".$hook} = \*{"BarnOwl::Hooks::".$hook}; |
---|
635 | } |
---|
636 | } |
---|
637 | |
---|
638 | 1; |
---|