← Documentation Index

NAME

Test::Mailmunge::RegressionUtils - utility functions for Mailmunge regression tests

ABSTRACT

This class defines a number of functions in the main package that are useful for regression tests.

GIANT WARNING

The mailmunge regression-tests assume they are running in an environment similar to the docker images built by the build-docker-container supplied in the mailmunge source code. THEY ARE UNLIKELY TO WORK IN ANY OTHER ENVIRONMENT.

FUNCTIONS

slurp_body_only ($file)

$file is assumed to be an RFC5322 mail message. Return only the body of the message after skipping the header lines.

server_running_postfix()

Returns true if it looks like the regression-test server is running Postfix; false otherwise. We assume the server is running Sendmail if it's not running Postfix.

get_smtp_server_ip()

Returns the regression-test server's IP address if it could be determined; undef if not. This will not be the loopback address, but the IP address of a non-loopback interface.

smtp_send($ip, $helo, $sender, $recips, $msg)

Runs an SMTP session. Connects to $ip and HELOs as $helo. Use $sender as the envelope sender. Uses each recipient in @$recips in a RCPT To: command. ($recips must be an arrayref.) And transmits $msg as the message body; $msg must be a string representing an RFC5322 mail message.

Returns a hash containing:

stage

The stage at which the SMTP session ended. One of "connect", "helo", "mail", "rcpt", "data", "datasend", or "quit".

code

The three-digit SMTP code returned by the SMTP server for the final command sent.

dsn

The three-number "a.b.c" DSN returned by the SMTP server for the final command sent.

txt

The reply text returned by the SMTP server for the final command sent.

maildrop_msg_dir()

Returns the directory in which regression-test messages are dropped.

clean_maildrop_dir()

Deletes all files in maildrop_msg_dir()

maildrop_msg_path([$file])

Returns the full path to the maildrop file. If $file is not supplied, defaults to 'maildrop.msg'

quarantine_dir()

Returns the quarantine directory '/var/spool/mm-quarantine'

clean_quarantine_dir()

Deletes all files from the quarantine directory.

first_quarantined_msg()

Returns the first directory under quarantine_dir() that has a quarantined message. Returns undef if no quarantined messages are found.

make_msg($subject, $source_msg, $output_file)

Returns a string containing an RFC5322 message taken from the file t/msgs/$source_msg. The string __SUBJECT__ in that file is replaced with $subject. If $output_file is provided, then the string : maildrop.msg in the source message is replaced with : $output_file. This directs the regression-test maildrop process to drop the message in maildrop_msg_dir() . '/' . $output_file

wait_for_files($file1 [, $file2 ...])

Waits up to (about) four seconds for all files named in the argument list to exist. Returns 1 if all of the files exist, or 0 if the function timed out before all files appeared.

flush_mta_queues()

Flushes the MTA queues using the appropriate commands depending on whether the MTA is Sendmail or Postfix. You need to run the regression tests as root for this to work.

clean_mta_queues()

Clears out the MTA queues using the appropriate commands depending on whether the MTA is Sendmail or Postfix. Again, only works if you're running as root.

get_mta_hold_queue()

Returns an arrayref of queue-IDs in the MTA's "hold" queue. The contents of the arrayref are unspecified, but the number of items is the number of messages in the "hold" queue of the MTA.

AUTHOR

Dianne Skoll <dianne@skollsoft.com>

LICENSE

This code is licensed under the terms of the GNU General Public License, version 2.

Copyright © 2024 Skoll Software Consulting