Changeset 22b54a7


Ignore:
Timestamp:
Jul 13, 2009, 10:06:27 PM (12 years ago)
Author:
Alex Dehnert <adehnert@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
7c83a32
Parents:
301c975
git-author:
Alex Dehnert <adehnert@mit.edu> (07/03/09 23:27:40)
git-committer:
Alex Dehnert <adehnert@mit.edu> (07/13/09 22:06:27)
Message:
Useful filter-modifying commands

filterappend FILTER TEXT
filterand FILTER TEXT
filteror FILTER TEXT

Append TEXT onto FILTER with appropriate
('', 'and', 'or') separators

The admin message can be enabled or disabled
by (un)setting showfilterchange.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/lib/BarnOwl.pm

    rcf26b72 r22b54a7  
    317317}
    318318
     319=head2 Modify filters by appending text
     320
     321=cut
     322
     323BarnOwl::new_command("filterappend",
     324    sub { filter_append_helper('appending', '', @_); },
     325    {
     326        summary => "append '<text>' to filter",
     327        usage => "filterappend <filter> <text>",
     328    });
     329
     330BarnOwl::new_command("filterand",
     331    sub { filter_append_helper('and-ing', 'and', @_); },
     332    {
     333        summary => "append 'and <text>' to filter",
     334        usage => "filterand <filter> <text>",
     335    });
     336
     337BarnOwl::new_command("filteror",
     338    sub { filter_append_helper('or-ing', 'or', @_); },
     339    {
     340        summary => "append 'or <text>' to filter",
     341        usage => "filteror <filter> <text>",
     342    });
     343
     344=head3 filter_append_helper ACTION SEP FUNC FILTER APPEND_TEXT
     345
     346Helper to append to filters.
     347
     348=cut
     349
     350sub filter_append_helper
     351{
     352    my $action = shift;
     353    my $sep = shift;
     354    my $func = shift;
     355    my $filter = shift;
     356    my @append = @_;
     357    my $oldfilter = BarnOwl::getfilter($filter);
     358    chomp $oldfilter;
     359    my $newfilter = join(' ', $oldfilter, $sep, @_);
     360    my $msgtext = "To filter '$filter' $action\n'".join(' ', @append)."' to get\n'$newfilter'";
     361    if (BarnOwl::getvar('showfilterchange') eq 'on') {
     362        BarnOwl::admin_message("Filter", $msgtext);
     363    }
     364    BarnOwl::filter($filter, $newfilter);
     365    return;
     366}
     367BarnOwl::new_variable_bool("showfilterchange",
     368                           { default => 1,
     369                             summary => 'Show modifications to filters by filterappend and friends.'});
    319370
    3203711;
Note: See TracChangeset for help on using the changeset viewer.