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 */
601 char *message_in_memory;
604 fp = fopen(filename, "rb");
606 /* Measure the message */
607 lprintf(9, "Measuring the message\n");
608 fseek(fp, 0L, SEEK_END);
611 /* Now read it into memory */
612 lprintf(9, "Allocating %ld bytes\n", templen);
613 message_in_memory = (char *) malloc(templen);
614 if (message_in_memory == NULL) {
615 lprintf(2, "Can't allocate memory to save message!\n");
617 retbuf->smnumber = 0L;
622 lprintf(9, "Reading it into memory\n");
623 fseek(fp, 0L, SEEK_SET);
624 fread(message_in_memory, templen, 1, fp);
627 /* Get a new message number */
628 newmsgid = get_new_message_number();
630 /* Write our little bundle of joy into the message base */
632 lprintf(9, "Storing message %ld\n", newmsgid);
633 begin_critical_section(S_MSGMAIN);
634 if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
635 message_in_memory, templen) < 0 ) {
636 lprintf(2, "Can't store message\n");
637 retbuf->smnumber = 0L;
641 end_critical_section(S_MSGMAIN);
642 free(message_in_memory);
645 /* Finally, return the pointers */
646 retbuf->smnumber = newmsgid;
647 retbuf->smpos= 1L; /* FIX we really won't be needing this */
655 void loadtroom(void) {
656 struct quickroom qrbuf;
660 /* first try to locate the twit room */
661 for (a=0; a<MAXROOMS; ++a) {
663 if (!strucmp(qrbuf.QRname,config.c_twitroom)) {
669 /* if not found, try to create it - put it in the last slot */
670 twitroom = get_free_room_slot(-1);
672 newflags = create_room(twitroom,config.c_twitroom,0,"",0);
676 /* as a last resort, point to Aide> */
682 * this is a simple file copy routine.
684 void copy_file(char *from, char *to)
690 if (ffp==NULL) return;
696 while (a=getc(ffp), a>=0) {
707 * message base operation to save a message and install its pointers
709 void save_message(char *mtmp, /* file containing proper message */
710 char *rec, /* Recipient (if mail) */
711 char mtsflag, /* 0 for normal, 1 to force Aide> room */
712 int mailtype, /* local or remote type, see citadel.h */
713 int generate_id) /* set to 1 to generate an 'I' field */
716 struct usersupp tempUS;
718 struct smreturn smreturn;
721 send_message(mtmp,&smreturn,generate_id);
724 /* if the user is a twit, move to the twit room for posting */
725 if (TWITDETECT) if (CC->usersupp.axlevel==2) {
726 if (twitroom<0) loadtroom();
728 CC->curr_rm=twitroom;
731 /* and if this message is destined for Aide> then go there */
737 /* this call to usergoto() changes rooms if necessary. It also
738 causes the latest fullroom structure to be read into memory */
739 usergoto(CC->curr_rm,0);
741 /* Store the message pointer, but NOT for sent mail! */
742 if (CC->curr_rm != 1) {
744 /* read in the quickroom record, obtaining a lock... */
745 lgetroom(&CC->quickroom,CC->curr_rm);
746 get_fullroom(&CC->fullroom,CC->curr_rm);
748 /* Delete the oldest message if there is one */
749 if (CC->fullroom.FRnum[0] != 0L) {
750 cdb_delete(CDB_MSGMAIN,
751 &CC->fullroom.FRnum[0], sizeof(long));
755 for (a=0; a<(MSGSPERRM-1); ++a) {
756 CC->fullroom.FRnum[a]=CC->fullroom.FRnum[a+1];
759 /* ...and add the new message */
760 CC->fullroom.FRnum[MSGSPERRM-1]=smreturn.smnumber;
762 /* Write it back to disk. */
763 put_fullroom(&CC->fullroom,CC->curr_rm);
765 /* update quickroom */
766 CC->quickroom.QRhighest=CC->fullroom.FRnum[MSGSPERRM-1];
767 lputroom(&CC->quickroom,CC->curr_rm);
770 /* Bump this user's messages posted counter. Also, if the user is a
771 twit, give them access to the twit room. */
772 lgetuser(&CC->usersupp,CC->curr_user);
773 CC->usersupp.posted = CC->usersupp.posted + 1;
774 if (CC->curr_rm==twitroom) CC->usersupp.generation[twitroom]=CC->quickroom.QRgen;
775 lputuser(&CC->usersupp,CC->curr_user);
777 /* if mail, there's still more to do, if not, skip it */
778 if ((CC->curr_rm!=1)||(mtsflag)) goto ENTFIN;
780 /* network mail - send a copy to the network program */
781 if (mailtype!=M_LOCAL) {
782 sprintf(aaa,"./network/spoolin/nm.%d",getpid());
784 system("exec nohup ./netproc >/dev/null 2>&1 &");
787 /* local mail - put a copy in the recipient's mailbox */
788 if (mailtype==M_LOCAL) {
789 if (lgetuser(&tempUS,rec)==0) {
790 if (tempUS.mailnum[0] != 0L) {
791 cdb_delete(CDB_MSGMAIN, &tempUS.mailnum[0],
794 for (e=0; e<(MAILSLOTS-1); ++e) {
795 tempUS.mailnum[e]=tempUS.mailnum[e+1];
797 tempUS.mailnum[MAILSLOTS-1]=smreturn.smnumber;
798 lputuser(&tempUS,rec);
802 /* if we've posted in a room other than the current room, then we
803 have to now go back to the current room... */
804 ENTFIN: if (hold_rm!=(-1)) {
807 unlink(mtmp); /* delete the temporary file */
812 * generate an administrative message and post it in the Aide> room
814 void aide_message(char *text)
820 fp=fopen(CC->temp,"wb");
821 fprintf(fp,"%c%c%c",255,MES_NORMAL,0);
822 fprintf(fp,"Psysop%c",0);
823 fprintf(fp,"T%ld%c",now,0);
824 fprintf(fp,"ACitadel%c",0);
825 fprintf(fp,"OAide%c",0);
826 fprintf(fp,"N%s%c",NODENAME,0);
827 fprintf(fp,"M%s\n%c",text,0);
829 save_message(CC->temp,"",1,M_LOCAL,1);
830 syslog(LOG_NOTICE,text);
836 * build a binary message to be saved on disk
838 void make_message(char *filename, struct usersupp *author, char *recipient, char *room, int type, int net_type, int format_type, char *fake_name)
839 /* temporary file name */
840 /* author's usersupp structure */
841 /* NULL if it's not mail */
842 /* room where it's going */
843 /* see MES_ types in header file */
844 /* local or remote type, see citadel.h */
845 /* format type (see citadel.h) */
853 /* don't confuse the poor folks if it's not routed mail. */
854 strcpy(dest_node,"");
856 /* if net_type is M_BINARY, split out the destination node */
857 if (net_type == M_BINARY) {
858 strcpy(dest_node,NODENAME);
859 for (a=0; a<strlen(recipient); ++a) {
860 if (recipient[a]=='@') {
862 strcpy(dest_node,&recipient[a+1]);
867 /* if net_type is M_INTERNET, set the dest node to 'internet' */
868 if (net_type == M_INTERNET) {
869 strcpy(dest_node,"internet");
872 while (isspace(recipient[strlen(recipient)-1]))
873 recipient[strlen(recipient)-1] = 0;
876 fp=fopen(filename,"w");
878 putc(type,fp); /* Normal or anonymous, see MES_ flags */
879 putc(format_type,fp); /* Formatted or unformatted */
880 fprintf(fp,"Pcit%ld%c",author->usernum,0); /* path */
881 fprintf(fp,"T%ld%c",now,0); /* date/time */
883 fprintf(fp,"A%s%c",fake_name,0);
885 fprintf(fp,"A%s%c",author->fullname,0); /* author */
886 fprintf(fp,"O%s%c",CC->quickroom.QRname,0); /* room */
887 fprintf(fp,"N%s%c",NODENAME,0); /* nodename */
888 fprintf(fp,"H%s%c",HUMANNODE,0); /* human nodename */
890 if (recipient[0]!=0) fprintf(fp,"R%s%c",recipient,0);
891 if (dest_node[0]!=0) fprintf(fp,"D%s%c",dest_node,0);
895 while (client_gets(buf), strcmp(buf,"000"))
897 fprintf(fp,"%s\n",buf);
899 syslog(LOG_INFO, "Closing message");
909 * message entry - mode 0 (normal) <bc>
911 void cmd_ent0(char *entargs)
917 char newusername[256]; /* <bc> */
921 struct usersupp tempUS;
924 post = extract_int(entargs,0);
925 extract(recipient,entargs,1);
926 anon_flag = extract_int(entargs,2);
927 format_type = extract_int(entargs,3);
929 /* first check to make sure the request is valid. */
931 if (!(CC->logged_in)) {
932 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
935 if (CC->curr_rm < 0) {
936 cprintf("%d No room selected.\n",ERROR);
939 if ((CC->usersupp.axlevel<2)&&(CC->curr_rm!=1)) {
940 cprintf("%d Need to be validated to enter (except in Mail> to sysop)\n",
941 ERROR+HIGHER_ACCESS_REQUIRED);
944 if ((CC->usersupp.axlevel<4)&&(CC->quickroom.QRflags&QR_NETWORK)) {
945 cprintf("%d Need net privileges to enter here.\n",
946 ERROR+HIGHER_ACCESS_REQUIRED);
949 if ((CC->usersupp.axlevel<6)&&(CC->quickroom.QRflags&QR_READONLY)) {
950 cprintf("%d Sorry, this is a read-only room.\n",
951 ERROR+HIGHER_ACCESS_REQUIRED);
958 if (post==2) { /* <bc> */
959 if (CC->usersupp.axlevel<6)
961 cprintf("%d\nYou don't have sufficient permission to do an aide post.\n", ERROR+HIGHER_ACCESS_REQUIRED);
964 extract(newusername,entargs,4);
965 bzero(CC->fake_postname, 32);
966 strcpy(CC->fake_postname, newusername);
967 cprintf("%d Ok\n",OK);
971 CC->cs_flags |= CS_POSTING;
974 if (CC->curr_rm==1) {
975 if (CC->usersupp.axlevel>=2) {
976 strcpy(buf,recipient);
978 else strcpy(buf,"sysop");
979 lprintf(9, "aliasing...\n");
980 e=alias(buf); /* alias and mail type */
981 lprintf(9,"...type is %d\n", e);
982 if ((buf[0]==0) || (e==M_ERROR)) {
983 cprintf("%d Unknown address - cannot send message.\n",
987 if ((e!=M_LOCAL)&&(CC->usersupp.axlevel<4)) {
988 cprintf("%d Net privileges required for network mail.\n",
989 ERROR+HIGHER_ACCESS_REQUIRED);
992 if ((RESTRICT_INTERNET==1)&&(e==M_INTERNET)
993 &&((CC->usersupp.flags&US_INTERNET)==0)
994 &&(!CC->internal_pgm) ) {
995 cprintf("%d You don't have access to Internet mail.\n",
996 ERROR+HIGHER_ACCESS_REQUIRED);
999 if (!strucmp(buf,"sysop")) {
1003 if (e!=M_LOCAL) goto SKFALL; /* don't search local file */
1004 if (!strucmp(buf,CC->usersupp.fullname)) {
1005 cprintf("%d Can't send mail to yourself!\n",
1006 ERROR+NO_SUCH_USER);
1010 /* Check to make sure the user exists; also get the correct
1011 * upper/lower casing of the name.
1013 lprintf(9, "checking validity of %s\n", buf);
1014 a = getuser(&tempUS,buf);
1015 lprintf(9, "getuser() returned %d\n", a);
1017 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
1020 strcpy(buf,tempUS.fullname);
1023 SKFALL: b=MES_NORMAL;
1024 if (CC->quickroom.QRflags&QR_ANONONLY) b=MES_ANON;
1025 if (CC->quickroom.QRflags&QR_ANON2) {
1026 if (anon_flag==1) b=MES_AN2;
1028 if (CC->curr_rm!=1) buf[0]=0;
1030 /* If we're only checking the validity of the request, return
1031 * success without creating the message.
1034 cprintf("%d %s\n",OK,buf);
1038 cprintf("%d send message\n",SEND_LISTING);
1039 if (CC->fake_postname[0])
1040 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname);
1042 if (CC->fake_username[0])
1043 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username);
1045 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "");
1046 save_message(CC->temp,buf,mtsflag,e,1);
1047 CC->fake_postname[0]='\0';
1054 * message entry - mode 3 (raw)
1056 void cmd_ent3(char *entargs)
1061 struct usersupp tempUS;
1066 if (CC->internal_pgm == 0) {
1067 cprintf("%d This command is for internal programs only.\n",
1072 if (CC->curr_rm < 0) {
1073 cprintf("%d No room selected.\n",ERROR);
1077 if (CC->curr_rm == 1) { /* If we're in Mail, check the recipient */
1078 extract(recp, entargs, 1);
1079 lprintf(9, "aliasing...\n");
1080 e=alias(recp); /* alias and mail type */
1081 lprintf(9,"...type is %d\n", e);
1082 if ((buf[0]==0) || (e==M_ERROR)) {
1083 cprintf("%d Unknown address - cannot send message.\n",
1084 ERROR+NO_SUCH_USER);
1088 a = getuser(&tempUS,recp);
1090 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
1096 /* At this point, message has been approved. */
1097 if (extract_int(entargs, 0) == 0) {
1098 cprintf("%d OK to send\n", OK);
1102 /* open a temp file to hold the message */
1103 fp = fopen(CC->temp, "wb");
1105 cprintf("%d Cannot open %s: %s\n",
1106 ERROR + INTERNAL_ERROR,
1107 CC->temp, strerror(errno) );
1111 msglen = extract_long(entargs, 2);
1112 cprintf("%d %ld\n", SEND_BINARY, msglen);
1113 while(msglen > 0L) {
1114 bloklen = ((msglen >= 255L) ? 255 : msglen);
1115 client_read(buf, (int)bloklen );
1116 fwrite(buf, (int)bloklen, 1, fp);
1117 msglen = msglen - bloklen;
1121 save_message(CC->temp, recp, 0, e, 0);
1126 * Delete message from current room
1128 void cmd_dele(char *delstr)
1133 getuser(&CC->usersupp,CC->curr_user);
1134 if ((CC->usersupp.axlevel < 6)
1135 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1136 cprintf("%d Higher access required.\n",
1137 ERROR+HIGHER_ACCESS_REQUIRED);
1141 delnum = atol(delstr);
1142 if (CC->curr_rm==1) {
1143 cprintf("%d Can't delete mail.\n",ERROR);
1147 /* get room records, obtaining a lock... */
1148 lgetroom(&CC->quickroom,CC->curr_rm);
1149 get_fullroom(&CC->fullroom,CC->curr_rm);
1152 for (a=0; a<MSGSPERRM; ++a)
1153 if (CC->fullroom.FRnum[a]==delnum) {
1154 CC->fullroom.FRnum[a]=0L;
1158 sort_fullroom(&CC->fullroom);
1159 CC->quickroom.QRhighest = CC->fullroom.FRnum[MSGSPERRM-1];
1161 put_fullroom(&CC->fullroom,CC->curr_rm);
1162 lputroom(&CC->quickroom,CC->curr_rm);
1164 cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
1165 cprintf("%d Message deleted.\n",OK);
1167 else cprintf("%d No message %ld.\n",ERROR,delnum);
1172 * move a message to another room
1174 void cmd_move(char *args)
1180 struct quickroom qtemp;
1181 struct fullroom ftemp;
1184 num = extract_long(args,0);
1185 extract(targ,args,1);
1187 if (CC->curr_rm < 0) {
1188 cprintf("%d no room\n",ERROR);
1192 getuser(&CC->usersupp,CC->curr_user);
1193 if ((CC->usersupp.axlevel < 6)
1194 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1195 cprintf("%d Higher access required.\n",
1196 ERROR+HIGHER_ACCESS_REQUIRED);
1201 for (a=0; a<MAXROOMS; ++a) {
1203 if (!strucmp(qtemp.QRname,targ)) {
1208 if (targ_slot < 0) {
1209 cprintf("%d '%s' does not exist.\n",ERROR,targ);
1213 /* yank the message out of the current room... */
1214 lgetroom(&CC->quickroom,CC->curr_rm);
1215 get_fullroom(&CC->fullroom,CC->curr_rm);
1218 for (a=0; a<MSGSPERRM; ++a) {
1219 if (CC->fullroom.FRnum[a] == num) {
1221 CC->fullroom.FRnum[a] = 0L;
1225 sort_fullroom(&CC->fullroom);
1226 put_fullroom(&CC->fullroom,CC->curr_rm);
1227 CC->quickroom.QRhighest = CC->fullroom.FRnum[MSGSPERRM-1];
1229 lputroom(&CC->quickroom,CC->curr_rm);
1231 cprintf("%d msg %ld does not exist.\n",ERROR,num);
1235 lgetroom(&qtemp,targ_slot);
1236 get_fullroom(&ftemp,targ_slot);
1237 if (CC->fullroom.FRnum[0] != 0L) {
1238 cdb_delete(CDB_MSGMAIN, &CC->fullroom.FRnum[0], sizeof(long));
1240 for (a=0; a<MSGSPERRM-1; ++a) {
1241 ftemp.FRnum[a]=ftemp.FRnum[a+1];
1243 ftemp.FRnum[MSGSPERRM-1] = num;
1244 sort_fullroom(&ftemp);
1245 qtemp.QRhighest = ftemp.FRnum[MSGSPERRM-1];
1246 put_fullroom(&ftemp,targ_slot);
1247 lputroom(&qtemp,targ_slot);
1248 cprintf("%d ok\n",OK);