23 extern struct config config;
28 * Aliasing for network mail.
29 * (Error messages have been commented out, because this is a server.)
31 int alias(char *name) /* process alias and routing info for mail */
35 char aaa[300],bbb[300];
37 fp=fopen("network/mail.aliases","r");
38 if (fp==NULL) fp=fopen("/dev/null","r");
39 if (fp==NULL) return(M_ERROR);
40 GNA: strcpy(aaa,""); strcpy(bbb,"");
63 if (strucmp(name,aaa)) goto GNA;
66 /* cprintf("*** Mail is being forwarded to %s\n",name); */
68 DETYPE: /* determine local or remote type, see citadel.h */
69 for (a=0; a<strlen(name); ++a) if (name[a]=='!') return(M_INTERNET);
70 for (a=0; a<strlen(name); ++a)
72 for (b=a; b<strlen(name); ++b)
73 if (name[b]=='.') return(M_INTERNET);
74 b=0; for (a=0; a<strlen(name); ++a) if (name[a]=='@') ++b;
76 /* cprintf("Too many @'s in address\n"); */
80 for (a=0; a<strlen(name); ++a)
81 if (name[a]=='@') strcpy(bbb,&name[a+1]);
82 while (bbb[0]==32) strcpy(bbb,&bbb[1]);
83 fp = fopen("network/mail.sysinfo","r");
84 if (fp==NULL) return(M_ERROR);
87 } while ((a>=0)&&(strucmp(aaa,bbb)));
89 if (!strncmp(aaa,"use ",4)) {
95 if (!strncmp(aaa,"uum",3)) {
97 for (a=0; a<strlen(bbb); ++a) {
98 if (bbb[a]=='@') bbb[a]=0;
99 if (bbb[a]==' ') bbb[a]='_';
101 while(bbb[strlen(bbb)-1]=='_') bbb[strlen(bbb)-1]=0;
102 sprintf(name,&aaa[4],bbb);
105 if (!strncmp(aaa,"bin",3)) {
106 strcpy(aaa,name); strcpy(bbb,name);
107 while (aaa[strlen(aaa)-1]!='@') aaa[strlen(aaa)-1]=0;
108 aaa[strlen(aaa)-1]=0;
109 while (aaa[strlen(aaa)-1]==' ') aaa[strlen(aaa)-1]=0;
110 while (bbb[0]!='@') strcpy(bbb,&bbb[1]);
112 while (bbb[0]==' ') strcpy(bbb,&bbb[1]);
113 sprintf(name,"%s @%s",aaa,bbb);
125 fp=fopen("citadel.control","r");
126 fread((char *)&CitControl,sizeof(struct CitControl),1,fp);
131 * cmd_msgs() - get list of message #'s in this room
133 void cmd_msgs(char *cmdbuf)
141 extract(which,cmdbuf,0);
145 if (!struncmp(which,"OLD",3)) mode = MSGS_OLD;
146 if (!struncmp(which,"NEW",3)) mode = MSGS_NEW;
147 if (!struncmp(which,"FIRST",5)) {
149 cm_howmany = extract_int(cmdbuf,1);
151 if (!struncmp(which,"LAST",4)) {
153 cm_howmany = extract_int(cmdbuf,1);
155 if (!struncmp(which,"GT",2)) {
157 cm_gt = extract_long(cmdbuf,1);
160 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
161 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
164 if (CC->curr_rm < 0) {
165 cprintf("%d no room\n",ERROR);
169 get_msglist(CC->curr_rm);
170 getuser(&CC->usersupp,CC->curr_user);
171 cprintf("%d %d messages...\n",LISTING_FOLLOWS, CC->num_msgs);
172 if (CC->num_msgs != 0) {
173 for (a=0; a<(CC->num_msgs); ++a)
174 if ((MessageFromList(a) >=0)
178 || ((mode==MSGS_OLD) && (MessageFromList(a) <= CC->usersupp.lastseen[CC->curr_rm]))
179 || ((mode==MSGS_NEW) && (MessageFromList(a) > CC->usersupp.lastseen[CC->curr_rm]))
180 || ((mode==MSGS_NEW) && (MessageFromList(a) >= CC->usersupp.lastseen[CC->curr_rm])
181 && (CC->usersupp.flags & US_LASTOLD))
182 || ((mode==MSGS_LAST)&& (a>=(CC->num_msgs-cm_howmany)))
183 || ((mode==MSGS_FIRST)&&(a<cm_howmany))
184 || ((mode==MSGS_GT) && (MessageFromList(a) > cm_gt))
188 cprintf("%ld\n", MessageFromList(a));
197 * help_subst() - support routine for help file viewer
199 void help_subst(char *strbuf, char *source, char *dest)
204 while (p=pattern2(strbuf,source), (p>=0)) {
205 strcpy(workbuf,&strbuf[p+strlen(source)]);
206 strcpy(&strbuf[p],dest);
207 strcat(strbuf,workbuf);
212 void do_help_subst(char *buffer)
216 help_subst(buffer,"^nodename",config.c_nodename);
217 help_subst(buffer,"^humannode",config.c_humannode);
218 help_subst(buffer,"^fqdn",config.c_fqdn);
219 help_subst(buffer,"^username",CC->usersupp.fullname);
220 sprintf(buf2,"%ld",CC->usersupp.usernum);
221 help_subst(buffer,"^usernum",buf2);
222 help_subst(buffer,"^sysadm",config.c_sysadm);
223 help_subst(buffer,"^variantname",CITADEL);
224 sprintf(buf2,"%d",config.c_maxsessions);
225 help_subst(buffer,"^maxsessions",buf2);
231 * memfmout() - Citadel text formatter and paginator.
232 * Although the original purpose of this routine was to format
233 * text to the reader's screen width, all we're really using it
234 * for here is to format text out to 80 columns before sending it
235 * to the client. The client software may reformat it again.
237 void memfmout(int width, char *mptr, char subst)
238 /* screen width to use */
239 /* where are we going to get our text from? */
240 /* nonzero if we should use hypertext mode */
247 strcpy(aaa,""); old=255;
249 c=1; /* c is the current pos */
252 while (ch=*mptr, ((ch!=0) && (strlen(buffer)<126) )) {
254 buffer[strlen(buffer)+1] = 0;
255 buffer[strlen(buffer)] = ch;
258 if (buffer[0]=='^') do_help_subst(buffer);
260 buffer[strlen(buffer)+1] = 0;
262 strcpy(buffer,&buffer[1]);
269 if (ch<=0) goto FMTEND;
271 if ( ((ch==13)||(ch==10)) && (old!=13) && (old!=10) ) ch=32;
272 if ( ((old==13)||(old==10)) && (isspace(real)) ) {
276 if (ch>126) goto FMTA;
279 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
280 { cprintf("\n%s",aaa); c=strlen(aaa); aaa[0]=0;
282 b=strlen(aaa); aaa[b]=ch; aaa[b+1]=0; }
284 if ((strlen(aaa)+c)>(width-5)) {
288 cprintf("%s ",aaa); ++c; c=c+strlen(aaa);
292 if ((ch==13)||(ch==10)) {
300 FMTEND: cprintf("\n");
305 * get a message off disk.
308 void output_message(char *msgid, int mode, int headers_only)
314 CIT_UBYTE format_type,anon_flag;
319 struct cdbdata *dmsgtext;
322 /* buffers needed for RFC822 translation */
331 msg_num = atol(msgid);
334 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
335 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
338 if (CC->curr_rm < 0) {
339 cprintf("%d No room selected.\n",ERROR);
343 /* We used to need to check in the current room's message list
344 * to determine where the message's disk position. We no longer need
345 * to do this, but we do it anyway as a security measure, in order to
346 * prevent rogue clients from reading messages not in the current room.
350 if (CC->num_msgs > 0) {
351 for (a=0; a<CC->num_msgs; ++a) {
352 if (MessageFromList(a) == msg_num) {
359 cprintf("%d Message %ld is not in this room.\n",
365 dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
367 if (dmsgtext == NULL) {
368 cprintf("%d Can't find message %ld\n", ERROR+INTERNAL_ERROR);
372 msg_len = (long) dmsgtext->len;
373 mptr = dmsgtext->ptr;
374 lprintf(9, "Returned message length is %ld\n", msg_len);
376 /* this loop spews out the whole message if we're doing raw format */
377 if (mode == MT_RAW) {
378 cprintf("%d %ld\n", BINARY_FOLLOWS, msg_len);
379 client_write(dmsgtext->ptr, (int) msg_len);
384 /* Otherwise, we'll start parsing it field by field... */
387 cprintf("%d Illegal message format on disk\n",
388 ERROR+INTERNAL_ERROR);
394 format_type = *mptr++;
396 /* now for the user-mode message reading loops */
397 cprintf("%d Message %ld:\n",LISTING_FOLLOWS,msg_num);
399 if (mode == MT_CITADEL) cprintf("type=%d\n",format_type);
401 if ( (anon_flag == MES_ANON) && (mode == MT_CITADEL) ) {
402 cprintf("nhdr=yes\n");
405 /* begin header processing loop for Citadel message format */
407 if (mode == MT_CITADEL) while(ch = *mptr++, (ch!='M' && ch!=0)) {
410 buf[strlen(buf)+1] = 0;
412 buf[strlen(buf)] = rch;
416 if (anon_flag==MES_ANON) cprintf("from=****");
417 else if (anon_flag==MES_AN2) cprintf("from=anonymous");
418 else cprintf("from=%s",buf);
419 if ((is_room_aide()) && ((anon_flag == MES_ANON)
420 || (anon_flag == MES_AN2)))
421 cprintf(" [%s]",buf);
424 else if (ch=='P') cprintf("path=%s\n",buf);
425 else if (ch=='U') cprintf("subj=%s\n",buf);
426 else if (ch=='I') cprintf("msgn=%s\n",buf);
427 else if (ch=='H') cprintf("hnod=%s\n",buf);
428 else if (ch=='O') cprintf("room=%s\n",buf);
429 else if (ch=='N') cprintf("node=%s\n",buf);
430 else if (ch=='R') cprintf("rcpt=%s\n",buf);
431 else if (ch=='T') cprintf("time=%s\n",buf);
432 /* else cprintf("fld%c=%s\n",ch,buf); */
435 /* begin header processing loop for RFC822 transfer format */
439 strcpy(snode, NODENAME);
440 strcpy(lnode, HUMANNODE);
441 if (mode == MT_RFC822) while(ch = *mptr++, (ch!='M' && ch!=0)) {
444 buf[strlen(buf)+1] = 0;
446 buf[strlen(buf)] = rch;
449 if (ch=='A') strcpy(luser, buf);
451 cprintf("Path: %s\n",buf);
452 for (a=0; a<strlen(buf); ++a) {
454 strcpy(buf,&buf[a+1]);
460 else if (ch=='U') cprintf("Subject: %s\n",buf);
461 else if (ch=='I') strcpy(mid, buf);
462 else if (ch=='H') strcpy(lnode, buf);
463 else if (ch=='O') cprintf("X-Citadel-Room: %s\n",buf);
464 else if (ch=='N') strcpy(snode, buf);
465 else if (ch=='R') cprintf("To: %s\n",buf);
468 cprintf("Date: %s", asctime(localtime(&xtime)));
472 if (mode == MT_RFC822) {
473 if (!strucmp(snode, NODENAME)) {
476 cprintf("Message-ID: <%s@%s>\n", mid, snode);
477 cprintf("From: %s@%s (%s)\n",
478 suser, snode, luser);
479 cprintf("Organization: %s\n", lnode);
482 /* end header processing loop ... at this point, we're in the text */
485 cprintf("text\n*** ?Message truncated\n000\n");
492 /* give 'em a length */
494 while(och=ch, ch = *mptr++, ch>0) {
497 cprintf("mlen=%ld\n", msg_len);
504 /* signify start of msg text */
505 if (mode == MT_CITADEL) cprintf("text\n");
506 if (mode == MT_RFC822) cprintf("\n");
508 /* If the format type on disk is 1 (fixed-format), then we want
509 * everything to be output completely literally ... regardless of
510 * what message transfer format is in use.
512 if (format_type == 1) {
515 while(och=ch, ch = *mptr++, ch>0) {
516 if (ch == 13) ch = 10;
518 if ((ch!=10)||(och!=10)) {
524 /* cprintf("%c", ch); */
528 if (len!=0) cprintf("%c", 10);
530 /* If the message on disk is format 0 (Citadel vari-format), we
531 * output using the formatter at 80 columns. This is the final output
532 * form if the transfer format is RFC822, but if the transfer format
533 * is Citadel proprietary, it'll still work, because the indentation
534 * for new paragraphs is correct and the client will reformat the
535 * message to the reader's screen width.
537 if (format_type == 0) {
549 * display a message (mode 0 - Citadel proprietary)
551 void cmd_msg0(char *cmdbuf)
554 int headers_only = 0;
556 extract(msgid,cmdbuf,0);
557 headers_only = extract_int(cmdbuf,1);
559 output_message(msgid,MT_CITADEL,headers_only);
564 * display a message (mode 2 - RFC822)
566 void cmd_msg2(char *cmdbuf)
569 int headers_only = 0;
571 extract(msgid,cmdbuf,0);
572 headers_only = extract_int(cmdbuf,1);
574 output_message(msgid,MT_RFC822,headers_only);
578 * display a message (mode 3 - IGnet raw format - internal programs only)
580 void cmd_msg3(char *cmdbuf)
583 int headers_only = 0;
585 if (CC->internal_pgm == 0) {
586 cprintf("%d This command is for internal programs only.\n",
591 extract(msgid,cmdbuf,0);
592 headers_only = extract_int(cmdbuf,1);
594 output_message(msgid,MT_RAW,headers_only);
600 * Message base operation to send a message to the master file
601 * (returns new message number)
603 long send_message(char *message_in_memory, /* pointer to buffer */
604 size_t message_length, /* length of buffer */
605 int generate_id) { /* 1 to generate an I field */
609 /* Get a new message number */
610 newmsgid = get_new_message_number();
612 /* Write our little bundle of joy into the message base */
614 lprintf(9, "Storing message %ld\n", newmsgid);
615 begin_critical_section(S_MSGMAIN);
616 if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
617 message_in_memory, message_length) < 0 ) {
618 lprintf(2, "Can't store message\n");
619 end_critical_section(S_MSGMAIN);
622 end_critical_section(S_MSGMAIN);
624 /* Finally, return the pointers */
633 void loadtroom(void) {
634 struct quickroom qrbuf;
638 /* first try to locate the twit room */
639 for (a=0; a<MAXROOMS; ++a) {
641 if (!strucmp(qrbuf.QRname,config.c_twitroom)) {
647 /* if not found, try to create it - put it in the last slot */
648 twitroom = get_free_room_slot(-1);
650 newflags = create_room(twitroom,config.c_twitroom,0,"",0);
654 /* as a last resort, point to Aide> */
660 * this is a simple file copy routine.
662 void copy_file(char *from, char *to)
668 if (ffp==NULL) return;
674 while (a=getc(ffp), a>=0) {
685 * message base operation to save a message and install its pointers
687 void save_message(char *mtmp, /* file containing proper message */
688 char *rec, /* Recipient (if mail) */
689 char mtsflag, /* 0 for normal, 1 to force Aide> room */
690 int mailtype, /* local or remote type, see citadel.h */
691 int generate_id) /* set to 1 to generate an 'I' field */
693 struct usersupp tempUS;
696 struct cdbdata *cdbmb;
700 char *message_in_memory;
705 /* Measure the message */
706 lprintf(9, "Measuring the message\n");
707 stat(mtmp, &statbuf);
708 templen = statbuf.st_size;
710 /* Now read it into memory */
711 lprintf(9, "Allocating %ld bytes\n", templen);
712 message_in_memory = (char *) malloc(templen);
713 if (message_in_memory == NULL) {
714 lprintf(2, "Can't allocate memory to save message!\n");
718 lprintf(9, "Reading it into memory\n");
719 fp = fopen(mtmp, "rb");
720 fread(message_in_memory, templen, 1, fp);
723 newmsgid = send_message(message_in_memory, templen, generate_id);
724 free(message_in_memory);
725 if (newmsgid <= 0L) return;
728 /* If the user is a twit, move to the twit room for posting... */
729 if (TWITDETECT) if (CC->usersupp.axlevel==2) {
730 if (twitroom<0) loadtroom();
732 CC->curr_rm=twitroom;
735 /* ...or if this message is destined for Aide> then go there. */
741 /* This call to usergoto() changes rooms if necessary. It also
742 * causes the latest message list to be read into memory.
744 usergoto(CC->curr_rm,0);
746 /* Store the message pointer, but NOT for sent mail! */
747 if (CC->curr_rm != 1) {
749 /* read in the quickroom record, obtaining a lock... */
750 lgetroom(&CC->quickroom,CC->curr_rm);
751 get_msglist(CC->curr_rm);
753 /* FIX here's where we have to to message expiry!! */
755 /* Now add the new message */
756 CC->num_msgs = CC->num_msgs + 1;
757 CC->msglist = realloc(CC->msglist,
758 ((CC->num_msgs) * sizeof(long)) );
759 if (CC->msglist == NULL) {
760 lprintf(3, "ERROR can't realloc message list!\n");
762 SetMessageInList(CC->num_msgs - 1, newmsgid);
764 /* Write it back to disk. */
765 put_msglist(CC->curr_rm);
767 /* update quickroom */
768 CC->quickroom.QRhighest = newmsgid;
769 lputroom(&CC->quickroom,CC->curr_rm);
772 /* Bump this user's messages posted counter. Also, if the user is a
773 * twit, give them access to the twit room.
775 lgetuser(&CC->usersupp,CC->curr_user);
776 CC->usersupp.posted = CC->usersupp.posted + 1;
777 if (CC->curr_rm==twitroom) {
778 CC->usersupp.generation[twitroom] = CC->quickroom.QRgen;
780 lputuser(&CC->usersupp, CC->curr_user);
782 /* If mail, there's still more to do, if not, skip it. */
783 if ((CC->curr_rm!=1)||(mtsflag)) goto ENTFIN;
785 /* Network mail - send a copy to the network program. */
786 if (mailtype!=M_LOCAL) {
787 sprintf(aaa,"./network/spoolin/nm.%d",getpid());
789 system("exec nohup ./netproc >/dev/null 2>&1 &");
792 /* Local mail - put a copy in the recipient's mailbox. */
793 /* FIX here's where we have to handle expiry, stuffed boxes, etc. */
794 if (mailtype == M_LOCAL) {
795 if (lgetuser(&tempUS,rec)==0) {
797 cdbmb = cdb_fetch(CDB_MAILBOXES,
798 &tempUS.usernum, sizeof(long));
800 memcpy(dmailbox, cdbmb->ptr, cdbmb->len);
801 dnum_mails = cdbmb->len / sizeof(long);
810 if (dmailbox == NULL) {
811 dmailbox = malloc(sizeof(long) * dnum_mails);
814 dmailbox = realloc(dmailbox,
815 sizeof(long) * dnum_mails);
818 dmailbox[dnum_mails - 1] = newmsgid;
819 cdb_store(CDB_MAILBOXES, &tempUS.usernum, sizeof(long),
820 dmailbox, (dnum_mails * sizeof(long)) );
821 lputuser(&tempUS,rec);
826 /* If we've posted in a room other than the current room, then we
827 * have to now go back to the current room...
829 ENTFIN: if (hold_rm!=(-1)) {
832 unlink(mtmp); /* delete the temporary file */
837 * Generate an administrative message and post it in the Aide> room.
839 void aide_message(char *text)
845 fp=fopen(CC->temp,"wb");
846 fprintf(fp,"%c%c%c",255,MES_NORMAL,0);
847 fprintf(fp,"Psysop%c",0);
848 fprintf(fp,"T%ld%c",now,0);
849 fprintf(fp,"ACitadel%c",0);
850 fprintf(fp,"OAide%c",0);
851 fprintf(fp,"N%s%c",NODENAME,0);
852 fprintf(fp,"M%s\n%c",text,0);
854 save_message(CC->temp,"",1,M_LOCAL,1);
855 syslog(LOG_NOTICE,text);
861 * Build a binary message to be saved on disk.
863 void make_message(char *filename, struct usersupp *author, char *recipient, char *room, int type, int net_type, int format_type, char *fake_name)
864 /* temporary file name */
865 /* author's usersupp structure */
866 /* NULL if it's not mail */
867 /* room where it's going */
868 /* see MES_ types in header file */
869 /* local or remote type, see citadel.h */
870 /* format type (see citadel.h) */
878 /* Don't confuse the poor folks if it's not routed mail. */
879 strcpy(dest_node, "");
881 /* If net_type is M_BINARY, split out the destination node. */
882 if (net_type == M_BINARY) {
883 strcpy(dest_node,NODENAME);
884 for (a=0; a<strlen(recipient); ++a) {
885 if (recipient[a]=='@') {
887 strcpy(dest_node,&recipient[a+1]);
892 /* if net_type is M_INTERNET, set the dest node to 'internet' */
893 if (net_type == M_INTERNET) {
894 strcpy(dest_node,"internet");
897 while (isspace(recipient[strlen(recipient)-1]))
898 recipient[strlen(recipient)-1] = 0;
901 fp=fopen(filename,"w");
903 putc(type,fp); /* Normal or anonymous, see MES_ flags */
904 putc(format_type,fp); /* Formatted or unformatted */
905 fprintf(fp,"Pcit%ld%c",author->usernum,0); /* path */
906 fprintf(fp,"T%ld%c",now,0); /* date/time */
908 fprintf(fp,"A%s%c",fake_name,0);
910 fprintf(fp,"A%s%c",author->fullname,0); /* author */
911 fprintf(fp,"O%s%c",CC->quickroom.QRname,0); /* room */
912 fprintf(fp,"N%s%c",NODENAME,0); /* nodename */
913 fprintf(fp,"H%s%c",HUMANNODE,0); /* human nodename */
915 if (recipient[0]!=0) fprintf(fp,"R%s%c",recipient,0);
916 if (dest_node[0]!=0) fprintf(fp,"D%s%c",dest_node,0);
920 while (client_gets(buf), strcmp(buf,"000"))
922 fprintf(fp,"%s\n",buf);
924 syslog(LOG_INFO, "Closing message");
934 * message entry - mode 0 (normal) <bc>
936 void cmd_ent0(char *entargs)
942 char newusername[256]; /* <bc> */
946 struct usersupp tempUS;
949 post = extract_int(entargs,0);
950 extract(recipient,entargs,1);
951 anon_flag = extract_int(entargs,2);
952 format_type = extract_int(entargs,3);
954 /* first check to make sure the request is valid. */
956 if (!(CC->logged_in)) {
957 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
960 if (CC->curr_rm < 0) {
961 cprintf("%d No room selected.\n",ERROR);
964 if ((CC->usersupp.axlevel<2)&&(CC->curr_rm!=1)) {
965 cprintf("%d Need to be validated to enter (except in Mail> to sysop)\n",
966 ERROR+HIGHER_ACCESS_REQUIRED);
969 if ((CC->usersupp.axlevel<4)&&(CC->quickroom.QRflags&QR_NETWORK)) {
970 cprintf("%d Need net privileges to enter here.\n",
971 ERROR+HIGHER_ACCESS_REQUIRED);
974 if ((CC->usersupp.axlevel<6)&&(CC->quickroom.QRflags&QR_READONLY)) {
975 cprintf("%d Sorry, this is a read-only room.\n",
976 ERROR+HIGHER_ACCESS_REQUIRED);
983 if (post==2) { /* <bc> */
984 if (CC->usersupp.axlevel<6)
986 cprintf("%d\nYou don't have sufficient permission to do an aide post.\n", ERROR+HIGHER_ACCESS_REQUIRED);
989 extract(newusername,entargs,4);
990 bzero(CC->fake_postname, 32);
991 strcpy(CC->fake_postname, newusername);
992 cprintf("%d Ok\n",OK);
996 CC->cs_flags |= CS_POSTING;
999 if (CC->curr_rm==1) {
1000 if (CC->usersupp.axlevel>=2) {
1001 strcpy(buf,recipient);
1003 else strcpy(buf,"sysop");
1004 lprintf(9, "aliasing...\n");
1005 e=alias(buf); /* alias and mail type */
1006 lprintf(9,"...type is %d\n", e);
1007 if ((buf[0]==0) || (e==M_ERROR)) {
1008 cprintf("%d Unknown address - cannot send message.\n",
1009 ERROR+NO_SUCH_USER);
1012 if ((e!=M_LOCAL)&&(CC->usersupp.axlevel<4)) {
1013 cprintf("%d Net privileges required for network mail.\n",
1014 ERROR+HIGHER_ACCESS_REQUIRED);
1017 if ((RESTRICT_INTERNET==1)&&(e==M_INTERNET)
1018 &&((CC->usersupp.flags&US_INTERNET)==0)
1019 &&(!CC->internal_pgm) ) {
1020 cprintf("%d You don't have access to Internet mail.\n",
1021 ERROR+HIGHER_ACCESS_REQUIRED);
1024 if (!strucmp(buf,"sysop")) {
1028 if (e!=M_LOCAL) goto SKFALL; /* don't search local file */
1029 if (!strucmp(buf,CC->usersupp.fullname)) {
1030 cprintf("%d Can't send mail to yourself!\n",
1031 ERROR+NO_SUCH_USER);
1035 /* Check to make sure the user exists; also get the correct
1036 * upper/lower casing of the name.
1038 lprintf(9, "checking validity of %s\n", buf);
1039 a = getuser(&tempUS,buf);
1040 lprintf(9, "getuser() returned %d\n", a);
1042 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
1045 strcpy(buf,tempUS.fullname);
1048 SKFALL: b=MES_NORMAL;
1049 if (CC->quickroom.QRflags&QR_ANONONLY) b=MES_ANON;
1050 if (CC->quickroom.QRflags&QR_ANON2) {
1051 if (anon_flag==1) b=MES_AN2;
1053 if (CC->curr_rm!=1) buf[0]=0;
1055 /* If we're only checking the validity of the request, return
1056 * success without creating the message.
1059 cprintf("%d %s\n",OK,buf);
1063 cprintf("%d send message\n",SEND_LISTING);
1064 if (CC->fake_postname[0])
1065 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname);
1067 if (CC->fake_username[0])
1068 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username);
1070 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "");
1071 save_message(CC->temp,buf,mtsflag,e,1);
1072 CC->fake_postname[0]='\0';
1079 * message entry - mode 3 (raw)
1081 void cmd_ent3(char *entargs)
1086 struct usersupp tempUS;
1091 if (CC->internal_pgm == 0) {
1092 cprintf("%d This command is for internal programs only.\n",
1097 if (CC->curr_rm < 0) {
1098 cprintf("%d No room selected.\n",ERROR);
1102 if (CC->curr_rm == 1) { /* If we're in Mail, check the recipient */
1103 extract(recp, entargs, 1);
1104 lprintf(9, "aliasing...\n");
1105 e=alias(recp); /* alias and mail type */
1106 lprintf(9,"...type is %d\n", e);
1107 if ((buf[0]==0) || (e==M_ERROR)) {
1108 cprintf("%d Unknown address - cannot send message.\n",
1109 ERROR+NO_SUCH_USER);
1113 a = getuser(&tempUS,recp);
1115 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
1121 /* At this point, message has been approved. */
1122 if (extract_int(entargs, 0) == 0) {
1123 cprintf("%d OK to send\n", OK);
1127 /* open a temp file to hold the message */
1128 fp = fopen(CC->temp, "wb");
1130 cprintf("%d Cannot open %s: %s\n",
1131 ERROR + INTERNAL_ERROR,
1132 CC->temp, strerror(errno) );
1136 msglen = extract_long(entargs, 2);
1137 cprintf("%d %ld\n", SEND_BINARY, msglen);
1138 while(msglen > 0L) {
1139 bloklen = ((msglen >= 255L) ? 255 : msglen);
1140 client_read(buf, (int)bloklen );
1141 fwrite(buf, (int)bloklen, 1, fp);
1142 msglen = msglen - bloklen;
1146 save_message(CC->temp, recp, 0, e, 0);
1151 * Delete message from current room
1153 void cmd_dele(char *delstr)
1158 getuser(&CC->usersupp,CC->curr_user);
1159 if ((CC->usersupp.axlevel < 6)
1160 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1161 cprintf("%d Higher access required.\n",
1162 ERROR+HIGHER_ACCESS_REQUIRED);
1166 delnum = atol(delstr);
1167 if (CC->curr_rm==1) {
1168 cprintf("%d Can't delete mail.\n",ERROR);
1172 /* get room records, obtaining a lock... */
1173 lgetroom(&CC->quickroom,CC->curr_rm);
1174 get_msglist(CC->curr_rm);
1177 if (CC->num_msgs > 0) for (a=0; a<(CC->num_msgs); ++a) {
1178 if (MessageFromList(a) == delnum) {
1179 SetMessageInList(a, 0L);
1184 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1185 CC->quickroom.QRhighest = MessageFromList(CC->num_msgs - 1);
1187 put_msglist(CC->curr_rm);
1188 lputroom(&CC->quickroom,CC->curr_rm);
1190 cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
1191 cprintf("%d Message deleted.\n",OK);
1193 else cprintf("%d No message %ld.\n",ERROR,delnum);
1198 * move a message to another room
1200 void cmd_move(char *args)
1206 struct quickroom qtemp;
1208 struct cdbdata *cdbtarg;
1212 num = extract_long(args,0);
1213 extract(targ,args,1);
1215 if (CC->curr_rm < 0) {
1216 cprintf("%d no room\n",ERROR);
1220 getuser(&CC->usersupp,CC->curr_user);
1221 if ((CC->usersupp.axlevel < 6)
1222 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1223 cprintf("%d Higher access required.\n",
1224 ERROR+HIGHER_ACCESS_REQUIRED);
1229 for (a=0; a<MAXROOMS; ++a) {
1231 if (!strucmp(qtemp.QRname,targ)) {
1236 if (targ_slot < 0) {
1237 cprintf("%d '%s' does not exist.\n",ERROR,targ);
1241 /* yank the message out of the current room... */
1242 lgetroom(&CC->quickroom,CC->curr_rm);
1243 get_msglist(CC->curr_rm);
1246 for (a=0; a<(CC->num_msgs); ++a) {
1247 if (MessageFromList(a) == num) {
1249 SetMessageInList(a, 0L);
1253 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1254 put_msglist(CC->curr_rm);
1255 CC->quickroom.QRhighest = MessageFromList((CC->num_msgs)-1);
1257 lputroom(&CC->quickroom,CC->curr_rm);
1259 cprintf("%d msg %ld does not exist.\n",ERROR,num);
1263 /* put the message into the target room */
1264 lgetroom(&qtemp,targ_slot);
1265 cdbtarg = cdb_fetch(CDB_MSGLISTS, &targ_slot, sizeof(int));
1266 if (cdbtarg != NULL) {
1267 targmsgs = malloc(cdbtarg->len);
1268 memcpy(targmsgs, cdbtarg->ptr, cdbtarg->len);
1269 targ_count = cdbtarg->len / sizeof(long);
1278 targmsgs = realloc(targmsgs, ((CC->num_msgs) * sizeof(long)));
1279 targmsgs[targ_count - 1] = num;
1280 targ_count = sort_msglist(targmsgs, targ_count);
1281 qtemp.QRhighest = targmsgs[targ_count - 1];
1282 cdb_store(CDB_MSGLISTS, &targ_slot, sizeof(int),
1283 targmsgs, targ_count * sizeof(long));
1285 lputroom(&qtemp,targ_slot);
1286 cprintf("%d ok\n",OK);