1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use strict;
use warnings;
use Mail::IMAPClient;
use IO::Socket::SSL;
############################
### SSL erstellen
############################
my $socket = IO::Socket::SSL->new ( PeerAddr => 'imap.web.de',
PeerPort => 993,
SSL_verify_mode => SSL_VERIFY_NONE,
) or die "socket(): $@";
my $client = Mail::IMAPClient->new ( Socket => $socket,
User => '****@web.de',
Password => '***********',
) or die "new(): $@";
############################
### select Ordner
############################
$client->select('INBOX');
############################
### Mails holen
############################
my @mails = ($client->seen(),$client->unseen);
############################
### Mail-Durchlauf
############################
foreach my $id (@mails)
{
print "\nid: $id\n";
my $from = $client->get_header($id, 'From');
my $subject = $client->get_header($id, 'Subject');
my $date = $client->get_header($id, 'Date');
print "\nFrom: $from Subject: $subject Date: $date";
####### Mail löschen
print "\nMail loeschen Ja \ Nein: ";
chomp (my $jn = <STDIN>);
if( $jn eq "J" || $jn eq "j" )
{
print "\nMail-ID $id wird geloescht";
$client->delete_message($id) or warn "Could not delete_message: $@\n";
}
};
############################
### Verbindung trennen
############################
$client->logout();
QuoteNOTE SOME MORE: In the grand tradition of the IMAP protocol, deleting a message doesn't actually delete the message. Really. If you want to make sure the message has been deleted, you need to expunge the folder (via the expunge method, which is implemented via the default method). Or at least close it. This is generally considered a feature, since after deleting a message, you can change your mind and undelete it at any time before your expunge or close.