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;
349 char boundary[256]; /* attachment boundary */
350 char current_section = 0; /* section currently being parsed */
351 int has_attachments = 0;
353 struct cdbdata *dmsgtext;
356 /* buffers needed for RFC822 translation */
365 strcpy(boundary, "");
366 msg_num = atol(msgid);
369 if ((!(CC->logged_in))&&(!(CC->internal_pgm))&&(mode!=MT_DATE)) {
370 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
374 /* We used to need to check in the current room's message list
375 * to determine where the message's disk position. We no longer need
376 * to do this, but we do it anyway as a security measure, in order to
377 * prevent rogue clients from reading messages not in the current room.
381 if (CC->num_msgs > 0) {
382 for (a=0; a<CC->num_msgs; ++a) {
383 if (MessageFromList(a) == msg_num) {
391 cprintf("%d Message %ld is not in this room.\n",
397 dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
399 if (dmsgtext == NULL) {
401 cprintf("%d Can't find message %ld\n",
402 ERROR+INTERNAL_ERROR);
406 msg_len = (long) dmsgtext->len;
407 mptr = dmsgtext->ptr;
409 /* this loop spews out the whole message if we're doing raw format */
410 if (mode == MT_RAW) {
411 cprintf("%d %ld\n", BINARY_FOLLOWS, msg_len);
412 client_write(dmsgtext->ptr, (int) msg_len);
417 /* Otherwise, we'll start parsing it field by field... */
420 cprintf("%d Illegal message format on disk\n",
421 ERROR+INTERNAL_ERROR);
427 format_type = *mptr++;
429 /* Are we just looking for the message date? */
430 if (mode == MT_DATE) while(ch = *mptr++, (ch!='M' && ch!=0)) {
433 buf[strlen(buf)+1] = 0;
435 buf[strlen(buf)] = rch;
446 /* now for the user-mode message reading loops */
447 cprintf("%d Message %ld:\n",LISTING_FOLLOWS,msg_num);
449 if (mode == MT_CITADEL) cprintf("type=%d\n",format_type);
451 if ( (anon_flag == MES_ANON) && (mode == MT_CITADEL) ) {
452 cprintf("nhdr=yes\n");
455 /* begin header processing loop for Citadel message format */
457 if (mode == MT_CITADEL) while(ch = *mptr++, (ch!='M' && ch!=0)) {
460 buf[strlen(buf)+1] = 0;
462 buf[strlen(buf)] = rch;
466 PerformUserHooks(buf, (-1L), EVT_OUTPUTMSG);
467 if (anon_flag==MES_ANON) cprintf("from=****");
468 else if (anon_flag==MES_AN2) cprintf("from=anonymous");
469 else cprintf("from=%s",buf);
470 if ((is_room_aide()) && ((anon_flag == MES_ANON)
471 || (anon_flag == MES_AN2)))
472 cprintf(" [%s]",buf);
477 sprintf(boundary, "--%s", buf);
479 else if (ch=='P') cprintf("path=%s\n",buf);
480 else if (ch=='U') cprintf("subj=%s\n",buf);
481 else if (ch=='I') cprintf("msgn=%s\n",buf);
482 else if (ch=='H') cprintf("hnod=%s\n",buf);
483 else if (ch=='O') cprintf("room=%s\n",buf);
484 else if (ch=='N') cprintf("node=%s\n",buf);
485 else if (ch=='R') cprintf("rcpt=%s\n",buf);
486 else if (ch=='T') cprintf("time=%s\n",buf);
487 /* else cprintf("fld%c=%s\n",ch,buf); */
490 /* begin header processing loop for RFC822 transfer format */
494 strcpy(snode, NODENAME);
495 strcpy(lnode, HUMANNODE);
496 if (mode == MT_RFC822) while(ch = *mptr++, (ch!='M' && ch!=0)) {
499 buf[strlen(buf)+1] = 0;
501 buf[strlen(buf)] = rch;
504 if (ch=='A') strcpy(luser, buf);
506 cprintf("Path: %s\n",buf);
507 for (a=0; a<strlen(buf); ++a) {
509 strcpy(buf,&buf[a+1]);
515 else if (ch=='U') cprintf("Subject: %s\n",buf);
516 else if (ch=='I') strcpy(mid, buf);
517 else if (ch=='H') strcpy(lnode, buf);
518 else if (ch=='O') cprintf("X-Citadel-Room: %s\n",buf);
519 else if (ch=='N') strcpy(snode, buf);
520 else if (ch=='R') cprintf("To: %s\n",buf);
523 cprintf("Date: %s", asctime(localtime(&xtime)));
527 if (mode == MT_RFC822) {
528 if (!strcasecmp(snode, NODENAME)) {
531 cprintf("Message-ID: <%s@%s>\n", mid, snode);
532 PerformUserHooks(luser, (-1L), EVT_OUTPUTMSG);
533 cprintf("From: %s@%s (%s)\n",
534 suser, snode, luser);
535 cprintf("Organization: %s\n", lnode);
538 /* end header processing loop ... at this point, we're in the text */
541 cprintf("text\n*** ?Message truncated\n000\n");
547 /* give 'em a length */
549 while(ch = *mptr++, ch>0) {
552 cprintf("mlen=%ld\n", msg_len);
558 /* signify start of msg text */
559 if (mode == MT_CITADEL) cprintf("text\n");
560 if (mode == MT_RFC822) cprintf("\n");
562 /* If the format type on disk is 1 (fixed-format), then we want
563 * everything to be output completely literally ... regardless of
564 * what message transfer format is in use.
566 if (format_type == 1) {
568 while(ch = *mptr++, ch>0) {
569 if (ch == 13) ch = 10;
570 if ( (ch == 10) || (strlen(buf)>250) ) {
571 if (has_attachments) if (!strncmp(buf, boundary, strlen(boundary))) {
574 if (current_section == desired_section) {
575 if ( (has_attachments == 0) || (strncmp(buf, boundary, strlen(boundary)))) {
576 cprintf("%s\n", buf);
582 buf[strlen(buf)+1] = 0;
583 buf[strlen(buf)] = ch;
586 if (strlen(buf)>0) cprintf("%s\n", buf);
588 /* If the message on disk is format 0 (Citadel vari-format), we
589 * output using the formatter at 80 columns. This is the final output
590 * form if the transfer format is RFC822, but if the transfer format
591 * is Citadel proprietary, it'll still work, because the indentation
592 * for new paragraphs is correct and the client will reformat the
593 * message to the reader's screen width.
595 if (format_type == 0) {
608 * display a message (mode 0 - Citadel proprietary)
610 void cmd_msg0(char *cmdbuf)
613 int headers_only = 0;
614 int desired_section = 0;
616 extract(msgid,cmdbuf,0);
617 headers_only = extract_int(cmdbuf, 1);
618 desired_section = extract_int(cmdbuf, 2);
620 output_message(msgid,MT_CITADEL, headers_only, desired_section);
626 * display a message (mode 2 - RFC822)
628 void cmd_msg2(char *cmdbuf)
631 int headers_only = 0;
633 extract(msgid,cmdbuf,0);
634 headers_only = extract_int(cmdbuf,1);
636 output_message(msgid,MT_RFC822,headers_only,0);
640 * display a message (mode 3 - IGnet raw format - internal programs only)
642 void cmd_msg3(char *cmdbuf)
645 int headers_only = 0;
647 if (CC->internal_pgm == 0) {
648 cprintf("%d This command is for internal programs only.\n",
653 extract(msgid,cmdbuf,0);
654 headers_only = extract_int(cmdbuf,1);
656 output_message(msgid,MT_RAW,headers_only,0);
662 * Message base operation to send a message to the master file
663 * (returns new message number)
665 long send_message(char *message_in_memory, /* pointer to buffer */
666 size_t message_length, /* length of buffer */
667 int generate_id) { /* 1 to generate an I field */
671 /* Get a new message number */
672 newmsgid = get_new_message_number();
674 /* Write our little bundle of joy into the message base */
676 begin_critical_section(S_MSGMAIN);
677 if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
678 message_in_memory, message_length) < 0 ) {
679 lprintf(2, "Can't store message\n");
680 end_critical_section(S_MSGMAIN);
683 end_critical_section(S_MSGMAIN);
685 /* Finally, return the pointers */
692 * this is a simple file copy routine.
694 void copy_file(char *from, char *to)
700 if (ffp==NULL) return;
706 while (a=getc(ffp), a>=0) {
717 * message base operation to save a message and install its pointers
719 void save_message(char *mtmp, /* file containing proper message */
720 char *rec, /* Recipient (if mail) */
721 char mtsflag, /* 0 for normal, 1 to force Aide> room */
722 int mailtype, /* local or remote type, see citadel.h */
723 int generate_id) /* set to 1 to generate an 'I' field */
726 char hold_rm[ROOMNAMELEN];
727 char actual_rm[ROOMNAMELEN];
730 char *message_in_memory;
734 struct usersupp userbuf;
737 lprintf(9, "save_message(%s,%s,%d,%d,%d)\n",
738 mtmp, rec, mtsflag, mailtype, generate_id);
740 /* Strip non-printable characters out of the recipient name */
741 strcpy(recipient, rec);
742 for (a=0; a<strlen(recipient); ++a)
743 if (!isprint(recipient[a]))
744 strcpy(&recipient[a], &recipient[a+1]);
746 /* Measure the message */
747 stat(mtmp, &statbuf);
748 templen = statbuf.st_size;
750 /* Now read it into memory */
751 message_in_memory = (char *) malloc(templen);
752 if (message_in_memory == NULL) {
753 lprintf(2, "Can't allocate memory to save message!\n");
757 fp = fopen(mtmp, "rb");
758 fread(message_in_memory, templen, 1, fp);
761 newmsgid = send_message(message_in_memory, templen, generate_id);
762 free(message_in_memory);
763 if (newmsgid <= 0L) return;
765 strcpy(actual_rm, CC->quickroom.QRname);
768 /* If the user is a twit, move to the twit room for posting... */
769 if (TWITDETECT) if (CC->usersupp.axlevel==2) {
770 strcpy(hold_rm, actual_rm);
771 strcpy(actual_rm, config.c_twitroom);
774 /* ...or if this is a private message, go to the target mailbox. */
775 if (strlen(recipient) > 0) {
776 mailtype = alias(recipient);
777 if (mailtype == M_LOCAL) {
778 if (getuser(&userbuf, recipient)!=0) {
779 mtsflag = 1; /* User not found, goto Aide */
782 strcpy(hold_rm, actual_rm);
783 MailboxName(actual_rm, &userbuf, MAILROOM);
788 /* ...or if this message is destined for Aide> then go there. */
790 strcpy(hold_rm, actual_rm);
791 strcpy(actual_rm, AIDEROOM);
794 /* This call to usergoto() changes rooms if necessary. It also
795 * causes the latest message list to be read into memory.
797 usergoto(actual_rm, 0);
799 /* read in the quickroom record, obtaining a lock... */
800 lgetroom(&CC->quickroom, actual_rm);
802 /* Fix an obscure bug */
803 if (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) {
804 CC->quickroom.QRflags = CC->quickroom.QRflags & ~QR_MAILBOX;
807 /* Add the message pointer to the room */
808 CC->quickroom.QRhighest = AddMessageToRoom(&CC->quickroom, newmsgid);
810 /* update quickroom */
811 lputroom(&CC->quickroom, actual_rm);
813 /* Network mail - send a copy to the network program. */
814 if ( (strlen(recipient)>0) && (mailtype != M_LOCAL) ) {
815 sprintf(aaa,"./network/spoolin/nm.%d",getpid());
817 system("exec nohup ./netproc >/dev/null 2>&1 &");
820 /* Bump this user's messages posted counter. */
821 lgetuser(&CC->usersupp, CC->curr_user);
822 CC->usersupp.posted = CC->usersupp.posted + 1;
823 lputuser(&CC->usersupp, CC->curr_user);
825 /* If we've posted in a room other than the current room, then we
826 * have to now go back to the current room...
828 if (strlen(hold_rm) > 0) {
829 usergoto(hold_rm, 0);
831 unlink(mtmp); /* delete the temporary file */
836 * Generate an administrative message and post it in the Aide> room.
838 void aide_message(char *text)
844 fp=fopen(CC->temp,"wb");
845 fprintf(fp,"%c%c%c",255,MES_NORMAL,0);
846 fprintf(fp,"Psysop%c",0);
847 fprintf(fp,"T%ld%c",now,0);
848 fprintf(fp,"ACitadel%c",0);
849 fprintf(fp,"OAide%c",0);
850 fprintf(fp,"N%s%c",NODENAME,0);
851 fprintf(fp,"M%s\n%c",text,0);
853 save_message(CC->temp,"",1,M_LOCAL,1);
854 syslog(LOG_NOTICE,text);
860 * Build a binary message to be saved on disk.
863 char *filename, /* temporary file name */
864 struct usersupp *author, /* author's usersupp structure */
865 char *recipient, /* NULL if it's not mail */
866 char *room, /* room where it's going */
867 int type, /* see MES_ types in header file */
868 int net_type, /* see MES_ types in header file */
869 int format_type, /* local or remote (see citadel.h) */
870 char *fake_name, /* who we're masquerading as */
871 char *boundary) { /* boundary (if exist attachments) */
879 /* Don't confuse the poor folks if it's not routed mail. */
880 strcpy(dest_node, "");
883 /* If net_type is M_BINARY, split out the destination node. */
884 if (net_type == M_BINARY) {
885 strcpy(dest_node,NODENAME);
886 for (a=0; a<strlen(recipient); ++a) {
887 if (recipient[a]=='@') {
889 strcpy(dest_node,&recipient[a+1]);
894 /* if net_type is M_INTERNET, set the dest node to 'internet' */
895 if (net_type == M_INTERNET) {
896 strcpy(dest_node,"internet");
899 while (isspace(recipient[strlen(recipient)-1]))
900 recipient[strlen(recipient)-1] = 0;
903 fp=fopen(filename,"w");
905 putc(type,fp); /* Normal or anonymous, see MES_ flags */
906 putc(format_type,fp); /* Formatted or unformatted */
907 fprintf(fp,"Pcit%ld%c",author->usernum,0); /* path */
908 fprintf(fp,"T%ld%c",now,0); /* date/time */
910 fprintf(fp,"A%s%c",fake_name,0);
912 fprintf(fp,"A%s%c",author->fullname,0); /* author */
914 if (CC->quickroom.QRflags & QR_MAILBOX) { /* room */
915 fprintf(fp,"O%s%c", &CC->quickroom.QRname[11], 0);
918 fprintf(fp,"O%s%c",CC->quickroom.QRname,0);
921 fprintf(fp,"N%s%c",NODENAME,0); /* nodename */
922 fprintf(fp,"H%s%c",HUMANNODE,0); /* human nodename */
924 if (recipient[0]!=0) fprintf(fp, "R%s%c", recipient, 0);
925 if (dest_node[0]!=0) fprintf(fp, "D%s%c", dest_node, 0);
926 if (boundary[0]!=0) fprintf(fp, "Z%s%c", boundary, 0);
930 while (client_gets(buf), strcmp(buf,"000"))
932 fprintf(fp,"%s\n",buf);
934 syslog(LOG_INFO, "Closing message");
944 * message entry - mode 0 (normal) <bc>
946 void cmd_ent0(char *entargs)
952 char newusername[256]; /* <bc> */
958 struct usersupp tempUS;
961 post = extract_int(entargs,0);
962 extract(recipient,entargs,1);
963 anon_flag = extract_int(entargs,2);
964 format_type = extract_int(entargs,3);
965 extract(boundary, entargs, 5);
967 /* first check to make sure the request is valid. */
969 if (!(CC->logged_in)) {
970 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
973 if ((CC->usersupp.axlevel<2)&&((CC->quickroom.QRflags&QR_MAILBOX)==0)) {
974 cprintf("%d Need to be validated to enter ",
975 ERROR+HIGHER_ACCESS_REQUIRED);
976 cprintf("(except in %s> to sysop)\n", MAILROOM);
979 if ((CC->usersupp.axlevel<4)&&(CC->quickroom.QRflags&QR_NETWORK)) {
980 cprintf("%d Need net privileges to enter here.\n",
981 ERROR+HIGHER_ACCESS_REQUIRED);
984 if ((CC->usersupp.axlevel<6)&&(CC->quickroom.QRflags&QR_READONLY)) {
985 cprintf("%d Sorry, this is a read-only room.\n",
986 ERROR+HIGHER_ACCESS_REQUIRED);
993 if (post==2) { /* <bc> */
994 if (CC->usersupp.axlevel<6)
996 cprintf("%d You don't have permission to do an aide post.\n",
997 ERROR+HIGHER_ACCESS_REQUIRED);
1000 extract(newusername,entargs,4);
1001 bzero(CC->fake_postname, 32);
1002 strcpy(CC->fake_postname, newusername);
1003 cprintf("%d Ok\n",OK);
1007 CC->cs_flags |= CS_POSTING;
1010 if (CC->quickroom.QRflags & QR_MAILBOX) {
1011 if (CC->usersupp.axlevel>=2) {
1012 strcpy(buf,recipient);
1014 else strcpy(buf,"sysop");
1015 e=alias(buf); /* alias and mail type */
1016 if ((buf[0]==0) || (e==M_ERROR)) {
1017 cprintf("%d Unknown address - cannot send message.\n",
1018 ERROR+NO_SUCH_USER);
1021 if ((e!=M_LOCAL)&&(CC->usersupp.axlevel<4)) {
1022 cprintf("%d Net privileges required for network mail.\n",
1023 ERROR+HIGHER_ACCESS_REQUIRED);
1026 if ((RESTRICT_INTERNET==1)&&(e==M_INTERNET)
1027 &&((CC->usersupp.flags&US_INTERNET)==0)
1028 &&(!CC->internal_pgm) ) {
1029 cprintf("%d You don't have access to Internet mail.\n",
1030 ERROR+HIGHER_ACCESS_REQUIRED);
1033 if (!strcasecmp(buf,"sysop")) {
1037 if (e!=M_LOCAL) goto SKFALL; /* don't search local file */
1038 if (!strcasecmp(buf,CC->usersupp.fullname)) {
1039 cprintf("%d Can't send mail to yourself!\n",
1040 ERROR+NO_SUCH_USER);
1044 /* Check to make sure the user exists; also get the correct
1045 * upper/lower casing of the name.
1047 a = getuser(&tempUS,buf);
1049 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
1052 strcpy(buf,tempUS.fullname);
1055 SKFALL: b=MES_NORMAL;
1056 if (CC->quickroom.QRflags&QR_ANONONLY) b=MES_ANON;
1057 if (CC->quickroom.QRflags&QR_ANONOPT) {
1058 if (anon_flag==1) b=MES_AN2;
1060 if ((CC->quickroom.QRflags & QR_MAILBOX) == 0) buf[0]=0;
1062 /* If we're only checking the validity of the request, return
1063 * success without creating the message.
1066 cprintf("%d %s\n",OK,buf);
1070 cprintf("%d send message\n",SEND_LISTING);
1071 if (CC->fake_postname[0])
1072 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname, boundary);
1074 if (CC->fake_username[0])
1075 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username, boundary);
1077 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "", boundary);
1078 save_message(CC->temp,buf,mtsflag,e,1);
1079 CC->fake_postname[0]='\0';
1086 * message entry - mode 3 (raw)
1088 void cmd_ent3(char *entargs)
1094 struct usersupp tempUS;
1099 if (CC->internal_pgm == 0) {
1100 cprintf("%d This command is for internal programs only.\n",
1105 /* See if there's a recipient, but make sure it's a real one */
1106 extract(recp, entargs, 1);
1107 for (a=0; a<strlen(recp); ++a)
1108 if (!isprint(recp[a]))
1109 strcpy(&recp[a], &recp[a+1]);
1110 while (isspace(recp[0])) strcpy(recp, &recp[1]);
1111 while (isspace(recp[strlen(recp)-1])) recp[strlen(recp)-1] = 0;
1113 /* If we're in Mail, check the recipient */
1114 if (strlen(recp) > 0) {
1115 e=alias(recp); /* alias and mail type */
1116 if ((recp[0]==0) || (e==M_ERROR)) {
1117 cprintf("%d Unknown address - cannot send message.\n",
1118 ERROR+NO_SUCH_USER);
1122 a = getuser(&tempUS,recp);
1124 cprintf("%d No such user.\n",
1125 ERROR+NO_SUCH_USER);
1131 /* At this point, message has been approved. */
1132 if (extract_int(entargs, 0) == 0) {
1133 cprintf("%d OK to send\n", OK);
1137 /* open a temp file to hold the message */
1138 fp = fopen(CC->temp, "wb");
1140 cprintf("%d Cannot open %s: %s\n",
1141 ERROR + INTERNAL_ERROR,
1142 CC->temp, strerror(errno) );
1146 msglen = extract_long(entargs, 2);
1147 cprintf("%d %ld\n", SEND_BINARY, msglen);
1148 while(msglen > 0L) {
1149 bloklen = ((msglen >= 255L) ? 255 : msglen);
1150 client_read(buf, (int)bloklen );
1151 fwrite(buf, (int)bloklen, 1, fp);
1152 msglen = msglen - bloklen;
1156 save_message(CC->temp, recp, 0, e, 0);
1161 * Delete message from current room
1163 void cmd_dele(char *delstr)
1168 getuser(&CC->usersupp,CC->curr_user);
1169 if ((CC->usersupp.axlevel < 6)
1170 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)
1171 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0)) {
1172 cprintf("%d Higher access required.\n",
1173 ERROR+HIGHER_ACCESS_REQUIRED);
1177 delnum = extract_long(delstr, 0);
1179 /* get room records, obtaining a lock... */
1180 lgetroom(&CC->quickroom,CC->quickroom.QRname);
1181 get_msglist(&CC->quickroom);
1184 if (CC->num_msgs > 0) for (a=0; a<(CC->num_msgs); ++a) {
1185 if (MessageFromList(a) == delnum) {
1186 SetMessageInList(a, 0L);
1191 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1192 CC->quickroom.QRhighest = MessageFromList(CC->num_msgs - 1);
1194 put_msglist(&CC->quickroom);
1195 lputroom(&CC->quickroom,CC->quickroom.QRname);
1197 cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
1198 cprintf("%d Message deleted.\n",OK);
1200 else cprintf("%d No message %ld.\n",ERROR,delnum);
1205 * move a message to another room
1207 void cmd_move(char *args)
1212 struct quickroom qtemp;
1215 num = extract_long(args,0);
1216 extract(targ,args,1);
1218 getuser(&CC->usersupp,CC->curr_user);
1219 if ((CC->usersupp.axlevel < 6)
1220 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1221 cprintf("%d Higher access required.\n",
1222 ERROR+HIGHER_ACCESS_REQUIRED);
1226 if (getroom(&qtemp, targ) != 0) {
1227 cprintf("%d '%s' does not exist.\n",ERROR,targ);
1231 /* yank the message out of the current room... */
1232 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1233 get_msglist(&CC->quickroom);
1236 for (a=0; a<(CC->num_msgs); ++a) {
1237 if (MessageFromList(a) == num) {
1239 SetMessageInList(a, 0L);
1243 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1244 put_msglist(&CC->quickroom);
1245 CC->quickroom.QRhighest = MessageFromList((CC->num_msgs)-1);
1247 lputroom(&CC->quickroom,CC->quickroom.QRname);
1249 cprintf("%d msg %ld does not exist.\n",ERROR,num);
1253 /* put the message into the target room */
1254 lgetroom(&qtemp, targ);
1255 qtemp.QRhighest = AddMessageToRoom(&qtemp, num);
1256 lputroom(&qtemp, targ);
1258 cprintf("%d Message moved.\n", OK);