*/
/************************************************/
/* */
+/* Procedure to set RCPT directive to */
+/* forward email to SMTP peers. */
+/* */
+/************************************************/
+static _Bool setdirectives(CONTYP *contact,char *ext)
+
+{
+#define OPEP "lvleml.c:setdirectives,"
+
+_Bool status;
+FILE *trans;
+int phase;
+_Bool proceed;
+
+status=false;
+trans=(FILE *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
+ switch (phase) {
+ case 0 : //Creating the file
+ if ((trans=eml_createqfile(contact->cursesid,ext))==(FILE *)0)
+ phase=999; //trouble trouble
+ break;
+ case 1 : //write data to trans file;
+ break;
+ case 2 : //closing transfile
+ if (eml_closeqfile(trans)<0)
+ phase=999; //Trouble trouble
+ break;
+ case 3 : //everythin fine
+ status=true;
+ break;
+ default : //SAFE guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+#undef OPEP
+return status;
+}
+/*
+\f
+*/
+/************************************************/
+/* */
/* Procedure to accept EMAIL contents from */
/* SMTP peers. */
/* Return true, if everything is fine */
queue=(FILE *)0;
got=0;
phase=0;
-proceed=true;
+proceed=setdirectives(contact,"tmp");
while (proceed==true) {
//(void) rou_alert(0,"JMPDBG %s phase='%d' empty='%d'",OPEP,phase,empty);
switch (phase) {
case 0 : //opening the queue email
- if ((queue=eml_opennewqueue(contact->cursesid))==(FILE *)0)
+ if ((queue=eml_createqfile(contact->cursesid,""))==(FILE *)0)
phase=999; //trouble trouble
break;
case 1 : //Do we have a parameter
line=rou_freestr(line);
break;
case 4 : //got all data
- if (eml_closenewqueue(queue)<0)
+ if (eml_closeqfile(queue)<0)
+ phase=999; //Trouble trouble
+ break;
+ case 5 : //renameing directive
+ if (eml_renameqfile(contact->cursesid,"tmp","trans")==false)
phase=999; //Trouble trouble
- case 5 : //everything fine
+ break;
+ case 6 : //everything fine
(void) transmit(contact,"%d 3.5.3 %s",
CMDOK,"Message accepted for delivery");
done=true;
/* */
/********************************************************/
#include <errno.h>
+#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
*/
/********************************************************/
/* */
-/* Procedure to open a file to store the email in */
-/* within the spool queue. */
+/* Procedure to change qfile extension */
+/* directory. */
/* */
/********************************************************/
-PUBLIC FILE *eml_opennewqueue(char *sessionid)
+PUBLIC _Bool eml_renameqfile(char *qfilename,char *oldext,char *newext)
{
-#define OPEP "unieml.c:eml_opennewqueue,"
+#define OPEP "unieml.c:eml_renameqfile,"
-FILE *newqueue;
+_Bool status;
+char *filename;
+char fold[300];
+char fnew[300];
+
+status=true;
+filename=rou_apppath(QDIR);
+(void) snprintf(fold,sizeof(fold),"%s/%s.%s",filename,qfilename,oldext);
+(void) snprintf(fnew,sizeof(fnew),"%s/%s.%s",filename,qfilename,newext);
+if (rename(fold,fnew)<0) {
+ (void) rou_alert(0,"%s Unable to rename file <%s> to <%s> (error=<%s>)",
+ OPEP,fold,fnew,strerror(errno));
+ status=false;
+ }
+filename=rou_freestr(filename);
+return status;
+#undef OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to open a file within the queue */
+/* directory. */
+/* */
+/********************************************************/
+PUBLIC FILE *eml_createqfile(char *qfilename,char *ext)
+
+{
+#define OPEP "unieml.c:eml_createqfile,"
+
+FILE *qfile;
+int handle;
char *filename;
int phase;
int proceed;
-newqueue=(FILE *)0;
+qfile=(FILE *)0;
+handle=-1;
filename=(char *)0;
phase=0;
proceed=true;
//(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
switch (phase) {
case 0 : //Do we have a session ID
- if ((sessionid==(char *)0)||(strlen(sessionid)==0)) {
+ if ((qfilename==(char *)0)||(strlen(qfilename)==0)) {
(void) rou_core_dump("%s sessionID is not set (bug?)",OPEP);
phase=999; //never reached
}
break;
case 1 : //"Computing" the file new queue filename
filename=rou_apppath(QDIR);
- filename=(char *)realloc(filename,strlen(filename)+strlen(sessionid)+10);
+ filename=(char *)realloc(filename,strlen(filename)+strlen(qfilename)+10);
(void) strcat(filename,"/");
- (void) strcat(filename,sessionid);
- if ((newqueue=fopen(filename,"w"))==(FILE *)0) {
+ (void) strcat(filename,qfilename);
+ if ((ext!=(char *)0)&&(strlen(ext)>0)) {
+ filename=(char *)realloc(filename,strlen(filename)+strlen(ext)+10);
+ (void) strcat(filename,".");
+ (void) strcat(filename,ext);
+ }
+ break;
+ case 2 : //creating and opening the file
+ if ((handle=open(filename,O_EXCL|O_CREAT|O_WRONLY|O_TRUNC,0640))<0) {
(void) rou_alert(0,"%s Unable to open file <%s> (error=<%s>)",
OPEP,filename,strerror(errno));
+ phase=999; //Trouble trouble
+ }
+ break;
+ case 3 : //convert handle to FILE *
+ if ((qfile=fdopen(handle,"w"))==(FILE *)0) {
+ (void) rou_alert(0,"%s Unable to fdopen file <%s> (error=<%s>)",
+ OPEP,filename,strerror(errno));
}
- filename=rou_freestr(filename);
break;
default : //SAFE guard
+ filename=rou_freestr(filename);
proceed=false;
break;
}
phase++;
}
-return newqueue;
+return qfile;
#undef OPEP
}
/*
/* stored within queue. */
/* */
/********************************************************/
-PUBLIC int eml_closenewqueue(FILE *newqueue)
+PUBLIC int eml_closeqfile(FILE *qfile)
{
-#define OPEP "unieml.c:eml_closenewqueue,"
+#define OPEP "unieml.c:eml_closeqfile,"
int status;
-if ((status=fclose(newqueue))<0) {
- (void) rou_alert(0,"%s Unable to close queuefile (error=<%s>)",
+if ((status=fclose(qfile))<0) {
+ (void) rou_alert(0,"%s Unable to close qfile (error=<%s>)",
OPEP,strerror(errno));
}
return status;