Skip to content

Instantly share code, notes, and snippets.

@tbrianjones
Created August 21, 2013 23:12
Show Gist options
  • Save tbrianjones/6301376 to your computer and use it in GitHub Desktop.
Save tbrianjones/6301376 to your computer and use it in GitHub Desktop.
Gist to delete Gmail Labels created by the Gmail plugin called Philterit.
<?php
// delete all labels / folders created by Philterit for Gmail
//
// - Philterit is an app that organizes your gmail by applying labels
// to emails for all the brands that email you. Philterit shut down,
// but the labels ( thousands of them ) remained in my Gmail account.
//
// - this app removes them all in bulk.
//
// - use:
//
// - update $user and $pass with your gmail username and password
// - execute this app from the command line ( eg. php remove_philterit_for_gmail_labels.php )
//
// *** you may have to install the php imap module
// - if you use yum, this can probably be accomplished by executing ( sudo yum install php-imap )
//
// *** this can take hours to run depending on how many labels Philterit created
// - roughly two seconds per label ( eg. 3,000 labels will take ~1.5hrs to process )
//
// your gmail credentials
$user = 'YOUR-GMAIL-ADDRESS';
$pass = 'YOUR-GMAIL-PASSWORD';
$host = '{imap.gmail.com:993/imap/ssl}';
// try to connect
$Inbox = imap_open( $host . 'INBOX', $user, $pass ) or die( 'Imap connection to Gmail Failed: ' . imap_last_error() );
// get all folders ( gmail calls most of these labels )
$folders = imap_list( $Inbox, $host, '*' );
// loop through folders and delete all Philterit brand labels
$i = 0;
$total = count( $folders );
foreach( $folders as $folder ) {
if( strpos( $folder, '&8HY-Brand/' ) ) {
$i++;
if( imap_deletemailbox( $Inbox, $folder ) )
echo "$i of $total) deleted: " . $folder . "\n";
}
}
echo "\n\nPhilterit labels have been removed!!!";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment