Added popt script

This commit is contained in:
Benjamin Renard 2013-04-11 20:47:36 +02:00
parent f653a89f38
commit 38d11a83d4
3 changed files with 153 additions and 3 deletions

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
mailt (1.2-1) unstable; urgency=low
* Added POP support
-- Benjamin Renard <brenard@easter-eggs.com> Thu, 11 Apr 2013 20:46:16 +0200
mailt (1.1-1) unstable; urgency=low
* Initial release

144
popt Executable file
View File

@ -0,0 +1,144 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# popt -- Simple command-line tool to test IMAP server
# By: Benjamin RENARD <brenard@easter-eggs.com>
#
# Copyright (C) 2013 Easter-eggs
# http://git.zionetrix.net/mailt
#
# This file is part of MailT.
#
# MailT 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 3 of the License,
# or (at your option) any later version.
#
# MailT 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from optparse import OptionParser
import os
import poplib
import logging
import sys
parser = OptionParser()
parser.add_option('-H',
'--host',
action="store",
type="string",
dest="host",
help="The IMAP host",
default="127.0.0.1")
parser.add_option('-p',
'--port',
action="store",
type="string",
dest="port",
help="The IMAP port",
default=None)
parser.add_option('-S',
'--ssl',
action="store_true",
dest="ssl",
help="IMAP Over SSL (IMAPS)",
default=False)
parser.add_option('-U',
'--user',
action="store",
type="string",
dest="user",
help="User login",
default=None)
parser.add_option('-P',
'--password',
action="store",
type="string",
dest="password",
help="User password",
default=None)
parser.add_option('-v',
'--verbose',
action="store_true",
dest="verbose")
parser.add_option('-d',
'--debug',
action="store_true",
dest="debug")
(options, args) = parser.parse_args()
if options.verbose or options.debug:
loglevel=logging.DEBUG
else:
loglevel=logging.INFO
logging.basicConfig(level=loglevel,format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
if not options.user or not options.password:
logging.fatal('You must provide the user login and password')
sys.exit(1)
if options.port is None:
if options.ssl:
options.port=995
else:
options.port=110
if options.ssl:
logging.debug('Establish SSL connexion to server')
try:
server = poplib.POP3_SSL(options.host,options.port)
logging.debug('Connected')
except Exception, e:
logging.critical("POP3 connection error : %s" % e)
sys.exit(2)
else:
logging.debug("Establish connexion to server")
try:
server = poplib.POP3(options.host,options.port)
logging.debug('Connected')
except Exception, e:
logging.critical("POP3 connection error : %s" % e)
sys.exit(2)
if options.debug:
server.set_debuglevel(2)
if options.user:
try:
logging.debug('Login into server as %s' % options.user)
server.user(options.user)
server.pass_(options.password)
logging.debug('Logged')
except Exception as e:
logging.critical("POP3 Auth error : %s" % e)
sys.exit(3)
try:
logging.debug("List mail")
ret = server.list()
if len(ret)>0:
logging.info("OK : %s message(s) founded" % len(ret[1]))
else:
logging.error("List message return incorrected : %s" % ret)
except Exception as e:
logging.critical('Error listing message(s) : %s' % e)
finally:
server.quit()

View File

@ -30,10 +30,10 @@ setup(
name = "MailT",
version = "1.1",
license = "http://www.gnu.org/licenses/gpl.html",
description = "MailT is a simple command-line tool to test SMTP/IMAP mail server.",
description = "MailT is a simple command-line tool to test SMTP/IMAP/POP mail server.",
author = "Benjamin Renard",
author_email = "brenard@easter-eggs.com",
url = "http://git.zionetrix.net/mailt",
keywords = "command-line smtp imap tool test",
scripts = ["smtpt","imapt"]
keywords = "command-line smtp imap pop tool test",
scripts = ["smtpt","imapt","popt"]
)