[Techtalk] delete mail from the server
Rasjid Wilcox
rasjidw at openminddev.net
Wed Dec 31 02:48:57 EST 2003
On Tuesday 30 December 2003 23:51, Noir wrote:
> On Tue, Dec 30, 2003 at 11:45:11PM +1100, Rasjid Wilcox wrote:
> > Keyword Opt Function
> > ------------------------------------------------------------
> > ...
> > limit -l Set message size limit
>
> Thanks. But that doesn't _delete_ the mail from the server it only keeps
> from d.loading it.
Ah. Sorry, I misunderstood your original post. In this case I'd recommend
writing a Python or Perl script. If you don't know either, I'd suggest
Python.
I had a quick play with the python imaplib library. You may want something
along the following lines:
----
#!/usr/bin/env python
import imaplib
mail = imaplib.IMAP4('hostname')
mail.login('username', 'password')
mail.select()
typ, data = mail.search(None, 'LARGER', 1000000)
for num in data[0].split():
typ, data = mail.store(num, '+FLAGS', '\Deleted')
mail.expunge()
mail.close()
mail.logout()
-----
I have just done a quick test with this, and it seems to work okay for me.
Adjust the size used in the search command to suit. The IMAP RFC (2060)
talks about 'Octets', which as far as I can tell just means 8 bit bytes.
Of course, the above assumes that you can make IMAP connections to the mailbox
in question, and not just POP3. Most ISPs seem to provide IMAP connections
now, even if they don't advertise the fact. (If they offer a webmail
interface to you mail, then they probably have IMAP running, although there
is a chance they have explicity blocked remote access to it). Just telnet to
port 143 on your ISP's mailserver to check. It will be obvious if it works.
The command to disconnect is '. logout'. Note the period at the beginning is
important.
DISCLAIMER: the above script comes with no warranty whatsoever. :-)
Cheers,
Rasjid.
--
Rasjid Wilcox
Canberra, Australia (UTC +10 hrs)
http://www.openminddev.net
More information about the Techtalk
mailing list