18 #include "sysdep_decls.h"
22 #include "dynloader.h"
32 extern struct config config;
36 * This function is self explanatory.
37 * (What can I say, I'm in a weird mood today...)
39 void remove_any_whitespace_to_the_left_or_right_of_at_symbol(char *name) {
42 for (i=0; i<strlen(name); ++i) if (name[i]=='@') {
43 if (i>0) if (isspace(name[i-1])) {
44 strcpy(&name[i-1], &name[i]);
47 while (isspace(name[i+1])) {
48 strcpy(&name[i+1], &name[i+2]);
55 * Aliasing for network mail.
56 * (Error messages have been commented out, because this is a server.)
58 int alias(char *name) /* process alias and routing info for mail */
62 char aaa[300],bbb[300];
64 lprintf(9, "alias() called for <%s>\n", name);
66 remove_any_whitespace_to_the_left_or_right_of_at_symbol(name);
68 fp=fopen("network/mail.aliases","r");
69 if (fp==NULL) fp=fopen("/dev/null","r");
70 if (fp==NULL) return(M_ERROR);
71 GNA: strcpy(aaa,""); strcpy(bbb,"");
94 if (strcasecmp(name,aaa)) goto GNA;
97 lprintf(7, "Mail is being forwarded to %s\n", name);
99 DETYPE: /* determine local or remote type, see citadel.h */
100 for (a=0; a<strlen(name); ++a) if (name[a]=='!') return(M_INTERNET);
101 for (a=0; a<strlen(name); ++a)
103 for (b=a; b<strlen(name); ++b)
104 if (name[b]=='.') return(M_INTERNET);
105 b=0; for (a=0; a<strlen(name); ++a) if (name[a]=='@') ++b;
107 lprintf(7, "Too many @'s in address\n");
111 for (a=0; a<strlen(name); ++a)
112 if (name[a]=='@') strcpy(bbb,&name[a+1]);
113 while (bbb[0]==32) strcpy(bbb,&bbb[1]);
114 fp = fopen("network/mail.sysinfo","r");
115 if (fp==NULL) return(M_ERROR);
118 } while ((a>=0)&&(strcasecmp(aaa,bbb)));
120 if (!strncmp(aaa,"use ",4)) {
126 if (!strncmp(aaa,"uum",3)) {
128 for (a=0; a<strlen(bbb); ++a) {
129 if (bbb[a]=='@') bbb[a]=0;
130 if (bbb[a]==' ') bbb[a]='_';
132 while(bbb[strlen(bbb)-1]=='_') bbb[strlen(bbb)-1]=0;
133 sprintf(name,&aaa[4],bbb);
136 if (!strncmp(aaa,"bin",3)) {
137 strcpy(aaa,name); strcpy(bbb,name);
138 while (aaa[strlen(aaa)-1]!='@') aaa[strlen(aaa)-1]=0;
139 aaa[strlen(aaa)-1]=0;
140 while (aaa[strlen(aaa)-1]==' ') aaa[strlen(aaa)-1]=0;
141 while (bbb[0]!='@') strcpy(bbb,&bbb[1]);
143 while (bbb[0]==' ') strcpy(bbb,&bbb[1]);
144 sprintf(name,"%s @%s",aaa,bbb);
156 fp=fopen("citadel.control","r");
157 fread((char *)&CitControl,sizeof(struct CitControl),1,fp);
162 * cmd_msgs() - get list of message #'s in this room
164 void cmd_msgs(char *cmdbuf)
173 extract(which,cmdbuf,0);
177 if (!strncasecmp(which,"OLD",3)) mode = MSGS_OLD;
178 if (!strncasecmp(which,"NEW",3)) mode = MSGS_NEW;
179 if (!strncasecmp(which,"FIRST",5)) {
181 cm_howmany = extract_int(cmdbuf,1);
183 if (!strncasecmp(which,"LAST",4)) {
185 cm_howmany = extract_int(cmdbuf,1);
187 if (!strncasecmp(which,"GT",2)) {
189 cm_gt = extract_long(cmdbuf,1);
192 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
193 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
197 get_msglist(&CC->quickroom);
198 getuser(&CC->usersupp,CC->curr_user);
199 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
201 cprintf("%d Message list...\n",LISTING_FOLLOWS);
202 if (CC->num_msgs != 0) {
203 for (a=0; a<(CC->num_msgs); ++a)
204 if ((MessageFromList(a) >=0)
208 || ((mode==MSGS_OLD) && (MessageFromList(a) <= vbuf.v_lastseen))
209 || ((mode==MSGS_NEW) && (MessageFromList(a) > vbuf.v_lastseen))
210 || ((mode==MSGS_NEW) && (MessageFromList(a) >= vbuf.v_lastseen)
211 && (CC->usersupp.flags & US_LASTOLD))
212 || ((mode==MSGS_LAST)&& (a>=(CC->num_msgs-cm_howmany)))
213 || ((mode==MSGS_FIRST)&&(a<cm_howmany))
214 || ((mode==MSGS_GT) && (MessageFromList(a) > cm_gt))
218 cprintf("%ld\n", MessageFromList(a));
227 * help_subst() - support routine for help file viewer
229 void help_subst(char *strbuf, char *source, char *dest)
234 while (p=pattern2(strbuf,source), (p>=0)) {
235 strcpy(workbuf,&strbuf[p+strlen(source)]);
236 strcpy(&strbuf[p],dest);
237 strcat(strbuf,workbuf);
242 void do_help_subst(char *buffer)
246 help_subst(buffer,"^nodename",config.c_nodename);
247 help_subst(buffer,"^humannode",config.c_humannode);
248 help_subst(buffer,"^fqdn",config.c_fqdn);
249 help_subst(buffer,"^username",CC->usersupp.fullname);
250 sprintf(buf2,"%ld",CC->usersupp.usernum);
251 help_subst(buffer,"^usernum",buf2);
252 help_subst(buffer,"^sysadm",config.c_sysadm);
253 help_subst(buffer,"^variantname",CITADEL);
254 sprintf(buf2,"%d",config.c_maxsessions);
255 help_subst(buffer,"^maxsessions",buf2);
261 * memfmout() - Citadel text formatter and paginator.
262 * Although the original purpose of this routine was to format
263 * text to the reader's screen width, all we're really using it
264 * for here is to format text out to 80 columns before sending it
265 * to the client. The client software may reformat it again.
267 void memfmout(int width, char *mptr, char subst)
268 /* screen width to use */
269 /* where are we going to get our text from? */
270 /* nonzero if we should use hypertext mode */
279 strcpy(aaa,""); old=255;
281 c=1; /* c is the current pos */
284 while (ch=*mptr, ((ch!=0) && (strlen(buffer)<126) )) {
286 buffer[strlen(buffer)+1] = 0;
287 buffer[strlen(buffer)] = ch;
290 if (buffer[0]=='^') do_help_subst(buffer);
292 buffer[strlen(buffer)+1] = 0;
294 strcpy(buffer,&buffer[1]);
301 if (ch<=0) goto FMTEND;
303 if ( ((ch==13)||(ch==10)) && (old!=13) && (old!=10) ) ch=32;
304 if ( ((old==13)||(old==10)) && (isspace(real)) ) {
308 if (ch>126) goto FMTA;
311 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
312 { cprintf("\n%s",aaa); c=strlen(aaa); aaa[0]=0;
314 b=strlen(aaa); aaa[b]=ch; aaa[b+1]=0; }
316 if ((strlen(aaa)+c)>(width-5)) {
320 cprintf("%s ",aaa); ++c; c=c+strlen(aaa);
324 if ((ch==13)||(ch==10)) {
332 FMTEND: cprintf("\n");
337 * Get a message off disk. (return value is the message's timestamp)
340 time_t output_message(char *msgid, int mode,
341 int headers_only, int desired_section) {
345 CIT_UBYTE format_type,anon_flag;
350 struct cdbdata *dmsgtext;
353 /* buffers needed for RFC822 translation */
362 msg_num = atol(msgid);
365 if ((!(CC->logged_in))&&(!(CC->internal_pgm))&&(mode!=MT_DATE)) {
366 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
370 /* We used to need to check in the current room's message list
371 * to determine where the message's disk position. We no longer need
372 * to do this, but we do it anyway as a security measure, in order to
373 * prevent rogue clients from reading messages not in the current room.
377 if (CC->num_msgs > 0) {
378 for (a=0; a<CC->num_msgs; ++a) {
379 if (MessageFromList(a) == msg_num) {
387 cprintf("%d Message %ld is not in this room.\n",
393 dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
395 if (dmsgtext == NULL) {
397 cprintf("%d Can't find message %ld\n",
398 ERROR+INTERNAL_ERROR);
402 msg_len = (long) dmsgtext->len;
403 mptr = dmsgtext->ptr;
405 /* this loop spews out the whole message if we're doing raw format */
406 if (mode == MT_RAW) {
407 cprintf("%d %ld\n", BINARY_FOLLOWS, msg_len);
408 client_write(dmsgtext->ptr, (int) msg_len);
413 /* Otherwise, we'll start parsing it field by field... */
416 cprintf("%d Illegal message format on disk\n",
417 ERROR+INTERNAL_ERROR);
423 format_type = *mptr++;
425 /* Are we just looking for the message date? */
426 if (mode == MT_DATE) while(ch = *mptr++, (ch!='M' && ch!=0)) {
429 buf[strlen(buf)+1] = 0;
431 buf[strlen(buf)] = rch;
442 /* now for the user-mode message reading loops */
443 cprintf("%d Message %ld:\n",LISTING_FOLLOWS,msg_num);
445 if (mode == MT_CITADEL) cprintf("type=%d\n",format_type);
447 if ( (anon_flag == MES_ANON) && (mode == MT_CITADEL) ) {
448 cprintf("nhdr=yes\n");
451 /* begin header processing loop for Citadel message format */
453 if (mode == MT_CITADEL) while(ch = *mptr++, (ch!='M' && ch!=0)) {
456 buf[strlen(buf)+1] = 0;
458 buf[strlen(buf)] = rch;
462 PerformUserHooks(buf, (-1L), EVT_OUTPUTMSG);
463 if (anon_flag==MES_ANON) cprintf("from=****");
464 else if (anon_flag==MES_AN2) cprintf("from=anonymous");
465 else cprintf("from=%s",buf);
466 if ((is_room_aide()) && ((anon_flag == MES_ANON)
467 || (anon_flag == MES_AN2)))
468 cprintf(" [%s]",buf);
471 else if (ch=='P') cprintf("path=%s\n",buf);
472 else if (ch=='U') cprintf("subj=%s\n",buf);
473 else if (ch=='I') cprintf("msgn=%s\n",buf);
474 else if (ch=='H') cprintf("hnod=%s\n",buf);
475 else if (ch=='O') cprintf("room=%s\n",buf);
476 else if (ch=='N') cprintf("node=%s\n",buf);
477 else if (ch=='R') cprintf("rcpt=%s\n",buf);
478 else if (ch=='T') cprintf("time=%s\n",buf);
479 /* else cprintf("fld%c=%s\n",ch,buf); */
482 /* begin header processing loop for RFC822 transfer format */
486 strcpy(snode, NODENAME);
487 strcpy(lnode, HUMANNODE);
488 if (mode == MT_RFC822) while(ch = *mptr++, (ch!='M' && ch!=0)) {
491 buf[strlen(buf)+1] = 0;
493 buf[strlen(buf)] = rch;
496 if (ch=='A') strcpy(luser, buf);
498 cprintf("Path: %s\n",buf);
499 for (a=0; a<strlen(buf); ++a) {
501 strcpy(buf,&buf[a+1]);
507 else if (ch=='U') cprintf("Subject: %s\n",buf);
508 else if (ch=='I') strcpy(mid, buf);
509 else if (ch=='H') strcpy(lnode, buf);
510 else if (ch=='O') cprintf("X-Citadel-Room: %s\n",buf);
511 else if (ch=='N') strcpy(snode, buf);
512 else if (ch=='R') cprintf("To: %s\n",buf);
515 cprintf("Date: %s", asctime(localtime(&xtime)));
519 if (mode == MT_RFC822) {
520 if (!strcasecmp(snode, NODENAME)) {
523 cprintf("Message-ID: <%s@%s>\n", mid, snode);
524 PerformUserHooks(luser, (-1L), EVT_OUTPUTMSG);
525 cprintf("From: %s@%s (%s)\n",
526 suser, snode, luser);
527 cprintf("Organization: %s\n", lnode);
530 /* end header processing loop ... at this point, we're in the text */
533 cprintf("text\n*** ?Message truncated\n000\n");
539 /* give 'em a length */
541 while(ch = *mptr++, ch>0) {
544 cprintf("mlen=%ld\n", msg_len);
550 /* signify start of msg text */
551 if (mode == MT_CITADEL) cprintf("text\n");
552 if (mode == MT_RFC822) cprintf("\n");
554 /* If the format type on disk is 1 (fixed-format), then we want
555 * everything to be output completely literally ... regardless of
556 * what message transfer format is in use.
558 if (format_type == 1) {
560 while(ch = *mptr++, ch>0) {
561 if (ch == 13) ch = 10;
562 if ( (ch == 10) || (strlen(buf)>250) ) {
563 cprintf("%s\n", buf);
567 buf[strlen(buf)+1] = 0;
568 buf[strlen(buf)] = ch;
571 if (strlen(buf)>0) cprintf("%s\n", buf);
573 /* If the message on disk is format 0 (Citadel vari-format), we
574 * output using the formatter at 80 columns. This is the final output
575 * form if the transfer format is RFC822, but if the transfer format
576 * is Citadel proprietary, it'll still work, because the indentation
577 * for new paragraphs is correct and the client will reformat the
578 * message to the reader's screen width.
580 if (format_type == 0) {
593 * display a message (mode 0 - Citadel proprietary)
595 void cmd_msg0(char *cmdbuf)
598 int headers_only = 0;
599 int desired_section = 0;
601 extract(msgid,cmdbuf,0);
602 headers_only = extract_int(cmdbuf, 1);
603 desired_section = extract_int(cmdbuf, 2);
605 output_message(msgid,MT_CITADEL, headers_only, desired_section);
611 * display a message (mode 2 - RFC822)
613 void cmd_msg2(char *cmdbuf)
616 int headers_only = 0;
618 extract(msgid,cmdbuf,0);
619 headers_only = extract_int(cmdbuf,1);
621 output_message(msgid,MT_RFC822,headers_only,0);
625 * display a message (mode 3 - IGnet raw format - internal programs only)
627 void cmd_msg3(char *cmdbuf)
630 int headers_only = 0;
632 if (CC->internal_pgm == 0) {
633 cprintf("%d This command is for internal programs only.\n",
638 extract(msgid,cmdbuf,0);
639 headers_only = extract_int(cmdbuf,1);
641 output_message(msgid,MT_RAW,headers_only,0);
647 * Message base operation to send a message to the master file
648 * (returns new message number)
650 long send_message(char *message_in_memory, /* pointer to buffer */
651 size_t message_length, /* length of buffer */
652 int generate_id) { /* 1 to generate an I field */
656 /* Get a new message number */
657 newmsgid = get_new_message_number();
659 /* Write our little bundle of joy into the message base */
661 begin_critical_section(S_MSGMAIN);
662 if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
663 message_in_memory, message_length) < 0 ) {
664 lprintf(2, "Can't store message\n");
665 end_critical_section(S_MSGMAIN);
668 end_critical_section(S_MSGMAIN);
670 /* Finally, return the pointers */
677 * this is a simple file copy routine.
679 void copy_file(char *from, char *to)
685 if (ffp==NULL) return;
691 while (a=getc(ffp), a>=0) {
702 * message base operation to save a message and install its pointers
704 void save_message(char *mtmp, /* file containing proper message */
705 char *rec, /* Recipient (if mail) */
706 char mtsflag, /* 0 for normal, 1 to force Aide> room */
707 int mailtype, /* local or remote type, see citadel.h */
708 int generate_id) /* set to 1 to generate an 'I' field */
711 char hold_rm[ROOMNAMELEN];
712 char actual_rm[ROOMNAMELEN];
715 char *message_in_memory;
719 struct usersupp userbuf;
721 static int seqnum = 0;
723 lprintf(9, "save_message(%s,%s,%d,%d,%d)\n",
724 mtmp, rec, mtsflag, mailtype, generate_id);
726 /* Strip non-printable characters out of the recipient name */
727 strcpy(recipient, rec);
728 for (a=0; a<strlen(recipient); ++a)
729 if (!isprint(recipient[a]))
730 strcpy(&recipient[a], &recipient[a+1]);
732 /* Measure the message */
733 stat(mtmp, &statbuf);
734 templen = statbuf.st_size;
736 /* Now read it into memory */
737 message_in_memory = (char *) malloc(templen);
738 if (message_in_memory == NULL) {
739 lprintf(2, "Can't allocate memory to save message!\n");
743 fp = fopen(mtmp, "rb");
744 fread(message_in_memory, templen, 1, fp);
747 newmsgid = send_message(message_in_memory, templen, generate_id);
748 free(message_in_memory);
749 if (newmsgid <= 0L) return;
751 strcpy(actual_rm, CC->quickroom.QRname);
754 /* If the user is a twit, move to the twit room for posting... */
755 if (TWITDETECT) if (CC->usersupp.axlevel==2) {
756 strcpy(hold_rm, actual_rm);
757 strcpy(actual_rm, config.c_twitroom);
760 /* ...or if this is a private message, go to the target mailbox. */
761 if (strlen(recipient) > 0) {
762 /* mailtype = alias(recipient); */
763 if (mailtype == M_LOCAL) {
764 if (getuser(&userbuf, recipient)!=0) {
765 mtsflag = 1; /* User not found, goto Aide */
768 strcpy(hold_rm, actual_rm);
769 MailboxName(actual_rm, &userbuf, MAILROOM);
774 /* ...or if this message is destined for Aide> then go there. */
776 strcpy(hold_rm, actual_rm);
777 strcpy(actual_rm, AIDEROOM);
780 /* This call to usergoto() changes rooms if necessary. It also
781 * causes the latest message list to be read into memory.
783 usergoto(actual_rm, 0);
785 /* read in the quickroom record, obtaining a lock... */
786 lgetroom(&CC->quickroom, actual_rm);
788 /* Fix an obscure bug */
789 if (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) {
790 CC->quickroom.QRflags = CC->quickroom.QRflags & ~QR_MAILBOX;
793 /* Add the message pointer to the room */
794 CC->quickroom.QRhighest = AddMessageToRoom(&CC->quickroom, newmsgid);
796 /* update quickroom */
797 lputroom(&CC->quickroom, actual_rm);
799 /* Network mail - send a copy to the network program. */
800 if ( (strlen(recipient)>0) && (mailtype != M_LOCAL) ) {
801 sprintf(aaa,"./network/spoolin/netmail.%04x.%04x.%04x",
802 getpid(), CC->cs_pid, ++seqnum);
804 system("exec nohup ./netproc >/dev/null 2>&1 &");
807 /* Bump this user's messages posted counter. */
808 lgetuser(&CC->usersupp, CC->curr_user);
809 CC->usersupp.posted = CC->usersupp.posted + 1;
810 lputuser(&CC->usersupp, CC->curr_user);
812 /* If we've posted in a room other than the current room, then we
813 * have to now go back to the current room...
815 if (strlen(hold_rm) > 0) {
816 usergoto(hold_rm, 0);
818 unlink(mtmp); /* delete the temporary file */
823 * Generate an administrative message and post it in the Aide> room.
825 void aide_message(char *text)
831 fp=fopen(CC->temp,"wb");
832 fprintf(fp,"%c%c%c",255,MES_NORMAL,0);
833 fprintf(fp,"Psysop%c",0);
834 fprintf(fp,"T%ld%c",now,0);
835 fprintf(fp,"ACitadel%c",0);
836 fprintf(fp,"OAide%c",0);
837 fprintf(fp,"N%s%c",NODENAME,0);
838 fprintf(fp,"M%s\n%c",text,0);
840 save_message(CC->temp,"",1,M_LOCAL,1);
841 syslog(LOG_NOTICE,text);
847 * Build a binary message to be saved on disk.
850 char *filename, /* temporary file name */
851 struct usersupp *author, /* author's usersupp structure */
852 char *recipient, /* NULL if it's not mail */
853 char *room, /* room where it's going */
854 int type, /* see MES_ types in header file */
855 int net_type, /* see MES_ types in header file */
856 int format_type, /* local or remote (see citadel.h) */
857 char *fake_name) { /* who we're masquerading as */
865 /* Don't confuse the poor folks if it's not routed mail. */
866 strcpy(dest_node, "");
869 /* If net_type is M_BINARY, split out the destination node. */
870 if (net_type == M_BINARY) {
871 strcpy(dest_node,NODENAME);
872 for (a=0; a<strlen(recipient); ++a) {
873 if (recipient[a]=='@') {
875 strcpy(dest_node,&recipient[a+1]);
880 /* if net_type is M_INTERNET, set the dest node to 'internet' */
881 if (net_type == M_INTERNET) {
882 strcpy(dest_node,"internet");
885 while (isspace(recipient[strlen(recipient)-1]))
886 recipient[strlen(recipient)-1] = 0;
889 fp=fopen(filename,"w");
891 putc(type,fp); /* Normal or anonymous, see MES_ flags */
892 putc(format_type,fp); /* Formatted or unformatted */
893 fprintf(fp,"Pcit%ld%c",author->usernum,0); /* path */
894 fprintf(fp,"T%ld%c",now,0); /* date/time */
896 fprintf(fp,"A%s%c",fake_name,0);
898 fprintf(fp,"A%s%c",author->fullname,0); /* author */
900 if (CC->quickroom.QRflags & QR_MAILBOX) { /* room */
901 fprintf(fp,"O%s%c", &CC->quickroom.QRname[11], 0);
904 fprintf(fp,"O%s%c",CC->quickroom.QRname,0);
907 fprintf(fp,"N%s%c",NODENAME,0); /* nodename */
908 fprintf(fp,"H%s%c",HUMANNODE,0); /* human nodename */
910 if (recipient[0]!=0) fprintf(fp, "R%s%c", recipient, 0);
911 if (dest_node[0]!=0) fprintf(fp, "D%s%c", dest_node, 0);
915 while (client_gets(buf), strcmp(buf,"000"))
917 fprintf(fp,"%s\n",buf);
919 syslog(LOG_INFO, "Closing message");
929 * message entry - mode 0 (normal) <bc>
931 void cmd_ent0(char *entargs)
937 char newusername[256]; /* <bc> */
942 struct usersupp tempUS;
945 post = extract_int(entargs,0);
946 extract(recipient,entargs,1);
947 anon_flag = extract_int(entargs,2);
948 format_type = extract_int(entargs,3);
950 /* first check to make sure the request is valid. */
952 if (!(CC->logged_in)) {
953 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
956 if ((CC->usersupp.axlevel<2)&&((CC->quickroom.QRflags&QR_MAILBOX)==0)) {
957 cprintf("%d Need to be validated to enter ",
958 ERROR+HIGHER_ACCESS_REQUIRED);
959 cprintf("(except in %s> to sysop)\n", MAILROOM);
962 if ((CC->usersupp.axlevel<4)&&(CC->quickroom.QRflags&QR_NETWORK)) {
963 cprintf("%d Need net privileges to enter here.\n",
964 ERROR+HIGHER_ACCESS_REQUIRED);
967 if ((CC->usersupp.axlevel<6)&&(CC->quickroom.QRflags&QR_READONLY)) {
968 cprintf("%d Sorry, this is a read-only room.\n",
969 ERROR+HIGHER_ACCESS_REQUIRED);
976 if (post==2) { /* <bc> */
977 if (CC->usersupp.axlevel<6)
979 cprintf("%d You don't have permission to do an aide post.\n",
980 ERROR+HIGHER_ACCESS_REQUIRED);
983 extract(newusername,entargs,4);
984 bzero(CC->fake_postname, 32);
985 strcpy(CC->fake_postname, newusername);
986 cprintf("%d Ok\n",OK);
990 CC->cs_flags |= CS_POSTING;
993 if (CC->quickroom.QRflags & QR_MAILBOX) {
994 if (CC->usersupp.axlevel>=2) {
995 strcpy(buf,recipient);
997 else strcpy(buf,"sysop");
998 e=alias(buf); /* alias and mail type */
999 if ((buf[0]==0) || (e==M_ERROR)) {
1000 cprintf("%d Unknown address - cannot send message.\n",
1001 ERROR+NO_SUCH_USER);
1004 if ((e!=M_LOCAL)&&(CC->usersupp.axlevel<4)) {
1005 cprintf("%d Net privileges required for network mail.\n",
1006 ERROR+HIGHER_ACCESS_REQUIRED);
1009 if ((RESTRICT_INTERNET==1)&&(e==M_INTERNET)
1010 &&((CC->usersupp.flags&US_INTERNET)==0)
1011 &&(!CC->internal_pgm) ) {
1012 cprintf("%d You don't have access to Internet mail.\n",
1013 ERROR+HIGHER_ACCESS_REQUIRED);
1016 if (!strcasecmp(buf,"sysop")) {
1020 if (e!=M_LOCAL) goto SKFALL; /* don't search local file */
1021 if (!strcasecmp(buf,CC->usersupp.fullname)) {
1022 cprintf("%d Can't send mail to yourself!\n",
1023 ERROR+NO_SUCH_USER);
1027 /* Check to make sure the user exists; also get the correct
1028 * upper/lower casing of the name.
1030 a = getuser(&tempUS,buf);
1032 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
1035 strcpy(buf,tempUS.fullname);
1038 SKFALL: b=MES_NORMAL;
1039 if (CC->quickroom.QRflags&QR_ANONONLY) b=MES_ANON;
1040 if (CC->quickroom.QRflags&QR_ANONOPT) {
1041 if (anon_flag==1) b=MES_AN2;
1043 if ((CC->quickroom.QRflags & QR_MAILBOX) == 0) buf[0]=0;
1045 /* If we're only checking the validity of the request, return
1046 * success without creating the message.
1049 cprintf("%d %s\n",OK,buf);
1053 cprintf("%d send message\n",SEND_LISTING);
1054 if (CC->fake_postname[0])
1055 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname);
1057 if (CC->fake_username[0])
1058 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username);
1060 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "");
1061 save_message(CC->temp,buf,mtsflag,e,1);
1062 CC->fake_postname[0]='\0';
1069 * message entry - mode 3 (raw)
1071 void cmd_ent3(char *entargs)
1077 struct usersupp tempUS;
1082 if (CC->internal_pgm == 0) {
1083 cprintf("%d This command is for internal programs only.\n",
1088 /* See if there's a recipient, but make sure it's a real one */
1089 extract(recp, entargs, 1);
1090 for (a=0; a<strlen(recp); ++a)
1091 if (!isprint(recp[a]))
1092 strcpy(&recp[a], &recp[a+1]);
1093 while (isspace(recp[0])) strcpy(recp, &recp[1]);
1094 while (isspace(recp[strlen(recp)-1])) recp[strlen(recp)-1] = 0;
1096 /* If we're in Mail, check the recipient */
1097 if (strlen(recp) > 0) {
1098 e=alias(recp); /* alias and mail type */
1099 if ((recp[0]==0) || (e==M_ERROR)) {
1100 cprintf("%d Unknown address - cannot send message.\n",
1101 ERROR+NO_SUCH_USER);
1105 a = getuser(&tempUS,recp);
1107 cprintf("%d No such user.\n",
1108 ERROR+NO_SUCH_USER);
1114 /* At this point, message has been approved. */
1115 if (extract_int(entargs, 0) == 0) {
1116 cprintf("%d OK to send\n", OK);
1120 /* open a temp file to hold the message */
1121 fp = fopen(CC->temp, "wb");
1123 cprintf("%d Cannot open %s: %s\n",
1124 ERROR + INTERNAL_ERROR,
1125 CC->temp, strerror(errno) );
1129 msglen = extract_long(entargs, 2);
1130 cprintf("%d %ld\n", SEND_BINARY, msglen);
1131 while(msglen > 0L) {
1132 bloklen = ((msglen >= 255L) ? 255 : msglen);
1133 client_read(buf, (int)bloklen );
1134 fwrite(buf, (int)bloklen, 1, fp);
1135 msglen = msglen - bloklen;
1139 save_message(CC->temp, recp, 0, e, 0);
1144 * Delete message from current room
1146 void cmd_dele(char *delstr)
1151 getuser(&CC->usersupp,CC->curr_user);
1152 if ((CC->usersupp.axlevel < 6)
1153 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)
1154 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0)) {
1155 cprintf("%d Higher access required.\n",
1156 ERROR+HIGHER_ACCESS_REQUIRED);
1160 delnum = extract_long(delstr, 0);
1162 /* get room records, obtaining a lock... */
1163 lgetroom(&CC->quickroom,CC->quickroom.QRname);
1164 get_msglist(&CC->quickroom);
1167 if (CC->num_msgs > 0) for (a=0; a<(CC->num_msgs); ++a) {
1168 if (MessageFromList(a) == delnum) {
1169 SetMessageInList(a, 0L);
1174 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1175 CC->quickroom.QRhighest = MessageFromList(CC->num_msgs - 1);
1177 put_msglist(&CC->quickroom);
1178 lputroom(&CC->quickroom,CC->quickroom.QRname);
1180 cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
1181 cprintf("%d Message deleted.\n",OK);
1183 else cprintf("%d No message %ld.\n",ERROR,delnum);
1188 * move a message to another room
1190 void cmd_move(char *args)
1195 struct quickroom qtemp;
1198 num = extract_long(args,0);
1199 extract(targ,args,1);
1201 getuser(&CC->usersupp,CC->curr_user);
1202 if ((CC->usersupp.axlevel < 6)
1203 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1204 cprintf("%d Higher access required.\n",
1205 ERROR+HIGHER_ACCESS_REQUIRED);
1209 if (getroom(&qtemp, targ) != 0) {
1210 cprintf("%d '%s' does not exist.\n",ERROR,targ);
1214 /* yank the message out of the current room... */
1215 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1216 get_msglist(&CC->quickroom);
1219 for (a=0; a<(CC->num_msgs); ++a) {
1220 if (MessageFromList(a) == num) {
1222 SetMessageInList(a, 0L);
1226 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1227 put_msglist(&CC->quickroom);
1228 CC->quickroom.QRhighest = MessageFromList((CC->num_msgs)-1);
1230 lputroom(&CC->quickroom,CC->quickroom.QRname);
1232 cprintf("%d msg %ld does not exist.\n",ERROR,num);
1236 /* put the message into the target room */
1237 lgetroom(&qtemp, targ);
1238 qtemp.QRhighest = AddMessageToRoom(&qtemp, num);
1239 lputroom(&qtemp, targ);
1241 cprintf("%d Message moved.\n", OK);