22 extern struct config config;
27 * Aliasing for network mail.
28 * (Error messages have been commented out, because this is a server.)
30 int alias(char *name) /* process alias and routing info for mail */
34 char aaa[300],bbb[300];
36 fp=fopen("network/mail.aliases","r");
37 if (fp==NULL) fp=fopen("/dev/null","r");
38 if (fp==NULL) return(M_ERROR);
39 GNA: strcpy(aaa,""); strcpy(bbb,"");
62 if (strucmp(name,aaa)) goto GNA;
65 /* cprintf("*** Mail is being forwarded to %s\n",name); */
67 DETYPE: /* determine local or remote type, see citadel.h */
68 for (a=0; a<strlen(name); ++a) if (name[a]=='!') return(M_INTERNET);
69 for (a=0; a<strlen(name); ++a)
71 for (b=a; b<strlen(name); ++b)
72 if (name[b]=='.') return(M_INTERNET);
73 b=0; for (a=0; a<strlen(name); ++a) if (name[a]=='@') ++b;
75 /* cprintf("Too many @'s in address\n"); */
79 for (a=0; a<strlen(name); ++a)
80 if (name[a]=='@') strcpy(bbb,&name[a+1]);
81 while (bbb[0]==32) strcpy(bbb,&bbb[1]);
82 fp = fopen("network/mail.sysinfo","r");
83 if (fp==NULL) return(M_ERROR);
86 } while ((a>=0)&&(strucmp(aaa,bbb)));
88 if (!strncmp(aaa,"use ",4)) {
94 if (!strncmp(aaa,"uum",3)) {
96 for (a=0; a<strlen(bbb); ++a) {
97 if (bbb[a]=='@') bbb[a]=0;
98 if (bbb[a]==' ') bbb[a]='_';
100 while(bbb[strlen(bbb)-1]=='_') bbb[strlen(bbb)-1]=0;
101 sprintf(name,&aaa[4],bbb);
104 if (!strncmp(aaa,"bin",3)) {
105 strcpy(aaa,name); strcpy(bbb,name);
106 while (aaa[strlen(aaa)-1]!='@') aaa[strlen(aaa)-1]=0;
107 aaa[strlen(aaa)-1]=0;
108 while (aaa[strlen(aaa)-1]==' ') aaa[strlen(aaa)-1]=0;
109 while (bbb[0]!='@') strcpy(bbb,&bbb[1]);
111 while (bbb[0]==' ') strcpy(bbb,&bbb[1]);
112 sprintf(name,"%s @%s",aaa,bbb);
124 fp=fopen("citadel.control","r");
125 fread((char *)&CitControl,sizeof(struct CitControl),1,fp);
130 * cmd_msgs() - get list of message #'s in this room
132 void cmd_msgs(char *cmdbuf)
140 extract(which,cmdbuf,0);
144 if (!struncmp(which,"OLD",3)) mode = MSGS_OLD;
145 if (!struncmp(which,"NEW",3)) mode = MSGS_NEW;
146 if (!struncmp(which,"FIRST",5)) {
148 cm_howmany = extract_int(cmdbuf,1);
150 if (!struncmp(which,"LAST",4)) {
152 cm_howmany = extract_int(cmdbuf,1);
154 if (!struncmp(which,"GT",2)) {
156 cm_gt = extract_long(cmdbuf,1);
159 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
160 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
163 if (CC->curr_rm < 0) {
164 cprintf("%d no room\n",ERROR);
168 get_fullroom(&CC->fullroom,CC->curr_rm);
169 getuser(&CC->usersupp,CC->curr_user);
170 cprintf("%d messages...\n",LISTING_FOLLOWS);
171 for (a=0; a<MSGSPERRM; ++a)
172 if ((CC->fullroom.FRnum[a] >=0)
176 || ((mode==MSGS_OLD) && (CC->fullroom.FRnum[a] <= CC->usersupp.lastseen[CC->curr_rm]))
177 || ((mode==MSGS_NEW) && (CC->fullroom.FRnum[a] > CC->usersupp.lastseen[CC->curr_rm]))
178 || ((mode==MSGS_NEW) && (CC->fullroom.FRnum[a] >= CC->usersupp.lastseen[CC->curr_rm])
179 && (CC->usersupp.flags & US_LASTOLD))
180 || ((mode==MSGS_LAST)&& (a>=(MSGSPERRM-cm_howmany)))
181 || ((mode==MSGS_FIRST)&&(a<cm_howmany))
182 || ((mode==MSGS_GT) && (CC->fullroom.FRnum[a] > cm_gt))
186 cprintf("%ld\n",CC->fullroom.FRnum[a]);
193 * help_subst() - support routine for help file viewer
195 void help_subst(char *strbuf, char *source, char *dest)
200 while (p=pattern2(strbuf,source), (p>=0)) {
201 strcpy(workbuf,&strbuf[p+strlen(source)]);
202 strcpy(&strbuf[p],dest);
203 strcat(strbuf,workbuf);
208 void do_help_subst(char *buffer)
212 help_subst(buffer,"^nodename",config.c_nodename);
213 help_subst(buffer,"^humannode",config.c_humannode);
214 help_subst(buffer,"^fqdn",config.c_fqdn);
215 help_subst(buffer,"^username",CC->usersupp.fullname);
216 sprintf(buf2,"%ld",CC->usersupp.usernum);
217 help_subst(buffer,"^usernum",buf2);
218 help_subst(buffer,"^sysadm",config.c_sysadm);
219 help_subst(buffer,"^variantname",CITADEL);
220 sprintf(buf2,"%d",config.c_maxsessions);
221 help_subst(buffer,"^maxsessions",buf2);
227 * memfmout() - Citadel text formatter and paginator.
228 * Although the original purpose of this routine was to format
229 * text to the reader's screen width, all we're really using it
230 * for here is to format text out to 80 columns before sending it
231 * to the client. The client software may reformat it again.
233 void memfmout(int width, char *mptr, char subst)
234 /* screen width to use */
235 /* where are we going to get our text from? */
236 /* nonzero if we should use hypertext mode */
243 strcpy(aaa,""); old=255;
245 c=1; /* c is the current pos */
248 while (ch=*mptr, ((ch!=0) && (strlen(buffer)<126) )) {
250 buffer[strlen(buffer)+1] = 0;
251 buffer[strlen(buffer)] = ch;
254 if (buffer[0]=='^') do_help_subst(buffer);
256 buffer[strlen(buffer)+1] = 0;
258 strcpy(buffer,&buffer[1]);
265 if (ch<=0) goto FMTEND;
267 if ( ((ch==13)||(ch==10)) && (old!=13) && (old!=10) ) ch=32;
268 if ( ((old==13)||(old==10)) && (isspace(real)) ) {
272 if (ch>126) goto FMTA;
275 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
276 { cprintf("\n%s",aaa); c=strlen(aaa); aaa[0]=0;
278 b=strlen(aaa); aaa[b]=ch; aaa[b+1]=0; }
280 if ((strlen(aaa)+c)>(width-5)) {
284 cprintf("%s ",aaa); ++c; c=c+strlen(aaa);
288 if ((ch==13)||(ch==10)) {
296 FMTEND: cprintf("\n");
301 * get a message off disk.
304 void output_message(char *msgid, int mode, int headers_only)
310 CIT_UBYTE format_type,anon_flag;
315 struct cdbdata *dmsgtext;
318 /* buffers needed for RFC822 translation */
327 msg_num = atol(msgid);
330 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
331 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
334 if (CC->curr_rm < 0) {
335 cprintf("%d No room selected.\n",ERROR);
339 /* We used to need to check in the current room's fullroom table
340 * to determine where the message's disk position. We no longer need
341 * to do this, but we do it anyway as a security measure, in order to
342 * prevent rogue clients from reading messages not in the current room.
344 for (a=0; a<MSGSPERRM; ++a) if (CC->fullroom.FRnum[a] == msg_num) {
348 cprintf("%d Message %ld is not in this room.\n",
354 dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
356 if (dmsgtext == NULL) {
357 cprintf("%d Can't find message %ld\n", ERROR+INTERNAL_ERROR);
361 msg_len = (long) dmsgtext->len;
362 mptr = dmsgtext->ptr;
363 lprintf(9, "Returned message length is %ld\n", msg_len);
365 /* this loop spews out the whole message if we're doing raw format */
366 if (mode == MT_RAW) {
367 cprintf("%d %ld\n", BINARY_FOLLOWS, msg_len);
368 client_write(dmsgtext->ptr, (int) msg_len);
373 /* Otherwise, we'll start parsing it field by field... */
376 cprintf("%d Illegal message format on disk\n",
377 ERROR+INTERNAL_ERROR);
383 format_type = *mptr++;
385 /* now for the user-mode message reading loops */
386 cprintf("%d Message %ld:\n",LISTING_FOLLOWS,msg_num);
388 if (mode == MT_CITADEL) cprintf("type=%d\n",format_type);
390 if ( (anon_flag == MES_ANON) && (mode == MT_CITADEL) ) {
391 cprintf("nhdr=yes\n");
394 /* begin header processing loop for Citadel message format */
396 if (mode == MT_CITADEL) while(ch = *mptr++, (ch!='M' && ch!=0)) {
399 buf[strlen(buf)+1] = 0;
401 buf[strlen(buf)] = rch;
405 if (anon_flag==MES_ANON) cprintf("from=****");
406 else if (anon_flag==MES_AN2) cprintf("from=anonymous");
407 else cprintf("from=%s",buf);
408 if ((is_room_aide()) && ((anon_flag == MES_ANON)
409 || (anon_flag == MES_AN2)))
410 cprintf(" [%s]",buf);
413 else if (ch=='P') cprintf("path=%s\n",buf);
414 else if (ch=='U') cprintf("subj=%s\n",buf);
415 else if (ch=='I') cprintf("msgn=%s\n",buf);
416 else if (ch=='H') cprintf("hnod=%s\n",buf);
417 else if (ch=='O') cprintf("room=%s\n",buf);
418 else if (ch=='N') cprintf("node=%s\n",buf);
419 else if (ch=='R') cprintf("rcpt=%s\n",buf);
420 else if (ch=='T') cprintf("time=%s\n",buf);
421 /* else cprintf("fld%c=%s\n",ch,buf); */
424 /* begin header processing loop for RFC822 transfer format */
428 strcpy(snode, NODENAME);
429 strcpy(lnode, HUMANNODE);
430 if (mode == MT_RFC822) while(ch = *mptr++, (ch!='M' && ch!=0)) {
433 buf[strlen(buf)+1] = 0;
435 buf[strlen(buf)] = rch;
438 if (ch=='A') strcpy(luser, buf);
440 cprintf("Path: %s\n",buf);
441 for (a=0; a<strlen(buf); ++a) {
443 strcpy(buf,&buf[a+1]);
449 else if (ch=='U') cprintf("Subject: %s\n",buf);
450 else if (ch=='I') strcpy(mid, buf);
451 else if (ch=='H') strcpy(lnode, buf);
452 else if (ch=='O') cprintf("X-Citadel-Room: %s\n",buf);
453 else if (ch=='N') strcpy(snode, buf);
454 else if (ch=='R') cprintf("To: %s\n",buf);
457 cprintf("Date: %s", asctime(localtime(&xtime)));
461 if (mode == MT_RFC822) {
462 if (!strucmp(snode, NODENAME)) {
465 cprintf("Message-ID: <%s@%s>\n", mid, snode);
466 cprintf("From: %s@%s (%s)\n",
467 suser, snode, luser);
468 cprintf("Organization: %s\n", lnode);
471 /* end header processing loop ... at this point, we're in the text */
474 cprintf("text\n*** ?Message truncated\n000\n");
481 /* give 'em a length */
483 while(och=ch, ch = *mptr++, ch>0) {
486 cprintf("mlen=%ld\n", msg_len);
493 /* signify start of msg text */
494 if (mode == MT_CITADEL) cprintf("text\n");
495 if (mode == MT_RFC822) cprintf("\n");
497 /* If the format type on disk is 1 (fixed-format), then we want
498 * everything to be output completely literally ... regardless of
499 * what message transfer format is in use.
501 if (format_type == 1) {
504 while(och=ch, ch = *mptr++, ch>0) {
505 if (ch == 13) ch = 10;
507 if ((ch!=10)||(och!=10)) {
513 /* cprintf("%c", ch); */
517 if (len!=0) cprintf("%c", 10);
519 /* If the message on disk is format 0 (Citadel vari-format), we
520 * output using the formatter at 80 columns. This is the final output
521 * form if the transfer format is RFC822, but if the transfer format
522 * is Citadel proprietary, it'll still work, because the indentation
523 * for new paragraphs is correct and the client will reformat the
524 * message to the reader's screen width.
526 if (format_type == 0) {
538 * display a message (mode 0 - Citadel proprietary)
540 void cmd_msg0(char *cmdbuf)
543 int headers_only = 0;
545 extract(msgid,cmdbuf,0);
546 headers_only = extract_int(cmdbuf,1);
548 output_message(msgid,MT_CITADEL,headers_only);
553 * display a message (mode 2 - RFC822)
555 void cmd_msg2(char *cmdbuf)
558 int headers_only = 0;
560 extract(msgid,cmdbuf,0);
561 headers_only = extract_int(cmdbuf,1);
563 output_message(msgid,MT_RFC822,headers_only);
567 * display a message (mode 3 - IGnet raw format - internal programs only)
569 void cmd_msg3(char *cmdbuf)
572 int headers_only = 0;
574 if (CC->internal_pgm == 0) {
575 cprintf("%d This command is for internal programs only.\n",
580 extract(msgid,cmdbuf,0);
581 headers_only = extract_int(cmdbuf,1);
583 output_message(msgid,MT_RAW,headers_only);
589 * message base operation to send a message to the master file
591 void send_message(char *filename, struct smreturn *retbuf, int generate_id)
592 /* tempfilename of proper message */
593 /* return information */
594 /* set to 1 to generate an 'I' field */
600 char *message_in_memory;
603 fp = fopen(filename, "rb");
605 /* Measure the message */
606 lprintf(9, "Measuring the message\n");
607 fseek(fp, 0L, SEEK_END);
610 /* Now read it into memory */
611 lprintf(9, "Allocating %ld bytes\n", templen);
612 message_in_memory = (char *) malloc(templen);
613 if (message_in_memory == NULL) {
614 lprintf(2, "Can't allocate memory to save message!\n");
616 retbuf->smnumber = 0L;
621 lprintf(9, "Reading it into memory\n");
622 fseek(fp, 0L, SEEK_SET);
623 fread(message_in_memory, templen, 1, fp);
626 /* Get a new message number */
627 newmsgid = get_new_message_number();
629 /* Write our little bundle of joy into the message base */
631 lprintf(9, "Storing message %ld\n", newmsgid);
632 begin_critical_section(S_MSGMAIN);
633 if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
634 message_in_memory, templen) < 0 ) {
635 lprintf(2, "Can't store message\n");
636 retbuf->smnumber = 0L;
640 end_critical_section(S_MSGMAIN);
641 free(message_in_memory);
644 /* Finally, return the pointers */
645 retbuf->smnumber = newmsgid;
646 retbuf->smpos= 1L; /* FIX we really won't be needing this */
654 void loadtroom(void) {
655 struct quickroom qrbuf;
659 /* first try to locate the twit room */
660 for (a=0; a<MAXROOMS; ++a) {
662 if (!strucmp(qrbuf.QRname,config.c_twitroom)) {
668 /* if not found, try to create it - put it in the last slot */
669 twitroom = get_free_room_slot(-1);
671 newflags = create_room(twitroom,config.c_twitroom,0,"",0);
675 /* as a last resort, point to Aide> */
681 * this is a simple file copy routine.
683 void copy_file(char *from, char *to)
689 if (ffp==NULL) return;
695 while (a=getc(ffp), a>=0) {
706 * message base operation to save a message and install its pointers
708 void save_message(char *mtmp, /* file containing proper message */
709 char *rec, /* Recipient (if mail) */
710 char mtsflag, /* 0 for normal, 1 to force Aide> room */
711 int mailtype, /* local or remote type, see citadel.h */
712 int generate_id) /* set to 1 to generate an 'I' field */
715 struct usersupp tempUS;
717 struct smreturn smreturn;
720 send_message(mtmp,&smreturn,generate_id);
723 /* if the user is a twit, move to the twit room for posting */
724 if (TWITDETECT) if (CC->usersupp.axlevel==2) {
725 if (twitroom<0) loadtroom();
727 CC->curr_rm=twitroom;
730 /* and if this message is destined for Aide> then go there */
736 /* this call to usergoto() changes rooms if necessary. It also
737 causes the latest fullroom structure to be read into memory */
738 usergoto(CC->curr_rm,0);
740 /* Store the message pointer, but NOT for sent mail! */
741 if (CC->curr_rm != 1) {
743 /* read in the quickroom record, obtaining a lock... */
744 lgetroom(&CC->quickroom,CC->curr_rm);
745 get_fullroom(&CC->fullroom,CC->curr_rm);
747 /* Delete the oldest message if there is one */
748 if (CC->fullroom.FRnum[0] != 0L) {
749 cdb_delete(CDB_MSGMAIN,
750 &CC->fullroom.FRnum[0], sizeof(long));
754 for (a=0; a<(MSGSPERRM-1); ++a) {
755 CC->fullroom.FRnum[a]=CC->fullroom.FRnum[a+1];
758 /* ...and add the new message */
759 CC->fullroom.FRnum[MSGSPERRM-1]=smreturn.smnumber;
761 /* Write it back to disk. */
762 put_fullroom(&CC->fullroom,CC->curr_rm);
764 /* update quickroom */
765 CC->quickroom.QRhighest=CC->fullroom.FRnum[MSGSPERRM-1];
766 lputroom(&CC->quickroom,CC->curr_rm);
769 /* Bump this user's messages posted counter. Also, if the user is a
770 twit, give them access to the twit room. */
771 lgetuser(&CC->usersupp,CC->curr_user);
772 CC->usersupp.posted = CC->usersupp.posted + 1;
773 if (CC->curr_rm==twitroom) CC->usersupp.generation[twitroom]=CC->quickroom.QRgen;
774 lputuser(&CC->usersupp,CC->curr_user);
776 /* if mail, there's still more to do, if not, skip it */
777 if ((CC->curr_rm!=1)||(mtsflag)) goto ENTFIN;
779 /* network mail - send a copy to the network program */
780 if (mailtype!=M_LOCAL) {
781 sprintf(aaa,"./network/spoolin/nm.%d",getpid());
783 system("exec nohup ./netproc >/dev/null 2>&1 &");
786 /* local mail - put a copy in the recipient's mailbox */
787 if (mailtype==M_LOCAL) {
788 if (lgetuser(&tempUS,rec)==0) {
789 if (tempUS.mailnum[0] != 0L) {
790 cdb_delete(CDB_MSGMAIN, &tempUS.mailnum[0],
793 for (e=0; e<(MAILSLOTS-1); ++e) {
794 tempUS.mailnum[e]=tempUS.mailnum[e+1];
796 tempUS.mailnum[MAILSLOTS-1]=smreturn.smnumber;
797 lputuser(&tempUS,rec);
801 /* if we've posted in a room other than the current room, then we
802 have to now go back to the current room... */
803 ENTFIN: if (hold_rm!=(-1)) {
806 unlink(mtmp); /* delete the temporary file */
811 * generate an administrative message and post it in the Aide> room
813 void aide_message(char *text)
819 fp=fopen(CC->temp,"wb");
820 fprintf(fp,"%c%c%c",255,MES_NORMAL,0);
821 fprintf(fp,"Psysop%c",0);
822 fprintf(fp,"T%ld%c",now,0);
823 fprintf(fp,"ACitadel%c",0);
824 fprintf(fp,"OAide%c",0);
825 fprintf(fp,"N%s%c",NODENAME,0);
826 fprintf(fp,"M%s\n%c",text,0);
828 save_message(CC->temp,"",1,M_LOCAL,1);
829 syslog(LOG_NOTICE,text);
835 * build a binary message to be saved on disk
837 void make_message(char *filename, struct usersupp *author, char *recipient, char *room, int type, int net_type, int format_type, char *fake_name)
838 /* temporary file name */
839 /* author's usersupp structure */
840 /* NULL if it's not mail */
841 /* room where it's going */
842 /* see MES_ types in header file */
843 /* local or remote type, see citadel.h */
844 /* format type (see citadel.h) */
852 /* don't confuse the poor folks if it's not routed mail. */
853 strcpy(dest_node,"");
855 /* if net_type is M_BINARY, split out the destination node */
856 if (net_type == M_BINARY) {
857 strcpy(dest_node,NODENAME);
858 for (a=0; a<strlen(recipient); ++a) {
859 if (recipient[a]=='@') {
861 strcpy(dest_node,&recipient[a+1]);
866 /* if net_type is M_INTERNET, set the dest node to 'internet' */
867 if (net_type == M_INTERNET) {
868 strcpy(dest_node,"internet");
871 while (isspace(recipient[strlen(recipient)-1]))
872 recipient[strlen(recipient)-1] = 0;
875 fp=fopen(filename,"w");
877 putc(type,fp); /* Normal or anonymous, see MES_ flags */
878 putc(format_type,fp); /* Formatted or unformatted */
879 fprintf(fp,"Pcit%ld%c",author->usernum,0); /* path */
880 fprintf(fp,"T%ld%c",now,0); /* date/time */
882 fprintf(fp,"A%s%c",fake_name,0);
884 fprintf(fp,"A%s%c",author->fullname,0); /* author */
885 fprintf(fp,"O%s%c",CC->quickroom.QRname,0); /* room */
886 fprintf(fp,"N%s%c",NODENAME,0); /* nodename */
887 fprintf(fp,"H%s%c",HUMANNODE,0); /* human nodename */
889 if (recipient[0]!=0) fprintf(fp,"R%s%c",recipient,0);
890 if (dest_node[0]!=0) fprintf(fp,"D%s%c",dest_node,0);
894 while (client_gets(buf), strcmp(buf,"000"))
896 fprintf(fp,"%s\n",buf);
898 syslog(LOG_INFO, "Closing message");
908 * message entry - mode 0 (normal) <bc>
910 void cmd_ent0(char *entargs)
916 char newusername[256]; /* <bc> */
920 struct usersupp tempUS;
923 post = extract_int(entargs,0);
924 extract(recipient,entargs,1);
925 anon_flag = extract_int(entargs,2);
926 format_type = extract_int(entargs,3);
928 /* first check to make sure the request is valid. */
930 if (!(CC->logged_in)) {
931 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
934 if (CC->curr_rm < 0) {
935 cprintf("%d No room selected.\n",ERROR);
938 if ((CC->usersupp.axlevel<2)&&(CC->curr_rm!=1)) {
939 cprintf("%d Need to be validated to enter (except in Mail> to sysop)\n",
940 ERROR+HIGHER_ACCESS_REQUIRED);
943 if ((CC->usersupp.axlevel<4)&&(CC->quickroom.QRflags&QR_NETWORK)) {
944 cprintf("%d Need net privileges to enter here.\n",
945 ERROR+HIGHER_ACCESS_REQUIRED);
948 if ((CC->usersupp.axlevel<6)&&(CC->quickroom.QRflags&QR_READONLY)) {
949 cprintf("%d Sorry, this is a read-only room.\n",
950 ERROR+HIGHER_ACCESS_REQUIRED);
957 if (post==2) { /* <bc> */
958 if (CC->usersupp.axlevel<6)
960 cprintf("%d\nYou don't have sufficient permission to do an aide post.\n", ERROR+HIGHER_ACCESS_REQUIRED);
963 extract(newusername,entargs,4);
964 bzero(CC->fake_postname, 32);
965 strcpy(CC->fake_postname, newusername);
966 cprintf("%d Ok\n",OK);
970 CC->cs_flags |= CS_POSTING;
973 if (CC->curr_rm==1) {
974 if (CC->usersupp.axlevel>=2) {
975 strcpy(buf,recipient);
977 else strcpy(buf,"sysop");
978 lprintf(9, "aliasing...\n");
979 e=alias(buf); /* alias and mail type */
980 lprintf(9,"...type is %d\n", e);
981 if ((buf[0]==0) || (e==M_ERROR)) {
982 cprintf("%d Unknown address - cannot send message.\n",
986 if ((e!=M_LOCAL)&&(CC->usersupp.axlevel<4)) {
987 cprintf("%d Net privileges required for network mail.\n",
988 ERROR+HIGHER_ACCESS_REQUIRED);
991 if ((RESTRICT_INTERNET==1)&&(e==M_INTERNET)
992 &&((CC->usersupp.flags&US_INTERNET)==0)
993 &&(!CC->internal_pgm) ) {
994 cprintf("%d You don't have access to Internet mail.\n",
995 ERROR+HIGHER_ACCESS_REQUIRED);
998 if (!strucmp(buf,"sysop")) {
1002 if (e!=M_LOCAL) goto SKFALL; /* don't search local file */
1003 if (!strucmp(buf,CC->usersupp.fullname)) {
1004 cprintf("%d Can't send mail to yourself!\n",
1005 ERROR+NO_SUCH_USER);
1009 /* Check to make sure the user exists; also get the correct
1010 * upper/lower casing of the name.
1012 lprintf(9, "checking validity of %s\n", buf);
1013 a = getuser(&tempUS,buf);
1014 lprintf(9, "getuser() returned %d\n", a);
1016 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
1019 strcpy(buf,tempUS.fullname);
1022 SKFALL: b=MES_NORMAL;
1023 if (CC->quickroom.QRflags&QR_ANONONLY) b=MES_ANON;
1024 if (CC->quickroom.QRflags&QR_ANON2) {
1025 if (anon_flag==1) b=MES_AN2;
1027 if (CC->curr_rm!=1) buf[0]=0;
1029 /* If we're only checking the validity of the request, return
1030 * success without creating the message.
1033 cprintf("%d %s\n",OK,buf);
1037 cprintf("%d send message\n",SEND_LISTING);
1038 if (CC->fake_postname[0])
1039 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname);
1041 if (CC->fake_username[0])
1042 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username);
1044 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "");
1045 save_message(CC->temp,buf,mtsflag,e,1);
1046 CC->fake_postname[0]='\0';
1053 * message entry - mode 3 (raw)
1055 void cmd_ent3(char *entargs)
1060 struct usersupp tempUS;
1065 if (CC->internal_pgm == 0) {
1066 cprintf("%d This command is for internal programs only.\n",
1071 if (CC->curr_rm < 0) {
1072 cprintf("%d No room selected.\n",ERROR);
1076 if (CC->curr_rm == 1) { /* If we're in Mail, check the recipient */
1077 extract(recp, entargs, 1);
1078 lprintf(9, "aliasing...\n");
1079 e=alias(recp); /* alias and mail type */
1080 lprintf(9,"...type is %d\n", e);
1081 if ((buf[0]==0) || (e==M_ERROR)) {
1082 cprintf("%d Unknown address - cannot send message.\n",
1083 ERROR+NO_SUCH_USER);
1087 a = getuser(&tempUS,recp);
1089 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
1095 /* At this point, message has been approved. */
1096 if (extract_int(entargs, 0) == 0) {
1097 cprintf("%d OK to send\n", OK);
1101 /* open a temp file to hold the message */
1102 fp = fopen(CC->temp, "wb");
1104 cprintf("%d Cannot open %s: %s\n",
1105 ERROR + INTERNAL_ERROR,
1106 CC->temp, strerror(errno) );
1110 msglen = extract_long(entargs, 2);
1111 cprintf("%d %ld\n", SEND_BINARY, msglen);
1112 while(msglen > 0L) {
1113 bloklen = ((msglen >= 255L) ? 255 : msglen);
1114 client_read(buf, (int)bloklen );
1115 fwrite(buf, (int)bloklen, 1, fp);
1116 msglen = msglen - bloklen;
1120 save_message(CC->temp, recp, 0, e, 0);
1125 * Delete message from current room
1127 void cmd_dele(char *delstr)
1132 getuser(&CC->usersupp,CC->curr_user);
1133 if ((CC->usersupp.axlevel < 6)
1134 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1135 cprintf("%d Higher access required.\n",
1136 ERROR+HIGHER_ACCESS_REQUIRED);
1140 delnum = atol(delstr);
1141 if (CC->curr_rm==1) {
1142 cprintf("%d Can't delete mail.\n",ERROR);
1146 /* get room records, obtaining a lock... */
1147 lgetroom(&CC->quickroom,CC->curr_rm);
1148 get_fullroom(&CC->fullroom,CC->curr_rm);
1151 for (a=0; a<MSGSPERRM; ++a)
1152 if (CC->fullroom.FRnum[a]==delnum) {
1153 CC->fullroom.FRnum[a]=0L;
1157 sort_fullroom(&CC->fullroom);
1158 CC->quickroom.QRhighest = CC->fullroom.FRnum[MSGSPERRM-1];
1160 put_fullroom(&CC->fullroom,CC->curr_rm);
1161 lputroom(&CC->quickroom,CC->curr_rm);
1163 cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
1164 cprintf("%d Message deleted.\n",OK);
1166 else cprintf("%d No message %ld.\n",ERROR,delnum);
1171 * move a message to another room
1173 void cmd_move(char *args)
1179 struct quickroom qtemp;
1180 struct fullroom ftemp;
1183 num = extract_long(args,0);
1184 extract(targ,args,1);
1186 if (CC->curr_rm < 0) {
1187 cprintf("%d no room\n",ERROR);
1191 getuser(&CC->usersupp,CC->curr_user);
1192 if ((CC->usersupp.axlevel < 6)
1193 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1194 cprintf("%d Higher access required.\n",
1195 ERROR+HIGHER_ACCESS_REQUIRED);
1200 for (a=0; a<MAXROOMS; ++a) {
1202 if (!strucmp(qtemp.QRname,targ)) {
1207 if (targ_slot < 0) {
1208 cprintf("%d '%s' does not exist.\n",ERROR,targ);
1212 /* yank the message out of the current room... */
1213 lgetroom(&CC->quickroom,CC->curr_rm);
1214 get_fullroom(&CC->fullroom,CC->curr_rm);
1217 for (a=0; a<MSGSPERRM; ++a) {
1218 if (CC->fullroom.FRnum[a] == num) {
1220 CC->fullroom.FRnum[a] = 0L;
1224 sort_fullroom(&CC->fullroom);
1225 put_fullroom(&CC->fullroom,CC->curr_rm);
1226 CC->quickroom.QRhighest = CC->fullroom.FRnum[MSGSPERRM-1];
1228 lputroom(&CC->quickroom,CC->curr_rm);
1230 cprintf("%d msg %ld does not exist.\n",ERROR,num);
1234 lgetroom(&qtemp,targ_slot);
1235 get_fullroom(&ftemp,targ_slot);
1236 if (CC->fullroom.FRnum[0] != 0L) {
1237 cdb_delete(CDB_MSGMAIN, &CC->fullroom.FRnum[0], sizeof(long));
1239 for (a=0; a<MSGSPERRM-1; ++a) {
1240 ftemp.FRnum[a]=ftemp.FRnum[a+1];
1242 ftemp.FRnum[MSGSPERRM-1] = num;
1243 sort_fullroom(&ftemp);
1244 qtemp.QRhighest = ftemp.FRnum[MSGSPERRM-1];
1245 put_fullroom(&ftemp,targ_slot);
1246 lputroom(&qtemp,targ_slot);
1247 cprintf("%d ok\n",OK);