home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* XBBS SOURCE CODE copyright (c) 1990 by M. Kimes */
- /* All Rights Reserved */
- /* */
- /* For complete details of the licensing restrictions, please refer */
- /* to the License agreement, which is published in its entirety in */
- /* the in the file LICENSE.XBS. */
- /* */
- /* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
- /* XBBS LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
- /* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
- /* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT M. KIMES */
- /* AT THE ADDRESS LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO USE */
- /* THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE XBBS LICENSING */
- /* AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE ABLE TO REACH WITH */
- /* M. KIMES */
- /* */
- /* */
- /* You can contact M. Kimes at the following address: */
- /* */
- /* M. Kimes 1:380/16.0@FidoNet */
- /* 542 Merrick (318)222-3455 data */
- /* Shreveport, LA 71104 */
- /* */
- /* */
- /* Please feel free to contact me at any time to share your comments about */
- /* my software and/or licensing policies. */
- /* */
- /*--------------------------------------------------------------------------*/
- /* Scanner for net/echo mail */
-
- #include "msg.h"
- #include "xext.h"
-
- #define MAXKLUDGE 133
- /* #define SETSCANNED(x) (x.m_attr |= MSGSCANNED) */
-
- static ulong totalmsgs=0;
- static struct _xmsg xmsg; /* The current msg's header */
-
- extern struct _mboard far *marea;
- extern word maxareas;
-
- /* Function declarations */
-
- static int pascal open_pkt (word zone,word net,word dest,word d_point,char *domain,word attr,word m_attr);
- static void pascal close_pkt (int *fp);
- static void pascal close_msg_files(void);
- static void pascal open_msg_files(word areanum);
- static void pascal report(void);
- static int pascal write_pkt_msg (int fp,struct _xmsg *amsg,char *text,char *area);
- static word pascal do_export(word areanum,word startat);
-
- static int dataptr=-1,textptr=-1;
-
-
-
- void pascal export_mail (word areano,word messno) {
-
- register word x,y;
- char temppause,tempsafe;
- struct _mboard far *tempmarea;
- char filename[133];
- struct ffblk f;
-
- tempmarea=marea;
- if(!user.pointid) {
- gprintf(0,say_prompt(586),conf.sysop);
- return;
- }
- else {
- if(nodenumber!=1) sprintf(filename,"%sXPORT%hu\\%04x%04x.PKT",conf.homepath,nodenumber,conf.net,conf.node);
- else sprintf(filename,"%sXPORT\\%04x%04x.PKT",conf.homepath,conf.net,conf.node);
- if(findfirst(filename,&f,0)) {
- gprintf(0,say_prompt(587),conf.zone,conf.net,conf.node,user.pointid,conf.domain);
- }
- }
- temppause=pauser;
- tempsafe=safe;
- pauser=safe=0;
- if(!areano) {
- for(x=0;x<maxareas;x++) {
- gprintf(0,say_prompt(588),marea[x].name);
- inkey();
- open_msg_files(marea[x].number);
- if(dataptr!=-1 && textptr!=-1) {
- if(!messno) y=lastread[marea[x].number-1]+1;
- else y=messno;
- gprintf(0,say_prompt(377),do_export(x,y));
- close_msg_files();
- report();
- }
- }
- }
- else {
- marea=&mboard;
- gprintf(0,say_prompt(588),marea[0].name);
- open_msg_files(marea[0].number);
- if(dataptr!=-1 && textptr!=-1) {
- if(!messno) y=lastread[marea[0].number-1]+1;
- else y=messno;
- gprintf(0,say_prompt(377),do_export(0,y));
- close_msg_files();
- }
- marea=tempmarea;
- printm("\n\n");
- }
- safe=tempsafe;
- pauser=temppause;
- }
-
-
-
- void pascal report (void) {
-
- printm("\n\n");
- if(!totalmsgs) {
- printm("No messages exported.\n");
- return;
- }
- gprintf(0,"Total msgs exported: %lu\n",totalmsgs);
- }
-
-
-
- word pascal do_export (word areanum,word startat) {
-
- word nummsgs;
- register word x;
- int fp=-1;
- char *text=NULL;
- char *area="NUL";
- char *lastarea=NULL;
- word anum=0;
- char aname[49];
-
- lseek(dataptr,0L,SEEK_END);
- nummsgs=(word)(tell(dataptr)/(long)sizeof(struct _xmsg));
- if(startat)startat--;
- if(startat>=nummsgs) return 0;
- errno=0;
- lseek(dataptr,(long)startat * (long)sizeof(struct _xmsg),SEEK_SET);
- if(errno==EACCES) {
- sleep(1);
- lseek(dataptr,(long)startat * (long)sizeof(struct _xmsg),SEEK_SET);
- }
- for(x=startat;x<(nummsgs+2);x++) {
- errno=0;
- if(_read(dataptr,&xmsg,sizeof(struct _xmsg))<1) {
- if(errno!=EACCES) break;
- sleep(1);
- if(_read(dataptr,&xmsg,sizeof(struct _xmsg))<1) break;
- }
- if(xmsg.m_attr & MSGDELETED) continue;
- if(xmsg.attr & MSGPRIVATE) {
- if(!(marea[areanum].attr & ECHO) && !(marea[areanum].attr & ALTECHO)) {
- if(marea[areanum].substat2>user.stat[1]) {
- if(stricmp(xmsg.to,user.name) && stricmp(xmsg.from,user.name) &&
- stricmp(xmsg.to,user.handle) && stricmp(xmsg.from,user.handle))
- continue;
- }
- }
- }
- if(marea[areanum].attr & NET) {
- if(!(xmsg.attr & MSGPRIVATE)) {
- if(xmsg.d_zone!=conf.zone || xmsg.dest_net!=conf.net || xmsg.dest!=conf.node || xmsg.d_point!=user.pointid) continue;
- }
- }
-
- /* Got one to export */
- lseek(textptr,xmsg.start,SEEK_SET);
-
- text=(char *)mmalloc(xmsg.length+2);
- if(!text)continue;
- *text=0;
- _read(textptr,text,xmsg.length+1);
- if(!*text){
- if(text)ffree(text);
- text=NULL;
- continue;
- }
- strcpy(aname,marea[areanum].name);
- strupr(aname);
- /* while(p=(strchr(aname,' '))) *p='_'; */
- area=aname;
-
- if(fp==-1) {
- fp=open_pkt(conf.zone,conf.net,conf.node,user.pointid,/* conf.domain */ "XBBS",xmsg.attr,xmsg.m_attr);
- /* Note use of XBBS in domain field to indicate to mailerless point
- that certain "liberties" may be taken with these messages */
- if(fp==-1) {
- if(text)ffree(text);
- text=NULL;
- continue;
- }
- }
- xmsg.d_zone=conf.zone;
- xmsg.dest_net=conf.net;
- xmsg.dest=conf.node;
- xmsg.d_point=user.pointid;
- if(lastarea!=area) {
- lprint("\n");
- }
- fast=1;
- gprintf(LOCALONLY,"\04Exporting msg #%u (#%u) from %s...",x+1,++anum,marea[areanum].name);
- lastread[areanum-1]=x;
- cputs("\r");
- mprint(".");
- inkey();
- if(xmsg.m_attr & MSGPACKED) {
-
- word temp;
-
- temp=msg.length;
- msg.length=xmsg.length;
- if(unpack_msg(&text)==NULL) {
- if(text) ffree(text);
- text=NULL;
- anum--;
- msg.length=temp;
- continue;
- }
- msg.length=temp;
- }
- text[xmsg.length]=0;
- text[xmsg.length-1]=0;
- write_pkt_msg(fp,&xmsg,text,area);
- if(text)ffree(text);
- text=NULL;
- totalmsgs++;
- lastarea=area;
- }
- if(fp!=-1)close_pkt(&fp);
- return anum;
- }
-
-
-
- int pascal open_pkt (word zone,word net,word node,word point,char *domain,word attr,word m_attr) {
-
- static int fp;
- char s[133];
- long pos;
- struct _pkthdr ph;
- struct date dd;
- struct time tt;
-
- /* Open (create if necessary) a packet for address given.
- Return a file handle for the packet positioned to eop */
-
- if(nodenumber==1) sprintf(s,"%sXPORT/%04x%04x.PKT",conf.homepath,net,node);
- else sprintf(s,"%sXPORT%hu/%04x%04x.PKT",conf.homepath,nodenumber,net,node);
-
- fp=oopen(s,O_RDWR | O_DENYWRITE | O_BINARY);
- if(fp==-1) {
- fp=ccreat(s,S_IWRITE);
- if(fp==-1) return -1; /* Shit */
- getdate(&dd); /* Create header */
- gettime(&tt);
- ph.orig_node=conf.node;
- ph.dest_node=node;
- ph.year=dd.da_year;
- ph.month=dd.da_mon;
- ph.day=dd.da_day;
- ph.hour=tt.ti_hour;
- ph.minute=tt.ti_min;
- ph.second=tt.ti_sec;
- ph.rate=0;
- ph.ver=2;
- ph.orig_net=conf.net;
- ph.dest_net=net;
- ph.product=0; /* Until I get a product code (snore) */
- ph.rev_lev=2;
- strset(ph.password,0);
- ph.qm_orig_zone=conf.zone;
- ph.qm_dest_zone=zone;
- strset(ph.domain,0);
- if(domain && *domain) strncpy(ph.domain,domain,8);
- ph.orig_zone=conf.zone;
- ph.dest_zone=zone;
- ph.orig_point=0;
- ph.dest_point=point;
- ph.pr_data=0L;
- _write(fp,&ph,sizeof(struct _pkthdr));
- }
- else {
- lseek(fp,0L,SEEK_END);
- pos=tell(fp);
- if(pos) lseek(fp,pos-2L,SEEK_SET); /* Position to next msg spot */
- }
- return fp;
- }
-
-
-
- void pascal close_pkt (int *fp) {
-
- /* Close a previously opened packet. */
-
- cclose(*fp);
- *fp=-1;
- }
-
-
-
- int pascal write_pkt_msg (int fp,struct _xmsg *amsg,char *text,char *area) {
-
- char pmsg[192];
- char *p;
- word x;
-
- /* Write the message given to the end of the file given as a
- packed msg */
-
- memset(pmsg,192,0);
- *pmsg=0x02;
- pmsg[1]=0x00;
- memcpy(&pmsg[2],&amsg->orig,2);
- memcpy(&pmsg[4],&amsg->dest,2);
- memcpy(&pmsg[6],&amsg->orig_net,2);
- memcpy(&pmsg[8],&amsg->dest_net,2);
- memcpy(&pmsg[10],&amsg->attr,2);
- /* memcpy(&pmsg[12],&amsg->cost,2); */ /* Old way, bleach */
- x=(word)(strlen(text)+strlen(amsg->to)+strlen(amsg->from)+strlen(amsg->subj)+4);
- if(area && *area) {
- x=(word)(strlen(area)+7);
- }
- memcpy(&pmsg[12],&x,2); /* Use cost field for msg length. Here's how it
- works: We add the message text length
- (including AREA: tag and kludges) to the
- variable length header fields (to,from,subj)
- and put this unsigned int into the useless
- cost field of the packed msg. Then an unpacker
- can use that field to speed up unpacking.
- Length should include the terminating
- null bytes */
- for(x=0;x<20;x++) if(amsg->date[x]==0) amsg->date[x]='Q';
- amsg->date[19]=0; /* Goddamn qmail anyway...can't count to 20 */
- memcpy(&pmsg[14],amsg->date,20);
- p=&pmsg[34];
- strcpy(p,amsg->to);
- x=34;
- while(*p){
- x++;
- p++;
- }
- p++;
- x++;
- strcpy(p,amsg->from);
- while(*p){
- x++;
- p++;
- }
- x++;
- p++;
- strcpy(p,amsg->subj);
- while(*p){
- x++;
- p++;
- }
- x++;
- p++;
- _write(fp,pmsg,x);
- if(*area && area) { /* Prepend area tag */
- _write(fp,"AREA:",5);
- _write(fp,area,strlen(area));
- _write(fp,"\r",1);
- }
- _write(fp,text,strlen(text));
- _write(fp,"\0\0",3);
- lseek(fp,(tell(fp)-2L),SEEK_SET); /* Ready for another msg */
- return 0;
- }
-
-
-
- void pascal close_msg_files (void) {
-
- if(dataptr!=-1) cclose(dataptr);
- if(textptr!=-1) cclose(textptr);
- dataptr=textptr=-1;
- }
-
-
-
- void pascal open_msg_files (word areanum) {
-
- static word lastarea=0;
- char s[133];
-
- if(lastarea==areanum) return;
- sprintf(s,"%sXDATA.%03x",messpath,areanum);
- dataptr=oopen(s,O_RDONLY | O_BINARY | O_DENYNONE);
- if(dataptr==-1) {
- lastarea=0;
- return;
- }
- sprintf(s,"%sXTEXT.%03x",messpath,areanum);
- textptr=oopen(s,O_RDONLY | O_BINARY | O_DENYNONE);
- if(textptr==-1) {
- close_msg_files();
- lastarea=0;
- return;
- }
- lastarea=areanum;
- return;
- }
-