[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Selective remote mail deletion



On Fri, 2006-03-17 at 22:05 +0000, B.Hoffmann wrote:
> Hi again,
> 
> does anybody know of a utility/package that would perform what I'm
> looking for?
> Would like to be able to remotely and selectively delete messages while
> they are still on the server without launching the mail  client or at
> least without fully logging in and downloading all new messages.
> Similar to the remote functionality offered by Foxmail on Windows since
> many years, and I hear since recently in Outlook as well...
> 
> Thanks for any suggestions.

Depending on how comfortable you are with the command line, you
could run this program:

$ python popdel.py <your.ISP's.pop> <your_username>

It asks you for a password, then displays From, Subj & Date and
asks you if you want to delete it.

-- 
-----------------------------------------------------------------
Ron Johnson, Jr.
Jefferson, LA USA

"Fighting terrorism is like being a goalkeeper. You can make a
hundred brilliant saves but the only shot that people remember is
the one that gets past you."
Paul Wilkinson

import getpass, poplib, string, sys
import re

################

def check_re(d, patt_re, patt,  s):
    mo = patt_re.search(s)
    if mo:
        d[patt] = s
    return d

################

M = poplib.POP3(sys.argv[1])
#M.set_debuglevel(2)
M.user(sys.argv[2])
M.pass_(getpass.getpass('POP password: ')
from_pattern = re.compile("^from\:")
subj_pattern = re.compile("^subject\:")
date_pattern = re.compile("^date\:")
msft1_pattern = re.compile("^content-disposition: attachment; filename=")
haggis_pattern = re.compile("\@haggis")
w = M.list()
print w[0]
print w[1]
print w[2]
size_array = w[1]
numMessages = len(size_array)
print 'Num emails ', numMessages
for i in range(1, numMessages+1):
    d = {'from': '', 'subj': '', 'date': '', 'attach': '', 'haggis': ''}
    b = ['==============================================', '==============================================']
    x = M.top(i, 20)
    a = string.split(size_array[i-1], ' ')
    ndx = int(a[0])
    bcnt = int(a[1])
    b.append(('%d   %d' % (ndx, bcnt)))
    for y in x[1]:
        y1 = y.lower()
        d = check_re(d, from_pattern, 'from', y1)
        d = check_re(d, subj_pattern, 'subj', y1)
        d = check_re(d, date_pattern, 'date', y1)
        d = check_re(d, msft1_pattern, 'attach', y1)
    for c in b:
        print c
    print d['from']
    print d['subj']
    print d['date']
    print d['attach']
    r = raw_input('Do you want to delete this message? -> ')
    if r in ('Y', 'y'):
        M.dele(i)
    if r in ('Q', 'q'):
        M.quit()
        sys.exit()
    
M.quit()

print '============================================================'
print '============================================================'
print '============================================================'
print '============================================================'

Reply to: