source: perl/lib/BarnOwl/Message/Zephyr.pm @ 8d16e58

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 8d16e58 was 892e897, checked in by Alex Dehnert <adehnert@mit.edu>, 15 years ago
Shift-R on CC zephyrs should go to the sender only
  • Property mode set to 100644
File size: 5.0 KB
RevLine 
[ee183be]1use strict;
2use warnings;
3
4package BarnOwl::Message::Zephyr;
5
6use constant WEBZEPHYR_PRINCIPAL => "daemon.webzephyr";
7use constant WEBZEPHYR_CLASS     => "webzephyr";
8use constant WEBZEPHYR_OPCODE    => "webzephyr";
9
10use base qw( BarnOwl::Message );
11
12sub strip_realm {
13    my $sender = shift;
14    my $realm = BarnOwl::zephyr_getrealm();
[bcde942d]15    $sender =~ s/\@\Q$realm\E$//;
[ee183be]16    return $sender;
17}
18
19sub login_type {
20    return (shift->zsig eq "") ? "(PSEUDO)" : "";
21}
22
23sub login_extra {
24    my $m = shift;
25    return undef if (!$m->is_loginout);
26    my $s = lc($m->host);
27    $s .= " " . $m->login_tty if defined $m->login_tty;
28    return $s;
29}
30
31sub long_sender {
32    my $m = shift;
33    return $m->zsig;
34}
35
36sub context {
37    return shift->class;
38}
39
40sub subcontext {
41    return shift->instance;
42}
43
44sub login_tty {
45    my ($m) = @_;
46    return undef if (!$m->is_loginout);
47    return $m->fields->[2];
48}
49
50sub login_host {
51    my ($m) = @_;
52    return undef if (!$m->is_loginout);
53    return $m->fields->[0];
54}
55
56sub zwriteline  { return shift->{"zwriteline"}; }
57
58sub is_ping     { return (lc(shift->opcode) eq "ping"); }
59
60sub is_personal {
61    my ($m) = @_;
62    return ((lc($m->class) eq "message")
63            && $m->is_private);
64}
65
66sub is_mail {
67    my ($m) = @_;
68    return ((lc($m->class) eq "mail") && $m->is_private);
69}
70
71sub pretty_sender {
72    my ($m) = @_;
73    return strip_realm($m->sender);
74}
75
76sub pretty_recipient {
77    my ($m) = @_;
78    return strip_realm($m->recipient);
79}
80
81# Portion of the reply command that preserves the context
82sub context_reply_cmd {
[bc8275e]83    my $mclass = shift;
84    my $minstance = shift;
[3a6277a]85    my @class;
[bc8275e]86    if (lc($mclass) ne "message") {
[3a6277a]87        @class = ('-c', $mclass);
[ee183be]88    }
[3a6277a]89    my @instance;
[bc8275e]90    if (lc($minstance) ne "personal") {
[3a6277a]91        @instance = ('-i', $minstance);
[ee183be]92    }
[3a6277a]93    return (@class, @instance);
[ee183be]94}
95
96sub personal_context {
97    my ($m) = @_;
[3a6277a]98    return BarnOwl::quote(context_reply_cmd($m->class, $m->instance));
[ee183be]99}
100
101sub short_personal_context {
102    my ($m) = @_;
103    if(lc($m->class) eq 'message')
104    {
105        if(lc($m->instance) eq 'personal')
106        {
107            return '';
108        } else {
109            return $m->instance;
110        }
111    } else {
112        return $m->class;
113    }
114}
115
116# These are arguably zephyr-specific
117sub class       { return shift->{"class"}; }
118sub instance    { return shift->{"instance"}; }
119sub realm       { return shift->{"realm"}; }
120sub opcode      { return shift->{"opcode"}; }
121sub host        { return shift->{"hostname"}; }
122sub hostname    { return shift->{"hostname"}; }
123sub header      { return shift->{"header"}; }
124sub auth        { return shift->{"auth"}; }
125sub fields      { return shift->{"fields"}; }
126sub zsig        { return shift->{"zsig"}; }
127
128sub zephyr_cc {
129    my $self = shift;
130    return $1 if $self->body =~ /^\s*cc:\s+([^\n]+)/i;
131    return undef;
132}
133
134sub replycmd {
135    my $self = shift;
136    my $sender = shift;
137    $sender = 0 unless defined $sender;
138    my ($class, $instance, $to, $cc);
139    if($self->is_outgoing) {
140        return $self->{zwriteline};
141    }
142
143    if($sender && $self->opcode eq WEBZEPHYR_OPCODE) {
144        $class = WEBZEPHYR_CLASS;
145        $instance = $self->pretty_sender;
146        $instance =~ s/-webzephyr$//;
147        $to = WEBZEPHYR_PRINCIPAL;
148    } elsif($self->class eq WEBZEPHYR_CLASS
149            && $self->is_loginout) {
150        $class = WEBZEPHYR_CLASS;
151        $instance = $self->instance;
152        $to = WEBZEPHYR_PRINCIPAL;
153    } elsif($self->is_loginout) {
154        $class = 'MESSAGE';
155        $instance = 'PERSONAL';
156        $to = $self->sender;
157    } elsif($sender && !$self->is_private) {
158        # Possible future feature: (Optionally?) include the class and/or
159        # instance of the message being replied to in the instance of the
160        # outgoing personal reply
161        $class = 'MESSAGE';
162        $instance = 'PERSONAL';
163        $to = $self->sender;
164    } else {
165        $class = $self->class;
166        $instance = $self->instance;
167        $to = $self->recipient;
168        $cc = $self->zephyr_cc();
169        if($to eq '*' || $to eq '') {
170            $to = '';
171        } elsif($to !~ /^@/) {
172            $to = $self->sender;
173        }
174    }
175
[3a6277a]176    my @cmd;
[30e7ffd]177    if(lc $self->opcode eq 'crypt' and ( not $sender or $self->is_private)) {
178        # Responses to zcrypted messages should be zcrypted, so long as we
179        # aren't switching to personals
[3a6277a]180        @cmd = ('zcrypt');
[ee183be]181    } else {
[3a6277a]182        @cmd = ('zwrite');
[ee183be]183    }
184
[3a6277a]185    push @cmd, context_reply_cmd($class, $instance);
[ee183be]186    if ($to ne '') {
187        $to = strip_realm($to);
[892e897]188        if (defined $cc and not $sender) {
[ee183be]189            my @cc = grep /^[^-]/, ($to, split /\s+/, $cc);
190            my %cc = map {$_ => 1} @cc;
191            delete $cc{strip_realm(BarnOwl::zephyr_getsender())};
192            @cc = keys %cc;
[3a6277a]193            push @cmd, '-C', @cc;
[ee183be]194        } else {
195            if(BarnOwl::getvar('smartstrip') eq 'on') {
196                $to = BarnOwl::zephyr_smartstrip_user($to);
197            }
[3a6277a]198            push @cmd, $to;
[ee183be]199        }
200    }
[3a6277a]201    return BarnOwl::quote(@cmd);
[ee183be]202}
203
204sub replysendercmd {
205    my $self = shift;
206    return $self->replycmd(1);
207}
208
209
2101;
Note: See TracBrowser for help on using the repository browser.