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