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