www.pudn.com > DTMS.rar > INTERFAC.C
#include "mail.h"
struct message *msgp;
MAIL *openfile(char *file)
{
MAIL *mail;
if( (mail=mail_open(file, O_RDWR ,FILE_MODE))==NULL)
err_sys("mail_open error");
return mail;
}
MAIL *newfile(char *file)
{
MAIL *mail;
if ( (mail = mail_open(file, O_RDWR | O_CREAT | O_TRUNC,
FILE_MODE)) == NULL)
err_sys("mail_new error");
return mail;
}
int getmsgfrmdb(char *user)
{
FILE *fp;
MAIL *mail;
char key[1024],*ptr,ch;
int i,j,keylen;
mail=openfile(user);
if((fp=fopen(TMPMSGFILE,"w+"))==NULL)
err_sys("open MSGFILE error");
i=0;
msgph=(struct message*)calloc(100,sizeof(struct message));
msgp=msgph;
mail_rewind(mail);
do
{
ptr=mail_nextrec(mail,key);
if(ptr!=NULL)
{
for(j=0,msgp=msgph;jmessageid=(char*)malloc(strlen(key));
msgp->content=(char*)malloc(strlen(ptr));
strcpy(msgp->messageid,key);
strcpy(msgp->content,ptr);
if(i==0)
{
fprintf (fp,"You have mail.\n");
fprintf (fp,"\n");
}
fprintf(fp,"%d\t%s\n",i+1,hint);
i++;
}
}while(ptr!=NULL);
if(i==0)
fprintf(fp,"No mail for you!");
fclose(fp);
mail_close(mail);
return 0;
}
void showmsghdr(int fd,int sd)
{
char buf[MAXLINE];
int len;
while((len=ReadLine(fd,buf,MAXLINE))>0)
write(sd,buf,len);
close(fd);
}
/*msgp can be set up when the client come into the system
and be free when the client leave the system*/
/*char *GetMail(int msgno)
{
return(msgp[msgno]->content);
}
*/
int StoreMail(struct message *msg)
{
MAIL *mail;
struct stat statbuf;
char *name;
int len;
/*msg.to=ms->to;
msg.from=ms->from;
msg.subject=ms->subject;
msg.content=ms->content;
*/
len=strlen(msg->to);
name=(char *)malloc(len+4+1);
strcpy(name,msg->to);
strcat(name,".idx");
if(stat(name,&statbuf)<0)
mail=newfile(msg->to);
else
mail=openfile(msg->to);
if (mail_store(mail, msg) != 0)
err_quit("mail_store error for");
mail_close(mail);
free(name);
return 0;
}
int DelMail(int msgno,char *user)
{
MAIL *mail;
int i;
msgp=msgph;
for(i=1;imessageid);
mail_close(mail);
}
int GetMail(int msgno,char *buf)
{
int i;
msgp=msgph;
for(i=1;icontent);*/
strcpy(buf,msgp->content);
}
int client_close(int sd)
{
free(msgp);
return close(sd);
}