| 1 | package Bot::BasicBot::Pluggable::Module::Notify; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 0 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||
| 6 | 38 | our $VERSION = '1.00'; | |||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||
| 8 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||
| 10 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||
| 11 | # Library Modules # | ||||||||||||||||||||||||||||||||||||||
| 12 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use base qw(Bot::BasicBot::Pluggable::Module); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | 8 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 18 | 8 | ▶ | use List::MoreUtils qw( any ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | 8 | ▶ | use MIME::Lite; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||
| 21 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||
| 22 | # Variables # | ||||||||||||||||||||||||||||||||||||||
| 23 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||
| 25 | 14 | my (%settings,%emails); | |||||||||||||||||||||||||||||||||||||
| 26 | 14 | my $load_time = 0; | |||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | 12 | my %defaults = ( | |||||||||||||||||||||||||||||||||||||
| 29 | smtp => '', | ||||||||||||||||||||||||||||||||||||||
| 30 | replyto => 'no-reply@example.com', | ||||||||||||||||||||||||||||||||||||||
| 31 | from => 'no-reply@example.com', | ||||||||||||||||||||||||||||||||||||||
| 32 | active => 15, | ||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||
| 38 | # Public Methods # | ||||||||||||||||||||||||||||||||||||||
| 39 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=2 SCAR=14.0
Pod
documented
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $file = $self->store->get( 'notify', 'notifications' ); | |||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | unless($file) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $file = $0; | |||||||||||||||||||||||||||||||||||||
| 47 | 0 | $file =~ s/\.pl$/.csv/; | |||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $self->store->set( 'notify', 'notifications', $file ); | |||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||
| 53 | 2 | ▶ | sub help { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
help: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | my $active = $settings{active} || $defaults{active}; | ||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$settings{'active'} || $defaults{'active'}
$settings{'active'} || $defaults{'active'}
MC/DC0%0/2
$settings{'active'} || $defaults{'active'}
$settings{'active'}
$defaults{'active'}
MC/DC0%0/2
$settings{'active'} || $defaults{'active'}
$settings{'active'}
$defaults{'active'}
Truth table0%0/3
A || B
A= $settings{'active'}B= $defaults{'active'}
Truth table0%0/3
A || B
A= $settings{'active'}B= $defaults{'active'}
| |||||||||||||||||||||||||||||||||||||||
| 55 | 2 | return "if you have been away for more than $active minutes, and someone posts a channel message, identifying you, this will email you the message."; | |||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub told { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
told: not called CC=17 SCAR=51.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 59 | 2 | my ( $self, $mess ) = @_; | |||||||||||||||||||||||||||||||||||||
| 60 | 1 | my $body = $mess->{body}; | |||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | return 0 unless defined $body; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | return 0 unless($self->_load_notification_file()); | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return 0 if($body =~ m!^\s*/?who(is|was)?\s+!); # ignore who requests | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my (@words) = split(/[^@\w\+\-]+/,$body); | |||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $data = $self->bot->channel_data( $mess->{channel} ); | |||||||||||||||||||||||||||||||||||||
| 68 | 0 | my %users = map { $_ => 0 } keys %$data; # get users in channel | |||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||
| 70 | # get identities | ||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $pocoirc = $self->bot->pocoirc( $mess->{channel} ); | |||||||||||||||||||||||||||||||||||||
| 72 | 0 | my @nicks = $pocoirc->nicks(); | |||||||||||||||||||||||||||||||||||||
| 73 | 0 | my %nicks = map { $_ => $pocoirc->nick_info($_) } @nicks; | |||||||||||||||||||||||||||||||||||||
| 74 | 0 | $self->{nicks} = \%nicks; | |||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | my $sender = $self->_match_user($mess->{who}, $self->{nicks}) || ''; | ||||||||||||||||||||||||||||||||||||
|
Condition16%1/6
$self->_match_user($mess->{'who'}, $self->{'nicks'}) || ''
$self->_match_user($mess->{'who'}, $self->{'nicks'}) || ''
MC/DC0%0/1
$self->_match_user($mess->{'who'}, $self->{'nicks'}) || ''
$self->_match_user($mess->{'who'}, $self->{'nicks'})
MC/DC0%0/1
$self->_match_user($mess->{'who'}, $self->{'nicks'}) || ''
$self->_match_user($mess->{'who'}, $self->{'nicks'})
Truth table0%0/2
A
A= $self->_match_user($mess->{'who'}, $self->{'nicks'})
Truth table50%1/2
A
A= $self->_match_user($mess->{'who'}, $self->{'nicks'})
| |||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my @recipients = grep { $_ ne $sender } keys %users; | |||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $prev = ''; | |||||||||||||||||||||||||||||||||||||
| 80 | 0 | for my $word (@words) { | |||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | next if($word =~ /(\-\-|\+\+)$/); # ignore karma messages | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | next if($prev eq 'seen'); # ignore seen messages | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $prev = $word; | |||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $nick = ''; | |||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if($word =~ /@?(\w+)/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $user = $1; | |||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $nick = $self->_match_user($user, $self->{nicks}) || ''; | ||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$self->_match_user($user, $self->{'nicks'}) || ''
$self->_match_user($user, $self->{'nicks'}) || ''
MC/DC0%0/1
$self->_match_user($user, $self->{'nicks'}) || ''
$self->_match_user($user, $self->{'nicks'})
MC/DC100%1/1
$self->_match_user($user, $self->{'nicks'}) || ''
$self->_match_user($user, $self->{'nicks'})
Truth table0%0/2
A
A= $self->_match_user($user, $self->{'nicks'})
Truth table100%2/2
A
A= $self->_match_user($user, $self->{'nicks'})
| |||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | next if($nick && $users{$nick}); # don't send repeated mails | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$nick and $users{$nick}
MC/DC0%0/2
$nick and $users{$nick}
$nick
$users{$nick}
Truth table0%0/3
A and B
A= $nickB= $users{$nick}
| |||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if($word eq '@all') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $self->_send_email(1,$mess,@recipients); | |||||||||||||||||||||||||||||||||||||
| 95 | 0 | return 1; # we only send 1 email per user | |||||||||||||||||||||||||||||||||||||
| 96 | } elsif($word eq '@here') { | ||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my @users = []; # filter based on seen in the last hour | |||||||||||||||||||||||||||||||||||||
| 98 | 0 | $self->_send_email(2,$mess,@recipients); | |||||||||||||||||||||||||||||||||||||
| 99 | 0 | return 1; # we only send 1 email per user | |||||||||||||||||||||||||||||||||||||
| 100 | ▶ | } elsif($nick && $emails{$nick}) { | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$nick and $emails{$nick}
MC/DC0%0/2
$nick and $emails{$nick}
$nick
$emails{$nick}
Truth table0%0/3
A and B
A= $nickB= $emails{$nick}
| |||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $self->_send_email(1,$mess,$nick); | |||||||||||||||||||||||||||||||||||||
| 102 | 0 | $users{$nick} = 1; # we only send 1 email per user | |||||||||||||||||||||||||||||||||||||
| 103 | 0 | @recipients = grep { $_ ne $nick } @recipients; # don't send repeated mails | |||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | return 1 if(any { $_ == 1 } values %users); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.5
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 108 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||
| 111 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||
| 112 | # Private Methods # | ||||||||||||||||||||||||||||||||||||||
| 113 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||
| 115 | 7 | ▶ | sub _send_email { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_send_email: called CC=9 SCAR=22.9
| |||||||||||||||||||||||||||||||||||||||
| 116 | 12 | my ($self,$type,$mess,@users) = @_; | |||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||
| 118 | my $subject = sprintf "IRC: %s sent you a message", | ||||||||||||||||||||||||||||||||||||||
| 119 | 5 | $mess->{who}; | |||||||||||||||||||||||||||||||||||||
| 120 | my $body = sprintf "Hi,\n\n%s sent the following message in channel %s at %s %s:\n\n%s\n\n", | ||||||||||||||||||||||||||||||||||||||
| 121 | $mess->{who}, | ||||||||||||||||||||||||||||||||||||||
| 122 | $mess->{channel}, | ||||||||||||||||||||||||||||||||||||||
| 123 | DateTime->now->ymd, DateTime->now->hms, | ||||||||||||||||||||||||||||||||||||||
| 124 | 5 | $mess->{body}; | |||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||
| 126 | 5 | my $data = $self->bot->channel_data( $mess->{channel} ); | |||||||||||||||||||||||||||||||||||||
| 127 | 5 | my %channel = map { $_ => 1 } keys %$data; # get users in channel | |||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||
| 129 | 5 | for my $user (@users) { | |||||||||||||||||||||||||||||||||||||
| 130 | 25 | my $nick = $self->_match_user($user, $self->{nicks}); | |||||||||||||||||||||||||||||||||||||
| 131 | 5 | ▶ | next unless($nick); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||
| 133 | # if user is in channel, they must be inactive for at least 15 minues | ||||||||||||||||||||||||||||||||||||||
| 134 | # if the user is not in the channel, send them an email, even if they | ||||||||||||||||||||||||||||||||||||||
| 135 | # were recently active, as they have likely just left. | ||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||
| 137 | 5 | ▶ | if($channel{$user}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 138 | 5 | my $seen = $self->store->get( 'Seen', "seen_$user"); | |||||||||||||||||||||||||||||||||||||
| 139 | 25 | ▶ | if($seen && $seen->{'time'}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$seen and $seen->{"time"}
MC/DC0%0/2
$seen and $seen->{"time"}
$seen
$seen->{"time"}
Truth table0%0/3
A and B
A= $seenB= $seen->{"time"}
| |||||||||||||||||||||||||||||||||||||||
| 140 | 5 | my $time = time - $seen->{'time'}; | |||||||||||||||||||||||||||||||||||||
| 141 | 5 | ▶ | next if($time < $settings{active} * 60); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 142 | 5 | ▶ | next if($time > 3600 && $type == 2); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$time > 3600 and $type == 2
MC/DC0%0/2
$time > 3600 and $type == 2
$time > 3600
$type == 2
Truth table0%0/3
A and B
A= $time > 3600B= $type == 2
| |||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||
| 146 | $self->_sendmail( | ||||||||||||||||||||||||||||||||||||||
| 147 | to => $emails{$nick}{email}, | ||||||||||||||||||||||||||||||||||||||
| 148 | 25 | subject => $subject, | |||||||||||||||||||||||||||||||||||||
| 149 | body => $body | ||||||||||||||||||||||||||||||||||||||
| 150 | ); | ||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||
| 154 | 4 | ▶ | sub _load_notification_file { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_notification_file: called CC=15 SCAR=29.6
| |||||||||||||||||||||||||||||||||||||||
| 155 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||
| 157 | 9 | ▶ | my $fn = $self->store->get( 'notify', 'notifications' ) or return 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 158 | 13 | ▶ | return 0 unless(-r $fn); # file must be readable | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||
| 160 | 13 | my $mod = (stat($fn))[9]; | |||||||||||||||||||||||||||||||||||||
| 161 | 13 | ▶ | return 1 if($mod <= $load_time && keys %emails); # don't reload if not modified | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mod <= $load_time and keys %emails
MC/DC0%0/2
$mod <= $load_time and keys %emails
$mod <= $load_time
keys %emails
Truth table66%2/3
A and B
A= $mod <= $load_timeB= keys %emails
| |||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||
| 163 | 29 | ▶ | my $fh = IO::File->new($fn,'r') or return 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 164 | 13 | (%settings,%emails) = (); | |||||||||||||||||||||||||||||||||||||
| 165 | 23 | ▶ | while(<$fh>) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 166 | 23 | s/\s+$//; | |||||||||||||||||||||||||||||||||||||
| 167 | 17 | ▶ | next if(/^#/ || /^$/); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
/^#/ or /^$/
MC/DC0%0/2
/^#/ or /^$/
/^#/
/^$/
Truth table0%0/3
A or B
A= /^#/B= /^$/
| |||||||||||||||||||||||||||||||||||||||
| 168 | 17 | my ($nick,$ident,$email) = split(/,/,$_,3); | |||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||
| 170 | 10 | ▶ | if($nick eq 'CONFIG') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 171 | 2 | $settings{$ident} = $email; | |||||||||||||||||||||||||||||||||||||
| 172 | 1 | next; | |||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||
| 175 | 1 | $emails{$nick}{email} = $email; | |||||||||||||||||||||||||||||||||||||
| 176 | 9 | ▶ | $emails{$nick}{ident} = $ident if($ident); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||
| 179 | 1 | $fh->close; | |||||||||||||||||||||||||||||||||||||
| 180 | 1 | $load_time = $mod; | |||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||
| 182 | 1 | for my $key (keys %defaults) { | |||||||||||||||||||||||||||||||||||||
| 183 | 4 | ▶ | $settings{$key} ||= $defaults{$key}; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$settings{$key} ||= $defaults{$key}
MC/DC0%0/2
$settings{$key} ||= $defaults{$key}
$settings{$key}
$defaults{$key}
Truth table0%0/3
A ||= B
A= $settings{$key}B= $defaults{$key}
| |||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||
| 186 | 2 | ▶ | return 0 unless($settings{smtp}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 187 | 1 | ▶ | return 1 if(keys %emails); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 188 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||
| 191 | 6 | ▶ | sub _match_user { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_match_user: called CC=9 SCAR=22.5
| |||||||||||||||||||||||||||||||||||||||
| 192 | 6 | my ($self,$user,$nicks) = @_; | |||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||
| 194 | # matches a known user | ||||||||||||||||||||||||||||||||||||||
| 195 | 6 | ▶ | return $user if($emails{$user}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||
| 197 | # see if idents match | ||||||||||||||||||||||||||||||||||||||
| 198 | 6 | for my $ident (keys %emails) { | |||||||||||||||||||||||||||||||||||||
| 199 | 6 | ▶ | next unless($emails{$ident}{ident}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||
| 201 | 6 | for my $nick (keys %$nicks) { | |||||||||||||||||||||||||||||||||||||
| 202 | 2 | ▶ | next unless($user eq $nick); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||
| 204 | 2 | ▶ | return $ident if($nicks->{$nick}->{Real} =~ /\Q$emails{$ident}{ident}\E/); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 205 | 2 | ▶ | return $ident if($nicks->{$nick}->{User} =~ /\Q$emails{$ident}{ident}\E/); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 206 | 8 | ▶ | return $ident if($nicks->{$nick}->{Userhost} =~ /\Q$emails{$ident}{ident}\E/); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||
| 210 | 8 | return; | |||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||
| 213 | 33 | ▶ | sub _sendmail { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_sendmail: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 214 | 41 | my ($self,%hash) = @_; | |||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||
| 216 | 41 | MIME::Lite->send('smtp', $settings{smtp}, Timeout=>60); | |||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||
| 218 | my $mail = MIME::Lite->new( | ||||||||||||||||||||||||||||||||||||||
| 219 | 'Reply-To' => $settings{replyto}, | ||||||||||||||||||||||||||||||||||||||
| 220 | 'From' => $settings{from}, | ||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||
| 222 | 'Subject' => $hash{subject}, | ||||||||||||||||||||||||||||||||||||||
| 223 | 'To' => $hash{to}, | ||||||||||||||||||||||||||||||||||||||
| 224 | 'Data' => $hash{body} | ||||||||||||||||||||||||||||||||||||||
| 225 | 20 | ); | |||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||
| 227 | 56 | eval { $mail->send }; | |||||||||||||||||||||||||||||||||||||
| 228 | 276 | ▶ | if($@) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 229 | 29 | print "MailError: eval=[$@]\n"; | |||||||||||||||||||||||||||||||||||||
| 230 | 29 | return; | |||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||
| 233 | 29 | return 1; | |||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||
| 237 | 12 | 1; | |||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||
| 239 | __END__ | ||||||||||||||||||||||||||||||||||||||