18 #include "sysdep_decls.h"
22 #include "dynloader.h"
24 #include "mime_parser.h"
33 extern struct config config;
37 * This function is self explanatory.
38 * (What can I say, I'm in a weird mood today...)
40 void remove_any_whitespace_to_the_left_or_right_of_at_symbol(char *name) {
43 for (i=0; i<strlen(name); ++i) if (name[i]=='@') {
44 if (i>0) if (isspace(name[i-1])) {
45 strcpy(&name[i-1], &name[i]);
48 while (isspace(name[i+1])) {
49 strcpy(&name[i+1], &name[i+2]);
56 * Aliasing for network mail.
57 * (Error messages have been commented out, because this is a server.)
59 int alias(char *name) /* process alias and routing info for mail */
63 char aaa[300],bbb[300];
65 lprintf(9, "alias() called for <%s>\n", name);
67 remove_any_whitespace_to_the_left_or_right_of_at_symbol(name);
69 fp=fopen("network/mail.aliases","r");
70 if (fp==NULL) fp=fopen("/dev/null","r");
71 if (fp==NULL) return(M_ERROR);
72 GNA: strcpy(aaa,""); strcpy(bbb,"");
95 if (strcasecmp(name,aaa)) goto GNA;
98 lprintf(7, "Mail is being forwarded to %s\n", name);
100 DETYPE: /* determine local or remote type, see citadel.h */
101 for (a=0; a<strlen(name); ++a) if (name[a]=='!') return(M_INTERNET);
102 for (a=0; a<strlen(name); ++a)
104 for (b=a; b<strlen(name); ++b)
105 if (name[b]=='.') return(M_INTERNET);
106 b=0; for (a=0; a<strlen(name); ++a) if (name[a]=='@') ++b;
108 lprintf(7, "Too many @'s in address\n");
112 for (a=0; a<strlen(name); ++a)
113 if (name[a]=='@') strcpy(bbb,&name[a+1]);
114 while (bbb[0]==32) strcpy(bbb,&bbb[1]);
115 fp = fopen("network/mail.sysinfo","r");
116 if (fp==NULL) return(M_ERROR);
119 } while ((a>=0)&&(strcasecmp(aaa,bbb)));
121 if (!strncmp(aaa,"use ",4)) {
127 if (!strncmp(aaa,"uum",3)) {
129 for (a=0; a<strlen(bbb); ++a) {
130 if (bbb[a]=='@') bbb[a]=0;
131 if (bbb[a]==' ') bbb[a]='_';
133 while(bbb[strlen(bbb)-1]=='_') bbb[strlen(bbb)-1]=0;
134 sprintf(name,&aaa[4],bbb);
137 if (!strncmp(aaa,"bin",3)) {
138 strcpy(aaa,name); strcpy(bbb,name);
139 while (aaa[strlen(aaa)-1]!='@') aaa[strlen(aaa)-1]=0;
140 aaa[strlen(aaa)-1]=0;
141 while (aaa[strlen(aaa)-1]==' ') aaa[strlen(aaa)-1]=0;
142 while (bbb[0]!='@') strcpy(bbb,&bbb[1]);
144 while (bbb[0]==' ') strcpy(bbb,&bbb[1]);
145 sprintf(name,"%s @%s",aaa,bbb);
157 fp=fopen("citadel.control","r");
158 fread((char *)&CitControl,sizeof(struct CitControl),1,fp);
163 * cmd_msgs() - get list of message #'s in this room
165 void cmd_msgs(char *cmdbuf)
174 extract(which,cmdbuf,0);
178 if (!strncasecmp(which,"OLD",3)) mode = MSGS_OLD;
179 if (!strncasecmp(which,"NEW",3)) mode = MSGS_NEW;
180 if (!strncasecmp(which,"FIRST",5)) {
182 cm_howmany = extract_int(cmdbuf,1);
184 if (!strncasecmp(which,"LAST",4)) {
186 cm_howmany = extract_int(cmdbuf,1);
188 if (!strncasecmp(which,"GT",2)) {
190 cm_gt = extract_long(cmdbuf,1);
193 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
194 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
198 get_msglist(&CC->quickroom);
199 getuser(&CC->usersupp,CC->curr_user);
200 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
202 cprintf("%d Message list...\n",LISTING_FOLLOWS);
203 if (CC->num_msgs != 0) {
204 for (a=0; a<(CC->num_msgs); ++a)
205 if ((MessageFromList(a) >=0)
209 || ((mode==MSGS_OLD) && (MessageFromList(a) <= vbuf.v_lastseen))
210 || ((mode==MSGS_NEW) && (MessageFromList(a) > vbuf.v_lastseen))
211 || ((mode==MSGS_NEW) && (MessageFromList(a) >= vbuf.v_lastseen)
212 && (CC->usersupp.flags & US_LASTOLD))
213 || ((mode==MSGS_LAST)&& (a>=(CC->num_msgs-cm_howmany)))
214 || ((mode==MSGS_FIRST)&&(a<cm_howmany))
215 || ((mode==MSGS_GT) && (MessageFromList(a) > cm_gt))
219 cprintf("%ld\n", MessageFromList(a));
228 * help_subst() - support routine for help file viewer
230 void help_subst(char *strbuf, char *source, char *dest)
235 while (p=pattern2(strbuf,source), (p>=0)) {
236 strcpy(workbuf,&strbuf[p+strlen(source)]);
237 strcpy(&strbuf[p],dest);
238 strcat(strbuf,workbuf);
243 void do_help_subst(char *buffer)
247 help_subst(buffer,"^nodename",config.c_nodename);
248 help_subst(buffer,"^humannode",config.c_humannode);
249 help_subst(buffer,"^fqdn",config.c_fqdn);
250 help_subst(buffer,"^username",CC->usersupp.fullname);
251 sprintf(buf2,"%ld",CC->usersupp.usernum);
252 help_subst(buffer,"^usernum",buf2);
253 help_subst(buffer,"^sysadm",config.c_sysadm);
254 help_subst(buffer,"^variantname",CITADEL);
255 sprintf(buf2,"%d",config.c_maxsessions);
256 help_subst(buffer,"^maxsessions",buf2);
262 * memfmout() - Citadel text formatter and paginator.
263 * Although the original purpose of this routine was to format
264 * text to the reader's screen width, all we're really using it
265 * for here is to format text out to 80 columns before sending it
266 * to the client. The client software may reformat it again.
268 void memfmout(int width, char *mptr, char subst)
269 /* screen width to use */
270 /* where are we going to get our text from? */
271 /* nonzero if we should use hypertext mode */
280 strcpy(aaa,""); old=255;
282 c=1; /* c is the current pos */
285 while (ch=*mptr, ((ch!=0) && (strlen(buffer)<126) )) {
287 buffer[strlen(buffer)+1] = 0;
288 buffer[strlen(buffer)] = ch;
291 if (buffer[0]=='^') do_help_subst(buffer);
293 buffer[strlen(buffer)+1] = 0;
295 strcpy(buffer,&buffer[1]);
302 if (ch<=0) goto FMTEND;
304 if ( ((ch==13)||(ch==10)) && (old!=13) && (old!=10) ) ch=32;
305 if ( ((old==13)||(old==10)) && (isspace(real)) ) {
309 if (ch>126) goto FMTA;
312 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
313 { cprintf("\n%s",aaa); c=strlen(aaa); aaa[0]=0;
315 b=strlen(aaa); aaa[b]=ch; aaa[b+1]=0; }
317 if ((strlen(aaa)+c)>(width-5)) {
321 cprintf("%s ",aaa); ++c; c=c+strlen(aaa);
325 if ((ch==13)||(ch==10)) {
333 FMTEND: cprintf("\n");
340 void part_handler(char *name, char *filename, char *encoding,
341 void *content, char *cbtype, size_t length) {
343 cprintf("part=%s|%s|%s|%s|%d\n",
344 name, filename, encoding, cbtype, length);
351 * Get a message off disk. (return value is the message's timestamp)
354 time_t output_message(char *msgid, int mode, int headers_only) {
358 CIT_UBYTE format_type,anon_flag;
363 struct cdbdata *dmsgtext;
366 /* buffers needed for RFC822 translation */
375 msg_num = atol(msgid);
378 if ((!(CC->logged_in))&&(!(CC->internal_pgm))&&(mode!=MT_DATE)) {
379 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
383 /* We used to need to check in the current room's message list
384 * to determine where the message's disk position. We no longer need
385 * to do this, but we do it anyway as a security measure, in order to
386 * prevent rogue clients from reading messages not in the current room.
390 if (CC->num_msgs > 0) {
391 for (a=0; a<CC->num_msgs; ++a) {
392 if (MessageFromList(a) == msg_num) {
400 cprintf("%d Message %ld is not in this room.\n",
406 dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
408 if (dmsgtext == NULL) {
410 cprintf("%d Can't find message %ld\n",
411 ERROR+INTERNAL_ERROR);
415 msg_len = (long) dmsgtext->len;
416 mptr = dmsgtext->ptr;
418 /* this loop spews out the whole message if we're doing raw format */
419 if (mode == MT_RAW) {
420 cprintf("%d %ld\n", BINARY_FOLLOWS, msg_len);
421 client_write(dmsgtext->ptr, (int) msg_len);
426 /* Otherwise, we'll start parsing it field by field... */
429 cprintf("%d Illegal message format on disk\n",
430 ERROR+INTERNAL_ERROR);
436 format_type = *mptr++;
438 /* Are we just looking for the message date? */
439 if (mode == MT_DATE) while(ch = *mptr++, (ch!='M' && ch!=0)) {
442 buf[strlen(buf)+1] = 0;
444 buf[strlen(buf)] = rch;
455 /* now for the user-mode message reading loops */
456 cprintf("%d Message %ld:\n",LISTING_FOLLOWS,msg_num);
458 if (mode == MT_CITADEL) cprintf("type=%d\n", format_type);
460 if ( (anon_flag == MES_ANON) && (mode == MT_CITADEL) ) {
461 cprintf("nhdr=yes\n");
464 /* begin header processing loop for Citadel message format */
466 if ((mode == MT_CITADEL)||(mode == MT_MIME))
467 while(ch = *mptr++, (ch!='M' && ch!=0)) {
470 buf[strlen(buf)+1] = 0;
472 buf[strlen(buf)] = rch;
476 PerformUserHooks(buf, (-1L), EVT_OUTPUTMSG);
477 if (anon_flag==MES_ANON) cprintf("from=****");
478 else if (anon_flag==MES_AN2) cprintf("from=anonymous");
479 else cprintf("from=%s",buf);
480 if ((is_room_aide()) && ((anon_flag == MES_ANON)
481 || (anon_flag == MES_AN2)))
482 cprintf(" [%s]",buf);
485 else if (ch=='P') cprintf("path=%s\n",buf);
486 else if (ch=='U') cprintf("subj=%s\n",buf);
487 else if (ch=='I') cprintf("msgn=%s\n",buf);
488 else if (ch=='H') cprintf("hnod=%s\n",buf);
489 else if (ch=='O') cprintf("room=%s\n",buf);
490 else if (ch=='N') cprintf("node=%s\n",buf);
491 else if (ch=='R') cprintf("rcpt=%s\n",buf);
492 else if (ch=='T') cprintf("time=%s\n",buf);
493 /* else cprintf("fld%c=%s\n",ch,buf); */
496 /* begin header processing loop for RFC822 transfer format */
500 strcpy(snode, NODENAME);
501 strcpy(lnode, HUMANNODE);
502 if (mode == MT_RFC822) while(ch = *mptr++, (ch!='M' && ch!=0)) {
505 buf[strlen(buf)+1] = 0;
507 buf[strlen(buf)] = rch;
510 if (ch=='A') strcpy(luser, buf);
512 cprintf("Path: %s\n",buf);
513 for (a=0; a<strlen(buf); ++a) {
515 strcpy(buf,&buf[a+1]);
521 else if (ch=='U') cprintf("Subject: %s\n",buf);
522 else if (ch=='I') strcpy(mid, buf);
523 else if (ch=='H') strcpy(lnode, buf);
524 else if (ch=='O') cprintf("X-Citadel-Room: %s\n",buf);
525 else if (ch=='N') strcpy(snode, buf);
526 else if (ch=='R') cprintf("To: %s\n",buf);
529 cprintf("Date: %s", asctime(localtime(&xtime)));
533 if (mode == MT_RFC822) {
534 if (!strcasecmp(snode, NODENAME)) {
537 cprintf("Message-ID: <%s@%s>\n", mid, snode);
538 PerformUserHooks(luser, (-1L), EVT_OUTPUTMSG);
539 cprintf("From: %s@%s (%s)\n",
540 suser, snode, luser);
541 cprintf("Organization: %s\n", lnode);
544 /* end header processing loop ... at this point, we're in the text */
547 cprintf("text\n*** ?Message truncated\n000\n");
552 /* do some sort of MIME output */
553 if ( (mode == MT_MIME) && (format_type == 4) ) {
554 mime_parser(mptr, NULL, *part_handler);
561 /* give 'em a length */
563 while(ch = *mptr++, ch>0) {
566 cprintf("mlen=%ld\n", msg_len);
572 /* signify start of msg text */
573 if (mode == MT_CITADEL) cprintf("text\n");
574 if ( (mode == MT_RFC822) && (format_type != 4) ) cprintf("\n");
576 /* If the format type on disk is 1 (fixed-format), then we want
577 * everything to be output completely literally ... regardless of
578 * what message transfer format is in use. Format type 4 is
579 * temporarily being output this way as well.
581 if ( (format_type == 1) || (format_type == 4)) {
583 while(ch = *mptr++, ch>0) {
584 if (ch == 13) ch = 10;
585 if ( (ch == 10) || (strlen(buf)>250) ) {
586 cprintf("%s\n", buf);
590 buf[strlen(buf)+1] = 0;
591 buf[strlen(buf)] = ch;
594 if (strlen(buf)>0) cprintf("%s\n", buf);
596 /* If the message on disk is format 0 (Citadel vari-format), we
597 * output using the formatter at 80 columns. This is the final output
598 * form if the transfer format is RFC822, but if the transfer format
599 * is Citadel proprietary, it'll still work, because the indentation
600 * for new paragraphs is correct and the client will reformat the
601 * message to the reader's screen width.
603 if (format_type == 0) {
616 * display a message (mode 0 - Citadel proprietary)
618 void cmd_msg0(char *cmdbuf)
621 int headers_only = 0;
623 extract(msgid,cmdbuf,0);
624 headers_only = extract_int(cmdbuf, 1);
626 output_message(msgid, MT_CITADEL, headers_only);
632 * display a message (mode 2 - RFC822)
634 void cmd_msg2(char *cmdbuf)
637 int headers_only = 0;
639 extract(msgid,cmdbuf,0);
640 headers_only = extract_int(cmdbuf,1);
642 output_message(msgid,MT_RFC822,headers_only);
646 * display a message (mode 3 - IGnet raw format - internal programs only)
648 void cmd_msg3(char *cmdbuf)
651 int headers_only = 0;
653 if (CC->internal_pgm == 0) {
654 cprintf("%d This command is for internal programs only.\n",
659 extract(msgid,cmdbuf,0);
660 headers_only = extract_int(cmdbuf,1);
662 output_message(msgid,MT_RAW,headers_only);
666 * display a message (mode 4 - MIME) (FIX ... still evolving, not complete)
668 void cmd_msg4(char *cmdbuf)
672 extract(msgid, cmdbuf, 0);
674 output_message(msgid, MT_MIME, 0);
680 * Message base operation to send a message to the master file
681 * (returns new message number)
683 long send_message(char *message_in_memory, /* pointer to buffer */
684 size_t message_length, /* length of buffer */
685 int generate_id) { /* 1 to generate an I field */
688 char *actual_message;
689 size_t actual_length;
693 /* Get a new message number */
694 newmsgid = get_new_message_number();
697 sprintf(msgidbuf, "I%ld", newmsgid);
698 actual_length = message_length + strlen(msgidbuf) + 1;
699 actual_message = mallok(actual_length);
700 memcpy(actual_message, message_in_memory, 3);
701 memcpy(&actual_message[3], msgidbuf, (strlen(msgidbuf)+1) );
702 memcpy(&actual_message[strlen(msgidbuf)+4],
703 &message_in_memory[3], message_length - 3);
707 actual_message = message_in_memory;
708 actual_length = message_length;
711 /* Write our little bundle of joy into the message base */
712 begin_critical_section(S_MSGMAIN);
713 if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
714 actual_message, actual_length) < 0 ) {
715 lprintf(2, "Can't store message\n");
721 end_critical_section(S_MSGMAIN);
724 phree(actual_message);
727 /* Finally, return the pointers */
734 * this is a simple file copy routine.
736 void copy_file(char *from, char *to)
742 if (ffp==NULL) return;
748 while (a=getc(ffp), a>=0) {
759 * message base operation to save a message and install its pointers
761 void save_message(char *mtmp, /* file containing proper message */
762 char *rec, /* Recipient (if mail) */
763 char *force_room, /* if non-zero length, force a room */
764 int mailtype, /* local or remote type, see citadel.h */
765 int generate_id) /* set to 1 to generate an 'I' field */
768 char hold_rm[ROOMNAMELEN];
769 char actual_rm[ROOMNAMELEN];
772 char *message_in_memory;
776 struct usersupp userbuf;
778 static int seqnum = 0;
780 lprintf(9, "save_message(%s,%s,%s,%d,%d)\n",
781 mtmp, rec, force_room, mailtype, generate_id);
783 /* Strip non-printable characters out of the recipient name */
784 strcpy(recipient, rec);
785 for (a=0; a<strlen(recipient); ++a)
786 if (!isprint(recipient[a]))
787 strcpy(&recipient[a], &recipient[a+1]);
789 /* Measure the message */
790 stat(mtmp, &statbuf);
791 templen = statbuf.st_size;
793 /* Now read it into memory */
794 message_in_memory = (char *) mallok(templen);
795 if (message_in_memory == NULL) {
796 lprintf(2, "Can't allocate memory to save message!\n");
800 fp = fopen(mtmp, "rb");
801 fread(message_in_memory, templen, 1, fp);
804 newmsgid = send_message(message_in_memory, templen, generate_id);
805 phree(message_in_memory);
806 if (newmsgid <= 0L) return;
808 strcpy(actual_rm, CC->quickroom.QRname);
811 /* If the user is a twit, move to the twit room for posting... */
812 if (TWITDETECT) if (CC->usersupp.axlevel==2) {
813 strcpy(hold_rm, actual_rm);
814 strcpy(actual_rm, config.c_twitroom);
817 /* ...or if this is a private message, go to the target mailbox. */
818 if (strlen(recipient) > 0) {
819 /* mailtype = alias(recipient); */
820 if (mailtype == M_LOCAL) {
821 if (getuser(&userbuf, recipient)!=0) {
822 /* User not found, goto Aide */
823 strcpy(force_room, AIDEROOM);
826 strcpy(hold_rm, actual_rm);
827 MailboxName(actual_rm, &userbuf, MAILROOM);
832 /* ...or if this message is destined for Aide> then go there. */
833 if (strlen(force_room) > 0) {
834 strcpy(hold_rm, actual_rm);
835 strcpy(actual_rm, force_room);
838 /* This call to usergoto() changes rooms if necessary. It also
839 * causes the latest message list to be read into memory.
841 usergoto(actual_rm, 0);
843 /* read in the quickroom record, obtaining a lock... */
844 lgetroom(&CC->quickroom, actual_rm);
846 /* Fix an obscure bug */
847 if (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) {
848 CC->quickroom.QRflags = CC->quickroom.QRflags & ~QR_MAILBOX;
851 /* Add the message pointer to the room */
852 CC->quickroom.QRhighest = AddMessageToRoom(&CC->quickroom, newmsgid);
854 /* update quickroom */
855 lputroom(&CC->quickroom, actual_rm);
857 /* Network mail - send a copy to the network program. */
858 if ( (strlen(recipient)>0) && (mailtype != M_LOCAL) ) {
859 sprintf(aaa,"./network/spoolin/netmail.%04x.%04x.%04x",
860 getpid(), CC->cs_pid, ++seqnum);
862 system("exec nohup ./netproc -i >/dev/null 2>&1 &");
865 /* Bump this user's messages posted counter. */
866 lgetuser(&CC->usersupp, CC->curr_user);
867 CC->usersupp.posted = CC->usersupp.posted + 1;
868 lputuser(&CC->usersupp, CC->curr_user);
870 /* If we've posted in a room other than the current room, then we
871 * have to now go back to the current room...
873 if (strlen(hold_rm) > 0) {
874 usergoto(hold_rm, 0);
876 unlink(mtmp); /* delete the temporary file */
881 * Generate an administrative message and post it in the Aide> room.
883 void aide_message(char *text)
887 fp=fopen(CC->temp,"wb");
888 fprintf(fp,"%c%c%c",255,MES_NORMAL,0);
889 fprintf(fp,"Psysop%c",0);
890 fprintf(fp,"T%ld%c", time(NULL), 0);
891 fprintf(fp,"ACitadel%c",0);
892 fprintf(fp,"OAide%c",0);
893 fprintf(fp,"N%s%c",NODENAME,0);
894 fprintf(fp,"M%s\n%c",text,0);
896 save_message(CC->temp,"",AIDEROOM,M_LOCAL,1);
897 syslog(LOG_NOTICE,text);
903 * Build a binary message to be saved on disk.
906 char *filename, /* temporary file name */
907 struct usersupp *author, /* author's usersupp structure */
908 char *recipient, /* NULL if it's not mail */
909 char *room, /* room where it's going */
910 int type, /* see MES_ types in header file */
911 int net_type, /* see MES_ types in header file */
912 int format_type, /* local or remote (see citadel.h) */
913 char *fake_name) { /* who we're masquerading as */
921 /* Don't confuse the poor folks if it's not routed mail. */
922 strcpy(dest_node, "");
925 /* If net_type is M_BINARY, split out the destination node. */
926 if (net_type == M_BINARY) {
927 strcpy(dest_node,NODENAME);
928 for (a=0; a<strlen(recipient); ++a) {
929 if (recipient[a]=='@') {
931 strcpy(dest_node,&recipient[a+1]);
936 /* if net_type is M_INTERNET, set the dest node to 'internet' */
937 if (net_type == M_INTERNET) {
938 strcpy(dest_node,"internet");
941 while (isspace(recipient[strlen(recipient)-1]))
942 recipient[strlen(recipient)-1] = 0;
945 fp=fopen(filename,"w");
947 putc(type,fp); /* Normal or anonymous, see MES_ flags */
948 putc(format_type,fp); /* Formatted or unformatted */
949 fprintf(fp,"Pcit%ld%c",author->usernum,0); /* path */
950 fprintf(fp,"T%ld%c",now,0); /* date/time */
952 fprintf(fp,"A%s%c",fake_name,0);
954 fprintf(fp,"A%s%c",author->fullname,0); /* author */
956 if (CC->quickroom.QRflags & QR_MAILBOX) { /* room */
957 fprintf(fp,"O%s%c", &CC->quickroom.QRname[11], 0);
960 fprintf(fp,"O%s%c",CC->quickroom.QRname,0);
963 fprintf(fp,"N%s%c",NODENAME,0); /* nodename */
964 fprintf(fp,"H%s%c",HUMANNODE,0); /* human nodename */
966 if (recipient[0]!=0) fprintf(fp, "R%s%c", recipient, 0);
967 if (dest_node[0]!=0) fprintf(fp, "D%s%c", dest_node, 0);
971 while (client_gets(buf), strcmp(buf,"000"))
973 fprintf(fp,"%s\n",buf);
975 syslog(LOG_INFO, "Closing message");
985 * message entry - mode 0 (normal) <bc>
987 void cmd_ent0(char *entargs)
993 char newusername[256]; /* <bc> */
998 struct usersupp tempUS;
1001 post = extract_int(entargs,0);
1002 extract(recipient,entargs,1);
1003 anon_flag = extract_int(entargs,2);
1004 format_type = extract_int(entargs,3);
1006 /* first check to make sure the request is valid. */
1008 if (!(CC->logged_in)) {
1009 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1012 if ((CC->usersupp.axlevel<2)&&((CC->quickroom.QRflags&QR_MAILBOX)==0)) {
1013 cprintf("%d Need to be validated to enter ",
1014 ERROR+HIGHER_ACCESS_REQUIRED);
1015 cprintf("(except in %s> to sysop)\n", MAILROOM);
1018 if ((CC->usersupp.axlevel<4)&&(CC->quickroom.QRflags&QR_NETWORK)) {
1019 cprintf("%d Need net privileges to enter here.\n",
1020 ERROR+HIGHER_ACCESS_REQUIRED);
1023 if ((CC->usersupp.axlevel<6)&&(CC->quickroom.QRflags&QR_READONLY)) {
1024 cprintf("%d Sorry, this is a read-only room.\n",
1025 ERROR+HIGHER_ACCESS_REQUIRED);
1032 if (post==2) { /* <bc> */
1033 if (CC->usersupp.axlevel<6)
1035 cprintf("%d You don't have permission to do an aide post.\n",
1036 ERROR+HIGHER_ACCESS_REQUIRED);
1039 extract(newusername,entargs,4);
1040 bzero(CC->fake_postname, 32);
1041 strcpy(CC->fake_postname, newusername);
1042 cprintf("%d Ok\n",OK);
1046 CC->cs_flags |= CS_POSTING;
1049 if (CC->quickroom.QRflags & QR_MAILBOX) {
1050 if (CC->usersupp.axlevel>=2) {
1051 strcpy(buf,recipient);
1053 else strcpy(buf,"sysop");
1054 e=alias(buf); /* alias and mail type */
1055 if ((buf[0]==0) || (e==M_ERROR)) {
1056 cprintf("%d Unknown address - cannot send message.\n",
1057 ERROR+NO_SUCH_USER);
1060 if ((e!=M_LOCAL)&&(CC->usersupp.axlevel<4)) {
1061 cprintf("%d Net privileges required for network mail.\n",
1062 ERROR+HIGHER_ACCESS_REQUIRED);
1065 if ((RESTRICT_INTERNET==1)&&(e==M_INTERNET)
1066 &&((CC->usersupp.flags&US_INTERNET)==0)
1067 &&(!CC->internal_pgm) ) {
1068 cprintf("%d You don't have access to Internet mail.\n",
1069 ERROR+HIGHER_ACCESS_REQUIRED);
1072 if (!strcasecmp(buf,"sysop")) {
1076 if (e!=M_LOCAL) goto SKFALL; /* don't search local file */
1077 if (!strcasecmp(buf,CC->usersupp.fullname)) {
1078 cprintf("%d Can't send mail to yourself!\n",
1079 ERROR+NO_SUCH_USER);
1083 /* Check to make sure the user exists; also get the correct
1084 * upper/lower casing of the name.
1086 a = getuser(&tempUS,buf);
1088 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
1091 strcpy(buf,tempUS.fullname);
1094 SKFALL: b=MES_NORMAL;
1095 if (CC->quickroom.QRflags&QR_ANONONLY) b=MES_ANON;
1096 if (CC->quickroom.QRflags&QR_ANONOPT) {
1097 if (anon_flag==1) b=MES_AN2;
1099 if ((CC->quickroom.QRflags & QR_MAILBOX) == 0) buf[0]=0;
1101 /* If we're only checking the validity of the request, return
1102 * success without creating the message.
1105 cprintf("%d %s\n",OK,buf);
1109 cprintf("%d send message\n",SEND_LISTING);
1110 if (CC->fake_postname[0])
1111 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname);
1113 if (CC->fake_username[0])
1114 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username);
1116 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "");
1117 save_message(CC->temp,buf, (mtsflag ? AIDEROOM : ""), e,1);
1118 CC->fake_postname[0]='\0';
1125 * message entry - mode 3 (raw)
1127 void cmd_ent3(char *entargs)
1133 struct usersupp tempUS;
1138 if (CC->internal_pgm == 0) {
1139 cprintf("%d This command is for internal programs only.\n",
1144 /* See if there's a recipient, but make sure it's a real one */
1145 extract(recp, entargs, 1);
1146 for (a=0; a<strlen(recp); ++a)
1147 if (!isprint(recp[a]))
1148 strcpy(&recp[a], &recp[a+1]);
1149 while (isspace(recp[0])) strcpy(recp, &recp[1]);
1150 while (isspace(recp[strlen(recp)-1])) recp[strlen(recp)-1] = 0;
1152 /* If we're in Mail, check the recipient */
1153 if (strlen(recp) > 0) {
1154 e=alias(recp); /* alias and mail type */
1155 if ((recp[0]==0) || (e==M_ERROR)) {
1156 cprintf("%d Unknown address - cannot send message.\n",
1157 ERROR+NO_SUCH_USER);
1161 a = getuser(&tempUS,recp);
1163 cprintf("%d No such user.\n",
1164 ERROR+NO_SUCH_USER);
1170 /* At this point, message has been approved. */
1171 if (extract_int(entargs, 0) == 0) {
1172 cprintf("%d OK to send\n", OK);
1176 /* open a temp file to hold the message */
1177 fp = fopen(CC->temp, "wb");
1179 cprintf("%d Cannot open %s: %s\n",
1180 ERROR + INTERNAL_ERROR,
1181 CC->temp, strerror(errno) );
1185 msglen = extract_long(entargs, 2);
1186 cprintf("%d %ld\n", SEND_BINARY, msglen);
1187 while(msglen > 0L) {
1188 bloklen = ((msglen >= 255L) ? 255 : msglen);
1189 client_read(buf, (int)bloklen );
1190 fwrite(buf, (int)bloklen, 1, fp);
1191 msglen = msglen - bloklen;
1195 save_message(CC->temp, recp, "", e, 0);
1200 * Delete message from current room
1202 void cmd_dele(char *delstr)
1207 getuser(&CC->usersupp,CC->curr_user);
1208 if ((CC->usersupp.axlevel < 6)
1209 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)
1210 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0)) {
1211 cprintf("%d Higher access required.\n",
1212 ERROR+HIGHER_ACCESS_REQUIRED);
1216 delnum = extract_long(delstr, 0);
1218 /* get room records, obtaining a lock... */
1219 lgetroom(&CC->quickroom,CC->quickroom.QRname);
1220 get_msglist(&CC->quickroom);
1223 if (CC->num_msgs > 0) for (a=0; a<(CC->num_msgs); ++a) {
1224 if (MessageFromList(a) == delnum) {
1225 SetMessageInList(a, 0L);
1230 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1231 CC->quickroom.QRhighest = MessageFromList(CC->num_msgs - 1);
1233 put_msglist(&CC->quickroom);
1234 lputroom(&CC->quickroom,CC->quickroom.QRname);
1236 cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
1237 cprintf("%d Message deleted.\n",OK);
1239 else cprintf("%d No message %ld.\n",ERROR,delnum);
1244 * move a message to another room
1246 void cmd_move(char *args)
1251 struct quickroom qtemp;
1254 num = extract_long(args,0);
1255 extract(targ,args,1);
1257 getuser(&CC->usersupp,CC->curr_user);
1258 if ((CC->usersupp.axlevel < 6)
1259 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1260 cprintf("%d Higher access required.\n",
1261 ERROR+HIGHER_ACCESS_REQUIRED);
1265 if (getroom(&qtemp, targ) != 0) {
1266 cprintf("%d '%s' does not exist.\n",ERROR,targ);
1270 /* yank the message out of the current room... */
1271 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1272 get_msglist(&CC->quickroom);
1275 for (a=0; a<(CC->num_msgs); ++a) {
1276 if (MessageFromList(a) == num) {
1278 SetMessageInList(a, 0L);
1282 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1283 put_msglist(&CC->quickroom);
1284 CC->quickroom.QRhighest = MessageFromList((CC->num_msgs)-1);
1286 lputroom(&CC->quickroom,CC->quickroom.QRname);
1288 cprintf("%d msg %ld does not exist.\n",ERROR,num);
1292 /* put the message into the target room */
1293 lgetroom(&qtemp, targ);
1294 qtemp.QRhighest = AddMessageToRoom(&qtemp, num);
1295 lputroom(&qtemp, targ);
1297 cprintf("%d Message moved.\n", OK);