logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

CVS: tmda/contrib collectaddys,NONE,1.1 ChangeLog,1.73,1.74: msg#00047

Subject: CVS: tmda/contrib collectaddys,NONE,1.1 ChangeLog,1.73,1.74
Update of /cvsroot/tmda/tmda/contrib
In directory usw-pr-cvs1:/tmp/cvs-serv25140/contrib

Modified Files:
        ChangeLog 
Added Files:
        collectaddys 
Log Message:
Add `collectaddys' to contrib.  This script might help new TMDA users
build an initial "whitelist" from their mail archives.

Suggested by John Hazen in
<Pine.LNX.4.04.10203011328390.490-100000@xxxxxxxxxxxxxx> on
tmda-users.


--- NEW FILE ---
#!/usr/bin/env python
#
# Copyright (C) 2001,2002 Jason R. Mastaler <jason@xxxxxxxxxxxx>
#
# This file is part of TMDA.
#
# TMDA is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  A copy of this license should
# be included in the file COPYING.
#
# TMDA is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with TMDA; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

"""
Collect e-mail addresses from mailboxes of various formats.
Unix-style mbox files, qmail-style Maildirs, and MH/nmh-style folders
are supported.  Each unique address is printed to stdout in lowercase,
with the results sorted.

Every file or directory within the current working directory is
assumed to be in one of the supported mailbox formats.

Sample usage:

$ cd ~/Mail/archive/
$ collectaddys
$ collectaddys > ~/.tmda/lists/whitelist
"""

import mailbox
import os

# Collect addresses from these headers only; season to taste.
hdrs = [ 'from', 'reply-to', 'return-path', 'sender' ]

addys = []

for path in os.listdir('.'):
    # If it's a directory, try to guess whether it's a Maildir or an
    # MH folder.
    if os.path.isdir(path):
        if os.path.exists(os.path.join(path, 'cur')) and \
           os.path.exists(os.path.join(path, 'new')) and \
           os.path.exists(os.path.join(path, 'tmp')):
            mb = mailbox.Maildir(path)
        else:
            mb = mailbox.MHMailbox(path)
    # Otherwise assume a Unix-style mbox file.
    else:
        try:
            # PortableUnixMailbox in Python >= 2.1 only
            mb = mailbox.PortableUnixMailbox(open(path))
        except AttributeError:
            mb = mailbox.UnixMailbox(open(path))
    while 1:
        msg = mb.next()
        if not msg:
            break
        else:
            for hdr in hdrs:
                if msg.has_key(hdr):
                    address = msg.getaddr(hdr)[1]
                    if address is not None:
                        address = address.lower()
                        if address not in addys:
                            addys.append(address)
                    
addys.sort()

for a in addys:
    if a:
        print a

Index: ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/contrib/ChangeLog,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -r1.73 -r1.74
--- ChangeLog   27 Mar 2002 02:09:45 -0000      1.73
+++ ChangeLog   28 Mar 2002 04:07:45 -0000      1.74
@@ -1,3 +1,7 @@
+2002-03-27  Jason R. Mastaler  <jason@xxxxxxxxxxxxxxxxxxxxxxx>
+
+       * Add collectaddys.
+
 2002-03-26  Jason R. Mastaler  <jasonrm@xxxxxxxxxxxxxxxxxxxxxxxxxx>
 
        * sample.tmdarc: Add DELIVERED_CACHE & DELIVERED_CACHE_LEN.

_______________________________________________
tmda-cvs mailing list
http://libertine.org/lists/listinfo/tmda-cvs



<Prev in Thread] Current Thread [Next in Thread>