grashoper has asked for the wisdom of the Perl Monks concerning the following question:

I have a sample script to check and autorespond to email and I would like to modify it to work on a windows platform for a pop3 account. I am really not sure how to pull this off but would really like to get it working, I figure I will need to connect to the pop3 and then somehow switch to inbox then parse the messages, most of this logic should work but I am stuck on figuring out how to connect to the pop3 and also switching to the inbox.
#!/usr/local/bin/perl5 use SMTPwrap; my %mailheader; my $mailbotaddress = "support\@mlxchange.com"; close(STDERR); close(STDOUT); my %commandlist = ( 'send' => 'send_file', 'list' => 'send_list', 'help' => 'send_help', ); chdir("/users/martinb/sub/mail"); my $state=1; while(<STDIN>) { chomp; if (length($_) eq 0) { $state=0; next; } if ($state) { if ( m/^From\s/) { next; } elsif ( m/(^[\w\-\.]+):\s*(.*\S)\s*$/) { $keyword = $1; $value = $2; $mailheader{$keyword} = $value; } else { $mailheader{$keyword} .= "\n" . $_; } } else { my ($command, @opts) = split; my $to = clean_address(return_address(\%mailheader)); next if /^\s*$/; unless ($commandlist{lc($command)}) { send_error($to,"Unknown command, $command.\n" . "Rest of Message ignored.\n",1); } my $function = $commandlist{lc($command)}; &$function($to,$opts[0]); } } sub send_error { my ($to,$error,$fatal) = @_; mail_a_message("Mailbot Error",$to,$mailbotaddress,$error); exit(1) if $fatal; } sub send_list { my $to = shift; send_file($to,"list"); } sub send_help { my $to = shift; send_file($to,"help"); } sub send_file { my ($to,$filename) = @_; $filename =~ s#^.*/##; $filename =~ s/[^\w\.\-]//g; send_error($to,"Cannot open $filename",0) unless (open(D, "<$filename")); my $message = "Attached below is the file $filename\n"; $message .= "------------------------------------\n\n"; $mailheader{subject} = "" unless $mailheader{subject}; { local $/; $message .= <D>; } close(D); send_error($to,"Error: $SMTPwrap::error",0) unless(mail_a_message("Mailbot Reply to job, " . "$mailheader{subject}", $to,$mailbotaddress,$message)); }

Replies are listed 'Best First'.
Re: modifying for windoze
by Akoya (Scribe) on Mar 13, 2008 at 21:27 UTC
Re: modifying for windoze
by dwm042 (Priest) on Mar 13, 2008 at 21:28 UTC
    In terms of getting a reliable POP3 connection, it might be simpler to start with a POP3 module, such as Net::POP3. I've used Net::POP3 and Mail::Sendmail to write scripts that did end-to-end testing of mail servers.
      It would probably be really good for me to write my own but for something this simple, all I really needed was something that will autorespond without responding multiple times, I thought for sure i would be able to find something that would serve, I guess its just a little too simple after-all since I am finding either replacement email clients or mailers, not a reader & mailer if that makes any sense. I guess I will take a stab at writing my own. Thanks very much for the input to both of you.