Changeset 740d5f7 for perlwrap.pm


Ignore:
Timestamp:
Aug 25, 2008, 8:11:16 PM (13 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
f830d84
Parents:
147d880
Message:
Move Zephyr and AIM reply command logic into perl.

This has the side effect of fixing quoting, so you can now correctly
reply to instances like ["can't touch this"].
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perlwrap.pm

    r5b75e8b r740d5f7  
    311311sub quote {
    312312    my $str = shift;
    313     if ($str !~ /'/ && $str !~ /"/) {
     313    return "''" if $str eq '';
     314    if ($str !~ /['" ]/) {
    314315        return "$str";
    315316    }
     
    493494}
    494495
     496sub replycmd {return 'loopwrite';}
     497sub replysendercmd {return 'loopwrite';}
     498
    495499#####################################################################
    496500#####################################################################
     
    505509}
    506510
     511sub replycmd {
     512    my $self = shift;
     513    if ($self->is_incoming) {
     514        return "aimwrite " . BarnOwl::quote($self->sender);
     515    } else {
     516        return "aimwrite " . BarnOwl::quote($self->recipient);
     517    }
     518}
     519
     520sub replysendercmd {
     521    return shift->replycmd;
     522}
     523
    507524#####################################################################
    508525#####################################################################
     
    510527package BarnOwl::Message::Zephyr;
    511528
     529use constant WEBZEPHYR_PRINCIPAL => "daemon.webzephyr";
     530use constant WEBZEPHYR_CLASS     => "webzephyr";
     531use constant WEBZEPHYR_OPCODE    => "webzephyr";
     532
    512533use base qw( BarnOwl::Message );
     534
     535sub strip_realm {
     536    my $sender = shift;
     537    my $realm = BarnOwl::zephyr_getrealm();
     538    $sender =~ s/\@$realm$//;
     539    return $sender;
     540}
    513541
    514542sub login_type {
     
    567595sub pretty_sender {
    568596    my ($m) = @_;
    569     my $sender = $m->sender;
    570     my $realm = BarnOwl::zephyr_getrealm();
    571     $sender =~ s/\@$realm$//;
    572     return $sender;
     597    return strip_realm($m->sender);
    573598}
    574599
    575600sub pretty_recipient {
    576601    my ($m) = @_;
    577     my $recip = $m->recipient;
    578     my $realm = BarnOwl::zephyr_getrealm();
    579     $recip =~ s/\@$realm$//;
    580     return $recip;
     602    return strip_realm($m->recipient);
    581603}
    582604
     
    593615sub zsig        { return shift->{"zsig"}; }
    594616
    595 #####################################################################
    596 #####################################################################
    597 ################################################################################
     617sub zephyr_cc {
     618    my $self = shift;
     619    return $1 if $self->body =~ /^\s*cc:\s+([^\n]+)/i;
     620    return undef;
     621}
     622
     623sub replycmd {
     624    my $self = shift;
     625    my $sender = shift;
     626    $sender = 0 unless defined $sender;
     627    my ($class, $instance, $to, $cc);
     628    if($self->is_outgoing) {
     629        return $self->{zwriteline};
     630    }
     631
     632    if($sender && $self->opcode eq WEBZEPHYR_OPCODE) {
     633        $class = WEBZEPHYR_CLASS;
     634        $instance = $self->sender;
     635        $to = WEBZEPHYR_PRINCIPAL;
     636    } elsif($self->class eq WEBZEPHYR_CLASS
     637            && $self->is_loginout) {
     638        $class = WEBZEPHYR_CLASS;
     639        $instance = $self->instance;
     640        $to = WEBZEPHYR_PRINCIPAL;
     641    } elsif($self->is_loginout || $sender) {
     642        $class = 'MESSAGE';
     643        $instance = 'PERSONAL';
     644        $to = $self->sender;
     645    } else {
     646        $class = $self->class;
     647        $instance = $self->instance;
     648        $to = $self->recipient;
     649        $cc = $self->zephyr_cc();
     650        if($to eq '*' || $to eq '') {
     651            $to = '';
     652        } elsif($to !~ /^@/) {
     653            $to = $self->sender;
     654        }
     655    }
     656
     657    my $cmd;
     658    if(lc $self->opcode eq 'crypt') {
     659        $cmd = 'zcrypt';
     660    } else {
     661        $cmd = 'zwrite';
     662    }
     663
     664    if (lc $class ne 'message') {
     665        $cmd .= " -c " . BarnOwl::quote($self->class);
     666    }
     667    if (lc $instance ne 'personal') {
     668        $cmd .= " -i " . BarnOwl::quote($self->instance);
     669    }
     670    if ($to ne '') {
     671        $to = strip_realm($to);
     672        if (defined $cc) {
     673            my @cc = grep /^[^-]/, ($to, split /\s+/, $cc);
     674            my %cc = map {$_ => 1} @cc;
     675            delete $cc{strip_realm(BarnOwl::zephyr_getsender())};
     676            @cc = keys %cc;
     677            $cmd .= " -C " . join(" ", @cc);
     678        } else {
     679            if(BarnOwl::getvar('smartstrip') eq 'on') {
     680                $to = BarnOwl::zephyr_smartstrip_user($to);
     681            }
     682            $cmd .= " $to";
     683        }
     684    }
     685    return $cmd;
     686}
     687
     688sub replysendercmd {
     689    my $self = shift;
     690    return $self->replycmd(1);
     691}
     692
     693#####################################################################
     694#####################################################################
     695#####################################################################
    598696
    599697package BarnOwl::Hook;
Note: See TracChangeset for help on using the changeset viewer.