(void) log_fprintlog(rmt->logptr,false,strloc);
return tcp_get_smtp_reply(rmt,WAITRMT);
}
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to send a queued email data contents */
+/* to a remote server. */
+/* Return the number of character sent. */
+/* */
+/********************************************************/
+PUBLIC int tcp_send_smtp_data(RMTTYP *rmt,const char *qemail)
+
+{
+#define OPEP "gestcpc.c:tcp_send_smtp_data,"
+
+int sent;
+FILE *qfile;
+int phase;
+_Bool proceed;
+
+sent=-1;
+qfile=(FILE *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //opending email data file
+ if ((qfile=eml_openqfile(qemail,(const char *)0))==(FILE *)0) {
+ (void) rou_alert(0,"%s, Unable to open file <%s> (bug?)",
+ OPEP,qemail);
+ phase=999; //no need to go further
+ }
+ break;
+ case 1 : { //transmitting data to remote
+ _Bool empty;
+ char data[300];
+
+ sent=0;
+ empty=false;
+ while (fgets(data,sizeof(data),qfile)!=(char *)0) {
+ if ((empty==true)&&(strcmp(data,".")==0))
+ (void) strcat(data,".");
+ empty=(strlen(data)==0);
+ sent+=tcp_write(rmt->socptr,data);
+ (void) rou_alert(0,"%s JMPDBG data=<%s>",OPEP,data);
+ }
+ break;
+ }
+ case 2 : //transmitting and empty line
+ (void) tcp_write(rmt->socptr,"");
+ break;
+ case 3 : //closing datafile
+ qfile=eml_closeqfile(qfile);
+ break;
+ default : //SAFE Guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+return sent;
+
+#undef OPEP
+}
//Transmit a command to remote SMTP server
extern int tcp_smtp_command(RMTTYP *rmt,char *fmt,...);
+//send the email data
+extern int tcp_send_smtp_data(RMTTYP *rmt,const char *qemail);
+
#endif
*/
/********************************************************/
/* */
+/* Procedure to send the data to the remote server */
+/* */
+/********************************************************/
+static int senddata(RMTTYP *rmt,TRATYP **tosend,const char *sessid)
+
+{
+#define OPEP "lvleml.c:senddata,"
+
+int rspcode;
+int phase;
+_Bool proceed;
+
+rspcode=0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //Sendig data request
+ rspcode=tcp_smtp_command(rmt,"DATA");
+ switch (rspcode) {
+ case DATAOK : //data accepted
+ break;
+ default : //Unexpected return code
+ phase=999; //Not accepting data
+ break;
+ }
+ break;
+ case 1 : //sending session data
+ (void) tcp_send_smtp_data(rmt,sessid);
+ break;
+ case 2 : //sending session data
+ rspcode=tcp_smtp_command(rmt,".");
+ switch (rspcode) {
+ case MALABRT : //Data rejected
+ break;
+ default : //Unexpected return code
+ break;
+ }
+ break;
+ default : //SAFE Guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+return rspcode;
+
+#undef OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/* */
/* Procedure to send the whole email transaction */
/* */
/********************************************************/
time_t isnow;
RMTTYP rmt;
+int tobesend;
TRATYP **tosend;
int phase;
_Bool proceed;
rmt.dstdomain=dstdomain;
rmt.orgdomain=orgdomain;
tosend=(TRATYP **)0;
+tobesend=0;
phase=0;
proceed=true;
while (proceed==true) {
}
break;
case 2 : //Checking if we have email to be sent
+ if (tosend==(TRATYP **)0)
+ phase=-1; //lets continue to see other email
+ break;
+ case 3 : { //checking if connection is open
char cmt[100];
(void) snprintf(cmt,sizeof(cmt),"session-id=%s",sessid);
rmt.logptr=log_openlog(sessid,false,cmt);
- if (tosend==(TRATYP **)0)
- phase=-1; //lets continue to see other email
- break;
- case 3 : //checking if connection is open
if (rmt.socptr!=(SOCPTR *)0) { //reset the connection
phase++; //NO need to open connection
}
break;
+ }
case 4 : //Opening connection if not open
if (connect_to_mx(&rmt)==false) {
char cmt[100];
phase=999; //No need to go further
}
break;
- case 5 : //sending originator
+ case 5 : { //sending originator
int rspcode;
rspcode=tcp_smtp_command(&rmt,"MAIL FROM: <%s>",(*tosend)->mailfrom);
break;
}
break;
- case 6 : //sending recipient list
+ }
+ case 6 : { //sending recipient list
+ int rspcode;
TRATYP **dest;
+ tobesend=0;
dest=tosend;
while (*dest!=(TRATYP *)0) {
rspcode=tcp_smtp_command(&rmt,"RCPT TO: <%s>",(*dest)->rcptto);
switch (rspcode) {
case CMDOK : //originator accepted
+ tobesend++;
break;
default : //Not accepted recipient
break;
dest++;
}
break;
+ }
case 7 : //send email data
+ if (tobesend>0)
+ (void) senddata(&rmt,tosend,sessid);
break;
case 8 : //cleaning recipient list
(void) free(tosend);
#include "subrou.h"
#include "unieml.h"
+//defining queued email repository
#define QDIR "/var/spool/"APPNAME"/queue"
typedef struct {
/* directory. */
/* */
/********************************************************/
-PUBLIC FILE *eml_openqfile(char *qfilename,const char *ext)
+PUBLIC FILE *eml_openqfile(const char *qfilename,const char *ext)
{
#define OPEP "unieml.c:eml_openqfile,"
#define BADPAR 501 //error in parameters
#define CMDBAD 502 //command not implemented
#define DATRJC 521 //Data Rejected
+#define MALABRT 552 //email data rejected
#define NOTEML 553 //Not an email address
#define MISSMX 563 //NO MX found for recipient
extern char **eml_getqfilelist(char **dnames,const char *ext);
//procedure to open a specific qfile
-extern FILE *eml_openqfile(char *qfilename,const char *ext);
+extern FILE *eml_openqfile(const char *qfilename,const char *ext);
//procedure to duplicate a specific qfile to another file
extern _Bool eml_dupqfile(char *qfilename,const char *dest);