Skip to main content

Spam vorlesen lassen mit espeak

Voraussetzungen:

  • Perlmodule: Net::IMAP::Simple, Email::Simple
  • espeak-Installation

getestet unter Ubuntu 10.10 Maverick

Dieses Script logt sich in eine IMAP-Mailbox ein und liest den Betreff aller Mails im SPAM/Junk-Ordner via espeak vor. Die Parameter sollten natürlich entsprechend angepasst werden.

#!/usr/bin/perl
 
use strict;
use warnings;
use Net::IMAP::Simple;
use Email::Simple;
 
my $server = "mail.domain.de";
my $user = "username";
my $pass = "passwort";
my $folder = "INBOX/Junk";
 
my $espeak_params = "-s 160";
 
# open a connection to the IMAP server
my $imap = Net::IMAP::Simple->new($server) || die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n";
 
# login
if(!$imap->login($user, $pass)) {
   print STDERR $imap->errstr . "\n";
   exit(64);
}
 
# select the SPAM-folder
my $nm = $imap->select($folder);
 
for(my $i = 1; $i <= $nm; $i++){
  my $es = Email::Simple->new(join '', @{ $imap->top($i) } );
  if($imap->seen($i)){
    # already read mail
    print "*";
  } else {
    # new mail
    print " ";
    # uncomment this to only read new mail
    #my @args = ("espeak", $espeak_param,  "\"" . $es->header('Subject') . "\"");
    #system(@args) || die("system @args failed: $?");
  }
  # print the mailnumber and subject
  printf("[%03d] %s\n", $i, $es->header('Subject'));
 
  # comment this out, when you've enabled the read of unread mails only above
  my @args = ("espeak", $espeak_params,  "\"" . $es->header('Subject') . "\"");
  system(@args) || die("system @args failed: $?");
}
 
$imap->quit;