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

@ -20608,3 +20608,5 @@
display-name component of e-mail addresses in 'RDSendMail()'.
2020-11-18 Fred Gleason <fredg@paravelsystems.com>
* Added a '--dry-run' switch to the 'sendmail_test' test harness.
2020-11-18 Fred Gleason <fredg@paravelsystems.com>
* Added a '--body-file' switch to the 'sendmail_test' test harness.

View File

@ -41,15 +41,44 @@ bool __RDSendMail_IsAscii(const QString &str)
QByteArray __RDSendMail_EncodeBody(QString *charset,QString *encoding,
const QString &str)
{
QByteArray raw;
int index=0;
QByteArray ret;
if(__RDSendMail_IsAscii(str)) {
//
// All 7 Bit Characters
//
*charset="";
*encoding="";
return str.toAscii();
//
// Ensure no naked CR or LF characters (RFC5322 Section 2.3)
//
ret=str.toAscii();
index=0;
while((index=ret.indexOf("/r",index))>=0) {
if(ret.mid(index+1,1)!="/n") {
ret.insert(index+1,"/n");
index++;
}
}
index=0;
while((index=ret.indexOf("\n",index))>=0) {
if((index==0)||(ret.mid(index-1,1)!="\r")) {
ret.insert(index,"\r");
index+=2;
}
}
return ret;
}
//
// 8+ Bit Characters
//
*charset=";charset=utf8";
*encoding="Content-Transfer-Encoding: base64\r\n";
QByteArray ret;
QByteArray raw=str.toUtf8();
raw=str.toUtf8();
for(int i=0;i<raw.length();i+=48) {
ret+=raw.mid(i,48).toBase64()+"\r\n";
}

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
{