use IO::File;
use Fcntl;
+eval {
+ require Mail::Send;
+};
+
use strict;
use vars qw($VERSION $BRANCH);
# does an identical message already exist?
my $m;
for $m (@msg) {
- if ($ref->{subject} eq $m->{subject} && $ref->{t} == $m->{t} && $ref->{from} eq $m->{from} && $ref->{to} eq $m->{to}) {
+ if (substr($ref->{subject},0,28) eq substr($m->{subject},0,28) && $ref->{t} == $m->{t} && $ref->{from} eq $m->{from} && $ref->{to} eq $m->{to}) {
$ref->stop_msg($fromnode);
my $msgno = $m->{msgno};
dbg("duplicate message from $ref->{from} -> $ref->{to} to msg: $msgno") if isdbg('msg');
$ref->{msgno} = next_transno("Msgno");
push @{$ref->{gotit}}, $fromnode; # mark this up as being received
$ref->store($ref->{lines});
+ $ref->notify;
add_dir($ref);
- my $dxchan = DXChannel->get($ref->{to});
- $dxchan->send($dxchan->msg('m9')) if $dxchan && $dxchan->is_user;
Log('msg', "Message $ref->{msgno} from $ref->{from} received from $fromnode for $ref->{to}");
}
}
}
+sub notify
+{
+ my $ref = shift;
+ my $to = $ref->{to};
+ my $uref = DXUser->get($to);
+ my $dxchan = DXChannel->get($to);
+ if (*Mail::Send && $uref && $uref->wantemail) {
+ my $email = $uref->email;
+ if ($email) {
+ my @list = ref $email ? @{$email} : $email;
+ my $msg = new Mail::Send Subject=>"[DXSpider: $ref->{from}] $ref->{subject}";
+ $msg->to(@list);
+ my $fh = $msg->open;
+ if ($fh) {
+ print $fh "From: $ref->{from} To: $to On Node: $main::mycall Origin: $ref->{origin} Msgno: $ref->{msgno}\r\n\r\n";
+ print $fh map {"$_\r\n"} $ref->read_msg_body;
+ $fh->close;
+ for (@list) {
+ Log('msg', "Msgno $ref->{msgno} from $ref->{from} emailed to $_");
+ }
+ } else {
+ dbg("email forwarding error $!") if isdbg('msg');
+ }
+ }
+ }
+ $dxchan->send($dxchan->msg('m9')) if $dxchan && $dxchan->is_user;
+}
+
# store a message away on disc or whatever
#
# NOTE the second arg is a REFERENCE not a list
my $call = '';
$call = ' by ' . $dxchan->call if $dxchan;
- Log("Msgno $self->{msgno} expunged$call");
+ Log('msg', "Msgno $self->{msgno} expunged$call");
# remove the file
unlink filename($self->{msgno});
$ref->add_dir();
push @out, $self->msg('m11', $ref->{msgno}, $to);
#push @out, "msgno $ref->{msgno} sent to $to";
- my $dxchan = DXChannel->get(uc $to);
- if ($dxchan) {
- if ($dxchan->is_user()) {
- $dxchan->send($dxchan->msg('m9'));
- }
- }
+ $ref->notify;
}
} else {
Log('msg', $self->call . " swore to @{$loc->{to}} subject: '$loc->{subject}' in msg, REJECTED");
my @out = import_one($main::me, \@msg, $splitit);
Log('msg', @out);
}
- queue_msg(0);
}
# import one message as a list in bbs (as extended) mode
# first line;
my $line = shift @$ref;
- my @f = split /\b/, $line;
+ my @f = split /([\s\@\$])/, $line;
@f = map {s/\s+//g; length $_ ? $_ : ()} @f;
unless (@f && $f[0] =~ /^(:?S|SP|SB|SEND)$/ ) {
} else {
push @chunk, $ref;
}
-
+
+ # does an identical message already exist?
+ my $m;
+ for $m (@msg) {
+ if (substr($subject,0,28) eq substr($m->{subject},0,28) && $from eq $m->{from} && grep $m->{to} eq $_, @to) {
+ my $msgno = $m->{msgno};
+ dbg("duplicate message from $from -> $m->{to} to msg: $msgno") if isdbg('msg');
+ Log('msg', "duplicate message from $from -> $m->{to} to msg: $msgno");
+ return;
+ }
+ }
+
# write all the messages away
my $i;
for ( $i = 0; $i < @chunk; $i++) {
$mref->add_dir();
push @out, $dxchan->msg('m11', $mref->{msgno}, $to);
#push @out, "msgno $ref->{msgno} sent to $to";
- my $todxchan = DXChannel->get(uc $to);
- if ($todxchan) {
- if ($todxchan->is_user()) {
- $todxchan->send($todxchan->msg('m9'));
- }
- }
+ $mref->notify;
}
}
return @out;