summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Vagelpohl <jens@netz.ooo>2005-02-21 19:08:35 +0000
committerJens Vagelpohl <jens@netz.ooo>2005-02-21 19:08:35 +0000
commit9029ba5a2d4c869eb17d558d8703339dd0200049 (patch)
treece6f1a04225d0eb8d0614507c6e1bbe8a4d078b6
parent89d262f4c0927dff37459ea5bc7a252a614c244f (diff)
downloadViewsManager-9029ba5a2d4c869eb17d558d8703339dd0200049.zip
ViewsManager-9029ba5a2d4c869eb17d558d8703339dd0200049.tar.gz
- add new testing harness
-rw-r--r--CHANGES.txt3
-rw-r--r--maildrop/testing/README.txt30
-rw-r--r--maildrop/testing/config.py45
-rwxr-xr-xmaildrop/testing/make_emails.py76
-rwxr-xr-xmaildrop/testing/start_maildrop16
-rwxr-xr-xmaildrop/testing/stop_maildrop23
6 files changed, 193 insertions, 0 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index ddd9c80..83125eb 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -25,6 +25,9 @@ MaildropHost version and change information
correctly with chkconfig/Yast2 and can be linked into /etc/rc.d
(SuSE) or /etc/rc.d/init.d (RedHat)
+ - Added a small "testing harness" to allow creating test emails in
+ a controlled way that can then be worked on by the maildrop daemon.
+
* Bugs fixed:
- More small improvements to the start_maildrop and stop_maildrop
diff --git a/maildrop/testing/README.txt b/maildrop/testing/README.txt
new file mode 100644
index 0000000..fac9f0a
--- /dev/null
+++ b/maildrop/testing/README.txt
@@ -0,0 +1,30 @@
+Testing package
+
+ This folder contains a configuration and start/stop scripts that help
+ you test out the maildrop daemon given various configurations. Tweak
+ config.py to your heart's content and see the results by running
+ the start/stop scripts.
+
+ To create "fake" email traffic there is a script called "make_emails.py"
+ that can be used to fill the spool directory ($MAILDROP_HOME/spool)
+ with fake email messages. You need to specify how many messages to
+ generate in total, how many of those are in "locked" status as if they
+ are still being generated, and the recipient email(s). The script
+ will randomly choose a recipient from the list of given email addresses.
+
+ The main purpose is to make sure that...
+
+ - your configuration is correct so that the maildrop daemon succeeds
+ in getting mail to the given recipient
+
+ - no email gets "lost" by the maildrop machinery (simple test: the
+ total number of received messages by the list of provided recipients
+ must match the total number of fake emails minus the number of locked
+ emails!)
+
+ - only "unlocked" emails get sent. "Locked" emails will be recognizable
+ by their subject line.
+
+ THE PURPOSE OF THESE SCRIPTS IS NOT TO ANNOY OTHERS! DO NOT SEND TO
+ ADDRESSES THAT ARE NOT AWARE YOU ARE DOING IT!
+
diff --git a/maildrop/testing/config.py b/maildrop/testing/config.py
new file mode 100644
index 0000000..bf6dca2
--- /dev/null
+++ b/maildrop/testing/config.py
@@ -0,0 +1,45 @@
+# This file contains configuration data, some of which may be shared
+# between the maildrop daemon and the MaildropHost object.
+#
+# IMPORTANT NOTE: This file is also sourced by a couple shell scripts,
+# which means you must not have any whitespace around
+# equal (=) signs!
+#
+
+# Which python interpreter to use for running the maildrop daemon
+PYTHON="/usr/bin/python"
+
+# The working directory keeping the spool and var directories
+MAILDROP_HOME="/tmp/maildrop"
+
+# The SMTP server to be used for sending out email (e.g. smtp-relay.domain.com)
+SMTP_HOST="localhost"
+
+# The SMTP server port used for sending out email
+SMTP_PORT=25
+
+# How long to wait between spool checks
+MAILDROP_INTERVAL=10
+
+# Set debug mode. This will PREVENT the daemon from detaching from
+# the controlling terminal! Do not use in production!
+DEBUG=1
+
+# Batch size for smtp-connection
+# = 0 means bulk all mails at once
+# > 0 means close/reopen connection after BATCH mails
+MAILDROP_BATCH=0
+
+# TLS usage. The values available are...
+# 0 : Don't try to us TLS
+# 1 : Try to use TLS if possible, but don't fail if TLS is not available
+# 2 : Force TLS and fail if TLS is not available
+# If a username/password is specified for the SMTP server, it is recommended
+# to set the value to "2" to prevent password sniffing.
+MAILDROP_TLS=0
+
+# SMTP Authentication
+# If the login and password are provided, authentication is attempted.
+# If the authentication attempt fails, mail processing stops. Beware.
+MAILDROP_LOGIN=""
+MAILDROP_PASSWORD=""
diff --git a/maildrop/testing/make_emails.py b/maildrop/testing/make_emails.py
new file mode 100755
index 0000000..ed9191d
--- /dev/null
+++ b/maildrop/testing/make_emails.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+#
+# make_emails Generate fake emails to be consumed by maildrop
+#
+
+#####################################################################
+# EDIT THESE VARIABLES
+#####################################################################
+
+# UNLOCKED_EMAILS - The number of unlocked email files to generate
+UNLOCKED_EMAILS = 10
+
+# LOCKED_EMAILS - The number of locked email files to generate.
+LOCKED_EMAILS = 2
+
+# RECIPIENTS - The list of email recipient addresses to be used
+RECIPIENTS = [ 'root@localhost' ]
+
+# SENDER - Who these emails appear to originate from
+SENDER = 'root@localhost'
+
+#####################################################################
+# NO EDITING BELOW HERE
+#####################################################################
+
+MAIL_TEMPLATE = """\
+##To:%(recipient)s
+##From:%(sender)s
+From: "Maildrop Testing" <%(sender)s>
+To: "Unlucky Recipient" <%(recipient)s>
+Subject: %(subject)s
+
+Sent by the maildrop testing script
+"""
+
+import sys
+import os
+import random
+import config
+
+def create_emails():
+ """ Create the test emails """
+ pathjoin = os.path.join
+ spool = pathjoin(config.MAILDROP_HOME, 'spool')
+ all_files = os.listdir(spool)
+
+ for old_file in all_files:
+ if ( old_file.startswith('unlocked_') or
+ old_file.startswith('unlocked_') ):
+ os.remove(pathjoin(spool, old_file))
+
+ for i in range(UNLOCKED_EMAILS):
+ f = open(pathjoin(spool, 'unlocked_%d' % i), 'w')
+ f.write(MAIL_TEMPLATE % { 'recipient' : random.choice(RECIPIENTS)
+ , 'sender' : SENDER
+ , 'subject' : 'unlocked email'
+ } )
+ f.close()
+
+ for i in range(LOCKED_EMAILS):
+ filename = 'locked_%d' % i
+ lockname = '%s.lck' % filename
+ l = open(pathjoin(spool, lockname), 'w')
+ l.write('locked')
+ l.close()
+ f = open(pathjoin(spool, 'locked_%d' % i), 'w')
+ f.write(MAIL_TEMPLATE % { 'recipient' : random.choice(RECIPIENTS)
+ , 'sender' : SENDER
+ , 'subject' : '***LOCKED***'
+ } )
+ f.close()
+
+
+if __name__ == '__main__':
+ create_emails()
+
diff --git a/maildrop/testing/start_maildrop b/maildrop/testing/start_maildrop
new file mode 100755
index 0000000..5a7e5a3
--- /dev/null
+++ b/maildrop/testing/start_maildrop
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#
+# TESTING start script to run the maildrop python process
+#
+reldir=`dirname $0`
+
+if [ $reldir = "." ]; then
+ reldir=`pwd`;
+fi
+
+MAILDROPHOME=`dirname $reldir`
+CONFIG="$reldir/config.py"
+. $CONFIG
+
+exec $PYTHON $MAILDROPHOME/maildrop.py "$CONFIG"
diff --git a/maildrop/testing/stop_maildrop b/maildrop/testing/stop_maildrop
new file mode 100755
index 0000000..fb434dc
--- /dev/null
+++ b/maildrop/testing/stop_maildrop
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+#
+# TESTING stop script to stop the maildrop python process
+#
+
+# Set the maildrop main directory
+reldir=`dirname $0`
+if [ $reldir = "." ]; then
+ reldir=`pwd`;
+fi
+
+# Source the config to find the location of the spool/var folder
+. $reldir/config.py
+
+# Where is the pid file?
+MAILDROP_PIDFILE=$MAILDROP_HOME/var/maildrop.pid
+
+# Kill the process
+kill `cat $MAILDROP_PIDFILE`
+
+# Remove the pid file
+rm -f $MAILDROP_PIDFILE