source: perl/lib/BarnOwl/Message/Zephyr.pm @ 0adbce1

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