note 93706 added to function.imap-delete

From: Date: Wed, 23 Sep 2009 17:48:18 +0000
Subject: note 93706 added to function.imap-delete
Groups: php.notes 
Request: Send a blank email to php-notes+get-160990@lists.php.net to get a copy of this message
In case you feel the need to kill all emails from before a certain year on your Gmail account, this would work: <?php error_reporting(E_ALL ^ (E_NOTICE | E_WARNING)); echo "parsing ini file...\n"; $ini = parse_ini_file('g.ini'); $user = $ini['user']; $pass = $ini['pass']; $year = $ini['year']; echo "account {$user} - killing msgs from before {$year}\n\n"; echo "connecting...\n"; $imap = imap_open("{imap.gmail.com:993/imap/ssl/novalidate-cert}[Gmail]/All Mail", $user, $pass) or die("can't connect: " . imap_last_error() . "\n"); echo "checking current mailbox...\n"; $mbox = imap_check($imap); echo "fetching overview...\n"; $flaggedForDelete = 0; for($n = 0; $n < $mbox->Nmsgs; $n++) { echo "processing {$n} of {$mbox->Nmsgs}...\r"; $hdr = imap_fetchheader($imap, $n); preg_match('/^Date: (.*?)$/m', $hdr, $matches); $date = date_parse(strtotime($matches[1])); if($date['year'] < 2009) { imap_delete($imap, $msg->msgno); $flaggedForDelete++; } } echo "expunging mailbox ({$flaggedForDelete} messages flagged)... "; echo ((imap_expunge($imap)) ? "ok" : "failed!")."\n"; imap_close($imap); ?> ---- Server IP: 208.69.120.35 Probable Submitter: 69.169.155.190 ---- Manual Page -- http://www.php.net/manual/en/function.imap-delete.php Edit -- https://master.php.net/note/edit/93706 Del: integrated -- https://master.php.net/note/delete/93706/integrated Del: useless -- https://master.php.net/note/delete/93706/useless Del: bad code -- https://master.php.net/note/delete/93706/bad+code Del: spam -- https://master.php.net/note/delete/93706/spam Del: non-english -- https://master.php.net/note/delete/93706/non-english Del: in docs -- https://master.php.net/note/delete/93706/in+docs Del: other reasons-- https://master.php.net/note/delete/93706 Reject -- https://master.php.net/note/reject/93706 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160990) next »