[ee183be] | 1 | use strict; |
---|
| 2 | use warnings; |
---|
| 3 | |
---|
| 4 | package BarnOwl::Message::Zephyr; |
---|
| 5 | |
---|
| 6 | use constant WEBZEPHYR_PRINCIPAL => "daemon.webzephyr"; |
---|
| 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 | |
---|
| 19 | sub login_type { |
---|
| 20 | return (shift->zsig eq "") ? "(PSEUDO)" : ""; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | sub 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 | |
---|
| 31 | sub long_sender { |
---|
| 32 | my $m = shift; |
---|
| 33 | return $m->zsig; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | sub context { |
---|
| 37 | return shift->class; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | sub subcontext { |
---|
| 41 | return shift->instance; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | sub login_tty { |
---|
| 45 | my ($m) = @_; |
---|
| 46 | return undef if (!$m->is_loginout); |
---|
| 47 | return $m->fields->[2]; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | sub login_host { |
---|
| 51 | my ($m) = @_; |
---|
| 52 | return undef if (!$m->is_loginout); |
---|
| 53 | return $m->fields->[0]; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | sub zwriteline { return shift->{"zwriteline"}; } |
---|
| 57 | |
---|
| 58 | sub is_ping { return (lc(shift->opcode) eq "ping"); } |
---|
| 59 | |
---|
| 60 | sub is_personal { |
---|
| 61 | my ($m) = @_; |
---|
| 62 | return ((lc($m->class) eq "message") |
---|
| 63 | && $m->is_private); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | sub is_mail { |
---|
| 67 | my ($m) = @_; |
---|
| 68 | return ((lc($m->class) eq "mail") && $m->is_private); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | sub pretty_sender { |
---|
| 72 | my ($m) = @_; |
---|
| 73 | return strip_realm($m->sender); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | sub pretty_recipient { |
---|
| 77 | my ($m) = @_; |
---|
| 78 | return strip_realm($m->recipient); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | # Portion of the reply command that preserves the context |
---|
| 82 | sub 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 | |
---|
| 96 | sub personal_context { |
---|
| 97 | my ($m) = @_; |
---|
[3a6277a] | 98 | return BarnOwl::quote(context_reply_cmd($m->class, $m->instance)); |
---|
[ee183be] | 99 | } |
---|
| 100 | |
---|
| 101 | sub 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 |
---|
| 117 | sub class { return shift->{"class"}; } |
---|
| 118 | sub instance { return shift->{"instance"}; } |
---|
| 119 | sub realm { return shift->{"realm"}; } |
---|
| 120 | sub opcode { return shift->{"opcode"}; } |
---|
| 121 | sub host { return shift->{"hostname"}; } |
---|
| 122 | sub hostname { return shift->{"hostname"}; } |
---|
| 123 | sub header { return shift->{"header"}; } |
---|
| 124 | sub auth { return shift->{"auth"}; } |
---|
| 125 | sub fields { return shift->{"fields"}; } |
---|
| 126 | sub zsig { return shift->{"zsig"}; } |
---|
| 127 | |
---|
| 128 | sub zephyr_cc { |
---|
| 129 | my $self = shift; |
---|
| 130 | return $1 if $self->body =~ /^\s*cc:\s+([^\n]+)/i; |
---|
| 131 | return undef; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | sub 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 | |
---|
| 204 | sub replysendercmd { |
---|
| 205 | my $self = shift; |
---|
| 206 | return $self->replycmd(1); |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | |
---|
| 210 | 1; |
---|