Changeset 740d5f7


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"].
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    rcdc6ff1 r740d5f7  
    20202020void owl_function_reply(int type, int enter)
    20212021{
    2022   char *buff=NULL, *oldbuff;
     2022  char *buff=NULL;
    20232023  owl_message *m;
    20242024  owl_filter *f;
     
    20272027    owl_function_error("No message selected");
    20282028  } else {
    2029     char *class, *inst, *to, *cc=NULL;
    20302029   
    20312030    m=owl_view_get_element(owl_global_get_current_view(&g), owl_global_get_curmsg(&g));
     
    20442043    }
    20452044
    2046     /* loopback */
    2047     if (owl_message_is_type_loopback(m)) {
    2048       owl_function_loopwrite_setup();
    2049       return;
    2050     }
    2051 
    2052     /* zephyr */
    2053     if (owl_message_is_type_zephyr(m)) {
    2054       /* if it's a zephyr we sent, send it out the same way again */
    2055       if (owl_message_is_direction_out(m)) {
    2056           buff = owl_strdup(owl_message_get_zwriteline(m));
    2057       } else {
    2058 
    2059         /* Special case a personal reply to a webzephyr user on a class */
    2060         if ((type==1) && !strcasecmp(owl_message_get_opcode(m), OWL_WEBZEPHYR_OPCODE)) {
    2061           class=OWL_WEBZEPHYR_CLASS;
    2062           inst=owl_message_get_sender(m);
    2063           to=OWL_WEBZEPHYR_PRINCIPAL;
    2064         } else if (!strcasecmp(owl_message_get_class(m), OWL_WEBZEPHYR_CLASS) && owl_message_is_loginout(m)) {
    2065           /* Special case LOGIN/LOGOUT notifications on class "webzephyr" */
    2066           class=OWL_WEBZEPHYR_CLASS;
    2067           inst=owl_message_get_instance(m);
    2068           to=OWL_WEBZEPHYR_PRINCIPAL;
    2069         } else if (owl_message_is_loginout(m)) {
    2070           /* Normal LOGIN/LOGOUT messages */
    2071           class="MESSAGE";
    2072           inst="PERSONAL";
    2073           to=owl_message_get_sender(m);
    2074         } else if (type==1) {
    2075           /* Personal reply */
    2076           class="MESSAGE";
    2077           inst="PERSONAL";
    2078           to=owl_message_get_sender(m);
    2079         } else {
    2080           /* General reply */
    2081           class=owl_message_get_class(m);
    2082           inst=owl_message_get_instance(m);
    2083           to=owl_message_get_recipient(m);
    2084           cc=owl_message_get_cc_without_recipient(m);
    2085           if (!strcmp(to, "") || !strcmp(to, "*")) {
    2086             to="";
    2087           } else if (to[0]=='@') {
    2088             /* leave it, to get the realm */
    2089           } else {
    2090             to=owl_message_get_sender(m);
    2091           }
    2092         }
    2093 
    2094         /* create the command line */
    2095         if (!strcasecmp(owl_message_get_opcode(m), "CRYPT")) {
    2096           buff=owl_strdup("zcrypt");
    2097         } else {
    2098           buff = owl_strdup("zwrite");
    2099         }
    2100         if (strcasecmp(class, "message")) {
    2101           buff = owl_sprintf("%s -c %s%s%s", oldbuff=buff, owl_getquoting(class), class, owl_getquoting(class));
    2102           owl_free(oldbuff);
    2103         }
    2104         if (strcasecmp(inst, "personal")) {
    2105           buff = owl_sprintf("%s -i %s%s%s", oldbuff=buff, owl_getquoting(inst), inst, owl_getquoting(inst));
    2106           owl_free(oldbuff);
    2107         }
    2108         if (*to != '\0') {
    2109           char *tmp, *oldtmp, *tmp2;
    2110           tmp=short_zuser(to);
    2111           if (cc) {
    2112             tmp = owl_util_uniq(oldtmp=tmp, cc, "-");
    2113             owl_free(oldtmp);
    2114             buff = owl_sprintf("%s -C %s", oldbuff=buff, tmp);
    2115             owl_free(oldbuff);
    2116           } else {
    2117             if (owl_global_is_smartstrip(&g)) {
    2118               tmp2=tmp;
    2119               tmp=owl_zephyr_smartstripped_user(tmp2);
    2120               owl_free(tmp2);
    2121             }
    2122             buff = owl_sprintf("%s %s", oldbuff=buff, tmp);
    2123             owl_free(oldbuff);
    2124           }
    2125           owl_free(tmp);
    2126         }
    2127         if (cc) owl_free(cc);
    2128       }
    2129     } else if (owl_message_is_type_aim(m)) {
    2130       /* aim */
    2131       if (owl_message_is_direction_out(m)) {
    2132         buff=owl_sprintf("aimwrite %s", owl_message_get_recipient(m));
    2133       } else {
    2134         buff=owl_sprintf("aimwrite %s", owl_message_get_sender(m));
    2135       }
    2136     } else {
    2137       char *cmd;
    2138       if((type == 0 &&
    2139           (cmd=owl_perlconfig_message_call_method(m, "replycmd", 0, NULL))) ||
    2140          (type == 1 &&
    2141           (cmd=owl_perlconfig_message_call_method(m, "replysendercmd", 0, NULL)))) {
    2142         buff = cmd;
    2143       }
     2045    char *cmd;
     2046    if((type == 0 &&
     2047        (cmd=owl_perlconfig_message_call_method(m, "replycmd", 0, NULL))) ||
     2048       (type == 1 &&
     2049        (cmd=owl_perlconfig_message_call_method(m, "replysendercmd", 0, NULL)))) {
     2050      buff = cmd;
    21442051    }
    21452052
     
    21482055        return;
    21492056    }
    2150    
     2057
    21512058    if (enter) {
    21522059      owl_history *hist = owl_global_get_cmd_history(&g);
  • perlglue.xs

    rc4ba74d r740d5f7  
    113113        CLEANUP:
    114114                if (rv) owl_free(rv);
     115
     116char *
     117zephyr_smartstrip_user(in)
     118        char *in
     119        PREINIT:
     120                char *rv = NULL;
     121        CODE:
     122        {
     123                rv = owl_zephyr_smartstripped_user(in);
     124                RETVAL = rv;
     125        }
     126        OUTPUT:
     127                RETVAL
     128        CLEANUP:
     129                owl_free(rv);
    115130
    116131char *
  • 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.