Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created June 16, 2010 18:48
Show Gist options
  • Save waffle2k/441099 to your computer and use it in GitHub Desktop.
Save waffle2k/441099 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
#
# A simple little script to send back a vaction message. Requires procmail to wrap around it.
#
use strict;
use Email::Simple;
use MIME::Lite;
sub check_for_sender( $ ){
my ($sender) = @_;
open FD, "<sender.log";
my $send_responder = 1;
SENDER:while( <FD> ){
chomp;
if( $_ eq $sender ){
$send_responder = 0 and last SENDER;
}
}
close FD;
if( $send_responder ){
open FD, ">>sender.log";
print FD "$sender\n";
close FD;
my $email = MIME::Lite->new(
To => $sender,
Subject => '(Autoresponder) Away until next week',
From => 'YOUREMAILADDRESSGOESHERE',
Data => 'Hi, Im away until next week, but will be checking my mail. Hope to get back to you soon.',
);
return $email;
}
return undef;
}
my $text = do { local $/; <>; };
my $email = Email::Simple->new($text);
my @v1 = $email->header( 'To' ) ;
#. "," . $email->header( 'Cc' );
my $txt = $v1[0];
@v1 = $email->header( 'Cc' );
$txt .= "," . $v1[0];
$txt = lc $txt;
my @v2 = split /,/, $txt;
for( @v2 ){
s/\s+//g;
if( /\<(\S+?)\>/ ){
$_ = $1;
}
}
my $sender = $email->header( 'Return-Path' ) || exit( 0 );
$sender =~ s/[\<\>\s]//g;
exit(0) if $sender eq '';
# I only want to send this to @tucows.com people
exit(0) unless $sender =~ /\@tucows\.com/;
if( my $email_to_send = check_for_sender( $sender ) ){
$email_to_send->send( "smtp", "127.0.0.1" );
exit( 0 );
}
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment