?? inetserverdlg.cpp.bak
字號:
listmail = TRUE;
AddLog("New Mailinglist (" + (CString) curname + ") mail");
HANDLE hFind1;
WIN32_FIND_DATA findData1 = {0};
hFind1 = FindFirstFile ("mail\\" + Fname, &findData1);
int mlsize = (findData1.nFileSizeHigh * MAXDWORD) + findData1.nFileSizeLow;
FindClose(hFind1);
FILE *fpf;
char listfname[255];
sprintf(listfname,"lists\\%s",findData.cFileName);
fpf = fopen (listfname,"rt");
if (fpf == NULL) //this sucks
{
AddLog ("Couldn't read mailing list file");
}
else
{
int readstatus = 0;
int maxsize = 0;
char reply_to[255];
char xtdsender[255];
char subject_prefix[255];
char templine[255];
sprintf(reply_to,"");
sprintf(subject_prefix,"");
sprintf(xtdsender,"");
while (!feof(fpf))
{
fgets(templine,255,fpf);
if(!feof(fpf))
{
DeleteCRLF(templine);
if ((templine[0] != '#') || (templine[0] != '['))
{
if (readstatus == 1)
{
char seps[] = "=";
char *token;
token = strtok( templine, seps );
char lastoption[255];
int xpos = 0;
while( token != NULL )
{
if (xpos == 0)
{
sprintf(lastoption,"%s",token);
}
if (xpos == 1)
{
if (stricmp(lastoption,"reply_to") == 0)
{
sprintf(reply_to,"%s",token);
}
if (stricmp(lastoption,"maxlength") == 0)
{
maxsize = atoi(token);
}
if (stricmp(lastoption,"subject_prefix") == 0)
{
sprintf(subject_prefix,"%s",token);
}
if (stricmp(lastoption,"sender") == 0)
{
sprintf(xtdsender,"%s",token);
}
}
xpos++;
token = strtok( NULL, seps );
}
if (maxsize != 0)
{
if (mlsize >= maxsize)
{
AddLog("Mail to large for mailing list");
break;
}
}
}
if (readstatus == 2)
{
mkdir("spool");
SMTPForwardInfo fwdinf;
//we generate a new filename for each send
//so we can easely delete the file
CTime t = CTime::GetCurrentTime();
SYSTEMTIME stime;
GetSystemTime(&stime);
char fnamenew[255];
sprintf(fnamenew,"%i%02i%02i%02i%02i%02i%i.out",t.GetYear(),t.GetMonth(),t.GetDay(),t.GetHour(),t.GetMinute(),t.GetSecond(),stime.wMilliseconds);
fwdinf.Fname = "spool\\" + (CString)fnamenew;
fwdinf.error= 0;
fwdinf.sendnr = 0;
fwdinf.Sender= "MAIL FROM: <" + (CString) xtdsender + ">\r\n";
fwdinf.Rcpt= "RCPT TO: <" + (CString)templine + ">";
time_t theTime;
time(&theTime);
fwdinf.timestamp = theTime;
fwdinf.islocal = true;
CopyFile("mail\\" + Fname,fwdinf.Fname ,FALSE );
AddLog ("Posting mailing-list mail to " + (CString)templine);
SMTPForwardList.Add(fwdinf); //have fun :)
}
}
if (strcmp(templine,"[Setup]") == 0) readstatus = 1;
if (strcmp(templine,"[Users]") == 0)
{
readstatus = 2;
FILE *fpin = fopen("mail\\" + Fname,"rt");
CTime t = CTime::GetCurrentTime();
SYSTEMTIME stime;
GetSystemTime(&stime);
char tempfile[255];
sprintf(tempfile,"mail\\%i%02i%02i%02i%02i%02i%i.in",t.GetYear(),t.GetMonth(),t.GetDay(),t.GetHour(),t.GetMinute(),t.GetSecond(),stime.wMilliseconds);
FILE *fpout = fopen(tempfile,"wt");
BOOL insideheader = TRUE;
while(!feof(fpin))
{
fgets(templine,255,fpin);
if(!feof(fpin))
{
if (insideheader)
{
if ((templine[0] == 'S') && (templine[1] == 'u') && (templine[2] == 'b')
&& (templine[3] == 'j') && (templine[4] == 'e') && (templine[5] == 'c')
&& (templine[6] == 't') && (templine[7] == ':'))
{
//modify subject?
if (strlen(subject_prefix) != 0)
{
//is our new subject already in the text?
if (strstr(templine,subject_prefix) == NULL)
{
//there isnt
for (UINT x = 9;x<= strlen(templine);x++)
{
templine[x-9] = templine[x];
}
fprintf(fpout,"Subject: %s %s",subject_prefix,templine);
sprintf(templine,"");
}
}
}
if ((templine[0] == 'S') && (templine[1] == 'e') && (templine[2] == 'n')
&& (templine[3] == 'd') && (templine[4] == 'e') && (templine[5] == 'r')
&& (templine[6] == ':') ) //sender already excist, use ours now
{
//if xtdsender is = 0 something is wrong or we already have it
if (strlen(xtdsender) != 0)
{
fprintf(fpout,"Sender: %s\r\n",xtdsender);
sprintf(xtdsender,"");
sprintf(templine,"");
}
}
if (stricmp(templine,"\r\n") == 0)
{
if (strlen(xtdsender) != 0) fprintf(fpout,"Sender: %s\r\n",xtdsender);
if (strlen(reply_to) != 0) fprintf(fpout,"Reply-To: %s\r\n",reply_to);
fprintf(fpout,"\r\n");
insideheader = FALSE;
}
else
{
fprintf(fpout,"%s",templine);
}
}
else
{
fprintf(fpout,"%s",templine);
}
}
}
fclose(fpin);
fclose(fpout);
CopyFile(tempfile,"mail\\" + Fname,FALSE );
DeleteFile(tempfile);
}
}
}
fclose(fpf);
}
}
}
}
} while (FindNextFile(hFind, &findData));
FindClose (hFind);
}
}
if ((fwd == FALSE) && (listmail == FALSE)) //dont know that user
{
//send to user who receives all unknown stuff
char tempstr1[255];
char fwddir[255];
sprintf(tempstr1,"%s",GetReg("Software\\InetServ","ForwardUser"));
sprintf(fwddir,"%s",tempstr1);
sprintf(tempstr1,"%s", GetReg("Software\\InetServ","UserForward"));
if (strcmp(tempstr1,"TRUE") == 0)
{
char mkd[255];
sprintf(mkd,"mail\\%s",fwddir);
mkdir (mkd);
CopyFile("mail\\" + Fname,"mail\\" + (CString) fwddir + "\\" + Fname,FALSE );
}
//after that lets relay (if allowed)
BOOL islocal = FALSE;
char tempstr2[255];
sprintf(tempstr2,"%s",GetReg("Software\\InetServ","RelayType"));
if ((atoi(tempstr2) != -1) && (aka_ok == FALSE))
{
char tempstra[255];
sprintf(tempstra,"%s",Sender);
int ps = 0;
for (UINT ci = 0;ci<strlen(tempstra);ci++)
{
if(tempstra[ci] == '@')
{
ps = ci;
}
}
for (UINT xi = ps;xi<strlen(tempstra);xi++)
{
tempstra[xi-ps] = tempstra[xi+1];
}
tempstra[xi-ps-4] = '\0';
strlwr(tempstra);
for (int bb = 0;bb<= MyAkaList.GetSize()-1;bb++)
{
if (strcmpi(MyAkaList[bb].Text,tempstra) == 0)
{
islocal = TRUE;
}
}
char tempstr2[255];
sprintf(tempstr2,"%s",GetReg("Software\\InetServ","SMTPRelayCheckHost"));
BOOL sender_ok = TRUE;
//lets check if we must validate hosts
if (strcmp(tempstr2,"TRUE") == 0)
{
if (islocal == FALSE) sender_ok = FALSE;
}
if (sender_ok == TRUE)
{
mkdir("spool");
SMTPForwardInfo fwdinf;
//we generate a new filename for each send
//so we can easely delete the file
CTime t = CTime::GetCurrentTime();
SYSTEMTIME stime;
GetSystemTime(&stime);
char fnamenew[255];
sprintf(fnamenew,"%i%02i%02i%02i%02i%02i%i.out",t.GetYear(),t.GetMonth(),t.GetDay(),t.GetHour(),t.GetMinute(),t.GetSecond(),stime.wMilliseconds);
fwdinf.Fname = "spool\\" + (CString)fnamenew;
fwdinf.error= 0;
fwdinf.sendnr = 0;
fwdinf.Sender= Sender;
fwdinf.Rcpt= rcptFull;
time_t theTime;
time(&theTime);
fwdinf.timestamp = theTime;
fwdinf.islocal = true;
CopyFile("mail\\" + Fname,fwdinf.Fname ,FALSE );
AddLog ("Relaying mail...");
SMTPForwardList.Add(fwdinf); //have fun :)
}
else
{
//user not known to me, mail dropped
AddLog("Relay tried to use by non local user: " + Sender);
}
}
else
{
CopyFile("mail\\" + Fname,"mail\\unknown\\" + Fname,FALSE );
char logstr[255];
sprintf(logstr,"User not local: %s (mail\\unknown\\%s)\n",tempstr,Fname);
LogError(logstr);
sprintf(logstr,"Could not send %s",tempstr);
AddLog(logstr);
}
}
}
}
}
}
fclose(stream);
if ( fwd_mapi ) //- MAPI forward envelop updation
{
fprintf(mapistream,"X-CMCEND\n");
if( (stream = fopen("mail\\" + Fname, "rt" )) != NULL )
{
while (!feof(stream))
{
fgets(tempstr,255,stream);
fputs(tempstr,mapistream);
}
fclose(stream);
}
else
{
char logstr[255];
sprintf(logstr,"Could not forward to mapi (read error): %s (mail\\unknown\\%s)\n",tempstr,Fname);
LogError(logstr);
CopyFile("mail\\" + Fname,"mail\\unknown\\" + Fname,FALSE );
sprintf(logstr,"Could not forward to mapi %s",tempstr);
AddLog(logstr);
}
fclose(mapistream);
ProcessPOP32CMC(Fname); //- MAPI forward the mail to MSmail Server
}
DeleteFile("mail\\" + Fname);
DeleteFile("mail\\" + CTL);
}
else
{
char logstr[255];
sprintf(logstr,"WARNING! Could not process NewMail"); //this is a hard error!
AddLog(logstr);
}
}
void CInetServerDlg::ProcessPendingRead(CClientSocket* pSocket)
{
for (int i= 0;i<=SocketList.GetSize()-1;i++)
{
if ((pSocket) == SocketList[i].pSock)
{
if (SocketList[i].typ == 1) ReadPop3(pSocket,i);
if (SocketList[i].typ == 2) ReadSmtp(pSocket,i);
if (SocketList[i].typ == 3) ReadTelnet(pSocket,i);
if (SocketList[i].typ == 4) ReadWebMail(pSocket,i);
}
}
}
void CInetServerDlg::ReadTelnet(CClientSocket* pSocket,int i)
{
char buf[1024];
char buf2[1024];
CString tempstr = "";
int nix = pSocket->Receive(&buf, 1024,0);
if (buf[0] == -1) return;
if (buf[0] == 0) return;
if ((buf[0] == 8) && (nix == 1))
{
if (SocketList[i].Temp.GetLength()>=1)
{
sprintf(buf,"%c %c",8,8);
pSocket->Send (buf,strlen(buf),0);
SocketList[i].Temp.GetBufferSetLength(SocketList[i].Temp.GetLength()-1);
}
return;
}
buf[nix] = '\0';
//ok, generally we send everything back to to client (w/o lf)
if (SocketList[i].dontwrite == FALSE)
{
sprintf(buf2,"%s",buf);
DeleteCRLF(buf2);
pSocket->Send (buf2,strlen(buf2),0);
}
CString tempcstr;
tempstr = buf;
char sendstr[255];
tempcstr = tempstr;
SocketList[i].Temp = SocketList[i].Temp + tempstr;
if (SocketList[i].Temp.GetLength()>240) { SocketList[i].Temp = "";return;}; //buffer to large problem
tempstr = SocketList[i].Temp;
BOOL flf = FALSE;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -