[1177] in BarnOwl Developers
[D-O-H] r1118 - trunk/owl
daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:13:48 2009
Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
X-Original-To: nelhage@nelhage.com
To: dirty-owl-hackers@MIT.EDU
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Mon, 25 Aug 2008 20:11:16 -0400 (EDT)
Author: nelhage
Date: 2008-08-25 20:11:16 -0400 (Mon, 25 Aug 2008)
New Revision: 1118
Modified:
trunk/owl/functions.c
trunk/owl/perlglue.xs
trunk/owl/perlwrap.pm
Log:
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"].
Modified: trunk/owl/functions.c
===================================================================
--- trunk/owl/functions.c 2008-08-26 00:11:12 UTC (rev 1117)
+++ trunk/owl/functions.c 2008-08-26 00:11:16 UTC (rev 1118)
@@ -2019,14 +2019,13 @@
*/
void owl_function_reply(int type, int enter)
{
- char *buff=NULL, *oldbuff;
+ char *buff=NULL;
owl_message *m;
owl_filter *f;
if (owl_view_get_size(owl_global_get_current_view(&g))==0) {
owl_function_error("No message selected");
} else {
- char *class, *inst, *to, *cc=NULL;
m=owl_view_get_element(owl_global_get_current_view(&g), owl_global_get_curmsg(&g));
if (!m) {
@@ -2043,111 +2042,19 @@
}
}
- /* loopback */
- if (owl_message_is_type_loopback(m)) {
- owl_function_loopwrite_setup();
- return;
+ char *cmd;
+ if((type == 0 &&
+ (cmd=owl_perlconfig_message_call_method(m, "replycmd", 0, NULL))) ||
+ (type == 1 &&
+ (cmd=owl_perlconfig_message_call_method(m, "replysendercmd", 0, NULL)))) {
+ buff = cmd;
}
- /* zephyr */
- if (owl_message_is_type_zephyr(m)) {
- /* if it's a zephyr we sent, send it out the same way again */
- if (owl_message_is_direction_out(m)) {
- buff = owl_strdup(owl_message_get_zwriteline(m));
- } else {
-
- /* Special case a personal reply to a webzephyr user on a class */
- if ((type==1) && !strcasecmp(owl_message_get_opcode(m), OWL_WEBZEPHYR_OPCODE)) {
- class=OWL_WEBZEPHYR_CLASS;
- inst=owl_message_get_sender(m);
- to=OWL_WEBZEPHYR_PRINCIPAL;
- } else if (!strcasecmp(owl_message_get_class(m), OWL_WEBZEPHYR_CLASS) && owl_message_is_loginout(m)) {
- /* Special case LOGIN/LOGOUT notifications on class "webzephyr" */
- class=OWL_WEBZEPHYR_CLASS;
- inst=owl_message_get_instance(m);
- to=OWL_WEBZEPHYR_PRINCIPAL;
- } else if (owl_message_is_loginout(m)) {
- /* Normal LOGIN/LOGOUT messages */
- class="MESSAGE";
- inst="PERSONAL";
- to=owl_message_get_sender(m);
- } else if (type==1) {
- /* Personal reply */
- class="MESSAGE";
- inst="PERSONAL";
- to=owl_message_get_sender(m);
- } else {
- /* General reply */
- class=owl_message_get_class(m);
- inst=owl_message_get_instance(m);
- to=owl_message_get_recipient(m);
- cc=owl_message_get_cc_without_recipient(m);
- if (!strcmp(to, "") || !strcmp(to, "*")) {
- to="";
- } else if (to[0]=='@') {
- /* leave it, to get the realm */
- } else {
- to=owl_message_get_sender(m);
- }
- }
-
- /* create the command line */
- if (!strcasecmp(owl_message_get_opcode(m), "CRYPT")) {
- buff=owl_strdup("zcrypt");
- } else {
- buff = owl_strdup("zwrite");
- }
- if (strcasecmp(class, "message")) {
- buff = owl_sprintf("%s -c %s%s%s", oldbuff=buff, owl_getquoting(class), class, owl_getquoting(class));
- owl_free(oldbuff);
- }
- if (strcasecmp(inst, "personal")) {
- buff = owl_sprintf("%s -i %s%s%s", oldbuff=buff, owl_getquoting(inst), inst, owl_getquoting(inst));
- owl_free(oldbuff);
- }
- if (*to != '\0') {
- char *tmp, *oldtmp, *tmp2;
- tmp=short_zuser(to);
- if (cc) {
- tmp = owl_util_uniq(oldtmp=tmp, cc, "-");
- owl_free(oldtmp);
- buff = owl_sprintf("%s -C %s", oldbuff=buff, tmp);
- owl_free(oldbuff);
- } else {
- if (owl_global_is_smartstrip(&g)) {
- tmp2=tmp;
- tmp=owl_zephyr_smartstripped_user(tmp2);
- owl_free(tmp2);
- }
- buff = owl_sprintf("%s %s", oldbuff=buff, tmp);
- owl_free(oldbuff);
- }
- owl_free(tmp);
- }
- if (cc) owl_free(cc);
- }
- } else if (owl_message_is_type_aim(m)) {
- /* aim */
- if (owl_message_is_direction_out(m)) {
- buff=owl_sprintf("aimwrite %s", owl_message_get_recipient(m));
- } else {
- buff=owl_sprintf("aimwrite %s", owl_message_get_sender(m));
- }
- } else {
- char *cmd;
- if((type == 0 &&
- (cmd=owl_perlconfig_message_call_method(m, "replycmd", 0, NULL))) ||
- (type == 1 &&
- (cmd=owl_perlconfig_message_call_method(m, "replysendercmd", 0, NULL)))) {
- buff = cmd;
- }
- }
-
if(!buff) {
owl_function_error("I don't know how to reply to that message.");
return;
}
-
+
if (enter) {
owl_history *hist = owl_global_get_cmd_history(&g);
owl_history_store(hist, buff);
Modified: trunk/owl/perlglue.xs
===================================================================
--- trunk/owl/perlglue.xs 2008-08-26 00:11:12 UTC (rev 1117)
+++ trunk/owl/perlglue.xs 2008-08-26 00:11:16 UTC (rev 1118)
@@ -114,6 +114,21 @@
if (rv) owl_free(rv);
char *
+zephyr_smartstrip_user(in)
+ char *in
+ PREINIT:
+ char *rv = NULL;
+ CODE:
+ {
+ rv = owl_zephyr_smartstripped_user(in);
+ RETVAL = rv;
+ }
+ OUTPUT:
+ RETVAL
+ CLEANUP:
+ owl_free(rv);
+
+char *
zephyr_getsubs()
PREINIT:
char *rv = NULL;
Modified: trunk/owl/perlwrap.pm
===================================================================
--- trunk/owl/perlwrap.pm 2008-08-26 00:11:12 UTC (rev 1117)
+++ trunk/owl/perlwrap.pm 2008-08-26 00:11:16 UTC (rev 1118)
@@ -310,7 +310,8 @@
sub quote {
my $str = shift;
- if ($str !~ /'/ && $str !~ /"/) {
+ return "''" if $str eq '';
+ if ($str !~ /['" ]/) {
return "$str";
}
if ($str !~ /'/) {
@@ -492,6 +493,9 @@
return 1;
}
+sub replycmd {return 'loopwrite';}
+sub replysendercmd {return 'loopwrite';}
+
#####################################################################
#####################################################################
@@ -504,13 +508,37 @@
return !(shift->is_loginout);
}
+sub replycmd {
+ my $self = shift;
+ if ($self->is_incoming) {
+ return "aimwrite " . BarnOwl::quote($self->sender);
+ } else {
+ return "aimwrite " . BarnOwl::quote($self->recipient);
+ }
+}
+
+sub replysendercmd {
+ return shift->replycmd;
+}
+
#####################################################################
#####################################################################
package BarnOwl::Message::Zephyr;
+use constant WEBZEPHYR_PRINCIPAL => "daemon.webzephyr";
+use constant WEBZEPHYR_CLASS => "webzephyr";
+use constant WEBZEPHYR_OPCODE => "webzephyr";
+
use base qw( BarnOwl::Message );
+sub strip_realm {
+ my $sender = shift;
+ my $realm = BarnOwl::zephyr_getrealm();
+ $sender =~ s/\@$realm$//;
+ return $sender;
+}
+
sub login_type {
return (shift->zsig eq "") ? "(PSEUDO)" : "";
}
@@ -566,18 +594,12 @@
sub pretty_sender {
my ($m) = @_;
- my $sender = $m->sender;
- my $realm = BarnOwl::zephyr_getrealm();
- $sender =~ s/\@$realm$//;
- return $sender;
+ return strip_realm($m->sender);
}
sub pretty_recipient {
my ($m) = @_;
- my $recip = $m->recipient;
- my $realm = BarnOwl::zephyr_getrealm();
- $recip =~ s/\@$realm$//;
- return $recip;
+ return strip_realm($m->recipient);
}
# These are arguably zephyr-specific
@@ -592,9 +614,85 @@
sub fields { return shift->{"fields"}; }
sub zsig { return shift->{"zsig"}; }
+sub zephyr_cc {
+ my $self = shift;
+ return $1 if $self->body =~ /^\s*cc:\s+([^\n]+)/i;
+ return undef;
+}
+
+sub replycmd {
+ my $self = shift;
+ my $sender = shift;
+ $sender = 0 unless defined $sender;
+ my ($class, $instance, $to, $cc);
+ if($self->is_outgoing) {
+ return $self->{zwriteline};
+ }
+
+ if($sender && $self->opcode eq WEBZEPHYR_OPCODE) {
+ $class = WEBZEPHYR_CLASS;
+ $instance = $self->sender;
+ $to = WEBZEPHYR_PRINCIPAL;
+ } elsif($self->class eq WEBZEPHYR_CLASS
+ && $self->is_loginout) {
+ $class = WEBZEPHYR_CLASS;
+ $instance = $self->instance;
+ $to = WEBZEPHYR_PRINCIPAL;
+ } elsif($self->is_loginout || $sender) {
+ $class = 'MESSAGE';
+ $instance = 'PERSONAL';
+ $to = $self->sender;
+ } else {
+ $class = $self->class;
+ $instance = $self->instance;
+ $to = $self->recipient;
+ $cc = $self->zephyr_cc();
+ if($to eq '*' || $to eq '') {
+ $to = '';
+ } elsif($to !~ /^@/) {
+ $to = $self->sender;
+ }
+ }
+
+ my $cmd;
+ if(lc $self->opcode eq 'crypt') {
+ $cmd = 'zcrypt';
+ } else {
+ $cmd = 'zwrite';
+ }
+
+ if (lc $class ne 'message') {
+ $cmd .= " -c " . BarnOwl::quote($self->class);
+ }
+ if (lc $instance ne 'personal') {
+ $cmd .= " -i " . BarnOwl::quote($self->instance);
+ }
+ if ($to ne '') {
+ $to = strip_realm($to);
+ if (defined $cc) {
+ my @cc = grep /^[^-]/, ($to, split /\s+/, $cc);
+ my %cc = map {$_ => 1} @cc;
+ delete $cc{strip_realm(BarnOwl::zephyr_getsender())};
+ @cc = keys %cc;
+ $cmd .= " -C " . join(" ", @cc);
+ } else {
+ if(BarnOwl::getvar('smartstrip') eq 'on') {
+ $to = BarnOwl::zephyr_smartstrip_user($to);
+ }
+ $cmd .= " $to";
+ }
+ }
+ return $cmd;
+}
+
+sub replysendercmd {
+ my $self = shift;
+ return $self->replycmd(1);
+}
+
#####################################################################
#####################################################################
-################################################################################
+#####################################################################
package BarnOwl::Hook;