source: perl/modules/Jabber/lib/BarnOwl/Message/Jabber.pm @ eea7bed4

Last change on this file since eea7bed4 was eea7bed4, checked in by Jason Gross <jasongross9@gmail.com>, 7 years ago
Moved log file name generation to perl I don't think that the class/personal distinction is the best for general protocols, but I don't know what should replace it. I've made class-logging default to only zephyr (a slight change from previous behavior, where jabber MUC's would be logged to $classlogpath, as well as all non-private non-login messages from other protocols), but made logging path generation overridable. TODO: Decide whether or not to filter out more 'bad' characters. Perhaps we should remove '!' because it indicates history in some shells and makes things obnoxious, or '~' becase it indicates homedirs in many shells. * '/' is for separating directories, and we don't want to accidentally make subdirectories We first NFKC for zephyrs, and then apply lc. The zephyr servers apply case-folded NFKC (so says http://zephyr.1ts.org/browser/zephyr/server/zstring.c). We should probably use Unicode::CaseFold instead of lc. I'm also not sure what the order case-adjustment and normalization should be. We first NFKC, then apply lc, to jabbers, as per http://xmpp.org/internet-drafts/attic/draft-ietf-xmpp-nodeprep-03.html (though I can't actually find anything that specifies the case-folding algorithm, nor the ordering). We now use lc instead of g_utf8_strdown to normalize AIM screennames.
  • Property mode set to 100644
File size: 4.3 KB
Line 
1use warnings;
2use strict;
3
4=head1 NAME
5
6BarnOwl::Message::Jabber
7
8=head1 DESCRIPTION
9
10A subclass of BarnOwl::Message for Jabber messages
11
12=cut
13
14package BarnOwl::Message::Jabber;
15
16use base qw( BarnOwl::Message );
17use Unicode::Normalize qw( NFKC );
18
19sub jtype { shift->{jtype} };
20sub from { shift->{from} };
21sub to { shift->{to} };
22sub room { shift->{room} };
23sub nick { shift->{nick} };
24sub subject { shift->{subject} };
25sub status { shift->{status} }
26
27sub login_type {
28    my $self = shift;
29    my $type = $self->jtype;
30    return " ($type)" if $type;
31}
32
33sub login_extra {
34    my $self = shift;
35    my $show = $self->{show};
36    my $status = $self->status;
37    my $s = "";
38    $s .= $show if $show;
39    $s .= ", $status" if $status;
40    return $s;
41}
42
43sub long_sender {
44    my $self = shift;
45    if ($self->jtype eq 'groupchat' && $self->nick) {
46        my $from_jid = Net::Jabber::JID->new($self->from);
47        if ($from_jid->GetJID('base') eq $self->room &&
48            $from_jid->GetResource() eq $self->nick) {
49            return $self->nick;
50        }
51    }
52    return $self->from;
53}
54
55sub context {
56    return shift->room;
57}
58
59sub subcontext {
60    return shift->subject || "";
61}
62
63sub personal_context {
64    my $self = shift;
65    if($self->subject) {
66        return "subject: " . $self->subject;
67    } elsif ($self->is_incoming) {
68        return "to " . $self->to;
69    } else {
70        return "from " . $self->from;
71    }
72}
73
74sub smartfilter {
75    my $self = shift;
76    my $inst = shift;
77
78    my $filter;
79
80    if($self->jtype eq 'chat') {
81        my $user;
82        if($self->direction eq 'in') {
83            $user = $self->from;
84        } else {
85            $user = $self->to;
86        }
87        return smartfilter_user($user, $inst);
88    } elsif ($self->jtype eq 'groupchat') {
89        my $room = $self->room;
90        if ($inst) {
91            my $subject = $self->subject;
92            $filter = "jabber-room-$room-subject-$subject";
93            BarnOwl::command(qw[filter], $filter,
94                             qw[type ^jabber$ and room], "^\Q$room\E\$",
95                             qw[and subject], "^\Q$subject\E\$");
96        } else {
97            $filter = "jabber-room-$room";
98            BarnOwl::command(qw[filter], $filter,
99                             qw[type ^jabber$ and room], "^\Q$room\E\$");
100        }
101        return $filter;
102    } elsif ($self->login ne 'none') {
103        return smartfilter_user($self->from, $inst);
104    }
105}
106
107sub smartfilter_user {
108    my $user = shift;
109    my $inst = shift;
110
111    $user   = Net::Jabber::JID->new($user)->GetJID( $inst ? 'full' : 'base' );
112    my $filter = "jabber-user-$user";
113    BarnOwl::command(qw[filter], $filter, qw[type ^jabber$],
114                     qw[and ( ( direction ^in$ and from], "^\Q$user\E(/.*)?\$",
115                     qw[) or ( direction ^out$ and to ], "^\Q$user\E(/.*)?\$",
116                     qw[ ) ) ]);
117    return $filter;
118
119}
120
121sub replycmd {
122    my $self = shift;
123    my ($recip, $account, $subject);
124    if ($self->is_loginout) {
125        $recip   = $self->sender;
126        $account = $self->recipient;
127    } elsif ($self->jtype eq 'chat') {
128        return $self->replysendercmd;
129    } elsif ($self->jtype eq 'groupchat') {
130        $recip = $self->room;
131        if ($self->is_incoming) {
132            $account = $self->to;
133        } else {
134            $account = $self->from;
135        }
136        $subject = $self->subject;
137    } else {
138        # Unknown type
139        return;
140    }
141    return jwrite_cmd($recip, $account, $subject);
142}
143
144sub replysendercmd {
145    my $self = shift;
146    if($self->jtype eq 'groupchat'
147       || $self->jtype eq 'chat') {
148        my ($recip, $account);
149        if ($self->is_incoming) {
150            $recip   = $self->from;
151            $account = $self->to;
152        } else {
153            $recip   = $self->to;
154            $account = $self->from;
155        }
156        return jwrite_cmd($recip, $account);
157    }
158    return $self->replycmd;
159}
160
161sub jwrite_cmd {
162    my ($recip, $account, $subject) = @_;
163    if (defined $recip) {
164        my @cmd = ('jwrite', '-a', $account);
165        if (defined $subject) {
166            push @cmd, '-s', $subject;
167        }
168        push @cmd, '--', $recip;
169        return BarnOwl::quote(@cmd);
170    } else {
171        return undef;
172    }
173}
174
175sub log_filenames {
176    return map { lc(NFKC($_)) } BarnOwl::Message::log_filenames(@_);
177}
178
179=head1 SEE ALSO
180
181L<BarnOwl::Message>
182
183=cut
184
1851;
Note: See TracBrowser for help on using the repository browser.