2020-11-18 Fred Gleason <fredg@paravelsystems.com>

* Added a '--body-file' switch to the 'sendmail_test' test harness.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason
2020-11-19 18:57:03 -05:00
parent 55db0e4dd9
commit 5386947984
4 changed files with 68 additions and 4 deletions

View File

@@ -41,7 +41,12 @@ MainObject::MainObject(QObject *parent)
QString bcc_addrs;
QString subject;
QString body;
QString body_file;
bool dry_run=false;
FILE *f=NULL;
QByteArray raw;
char data[1024];
size_t n;
//
// Read Command Options
@@ -74,6 +79,10 @@ MainObject::MainObject(QObject *parent)
body=cmd->value(i);
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--body-file") {
body_file=cmd->value(i);
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--dry-run") {
dry_run=true;
cmd->setProcessed(i,true);
@@ -85,6 +94,30 @@ MainObject::MainObject(QObject *parent)
}
}
//
// Sanity Checks
//
if((!body.isEmpty())&&(!body_file.isEmpty())) {
fprintf(stderr,
"sendmail_test: --body and --body-file are mutually exclusive\n");
exit(RDApplication::ExitInvalidOption);
}
//
// Load Message Body
//
if(!body_file.isEmpty()) {
if((f=fopen(body_file.toUtf8(),"r"))==NULL) {
perror("sendmail_test");
exit(256);
}
while((n=fread(data,1,1024,f))>0) {
raw+=QByteArray(data,n);
}
fclose(f);
body=QString::fromUtf8(raw);
}
if(!RDSendMail(&err_msg,subject,body,
from_addr,to_addrs,cc_addrs,bcc_addrs,dry_run)) {
fprintf(stderr,"%s\n",err_msg.toUtf8().constData());

View File

@@ -23,7 +23,7 @@
#include <qobject.h>
#define SENDMAIL_TEST_USAGE "[options]\n\nTest the Rivendell email sending routines\n\nOptions are:\n--from-address=<addr>\n Originating email address\n\n--to-addresses=<addrs>\n To addresses (comma seperated)\n\n--cc-addresses=<addrs>\n CC addresses (comma seperated)\n\n--bcc-addresses=<addrs>\n BCC addresses (comma seperated)\n\n--subject=<str>\n Message subject\n\n--body=<str>\n Message body\n\n--dry-run\n Print the raw message to STDOUT, then exit\n\n"
#define SENDMAIL_TEST_USAGE "[options]\n\nTest the Rivendell email sending routines\n\nOptions are:\n--from-address=<addr>\n Originating email address\n\n--to-addresses=<addrs>\n To addresses (comma seperated)\n\n--cc-addresses=<addrs>\n CC addresses (comma seperated)\n\n--bcc-addresses=<addrs>\n BCC addresses (comma seperated)\n\n--subject=<str>\n Message subject\n\n--body=<str>\n Message body\n\n--body-file=<filename>\n Use contents of <filename> for body\n\n--dry-run\n Print the raw message to STDOUT, then exit\n\n"
class MainObject : public QObject
{