Archive for April, 2006

Laziness-proof eMail backend script

Saturday, April 22nd, 2006

This started yesterday at work and was finished this morning after I passed out dead-tired last night.

I wrote a backend script for handling the emails that come to “all AT pranav NOSPACE sharma DOT com”

Now why did I do this?

Many emails were going around to that address and since some people simply hit “Reply All”, the authors of previous emails got the reply twice. This was annoying!!!

So, without going into much detail, I redesigned the whole process of how these emails got relayed to each person. Now you can click either “Reply” or “Reply All”, it won’t matter. This thing is laziness-proof (although I want to say idiot-proof).

So without further delay, here is my script which was shamelessly inspired from MEOW (ebackend.com). If you want to use this, please remove the ‘\’ before each ‘<' and '>‘. Also, notice the email addresses have been written so that robots cannot read it on this post. For the actual script, you must use actual email addresses with the ‘@’ preceeded by a ‘\’ like this: ‘\@’

#!/usr/bin/perl -w

######################################################################
## The following code has been adapted from MEOW (www.ebackend.com) ##
######################################################################

BEGIN {

$::INC[@::INC] = “/home/pranavs/public_html/all AT pranav NOSPACE sharma DOT com/Lib”;

require Mail::POP3Client;
require XML::Simple;
}

print “Content-type: text/html\n\n”;

# Read login information

my $xml_config = ‘/home/pranavs/public_html/all AT pranav NOSPACE sharma DOT com/config.xml’; # XML Configuration

my $config = &ReadConfig($xml_config);
if ( !$config ) {
print “\nConfiguration file Invalid / Not Present\n “;
exit;
}

# Get mails from the mailbox into %NewItems
# $new_items stores count
my $new_items = &ReadMailBox($config, \%NewItems);

if ( !$new_items) {
print “\nNo new messages for all AT pranav NOSPACE sharma DOT com”;
exit;
} else {
&SendMail(\%NewItems);
}

######################################################################
####################### Helper Functions #############################
######################################################################

sub ReadConfig {

my ($config) = @_;

$config = XML::Simple::XMLin(”$config”) ;

return $config;
}

sub ReadMailBox {

my ($config_hash, $new_item_hash) = @_;
my $msg_count;

# Connect to a POP Mailbox using POP3Client library
$Mail = new Mail::POP3Client( USER =\> “$$config_hash{’mail’}{’user’}”,
PASSWORD =\> “$$config_hash{’mail’}{’pass’}”,
HOST =\> “$$config_hash{’mail’}{’host’}”,
);

$$config_hash{’mail’}{’newitems’} = $Mail-\>Count();

if ( $$config_hash{’mail’}{’newitems’} \< 1 ) {
return 0;
}

for( $msg_count = 1; $msg_count \<= $$config_hash{'mail'}{'newitems'}; $msg_count++ ) {

foreach( $Mail-\>Head( $msg_count ) ) {

if ( $_ =~ m/^((From|Subject)):(.*?)$/i ) {
$header = lc($1);
$$new_item_hash{$msg_count}{$header} = $3;
}
}

$$new_item_hash{$msg_count}{’body’} = $Mail-\>Body( $msg_count );

#Adding a footer to each email with unsibscribe instructions
if ($$new_item_hash{$msg_count}{’body’} =~ m/\<\/body\>\s*\<\/html\>/i) {
$$new_item_hash{$msg_count}{’body’} =~ s/\<\/body\>\s*\<\/html\>/\\\
To stop receiving these emails, send an email to unsubscribe AT pranav NOSPACE sharma DOT com.\To see a list of subscribed members, send an email to whois AT pranav NOSPACE sharma DOT com.\<\/body\>\<\/html\>/i ;
} else {
$$new_item_hash{$msg_count}{’body’} .=”\n\n——————————————————-\nTo stop receiving these emails, send an email to unsubscribe AT pranav NOSPACE sharma DOT com.\nTo see a list of subscribed members, send an email to whois AT pranav NOSPACE sharma DOT com”;
}

if( $$new_item_hash{$msg_count}{’from’} =~ m/(.+)\s*\<([\+\w\.\-]+\@[\w\.\-]+\.[a-z][a-z]+)\>/i ) {
$$new_item_hash{$msg_count}{’from’} = $1;
}

$$new_item_hash{$msg_count}{’valid’} = 0;
$Mail-\>Delete( $msg_count);
}

$Mail-\>Close();

return $$config_hash{’mail’}{’newitems’};
}

sub SendMail {

my ($newItems_List ) = @_;

foreach $msg_count ( keys %$newItems_List ) {

unless(open (MAIL, “|/usr/sbin/sendmail -t”)) {
print “error.\n”;
warn “Error starting sendmail: $!”;
}
else{
if($$newItems_List{$msg_count}{’body’} =~ m/\s+–(.*[=_\.0-9a-z]+)–/i ) {
my $boundary = $1;
print MAIL “Content-Type: multipart/alternative;\n”;
print MAIL ” boundary=\”$1\”\n”;
print MAIL “MIME-Version: 1.0\n”;
}
print MAIL “From: $$newItems_List{$msg_count}{’from’}\\n”;
print MAIL “BCC: all DO NOT REPLY to this address AT pranav NOSPACE sharma DOT com\n”;
print MAIL “Subject: $$newItems_List{$msg_count}{’subject’}\n”;
print MAIL “\n$$newItems_List{$msg_count}{’body’}”;
close(MAIL) || warn “Error closing mail: $!”;
print “Mail sent.\n”;
}

}
}

Why is death so bad?

Monday, April 17th, 2006

Why is death so bad?

For the purpose of this narrative, I will define Death as the absolute cessation of a being with no existence after the exact moment of death.

The first premise is that a terrible event is something where we feel sorry for the subject on whom the ill has befallen. For example, if one were to become crippled for the rest of their life, we would feel sorry for them because they are the subject on whom the terrible ill has befallen.

The second premise is that we don’t feel sorry for someone that does not exist. For example, we do not feel sorry for the children Beethoven did not have.

Death is considered a terrible event. However, since after death, the subject this “terrible event” has befallen upon, ceases to exist, who do we feel sorry for?

To conclude, the person who experiences death, ceases to exist and for a terrible event, there must be a subject who we can feel sorry for. Therefore, death is not a terrible event.

Think about this for a second. When a person dies, we cannot feel sorry for him/her because they do not exist. So why do we consider death to be so bad?

Disclaimer: No I am not thinking about suicide. This topic is solely inspired by my PHIL140 class over the Winter Break.

Kiss Kiss Bang Bangalore

Tuesday, April 11th, 2006

Those of you who did not check out the latest Simpson’s episode titled “Kiss Kiss Bang Bangalore”, missed out on a great episode.

Synopsis from TV.com:
At the power plant a movie is shown where the workers endorse outsourcing and Mr. Burns announces that he is closing the plant and moving the work to India. Homer is the only union employee left on the payroll and he is sent to India to train the replacement workers, when he succeeds beyond expectations, he is given total control of the plant and declares himself a god. Meanwhile, Selma & Patty take Bart and Lisa to their MacGyver convention. When they discover Richard Dean Anderson doesn’t like MacGyver and much as they do, they kidnap him in retaliation. Anderson escapes only to enjoy the thrill and he turns himself back in so that he can escape again. When it happens over and over again, soon Patty and Selma are the ones who need a means of escape.

Check out a clip from the episode that I recorded:
You Ignorant American.wmv (1 MB)

Windows Media Player 10 required to play the above video.

Due to copyright protection laws, I cannot post the entire episode but feel free to contact me and we can arrange something.

Weekend events & pictures

Sunday, April 9th, 2006

Friday: Dinner with Usman and Neremaan at Thai Chef in DC.
Saturday: Ritu’s 22nd birthday at Cloud lounge in DC.
Sunday: Ritu’s 22nd birthday lunch at Indique in DC.

Pictures are up from all three events. Please click the “My Pictures” link on the right.

Fun in the ’sky’

Monday, April 3rd, 2006

On Sunday morning, Prateek took me, Ritu & Rashi for a little flying around MD. The pictures are up in the “My Pictures” section. It was a fun trip and I got to do a little flying too.

Gemstone Thesis Conference

Sunday, April 2nd, 2006

Yesterday was my Gemstone Thesis Conference … a culmination of about 3 years of research. There are a couple of pictures in the pictures section. It went good and we got a lot of constructive feedback. I just can’t believe that Gemstone is over (Its a good thing).