-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.php
31 lines (26 loc) · 1.1 KB
/
delete.php
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
<?php
include('config.php');
foreach ($accounts as $account) {
print ("ACCOUNT: {$account['username']}\n");
// connect to IMAP server by account data
$append = $account['ssl'] ? '/ssl' : '';
$connect = "{{$account['domain']}:{$account['port']}/imap{$append}}";
$mailbox = imap_open("{$connect}INBOX", $account['username'], $account['password']);
if ( $mailbox ) {
// retrieve all mails older than the age_in_seconds variable from now - the UID is returned in an array
$seconds = $account['age_in_days'] * 86400;
$mails = imap_search($mailbox, 'BEFORE "' . date('d-M-Y', (time() - $seconds)) . '"', SE_UID);
if ($mails)
// mark all the mails older than age_in_seconds as deleted
foreach($mails as $id) {
$info = imap_fetch_overview($mailbox, $id, FT_UID);
if ($info && $info[0]) {
print ("{$account['username']}: delete id {$id} - {$info[0]->from}: {$info[0]->subject}\n");
imap_delete($mailbox, $id, FT_UID);
}
}
imap_close($mailbox, CL_EXPUNGE);
} else {
echo ("could not connect to {{$account['domain']}:{$account['port']}/imap} for {$account['username']}.\n");
}
}