Hi,
I wrote very simple dbmail2mailbox tool. It can be used to
learn some
spam filters directly from IMAP folder with spam messages,
for example,
or for another purposes.
Usage:
./dbmail2mailbox --server=localhost --database=dbmail
--login=dbmail
--password=dbmailpwd --address=testuser mydomain.com --mailbox=testbox
Can anybody need it or can test it?
--
Thanks,
Eugene Prokopiev
#!/usr/bin/python
# Copyright (C) 2006 Eugene Prokopiev <enp at altlinux
dot org>
#
# This program 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.
#
# This program 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 this program; if not, write to the Free
Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import sys
import getopt
import psycopg as db
import email.Parser
def export(connection, address, mailbox):
parser = email.Parser.Parser()
cursor_messages = connection.cursor()
cursor_messageblks = connection.cursor()
sql_messages = """select message_idnr,
internal_date
from dbmail_aliases
inner join dbmail_users on dbmail_aliases.deliver_to =
dbmail_users.user_idnr
inner join dbmail_mailboxes on dbmail_users.user_idnr =
dbmail_mailboxes.owner_idnr
inner join dbmail_messages on
dbmail_mailboxes.mailbox_idnr = dbmail_messages.mailbox_idnr
inner join dbmail_physmessage on
dbmail_messages.physmessage_id = dbmail_physmessage.id
where dbmail_messages.deleted_flag=0 and
dbmail_mailboxes.name = %s and alias = %s
"""
sql_messageblks = """
select messageblk, is_header from dbmail_messageblks
inner join dbmail_messages on
dbmail_messageblks.physmessage_id =
dbmail_messages.physmessage_id
where message_idnr = %s order by
dbmail_messageblks.messageblk_idnr
"""
cursor_messages.execute(sql_messages, (mailbox, address,))
for message_idnr, internal_date in
cursor_messages.fetchall():
cursor_messageblks.execute(sql_messageblks,
("%s" % (message_idnr),))
for messageblk, is_header in
cursor_messageblks.fetchall():
if (is_header == 1):
print "From %s %s" %
(parser.parsestr(messageblk).get("From"),
internal_date.strftime())
print "%s" % (messageblk)
def usage():
usage_text = """
dbmail2mailbox - DBMail to mbox conversion (output to
stdout)
arguments:
-h|--help - show this text
-s|--server - server where DBMail database installed
-d|--database - DBMail database name
-l|--login - login to database
-p|--password - password to database
-a|--address - any mail user address (alias)
-m|--mailbox - mailbox name
"""
print usage_text
def main(argv):
server = "localhost"
database = "dbmail"
login = "dbmail"
password = "dbmailpwd"
address = "testuser mydomain.com"
mailbox = "testbox"
try:
opts, args = getopt.getopt(argv,
"hs:d:l:p:a:m:", ["help",
"server=", "database=",
"login=", "password=",
"address=", "mailbox="])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
elif opt in ("-s", "--server"):
server = arg
elif opt in ("-d", "--database"):
database = arg
elif opt in ("-l", "--login"):
login = arg
elif opt in ("-p", "--password"):
password = arg
elif opt in ("-a", "--address"):
address = arg
elif opt in ("-m", "--mailbox"):
mailbox = arg
connection = db.connect("host="+server+"
dbname="+database+" user="+login+"
password="+password)
export(connection, address, mailbox)
if __name__ == "__main__":
main(sys.argv[1:])
_______________________________________________
Dbmail mailing list
Dbmail dbmail.org
htt
ps://mailman.fastxs.nl/mailman/listinfo/dbmail
|