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 live |
---|
10 | # in BarnOwl::Hooks::_startup |
---|
11 | |
---|
12 | use strict; |
---|
13 | use warnings; |
---|
14 | |
---|
15 | package BarnOwl; |
---|
16 | |
---|
17 | BEGIN { |
---|
18 | # bootstrap in C bindings and glue |
---|
19 | *owl:: = \*BarnOwl::; |
---|
20 | bootstrap BarnOwl 1.2; |
---|
21 | }; |
---|
22 | |
---|
23 | use lib(get_data_dir() . "/lib"); |
---|
24 | use lib(get_config_dir() . "/lib"); |
---|
25 | |
---|
26 | # perlconfig.c will set this to the value of the -c command-line |
---|
27 | # switch, if present. |
---|
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 => "", |
---|
75 | usage => "", |
---|
76 | description => "", |
---|
77 | %{$args} |
---|
78 | ); |
---|
79 | |
---|
80 | BarnOwl::new_command_internal($name, $func, $args{summary}, $args{usage}, $args{description}); |
---|
81 | } |
---|
82 | |
---|
83 | =head2 new_variable_int NAME [{ARGS}] |
---|
84 | |
---|
85 | =head2 new_variable_bool NAME [{ARGS}] |
---|
86 | |
---|
87 | =head2 new_variable_string NAME [{ARGS}] |
---|
88 | |
---|
89 | Add a new owl variable, either an int, a bool, or a string, with the |
---|
90 | specified name. |
---|
91 | |
---|
92 | ARGS can optionally contain the following keys: |
---|
93 | |
---|
94 | =over 4 |
---|
95 | |
---|
96 | =item default |
---|
97 | |
---|
98 | The default and initial value for the variable |
---|
99 | |
---|
100 | =item summary |
---|
101 | |
---|
102 | A one-line summary of the variable's purpose |
---|
103 | |
---|
104 | =item description |
---|
105 | |
---|
106 | A longer description of the function of the variable |
---|
107 | |
---|
108 | =back |
---|
109 | |
---|
110 | =cut |
---|
111 | |
---|
112 | sub new_variable_int { |
---|
113 | unshift @_, \&BarnOwl::new_variable_int_internal, 0; |
---|
114 | goto \&_new_variable; |
---|
115 | } |
---|
116 | |
---|
117 | sub new_variable_bool { |
---|
118 | unshift @_, \&BarnOwl::new_variable_bool_internal, 0; |
---|
119 | goto \&_new_variable; |
---|
120 | } |
---|
121 | |
---|
122 | sub new_variable_string { |
---|
123 | unshift @_, \&BarnOwl::new_variable_string_internal, ""; |
---|
124 | goto \&_new_variable; |
---|
125 | } |
---|
126 | |
---|
127 | sub _new_variable { |
---|
128 | my $func = shift; |
---|
129 | my $default_default = shift; |
---|
130 | my $name = shift; |
---|
131 | my $args = shift || {}; |
---|
132 | my %args = ( |
---|
133 | summary => "", |
---|
134 | description => "", |
---|
135 | default => $default_default, |
---|
136 | %{$args}); |
---|
137 | $func->($name, $args{default}, $args{summary}, $args{description}); |
---|
138 | } |
---|
139 | |
---|
140 | ##################################################################### |
---|
141 | ##################################################################### |
---|
142 | |
---|
143 | package BarnOwl::Message; |
---|
144 | |
---|
145 | sub new { |
---|
146 | my $class = shift; |
---|
147 | my %args = (@_); |
---|
148 | if($class eq __PACKAGE__ && $args{type}) { |
---|
149 | $class = "BarnOwl::Message::" . ucfirst $args{type}; |
---|
150 | } |
---|
151 | return bless {%args}, $class; |
---|
152 | } |
---|
153 | |
---|
154 | sub type { return shift->{"type"}; } |
---|
155 | sub direction { return shift->{"direction"}; } |
---|
156 | sub time { return shift->{"time"}; } |
---|
157 | sub id { return shift->{"id"}; } |
---|
158 | sub body { return shift->{"body"}; } |
---|
159 | sub sender { return shift->{"sender"}; } |
---|
160 | sub recipient { return shift->{"recipient"}; } |
---|
161 | sub login { return shift->{"login"}; } |
---|
162 | sub is_private { return shift->{"private"}; } |
---|
163 | |
---|
164 | sub is_login { return shift->login eq "login"; } |
---|
165 | sub is_logout { return shift->login eq "logout"; } |
---|
166 | sub is_loginout { my $m=shift; return ($m->is_login or $m->is_logout); } |
---|
167 | sub is_incoming { return (shift->{"direction"} eq "in"); } |
---|
168 | sub is_outgoing { return (shift->{"direction"} eq "out"); } |
---|
169 | |
---|
170 | sub is_deleted { return shift->{"deleted"}; } |
---|
171 | |
---|
172 | sub is_admin { return (shift->{"type"} eq "admin"); } |
---|
173 | sub is_generic { return (shift->{"type"} eq "generic"); } |
---|
174 | sub is_zephyr { return (shift->{"type"} eq "zephyr"); } |
---|
175 | sub is_aim { return (shift->{"type"} eq "AIM"); } |
---|
176 | sub is_jabber { return (shift->{"type"} eq "jabber"); } |
---|
177 | sub is_icq { return (shift->{"type"} eq "icq"); } |
---|
178 | sub is_yahoo { return (shift->{"type"} eq "yahoo"); } |
---|
179 | sub is_msn { return (shift->{"type"} eq "msn"); } |
---|
180 | sub is_loopback { return (shift->{"type"} eq "loopback"); } |
---|
181 | |
---|
182 | # These are overridden by appropriate message types |
---|
183 | sub is_ping { return 0; } |
---|
184 | sub is_mail { return 0; } |
---|
185 | sub is_personal { return shift->is_private; } |
---|
186 | sub class { return undef; } |
---|
187 | sub instance { return undef; } |
---|
188 | sub realm { return undef; } |
---|
189 | sub opcode { return undef; } |
---|
190 | sub header { return undef; } |
---|
191 | sub host { return undef; } |
---|
192 | sub hostname { return undef; } |
---|
193 | sub auth { return undef; } |
---|
194 | sub fields { return undef; } |
---|
195 | sub zsig { return undef; } |
---|
196 | sub zwriteline { return undef; } |
---|
197 | sub login_host { return undef; } |
---|
198 | sub login_tty { return undef; } |
---|
199 | |
---|
200 | sub pretty_sender { return shift->sender; } |
---|
201 | sub pretty_recipient { return shift->recipient; } |
---|
202 | |
---|
203 | sub delete { |
---|
204 | my ($m) = @_; |
---|
205 | &BarnOwl::command("delete --id ".$m->id); |
---|
206 | } |
---|
207 | |
---|
208 | sub undelete { |
---|
209 | my ($m) = @_; |
---|
210 | &BarnOwl::command("undelete --id ".$m->id); |
---|
211 | } |
---|
212 | |
---|
213 | # Serializes the message into something similar to the zwgc->vt format |
---|
214 | sub serialize { |
---|
215 | my ($this) = @_; |
---|
216 | my $s; |
---|
217 | for my $f (keys %$this) { |
---|
218 | my $val = $this->{$f}; |
---|
219 | if (ref($val) eq "ARRAY") { |
---|
220 | for my $i (0..@$val-1) { |
---|
221 | my $aval; |
---|
222 | $aval = $val->[$i]; |
---|
223 | $aval =~ s/\n/\n$f.$i: /g; |
---|
224 | $s .= "$f.$i: $aval\n"; |
---|
225 | } |
---|
226 | } else { |
---|
227 | $val =~ s/\n/\n$f: /g; |
---|
228 | $s .= "$f: $val\n"; |
---|
229 | } |
---|
230 | } |
---|
231 | return $s; |
---|
232 | } |
---|
233 | |
---|
234 | # Populate the annoying legacy global variables |
---|
235 | sub legacy_populate_global { |
---|
236 | my ($m) = @_; |
---|
237 | $BarnOwl::direction = $m->direction ; |
---|
238 | $BarnOwl::type = $m->type ; |
---|
239 | $BarnOwl::id = $m->id ; |
---|
240 | $BarnOwl::class = $m->class ; |
---|
241 | $BarnOwl::instance = $m->instance ; |
---|
242 | $BarnOwl::recipient = $m->recipient ; |
---|
243 | $BarnOwl::sender = $m->sender ; |
---|
244 | $BarnOwl::realm = $m->realm ; |
---|
245 | $BarnOwl::opcode = $m->opcode ; |
---|
246 | $BarnOwl::zsig = $m->zsig ; |
---|
247 | $BarnOwl::msg = $m->body ; |
---|
248 | $BarnOwl::time = $m->time ; |
---|
249 | $BarnOwl::host = $m->host ; |
---|
250 | $BarnOwl::login = $m->login ; |
---|
251 | $BarnOwl::auth = $m->auth ; |
---|
252 | if ($m->fields) { |
---|
253 | @BarnOwl::fields = @{$m->fields}; |
---|
254 | @main::fields = @{$m->fields}; |
---|
255 | } else { |
---|
256 | @BarnOwl::fields = undef; |
---|
257 | @main::fields = undef; |
---|
258 | } |
---|
259 | } |
---|
260 | |
---|
261 | sub smartfilter { |
---|
262 | die("smartfilter not supported for this message\n"); |
---|
263 | } |
---|
264 | |
---|
265 | # Display fields -- overridden by subclasses when needed |
---|
266 | sub login_type {""} |
---|
267 | sub login_extra {""} |
---|
268 | sub long_sender {""} |
---|
269 | |
---|
270 | # The context in which a non-personal message was sent, e.g. a chat or |
---|
271 | # class |
---|
272 | sub context {""} |
---|
273 | |
---|
274 | # Some indicator of context *within* $self->context. e.g. the zephyr |
---|
275 | # instance |
---|
276 | sub subcontext {""} |
---|
277 | |
---|
278 | ##################################################################### |
---|
279 | ##################################################################### |
---|
280 | |
---|
281 | package BarnOwl::Message::Admin; |
---|
282 | |
---|
283 | use base qw( BarnOwl::Message ); |
---|
284 | |
---|
285 | sub header { return shift->{"header"}; } |
---|
286 | |
---|
287 | ##################################################################### |
---|
288 | ##################################################################### |
---|
289 | |
---|
290 | package BarnOwl::Message::Generic; |
---|
291 | |
---|
292 | use base qw( BarnOwl::Message ); |
---|
293 | |
---|
294 | ##################################################################### |
---|
295 | ##################################################################### |
---|
296 | |
---|
297 | package BarnOwl::Message::Loopback; |
---|
298 | |
---|
299 | use base qw( BarnOwl::Message ); |
---|
300 | |
---|
301 | # all loopback messages are private |
---|
302 | sub is_private { |
---|
303 | return 1; |
---|
304 | } |
---|
305 | |
---|
306 | ##################################################################### |
---|
307 | ##################################################################### |
---|
308 | |
---|
309 | package BarnOwl::Message::AIM; |
---|
310 | |
---|
311 | use base qw( BarnOwl::Message ); |
---|
312 | |
---|
313 | # all non-loginout AIM messages are private for now... |
---|
314 | sub is_private { |
---|
315 | return !(shift->is_loginout); |
---|
316 | } |
---|
317 | |
---|
318 | ##################################################################### |
---|
319 | ##################################################################### |
---|
320 | |
---|
321 | package BarnOwl::Message::Zephyr; |
---|
322 | |
---|
323 | use base qw( BarnOwl::Message ); |
---|
324 | |
---|
325 | sub login_type { |
---|
326 | return (shift->zsig eq "") ? "(PSEUDO)" : ""; |
---|
327 | } |
---|
328 | |
---|
329 | sub login_extra { |
---|
330 | my $m = shift; |
---|
331 | return undef if (!$m->is_loginout); |
---|
332 | my $s = lc($m->host); |
---|
333 | $s .= " " . $m->login_tty if defined $m->login_tty; |
---|
334 | return $s; |
---|
335 | } |
---|
336 | |
---|
337 | sub long_sender { |
---|
338 | my $m = shift; |
---|
339 | return $m->zsig; |
---|
340 | } |
---|
341 | |
---|
342 | sub context { |
---|
343 | return shift->class; |
---|
344 | } |
---|
345 | |
---|
346 | sub subcontext { |
---|
347 | return shift->instance; |
---|
348 | } |
---|
349 | |
---|
350 | sub login_tty { |
---|
351 | my ($m) = @_; |
---|
352 | return undef if (!$m->is_loginout); |
---|
353 | return $m->fields->[2]; |
---|
354 | } |
---|
355 | |
---|
356 | sub login_host { |
---|
357 | my ($m) = @_; |
---|
358 | return undef if (!$m->is_loginout); |
---|
359 | return $m->fields->[0]; |
---|
360 | } |
---|
361 | |
---|
362 | sub zwriteline { return shift->{"zwriteline"}; } |
---|
363 | |
---|
364 | sub is_ping { return (lc(shift->opcode) eq "ping"); } |
---|
365 | |
---|
366 | sub is_personal { |
---|
367 | my ($m) = @_; |
---|
368 | return ((lc($m->class) eq "message") |
---|
369 | && (lc($m->instance) eq "personal") |
---|
370 | && $m->is_private); |
---|
371 | } |
---|
372 | |
---|
373 | sub is_mail { |
---|
374 | my ($m) = @_; |
---|
375 | return ((lc($m->class) eq "mail") && $m->is_private); |
---|
376 | } |
---|
377 | |
---|
378 | sub pretty_sender { |
---|
379 | my ($m) = @_; |
---|
380 | my $sender = $m->sender; |
---|
381 | my $realm = BarnOwl::zephyr_getrealm(); |
---|
382 | $sender =~ s/\@$realm$//; |
---|
383 | return $sender; |
---|
384 | } |
---|
385 | |
---|
386 | sub pretty_recipient { |
---|
387 | my ($m) = @_; |
---|
388 | my $recip = $m->recipient; |
---|
389 | my $realm = BarnOwl::zephyr_getrealm(); |
---|
390 | $recip =~ s/\@$realm$//; |
---|
391 | return $recip; |
---|
392 | } |
---|
393 | |
---|
394 | # These are arguably zephyr-specific |
---|
395 | sub class { return shift->{"class"}; } |
---|
396 | sub instance { return shift->{"instance"}; } |
---|
397 | sub realm { return shift->{"realm"}; } |
---|
398 | sub opcode { return shift->{"opcode"}; } |
---|
399 | sub host { return shift->{"hostname"}; } |
---|
400 | sub hostname { return shift->{"hostname"}; } |
---|
401 | sub header { return shift->{"header"}; } |
---|
402 | sub auth { return shift->{"auth"}; } |
---|
403 | sub fields { return shift->{"fields"}; } |
---|
404 | sub zsig { return shift->{"zsig"}; } |
---|
405 | |
---|
406 | ##################################################################### |
---|
407 | ##################################################################### |
---|
408 | ################################################################################ |
---|
409 | |
---|
410 | package BarnOwl::Hook; |
---|
411 | |
---|
412 | sub new { |
---|
413 | my $class = shift; |
---|
414 | return bless [], $class; |
---|
415 | } |
---|
416 | |
---|
417 | sub run { |
---|
418 | my $self = shift; |
---|
419 | my @args = @_; |
---|
420 | return map {$_->(@args)} @$self; |
---|
421 | } |
---|
422 | |
---|
423 | sub add { |
---|
424 | my $self = shift; |
---|
425 | my $func = shift; |
---|
426 | die("Not a coderef!") unless ref($func) eq 'CODE'; |
---|
427 | push @$self, $func; |
---|
428 | } |
---|
429 | |
---|
430 | sub clear { |
---|
431 | my $self = shift; |
---|
432 | @$self = (); |
---|
433 | } |
---|
434 | |
---|
435 | package BarnOwl::Hooks; |
---|
436 | |
---|
437 | use Exporter; |
---|
438 | |
---|
439 | our @EXPORT_OK = qw($startup $shutdown |
---|
440 | $receiveMessage $mainLoop |
---|
441 | $getBuddyList); |
---|
442 | |
---|
443 | our %EXPORT_TAGS = (all => [@EXPORT_OK]); |
---|
444 | |
---|
445 | our $startup = BarnOwl::Hook->new; |
---|
446 | our $shutdown = BarnOwl::Hook->new; |
---|
447 | our $receiveMessage = BarnOwl::Hook->new; |
---|
448 | our $mainLoop = BarnOwl::Hook->new; |
---|
449 | our $getBuddyList = BarnOwl::Hook->new; |
---|
450 | |
---|
451 | # Internal startup/shutdown routines called by the C code |
---|
452 | |
---|
453 | sub _load_owlconf { |
---|
454 | # load the config file |
---|
455 | if ( -r $BarnOwl::configfile ) { |
---|
456 | undef $@; |
---|
457 | package main; |
---|
458 | do $BarnOwl::configfile; |
---|
459 | die $@ if $@; |
---|
460 | package BarnOwl; |
---|
461 | if(*BarnOwl::format_msg{CODE}) { |
---|
462 | # if the config defines a legacy formatting function, add 'perl' as a style |
---|
463 | BarnOwl::_create_style("perl", "BarnOwl::_format_msg_legacy_wrap", |
---|
464 | "User-defined perl style that calls BarnOwl::format_msg" |
---|
465 | . " with legacy global variable support"); |
---|
466 | BarnOwl::set("-q default_style perl"); |
---|
467 | } |
---|
468 | } |
---|
469 | } |
---|
470 | |
---|
471 | sub _startup { |
---|
472 | _load_owlconf(); |
---|
473 | |
---|
474 | if(eval {require BarnOwl::ModuleLoader}) { |
---|
475 | eval { |
---|
476 | BarnOwl::ModuleLoader->load_all; |
---|
477 | }; |
---|
478 | BarnOwl::error("$@") if $@; |
---|
479 | |
---|
480 | } else { |
---|
481 | BarnOwl::error("Can't load BarnOwl::ModuleLoader, loadable module support disabled:\n$@"); |
---|
482 | } |
---|
483 | |
---|
484 | $startup->run(0); |
---|
485 | BarnOwl::startup() if *BarnOwl::startup{CODE}; |
---|
486 | } |
---|
487 | |
---|
488 | sub _shutdown { |
---|
489 | $shutdown->run; |
---|
490 | |
---|
491 | BarnOwl::shutdown() if *BarnOwl::shutdown{CODE}; |
---|
492 | } |
---|
493 | |
---|
494 | sub _receive_msg { |
---|
495 | my $m = shift; |
---|
496 | |
---|
497 | $receiveMessage->run($m); |
---|
498 | |
---|
499 | BarnOwl::receive_msg($m) if *BarnOwl::receive_msg{CODE}; |
---|
500 | } |
---|
501 | |
---|
502 | sub _mainloop_hook { |
---|
503 | $mainLoop->run; |
---|
504 | BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE}; |
---|
505 | } |
---|
506 | |
---|
507 | sub _get_blist { |
---|
508 | return join("\n", $getBuddyList->run); |
---|
509 | } |
---|
510 | |
---|
511 | ################################################################################ |
---|
512 | # Built-in perl styles |
---|
513 | ################################################################################ |
---|
514 | package BarnOwl::Style::Default; |
---|
515 | ################################################################################ |
---|
516 | # Branching point for various formatting functions in this style. |
---|
517 | ################################################################################ |
---|
518 | sub format_message($) |
---|
519 | { |
---|
520 | my $m = shift; |
---|
521 | |
---|
522 | if ( $m->is_loginout) { |
---|
523 | return format_login($m); |
---|
524 | } elsif($m->is_ping && $m->is_personal) { |
---|
525 | return ( "\@b(PING) from \@b(" . $m->pretty_sender . ")\n" ); |
---|
526 | } elsif($m->is_admin) { |
---|
527 | return "\@bold(OWL ADMIN)\n" . indentBody($m); |
---|
528 | } else { |
---|
529 | return format_chat($m); |
---|
530 | } |
---|
531 | } |
---|
532 | |
---|
533 | BarnOwl::_create_style("default", "BarnOwl::Style::Default::format_message", "Default style"); |
---|
534 | |
---|
535 | ################################################################################ |
---|
536 | |
---|
537 | sub time_hhmm { |
---|
538 | my $m = shift; |
---|
539 | my ($time) = $m->time =~ /(\d\d:\d\d)/; |
---|
540 | return $time; |
---|
541 | } |
---|
542 | |
---|
543 | sub format_login($) { |
---|
544 | my $m = shift; |
---|
545 | return sprintf( |
---|
546 | '@b<%s%s> for @b(%s) (%s) %s', |
---|
547 | uc( $m->login ), |
---|
548 | $m->login_type, |
---|
549 | $m->pretty_sender, |
---|
550 | $m->login_extra, |
---|
551 | time_hhmm($m) |
---|
552 | ); |
---|
553 | } |
---|
554 | |
---|
555 | sub format_chat($) { |
---|
556 | my $m = shift; |
---|
557 | my $header; |
---|
558 | if ( $m->is_personal ) { |
---|
559 | if ( $m->direction eq "out" ) { |
---|
560 | $header = ucfirst $m->type . " sent to " . $m->pretty_recipient; |
---|
561 | } else { |
---|
562 | $header = ucfirst $m->type . " from " . $m->pretty_sender; |
---|
563 | } |
---|
564 | } else { |
---|
565 | $header = $m->context; |
---|
566 | if(defined $m->subcontext) { |
---|
567 | $header .= ' / ' . $m->subcontext; |
---|
568 | } |
---|
569 | $header .= ' / @b{' . $m->pretty_sender . '}'; |
---|
570 | } |
---|
571 | |
---|
572 | if($m->opcode) { |
---|
573 | $header .= " [" . $m->opcode . "]"; |
---|
574 | } |
---|
575 | $header .= " " . time_hhmm($m); |
---|
576 | my $sender = $m->long_sender; |
---|
577 | $sender =~ s/\n.*$//s; |
---|
578 | $header .= " " x (4 - ((length $header) % 4)); |
---|
579 | $header .= "(" . $sender . '@color[default]' . ")"; |
---|
580 | my $message = $header . "\n". indentBody($m); |
---|
581 | if($m->is_personal && $m->direction eq "in") { |
---|
582 | $message = BarnOwl::Style::boldify($message); |
---|
583 | } |
---|
584 | return $message; |
---|
585 | } |
---|
586 | |
---|
587 | sub indentBody($) |
---|
588 | { |
---|
589 | my $m = shift; |
---|
590 | |
---|
591 | my $body = $m->body; |
---|
592 | if ($m->{should_wordwrap}) { |
---|
593 | $body = BarnOwl::wordwrap($body, BarnOwl::getnumcols()-8); |
---|
594 | } |
---|
595 | # replace newline followed by anything with |
---|
596 | # newline plus four spaces and that thing. |
---|
597 | $body =~ s/\n(.)/\n $1/g; |
---|
598 | |
---|
599 | return " ".$body; |
---|
600 | } |
---|
601 | |
---|
602 | |
---|
603 | package BarnOwl::Style; |
---|
604 | |
---|
605 | # This takes a zephyr to be displayed and modifies it to be displayed |
---|
606 | # entirely in bold. |
---|
607 | sub boldify($) |
---|
608 | { |
---|
609 | local $_ = shift; |
---|
610 | if ( !(/\)/) ) { |
---|
611 | return '@b(' . $_ . ')'; |
---|
612 | } elsif ( !(/\>/) ) { |
---|
613 | return '@b<' . $_ . '>'; |
---|
614 | } elsif ( !(/\}/) ) { |
---|
615 | return '@b{' . $_ . '}'; |
---|
616 | } elsif ( !(/\]/) ) { |
---|
617 | return '@b[' . $_ . ']'; |
---|
618 | } else { |
---|
619 | my $txt = "\@b($_"; |
---|
620 | $txt =~ s/\)/\)\@b\[\)\]\@b\(/g; |
---|
621 | return $txt . ')'; |
---|
622 | } |
---|
623 | } |
---|
624 | |
---|
625 | |
---|
626 | # switch to package main when we're done |
---|
627 | package main; |
---|
628 | |
---|
629 | # Shove a bunch of fake entries into @INC so modules can use or |
---|
630 | # require them without choking |
---|
631 | $::INC{$_} = 1 for (qw(BarnOwl.pm BarnOwl/Hooks.pm |
---|
632 | BarnOwl/Message.pm BarnOwl/Style.pm)); |
---|
633 | |
---|
634 | 1; |
---|
635 | |
---|