<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shami&#039;s Blog &#187; clear</title>
	<atom:link href="http://blog.al-shami.net/tag/clear/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.al-shami.net</link>
	<description>A Mushroom A Day Keeps The Koopas Away</description>
	<lastBuildDate>Wed, 03 Aug 2011 18:39:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Delete all Messages from a POP3 Account</title>
		<link>http://blog.al-shami.net/2010/04/delete-all-messages-from-a-pop3-account/</link>
		<comments>http://blog.al-shami.net/2010/04/delete-all-messages-from-a-pop3-account/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 10:52:54 +0000</pubDate>
		<dc:creator>Mohammad Al-Shami</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[clear]]></category>
		<category><![CDATA[delete all]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[IP]]></category>
		<category><![CDATA[pop3]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[verio]]></category>

		<guid isPermaLink="false">http://blog.al-shami.net/?p=236</guid>
		<description><![CDATA[Here at the office, we host a few domains with Verio. Not my choice, and I&#8217;m not happy with it. We also host some mailboxes for one of those domains with Verio. I got a message from Verio support saying the mailboxes for that domain are occupying around 1GB of space, and that we need [...]]]></description>
			<content:encoded><![CDATA[<p>Here at the office, we host a few domains with <a href="http://www.verio.com/">Verio</a>. Not my choice, and I&#8217;m not happy with it. We also host some mailboxes for one of those domains with Verio. I got a message from Verio support saying the mailboxes for that domain are occupying around 1GB of space, and that we need to delete some of them.</p>
<p>Turns out the mailboxes were neglected for months, and one of those mailboxes got around 55,000 messages.</p>
<p>Simple enough, I said, let&#8217;s log in to web mail, keep recent relevant messages and delete the rest. But the web mail interface kept timing out, and I couldn&#8217;t access any of the accounts. Seems they built their own web mail interface, which tries to load everything in your mailbox. This makes it time out when a mailbox has this huge number of messages.</p>
<p>After contacting Verio&#8217;s support they gave me an IP address to use as an IMAP server, which, surprisingly (well, not really, I expected it) wouldn&#8217;t connect. After a few days of deliberation the department in charge of the accounts decided to delete all messages in all accounts.</p>
<p>At first I configured Evolution to download all messages from POP3, which thankfully worked (Thanks Dovecot), but that took too long, and downloading 50K messages would overload our uplink. A simple solution would be as follows:</p>
<pre><code>
#!/usr/bin/python

import poplib

server = 'server'
user = 'user'
password = 'password'

whenToQuit = 500
loop = 0
totalMessages = 0 

while 1:
        M = poplib.POP3(server)
        M.user(user)
        M.pass_(password)
        numMessages = len(M.list()[1])
        if totalMessages == 0: totalMessages = numMessages
        i = 0
        for i in range(numMessages):
                print 'Deleted %d out of %d messages' % (loop * whenToQuit + i + 1, totalMessages)
                M.dele(i+1)
                if i == whenToQuit - 1:
                        M.quit()
                        loop = loop + 1
                        break

        if i != whenToQuit - 1:
                M.quit()
                break
</code></pre>
<p>Since the actual deletion of messages happens when a client &#8220;quit&#8221;s, I wrote this to do a quit after 500 message, this will enable you to quit the script after some time without having to lose all the progress.</p>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.al-shami.net/2010/04/delete-all-messages-from-a-pop3-account/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  blog.al-shami.net/tag/clear/feed/ ) in 0.31371 seconds, on Feb 8th, 2012 at 10:54 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 8th, 2012 at 11:54 pm UTC -->
