Difference between revisions of "POP3.pl"

From Organic Design wiki
(hack email fwd cos didn't work at zoneedit)
m
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{legacy}}
 +
<source lang="perl">
 
use Net::POP3;
 
use Net::POP3;
  
Line 22: Line 24:
  
 
( my $page, my $domain ) = ( $1, $2 );
 
( my $page, my $domain ) = ( $1, $2 );
 +
$to = "$page\@$domain";
 
$page =~ tr/&/%/;
 
$page =~ tr/&/%/;
 
( my $from ) = grep /^from:/i, @$msg;
 
( my $from ) = grep /^from:/i, @$msg;
Line 29: Line 32:
  
 
# Couldn't forward an od addr to another od addr at zoneedit
 
# Couldn't forward an od addr to another od addr at zoneedit
$page = 'user_talk%3ajewel@organicdesign.co.nz' if $to =~ /^jewel@/;
+
$page = 'user_talk%3ajewel' if $to =~ /^jewel@/;
  
 
# Append if addressed to a talk page
 
# Append if addressed to a talk page
Line 45: Line 48:
 
spawn $2, split /\s*,\s*/, $3;
 
spawn $2, split /\s*,\s*/, $3;
 
logAdd "Executing $2";
 
logAdd "Executing $2";
$pop3->delete($_);
 
}
 
 
# Delete if spam score > 5
 
if ( $subject =~ /^\[SPAM:: score=([0-9.]+)\]\s+(.+)$/ and $1 > 5 ) {
 
logAdd "Deleted spam: $2";
 
 
$pop3->delete($_);
 
$pop3->delete($_);
 
}
 
}
Line 59: Line 56:
 
logAdd 'Exit';
 
logAdd 'Exit';
 
}
 
}
 +
</source>
 +
[[Category:PERL]]

Latest revision as of 21:43, 20 November 2019

Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, now this page is for historic record only.
use Net::POP3;

sub popCheck {

	# Login in to POP box
	my( $domain, $user ) = @_;
	my $loggedIn = 0;
	my $pop3 = Net::POP3->new( $domain );
	$pop3->login( $user, $::pwd4 );

	# Loop through all messages
	my $list = $pop3->list();
	my @messages = keys %$list;
	logAdd( ($#messages+1)." messages on $user\@$domain" );
	for ( @messages ) {

		# Get relevent message headers and content
		my $msg = $pop3->top( $_, 4096 );
		chomp @$msg;
		( my $to ) = grep /^to:/i, @$msg;
		if ( $to =~ /([-.&a-z0-9_]+)@([-.a-z0-9_]+)/i ) {

			( my $page, my $domain ) = ( $1, $2 );
			$to = "$page\@$domain";
			$page =~ tr/&/%/;
			( my $from ) = grep /^from:/i, @$msg;
			$from = $1 if $from =~ /([-.&a-z0-9_]+@[-&.a-z0-9_]+)/i;
			( my $subject ) = grep /^subject:/i, @$msg;
			$subject =~ s/^.+?:\s*(.*?)(\r?\n)*/$1/;

			# Couldn't forward an od addr to another od addr at zoneedit
			$page = 'user_talk%3ajewel' if $to =~ /^jewel@/;

			# Append if addressed to a talk page
			if ( $page =~ /^(\w*?_)?talk%3a/i ) {
				$) while shift @$msg;
				my $append = "\n----\n'''Email from [mailto:$from $from]''', ~~";
				$append .= "~~\n\n'''''$subject'''''\n:".join( "\n:", @$msg )."\n";
				$loggedIn = wikiLogin $::wiki, $::peer, $::pwd1 unless $loggedIn;
				wikiPageAppend $::wiki, $page, $append, $subject;
				$pop3->delete($_);
				}

			# Execute if an email command
			if ( $subject =~ /^(.+?):(.+?)\((.*?)\)\s*(.*)$/ and $1 eq $::pwd5 ) {
				spawn $2, split /\s*,\s*/, $3;
				logAdd "Executing $2";
				$pop3->delete($_);
				}

			}
		}
	$pop3->quit();
	logAdd 'Exit';
	}