Initial commit

This commit is contained in:
bn8 2013-04-10 21:29:01 +02:00
commit bb969b9c9c
10 changed files with 509 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*~
build

4
debian/.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
mailt.*debhelper*
mailt.substvars
mailt
files

6
debian/changelog vendored Normal file
View file

@ -0,0 +1,6 @@
mailt (1.1-1) unstable; urgency=low
* Initial release
-- Benjamin Renard <brenard@easter-eggs.com> Wed, 10 Apr 2013 21:17:35 +0200

1
debian/compat vendored Normal file
View file

@ -0,0 +1 @@
7

12
debian/control vendored Normal file
View file

@ -0,0 +1,12 @@
Source: mailt
Priority: extra
Section: net
Maintainer: Benjamin Renard <brenard@easter-eggs.com>
Build-Depends: debhelper (>= 7.0.50~), python-all-dev, python-support (>= 0.90.0~), python-setuptools
Homepage: http://git.zionetrix.net/mailt
Vcs-git: http://git.zionetrix.net/mailt
Package: mailt
Architecture: all
Depends: ${python:Depends}, ${misc:Depends}
Description: Simple command-line tool to test SMTP/IMAP mail server

41
debian/copyright vendored Normal file
View file

@ -0,0 +1,41 @@
This work was packaged for Debian by:
Benjamin Renard <brenard@easter-eggs.com> on Fri, 06 Apr 2012 18:22:16 +0200
It was downloaded from Git repository of project :
http://git.zionetrix.net/mailt
Upstream Author:
Benjamin Renard <brenard@easter-eggs.com>
Copyright:
Copyright (C) 2013 Benjamin Renard <brenard@easter-eggs.com>
License:
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 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
On Debian systems, the complete text of the GNU General Public license version 3.0
can be found in "/usr/share/common-licenses/GPL-3".
The Debian packaging is:
Copyright (C) 2013 Benjamin Renard <brenard@easter-eggs.com>
and is licensed under the GNU General Public License version 3.0
see "/usr/share/common-licenses/GPL-3".

5
debian/rules vendored Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/make -f
%:
dh $@

154
imapt Executable file
View file

@ -0,0 +1,154 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# imapt -- Simple command-line tool to test IMAP server
# By: Benjamin RENARD <brenard@easter-eggs.com>
#
# Copyright (C) 2013 Easter-eggs
# http://git.zionetrix.net/pyimapt
#
# 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 imaplib
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('--md5',
action="store_true",
dest="md5",
help="Use CRAM-MD5 password for authentication",
default=False)
parser.add_option('-m',
'--mailbox',
action="store",
type="string",
dest="mailbox",
help="The mailbox directory to select",
default='INBOX')
parser.add_option('-v',
'--verbose',
action="store_true",
dest="verbose")
(options, args) = parser.parse_args()
if options.verbose:
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=993
else:
options.port=143
if options.ssl:
logging.debug('Establish SSL connexion to server')
try:
server = imaplib.IMAP4_SSL(options.host,options.port)
logging.debug('Connected')
except Exception, e:
logging.critical("IMAP connection error : %s" % e)
sys.exit(2)
else:
logging.debug("Establish connexion to server")
try:
server = imaplib.IMAP4(options.host,options.port)
logging.debug('Connected')
except Exception, e:
logging.critical("IMAP connection error : %s" % e)
sys.exit(2)
if options.user:
try:
if options.md5:
logging.debug('Login into server as %s (with CRAM-MD5 password)' % options.user)
server.login_cram_md5(options.user,options.password)
else:
logging.debug('Login into server as %s' % options.user)
server.login(options.user,options.password)
logging.debug('Logged')
except Exception as e:
logging.critical("IMAP Auth error : %s" % e)
sys.exit(3)
try:
logging.debug("Select mailbox")
ret = server.select(options.mailbox)
if len(ret)>0 and ret[0]=='OK':
logging.info("Mailbox %s content %s message(s)" % (options.mailbox,ret[1][0]))
else:
logging.error("Selecting return incorrected : %s" % ret)
except Exception as e:
logging.critical('Error selecting mailbox %s : %s' % (option.mailbox,e))
finally:
server.close()
server.logout()

39
setup.py Normal file
View file

@ -0,0 +1,39 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# MailT -- Simple command-line tool to test SMTP/IMAP mail server
# By: Benjamin RENARD <brenard@easter-eggs.com>
#
# Copyright (C) 2011 Easter-eggs
# http://git.zionetrix.net/pysmtpt
#
# 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/>.
import os
import imp
from distutils.core import setup
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.",
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"]
)

245
smtpt Executable file
View file

@ -0,0 +1,245 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# smtpt -- Simple command-line tool to test SMTP server
# By: Benjamin RENARD <brenard@easter-eggs.com>
#
# Copyright (C) 2011 Easter-eggs
# http://git.zionetrix.net/pysmtpt
#
# 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 smtplib
import email.utils
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email import Encoders
import logging
import sys
parser = OptionParser()
default_subject="Simple test message"
parser.add_option('-s',
'--subject',
action="store",
type="string",
dest="subject",
help="The subject",
default=default_subject)
parser.add_option('-f',
'--from',
action="store",
type="string",
dest="author",
help="The sender email",
default="author@example.com")
parser.add_option('-t',
'--to',
action="store",
type="string",
dest="to",
help="The recipient email",
default="recipient@example.com")
parser.add_option('-c',
'--content',
action="store",
type="string",
dest="content",
help="The content",
default="This is the body of the message.")
parser.add_option('-H',
'--host',
action="store",
type="string",
dest="host",
help="The SMTP host",
default="127.0.0.1")
parser.add_option('-p',
'--port',
action="store",
type="string",
dest="port",
help="The SMTP port",
default=None)
parser.add_option('-S',
'--ssl',
action="store_true",
dest="ssl",
help="SMTP Over SSL (SMTPS)",
default=False)
parser.add_option('-T',
'--starttls',
action="store_true",
dest="starttls",
help="Use STARTTLS",
default=False)
parser.add_option('-U',
'--user',
action="store",
type="string",
dest="user",
help="SMTP Auth - User login",
default=None)
parser.add_option('-P',
'--password',
action="store",
type="string",
dest="password",
help="SMTP Auth - User password",
default=None)
parser.add_option('-a',
'--attachement',
action="append",
type="string",
dest="attach",
help="The attachment(s) file(s) path",
default=None)
parser.add_option('-d',
'--debug',
action="store_true",
dest="debug")
parser.add_option('-v',
'--verbose',
action="store_true",
dest="verbose")
parser.add_option('--spam',
action="store_true",
dest="spam")
parser.add_option('--virus',
action="store_true",
dest="virus")
(options, args) = parser.parse_args()
if options.spam:
if options.subject == default_subject:
options.subject = "Test spam message"
options.content="""This is the GTUBE, the
Generic
Test for
Unsolicited
Bulk
Email
If your spam filter supports it, the GTUBE provides a test by which you
can verify that the filter is installed correctly and is detecting incoming
spam. You can send yourself a test mail containing the following string of
characters (in upper case and with no white spaces and line breaks):
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
You should send this test mail from an account outside of your network."""
elif options.virus:
if options.subject == default_subject:
options.subject = "Test virus message"
options.content="""This is the EICAR standard antivirus test string :
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"""
if not options.port:
if options.ssl:
options.port=465
else:
options.port=25
if options.debug:
loglevel=logging.DEBUG
elif options.verbose:
loglevel=logging.INFO
else:
loglevel=logging.WARNING
logging.basicConfig(level=loglevel,format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
# Create the message
msg = MIMEMultipart()
msg['To'] = email.utils.formataddr(('Recipient', options.to))
logging.info("To : %s" % options.to)
msg['From'] = email.utils.formataddr(('Author', options.author))
logging.info("From : %s" % options.author)
msg['Subject'] = options.subject
logging.info("Subject : %s" % options.subject)
msg.attach( MIMEText(options.content) )
if options.attach:
for filepath in options.attach:
logging.info("Attache file %s" % filepath)
part = MIMEBase('application', "octet-stream")
part.set_payload( open(filepath,"rb").read() )
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(filepath))
msg.attach(part)
if options.ssl:
logging.info("Establish SSL connexion to server")
server = smtplib.SMTP_SSL(options.host,options.port)
else:
logging.info("Establish connexion to server")
server = smtplib.SMTP(options.host,options.port)
if options.starttls:
try:
logging.info("Start TLS")
server.starttls()
except Exception as e:
logging.critical('Error using STARTTLS : %s' % e)
server.quit()
sys.exit(2)
if options.debug:
logging.info("Establish connexion to server")
server.set_debuglevel(True)
if options.user:
error = None
try:
server.login(options.user,options.password)
except Exception as e:
logging.critical("SMTP Auth error : %s" % error)
server.quit()
sys.exit(3)
try:
logging.info("Sending email")
server.sendmail(options.author, [options.to], msg.as_string())
except Exception as e:
logging.critical('Error sending email : %s' % e)
finally:
server.quit()