17 #include "sysdep_decls.h"
21 #include "dynloader.h"
30 extern struct config config;
34 * Aliasing for network mail.
35 * (Error messages have been commented out, because this is a server.)
37 int alias(char *name) /* process alias and routing info for mail */
41 char aaa[300],bbb[300];
43 fp=fopen("network/mail.aliases","r");
44 if (fp==NULL) fp=fopen("/dev/null","r");
45 if (fp==NULL) return(M_ERROR);
46 GNA: strcpy(aaa,""); strcpy(bbb,"");
69 if (strcasecmp(name,aaa)) goto GNA;
72 lprintf(7, "Mail is being forwarded to %s\n", name);
74 DETYPE: /* determine local or remote type, see citadel.h */
75 for (a=0; a<strlen(name); ++a) if (name[a]=='!') return(M_INTERNET);
76 for (a=0; a<strlen(name); ++a)
78 for (b=a; b<strlen(name); ++b)
79 if (name[b]=='.') return(M_INTERNET);
80 b=0; for (a=0; a<strlen(name); ++a) if (name[a]=='@') ++b;
82 lprintf(7, "Too many @'s in address\n");
86 for (a=0; a<strlen(name); ++a)
87 if (name[a]=='@') strcpy(bbb,&name[a+1]);
88 while (bbb[0]==32) strcpy(bbb,&bbb[1]);
89 fp = fopen("network/mail.sysinfo","r");
90 if (fp==NULL) return(M_ERROR);
93 } while ((a>=0)&&(strcasecmp(aaa,bbb)));
95 if (!strncmp(aaa,"use ",4)) {
101 if (!strncmp(aaa,"uum",3)) {
103 for (a=0; a<strlen(bbb); ++a) {
104 if (bbb[a]=='@') bbb[a]=0;
105 if (bbb[a]==' ') bbb[a]='_';
107 while(bbb[strlen(bbb)-1]=='_') bbb[strlen(bbb)-1]=0;
108 sprintf(name,&aaa[4],bbb);
111 if (!strncmp(aaa,"bin",3)) {
112 strcpy(aaa,name); strcpy(bbb,name);
113 while (aaa[strlen(aaa)-1]!='@') aaa[strlen(aaa)-1]=0;
114 aaa[strlen(aaa)-1]=0;
115 while (aaa[strlen(aaa)-1]==' ') aaa[strlen(aaa)-1]=0;
116 while (bbb[0]!='@') strcpy(bbb,&bbb[1]);
118 while (bbb[0]==' ') strcpy(bbb,&bbb[1]);
119 sprintf(name,"%s @%s",aaa,bbb);
131 fp=fopen("citadel.control","r");
132 fread((char *)&CitControl,sizeof(struct CitControl),1,fp);
137 * cmd_msgs() - get list of message #'s in this room
139 void cmd_msgs(char *cmdbuf)
148 extract(which,cmdbuf,0);
152 if (!strncasecmp(which,"OLD",3)) mode = MSGS_OLD;
153 if (!strncasecmp(which,"NEW",3)) mode = MSGS_NEW;
154 if (!strncasecmp(which,"FIRST",5)) {
156 cm_howmany = extract_int(cmdbuf,1);
158 if (!strncasecmp(which,"LAST",4)) {
160 cm_howmany = extract_int(cmdbuf,1);
162 if (!strncasecmp(which,"GT",2)) {
164 cm_gt = extract_long(cmdbuf,1);
167 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
168 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
172 get_msglist(&CC->quickroom);
173 getuser(&CC->usersupp,CC->curr_user);
174 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
176 cprintf("%d Message list...\n",LISTING_FOLLOWS);
177 if (CC->num_msgs != 0) {
178 for (a=0; a<(CC->num_msgs); ++a)
179 if ((MessageFromList(a) >=0)
183 || ((mode==MSGS_OLD) && (MessageFromList(a) <= vbuf.v_lastseen))
184 || ((mode==MSGS_NEW) && (MessageFromList(a) > vbuf.v_lastseen))
185 || ((mode==MSGS_NEW) && (MessageFromList(a) >= vbuf.v_lastseen)
186 && (CC->usersupp.flags & US_LASTOLD))
187 || ((mode==MSGS_LAST)&& (a>=(CC->num_msgs-cm_howmany)))
188 || ((mode==MSGS_FIRST)&&(a<cm_howmany))
189 || ((mode==MSGS_GT) && (MessageFromList(a) > cm_gt))
193 cprintf("%ld\n", MessageFromList(a));
202 * help_subst() - support routine for help file viewer
204 void help_subst(char *strbuf, char *source, char *dest)
209 while (p=pattern2(strbuf,source), (p>=0)) {
210 strcpy(workbuf,&strbuf[p+strlen(source)]);
211 strcpy(&strbuf[p],dest);
212 strcat(strbuf,workbuf);
217 void do_help_subst(char *buffer)
221 help_subst(buffer,"^nodename",config.c_nodename);
222 help_subst(buffer,"^humannode",config.c_humannode);
223 help_subst(buffer,"^fqdn",config.c_fqdn);
224 help_subst(buffer,"^username",CC->usersupp.fullname);
225 sprintf(buf2,"%ld",CC->usersupp.usernum);
226 help_subst(buffer,"^usernum",buf2);
227 help_subst(buffer,"^sysadm",config.c_sysadm);
228 help_subst(buffer,"^variantname",CITADEL);
229 sprintf(buf2,"%d",config.c_maxsessions);
230 help_subst(buffer,"^maxsessions",buf2);
236 * memfmout() - Citadel text formatter and paginator.
237 * Although the original purpose of this routine was to format
238 * text to the reader's screen width, all we're really using it
239 * for here is to format text out to 80 columns before sending it
240 * to the client. The client software may reformat it again.
242 void memfmout(int width, char *mptr, char subst)
243 /* screen width to use */
244 /* where are we going to get our text from? */
245 /* nonzero if we should use hypertext mode */
254 strcpy(aaa,""); old=255;
256 c=1; /* c is the current pos */
259 while (ch=*mptr, ((ch!=0) && (strlen(buffer)<126) )) {
261 buffer[strlen(buffer)+1] = 0;
262 buffer[strlen(buffer)] = ch;
265 if (buffer[0]=='^') do_help_subst(buffer);
267 buffer[strlen(buffer)+1] = 0;
269 strcpy(buffer,&buffer[1]);
276 if (ch<=0) goto FMTEND;
278 if ( ((ch==13)||(ch==10)) && (old!=13) && (old!=10) ) ch=32;
279 if ( ((old==13)||(old==10)) && (isspace(real)) ) {
283 if (ch>126) goto FMTA;
286 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
287 { cprintf("\n%s",aaa); c=strlen(aaa); aaa[0]=0;
289 b=strlen(aaa); aaa[b]=ch; aaa[b+1]=0; }
291 if ((strlen(aaa)+c)>(width-5)) {
295 cprintf("%s ",aaa); ++c; c=c+strlen(aaa);
299 if ((ch==13)||(ch==10)) {
307 FMTEND: cprintf("\n");
312 * get a message off disk.
315 void output_message(char *msgid, int mode,
316 int headers_only, int desired_section) {
320 CIT_UBYTE format_type,anon_flag;
324 char boundary[256]; /* attachment boundary */
325 char current_section = 0; /* section currently being parsed */
326 int has_attachments = 0;
328 struct cdbdata *dmsgtext;
331 /* buffers needed for RFC822 translation */
340 strcpy(boundary, "");
341 msg_num = atol(msgid);
344 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
345 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
349 /* We used to need to check in the current room's message list
350 * to determine where the message's disk position. We no longer need
351 * to do this, but we do it anyway as a security measure, in order to
352 * prevent rogue clients from reading messages not in the current room.
356 if (CC->num_msgs > 0) {
357 for (a=0; a<CC->num_msgs; ++a) {
358 if (MessageFromList(a) == msg_num) {
365 cprintf("%d Message %ld is not in this room.\n",
371 dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
373 if (dmsgtext == NULL) {
374 cprintf("%d Can't find message %ld\n", ERROR+INTERNAL_ERROR);
378 msg_len = (long) dmsgtext->len;
379 mptr = dmsgtext->ptr;
380 lprintf(9, "Returned message length is %ld\n", msg_len);
382 /* this loop spews out the whole message if we're doing raw format */
383 if (mode == MT_RAW) {
384 cprintf("%d %ld\n", BINARY_FOLLOWS, msg_len);
385 client_write(dmsgtext->ptr, (int) msg_len);
390 /* Otherwise, we'll start parsing it field by field... */
393 cprintf("%d Illegal message format on disk\n",
394 ERROR+INTERNAL_ERROR);
400 format_type = *mptr++;
402 /* now for the user-mode message reading loops */
403 cprintf("%d Message %ld:\n",LISTING_FOLLOWS,msg_num);
405 if (mode == MT_CITADEL) cprintf("type=%d\n",format_type);
407 if ( (anon_flag == MES_ANON) && (mode == MT_CITADEL) ) {
408 cprintf("nhdr=yes\n");
411 /* begin header processing loop for Citadel message format */
413 if (mode == MT_CITADEL) while(ch = *mptr++, (ch!='M' && ch!=0)) {
416 buf[strlen(buf)+1] = 0;
418 buf[strlen(buf)] = rch;
422 PerformUserHooks(buf, (-1L), EVT_OUTPUTMSG);
423 if (anon_flag==MES_ANON) cprintf("from=****");
424 else if (anon_flag==MES_AN2) cprintf("from=anonymous");
425 else cprintf("from=%s",buf);
426 if ((is_room_aide()) && ((anon_flag == MES_ANON)
427 || (anon_flag == MES_AN2)))
428 cprintf(" [%s]",buf);
433 sprintf(boundary, "--%s", buf);
435 else if (ch=='P') cprintf("path=%s\n",buf);
436 else if (ch=='U') cprintf("subj=%s\n",buf);
437 else if (ch=='I') cprintf("msgn=%s\n",buf);
438 else if (ch=='H') cprintf("hnod=%s\n",buf);
439 else if (ch=='O') cprintf("room=%s\n",buf);
440 else if (ch=='N') cprintf("node=%s\n",buf);
441 else if (ch=='R') cprintf("rcpt=%s\n",buf);
442 else if (ch=='T') cprintf("time=%s\n",buf);
443 /* else cprintf("fld%c=%s\n",ch,buf); */
446 /* begin header processing loop for RFC822 transfer format */
450 strcpy(snode, NODENAME);
451 strcpy(lnode, HUMANNODE);
452 if (mode == MT_RFC822) while(ch = *mptr++, (ch!='M' && ch!=0)) {
455 buf[strlen(buf)+1] = 0;
457 buf[strlen(buf)] = rch;
460 if (ch=='A') strcpy(luser, buf);
462 cprintf("Path: %s\n",buf);
463 for (a=0; a<strlen(buf); ++a) {
465 strcpy(buf,&buf[a+1]);
471 else if (ch=='U') cprintf("Subject: %s\n",buf);
472 else if (ch=='I') strcpy(mid, buf);
473 else if (ch=='H') strcpy(lnode, buf);
474 else if (ch=='O') cprintf("X-Citadel-Room: %s\n",buf);
475 else if (ch=='N') strcpy(snode, buf);
476 else if (ch=='R') cprintf("To: %s\n",buf);
479 cprintf("Date: %s", asctime(localtime(&xtime)));
483 if (mode == MT_RFC822) {
484 if (!strcasecmp(snode, NODENAME)) {
487 cprintf("Message-ID: <%s@%s>\n", mid, snode);
488 PerformUserHooks(luser, (-1L), EVT_OUTPUTMSG);
489 cprintf("From: %s@%s (%s)\n",
490 suser, snode, luser);
491 cprintf("Organization: %s\n", lnode);
494 /* end header processing loop ... at this point, we're in the text */
497 cprintf("text\n*** ?Message truncated\n000\n");
503 /* give 'em a length */
505 while(ch = *mptr++, ch>0) {
508 cprintf("mlen=%ld\n", msg_len);
514 /* signify start of msg text */
515 if (mode == MT_CITADEL) cprintf("text\n");
516 if (mode == MT_RFC822) cprintf("\n");
518 /* If the format type on disk is 1 (fixed-format), then we want
519 * everything to be output completely literally ... regardless of
520 * what message transfer format is in use.
522 if (format_type == 1) {
524 while(ch = *mptr++, ch>0) {
525 if (ch == 13) ch = 10;
526 if ( (ch == 10) || (strlen(buf)>250) ) {
527 if (has_attachments) if (!strncmp(buf, boundary, strlen(boundary))) {
530 if (current_section == desired_section) {
531 if ( (has_attachments == 0) || (strncmp(buf, boundary, strlen(boundary)))) {
532 cprintf("%s\n", buf);
538 buf[strlen(buf)+1] = 0;
539 buf[strlen(buf)] = ch;
542 if (strlen(buf)>0) cprintf("%s\n", buf);
544 /* If the message on disk is format 0 (Citadel vari-format), we
545 * output using the formatter at 80 columns. This is the final output
546 * form if the transfer format is RFC822, but if the transfer format
547 * is Citadel proprietary, it'll still work, because the indentation
548 * for new paragraphs is correct and the client will reformat the
549 * message to the reader's screen width.
551 if (format_type == 0) {
563 * display a message (mode 0 - Citadel proprietary)
565 void cmd_msg0(char *cmdbuf)
568 int headers_only = 0;
569 int desired_section = 0;
571 extract(msgid,cmdbuf,0);
572 headers_only = extract_int(cmdbuf, 1);
573 desired_section = extract_int(cmdbuf, 2);
575 output_message(msgid,MT_CITADEL, headers_only, desired_section);
580 * display a message (mode 2 - RFC822)
582 void cmd_msg2(char *cmdbuf)
585 int headers_only = 0;
587 extract(msgid,cmdbuf,0);
588 headers_only = extract_int(cmdbuf,1);
590 output_message(msgid,MT_RFC822,headers_only,0);
594 * display a message (mode 3 - IGnet raw format - internal programs only)
596 void cmd_msg3(char *cmdbuf)
599 int headers_only = 0;
601 if (CC->internal_pgm == 0) {
602 cprintf("%d This command is for internal programs only.\n",
607 extract(msgid,cmdbuf,0);
608 headers_only = extract_int(cmdbuf,1);
610 output_message(msgid,MT_RAW,headers_only,0);
616 * Message base operation to send a message to the master file
617 * (returns new message number)
619 long send_message(char *message_in_memory, /* pointer to buffer */
620 size_t message_length, /* length of buffer */
621 int generate_id) { /* 1 to generate an I field */
625 /* Get a new message number */
626 newmsgid = get_new_message_number();
628 /* Write our little bundle of joy into the message base */
630 lprintf(9, "Storing message %ld\n", newmsgid);
631 begin_critical_section(S_MSGMAIN);
632 if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
633 message_in_memory, message_length) < 0 ) {
634 lprintf(2, "Can't store message\n");
635 end_critical_section(S_MSGMAIN);
638 end_critical_section(S_MSGMAIN);
640 /* Finally, return the pointers */
647 * this is a simple file copy routine.
649 void copy_file(char *from, char *to)
655 if (ffp==NULL) return;
661 while (a=getc(ffp), a>=0) {
672 * message base operation to save a message and install its pointers
674 void save_message(char *mtmp, /* file containing proper message */
675 char *rec, /* Recipient (if mail) */
676 char mtsflag, /* 0 for normal, 1 to force Aide> room */
677 int mailtype, /* local or remote type, see citadel.h */
678 int generate_id) /* set to 1 to generate an 'I' field */
681 char hold_rm[ROOMNAMELEN];
682 char actual_rm[ROOMNAMELEN];
685 char *message_in_memory;
689 struct usersupp userbuf;
691 /* Measure the message */
692 lprintf(9, "Measuring the message\n");
693 stat(mtmp, &statbuf);
694 templen = statbuf.st_size;
696 /* Now read it into memory */
697 lprintf(9, "Allocating %ld bytes\n", templen);
698 message_in_memory = (char *) malloc(templen);
699 if (message_in_memory == NULL) {
700 lprintf(2, "Can't allocate memory to save message!\n");
704 lprintf(9, "Reading it into memory\n");
705 fp = fopen(mtmp, "rb");
706 fread(message_in_memory, templen, 1, fp);
709 newmsgid = send_message(message_in_memory, templen, generate_id);
710 free(message_in_memory);
711 if (newmsgid <= 0L) return;
713 strcpy(actual_rm, CC->quickroom.QRname);
715 strcpy(recipient, rec);
717 /* If the user is a twit, move to the twit room for posting... */
718 if (TWITDETECT) if (CC->usersupp.axlevel==2) {
719 strcpy(hold_rm, actual_rm);
720 strcpy(actual_rm, config.c_twitroom);
723 /* ...or if this is a private message, go to the target mailbox. */
724 if (strlen(recipient) > 0) {
725 mailtype = alias(recipient);
726 if (mailtype == M_LOCAL) {
727 if (getuser(&userbuf, recipient)!=0) {
728 mtsflag = 1; /* User not found, goto Aide */
731 strcpy(hold_rm, actual_rm);
732 MailboxName(actual_rm, &userbuf, MAILROOM);
737 /* ...or if this message is destined for Aide> then go there. */
739 strcpy(hold_rm, actual_rm);
740 strcpy(actual_rm, AIDEROOM);
744 /* This call to usergoto() changes rooms if necessary. It also
745 * causes the latest message list to be read into memory.
747 lprintf(9, "Changing rooms if necessary...\n");
748 usergoto(actual_rm, 0);
750 /* read in the quickroom record, obtaining a lock... */
751 lprintf(9, "Reading/locking <%s>...\n", actual_rm);
752 lgetroom(&CC->quickroom, actual_rm);
753 lprintf(9, "Fetching message list...\n");
754 get_msglist(&CC->quickroom);
756 /* FIX here's where we have to handle message expiry!! */
758 /* Now add the new message */
759 CC->num_msgs = CC->num_msgs + 1;
760 CC->msglist = realloc(CC->msglist,
761 ((CC->num_msgs) * sizeof(long)) );
762 if (CC->msglist == NULL) {
763 lprintf(3, "ERROR: can't realloc message list!\n");
765 SetMessageInList(CC->num_msgs - 1, newmsgid);
767 /* Write it back to disk. */
768 lprintf(9, "Writing message list...\n");
769 put_msglist(&CC->quickroom);
771 /* update quickroom */
772 CC->quickroom.QRhighest = newmsgid;
773 lprintf(9, "Writing/unlocking room <%s>...\n", actual_rm);
774 lputroom(&CC->quickroom, actual_rm);
776 /* Bump this user's messages posted counter. Also, if the user is a
777 * twit, give them access to the twit room.
779 lgetuser(&CC->usersupp, CC->curr_user);
780 CC->usersupp.posted = CC->usersupp.posted + 1;
781 /* FIX if user is twit, grant access to twitroom here */
782 lputuser(&CC->usersupp, CC->curr_user);
784 /* Network mail - send a copy to the network program. */
785 if ((strlen(recipient)>0)&&(mailtype != M_LOCAL)) {
786 sprintf(aaa,"./network/spoolin/nm.%d",getpid());
788 system("exec nohup ./netproc >/dev/null 2>&1 &");
791 /* If we've posted in a room other than the current room, then we
792 * have to now go back to the current room...
794 if (strlen(hold_rm) > 0) {
795 lprintf(9, "Returning to <%s>\n", hold_rm);
796 usergoto(hold_rm, 0);
798 lprintf(9, "Deleting temporary file\n");
799 unlink(mtmp); /* delete the temporary file */
800 lprintf(9, "Finished with save_message()\n");
805 * Generate an administrative message and post it in the Aide> room.
807 void aide_message(char *text)
813 fp=fopen(CC->temp,"wb");
814 fprintf(fp,"%c%c%c",255,MES_NORMAL,0);
815 fprintf(fp,"Psysop%c",0);
816 fprintf(fp,"T%ld%c",now,0);
817 fprintf(fp,"ACitadel%c",0);
818 fprintf(fp,"OAide%c",0);
819 fprintf(fp,"N%s%c",NODENAME,0);
820 fprintf(fp,"M%s\n%c",text,0);
822 save_message(CC->temp,"",1,M_LOCAL,1);
823 syslog(LOG_NOTICE,text);
829 * Build a binary message to be saved on disk.
832 char *filename, /* temporary file name */
833 struct usersupp *author, /* author's usersupp structure */
834 char *recipient, /* NULL if it's not mail */
835 char *room, /* room where it's going */
836 int type, /* see MES_ types in header file */
837 int net_type, /* see MES_ types in header file */
838 int format_type, /* local or remote (see citadel.h) */
839 char *fake_name, /* who we're masquerading as */
840 char *boundary) { /* boundary (if exist attachments) */
848 /* Don't confuse the poor folks if it's not routed mail. */
849 strcpy(dest_node, "");
851 /* If net_type is M_BINARY, split out the destination node. */
852 if (net_type == M_BINARY) {
853 strcpy(dest_node,NODENAME);
854 for (a=0; a<strlen(recipient); ++a) {
855 if (recipient[a]=='@') {
857 strcpy(dest_node,&recipient[a+1]);
862 /* if net_type is M_INTERNET, set the dest node to 'internet' */
863 if (net_type == M_INTERNET) {
864 strcpy(dest_node,"internet");
867 while (isspace(recipient[strlen(recipient)-1]))
868 recipient[strlen(recipient)-1] = 0;
871 fp=fopen(filename,"w");
873 putc(type,fp); /* Normal or anonymous, see MES_ flags */
874 putc(format_type,fp); /* Formatted or unformatted */
875 fprintf(fp,"Pcit%ld%c",author->usernum,0); /* path */
876 fprintf(fp,"T%ld%c",now,0); /* date/time */
878 fprintf(fp,"A%s%c",fake_name,0);
880 fprintf(fp,"A%s%c",author->fullname,0); /* author */
881 fprintf(fp,"O%s%c",CC->quickroom.QRname,0); /* room */
882 fprintf(fp,"N%s%c",NODENAME,0); /* nodename */
883 fprintf(fp,"H%s%c",HUMANNODE,0); /* human nodename */
885 if (recipient[0]!=0) fprintf(fp, "R%s%c", recipient, 0);
886 if (dest_node[0]!=0) fprintf(fp, "D%s%c", dest_node, 0);
887 if (boundary[0]!=0) fprintf(fp, "Z%s%c", boundary, 0);
891 while (client_gets(buf), strcmp(buf,"000"))
893 fprintf(fp,"%s\n",buf);
895 syslog(LOG_INFO, "Closing message");
905 * message entry - mode 0 (normal) <bc>
907 void cmd_ent0(char *entargs)
913 char newusername[256]; /* <bc> */
919 struct usersupp tempUS;
922 post = extract_int(entargs,0);
923 extract(recipient,entargs,1);
924 anon_flag = extract_int(entargs,2);
925 format_type = extract_int(entargs,3);
926 extract(boundary, entargs, 5);
928 /* first check to make sure the request is valid. */
930 if (!(CC->logged_in)) {
931 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
934 if ((CC->usersupp.axlevel<2)&&((CC->quickroom.QRflags&QR_MAILBOX)==0)) {
935 cprintf("%d Need to be validated to enter ",
936 ERROR+HIGHER_ACCESS_REQUIRED);
937 cprintf("(except in %s> to sysop)\n", MAILROOM);
940 if ((CC->usersupp.axlevel<4)&&(CC->quickroom.QRflags&QR_NETWORK)) {
941 cprintf("%d Need net privileges to enter here.\n",
942 ERROR+HIGHER_ACCESS_REQUIRED);
945 if ((CC->usersupp.axlevel<6)&&(CC->quickroom.QRflags&QR_READONLY)) {
946 cprintf("%d Sorry, this is a read-only room.\n",
947 ERROR+HIGHER_ACCESS_REQUIRED);
954 if (post==2) { /* <bc> */
955 if (CC->usersupp.axlevel<6)
957 cprintf("%d You don't have permission to do an aide post.\n",
958 ERROR+HIGHER_ACCESS_REQUIRED);
961 extract(newusername,entargs,4);
962 bzero(CC->fake_postname, 32);
963 strcpy(CC->fake_postname, newusername);
964 cprintf("%d Ok\n",OK);
968 CC->cs_flags |= CS_POSTING;
971 if (CC->quickroom.QRflags & QR_MAILBOX) {
972 if (CC->usersupp.axlevel>=2) {
973 strcpy(buf,recipient);
975 else strcpy(buf,"sysop");
976 lprintf(9, "aliasing...\n");
977 e=alias(buf); /* alias and mail type */
978 lprintf(9,"...type is %d\n", e);
979 if ((buf[0]==0) || (e==M_ERROR)) {
980 cprintf("%d Unknown address - cannot send message.\n",
984 if ((e!=M_LOCAL)&&(CC->usersupp.axlevel<4)) {
985 cprintf("%d Net privileges required for network mail.\n",
986 ERROR+HIGHER_ACCESS_REQUIRED);
989 if ((RESTRICT_INTERNET==1)&&(e==M_INTERNET)
990 &&((CC->usersupp.flags&US_INTERNET)==0)
991 &&(!CC->internal_pgm) ) {
992 cprintf("%d You don't have access to Internet mail.\n",
993 ERROR+HIGHER_ACCESS_REQUIRED);
996 if (!strcasecmp(buf,"sysop")) {
1000 if (e!=M_LOCAL) goto SKFALL; /* don't search local file */
1001 if (!strcasecmp(buf,CC->usersupp.fullname)) {
1002 cprintf("%d Can't send mail to yourself!\n",
1003 ERROR+NO_SUCH_USER);
1007 /* Check to make sure the user exists; also get the correct
1008 * upper/lower casing of the name.
1010 lprintf(9, "checking validity of %s\n", buf);
1011 a = getuser(&tempUS,buf);
1012 lprintf(9, "getuser() returned %d\n", a);
1014 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
1017 strcpy(buf,tempUS.fullname);
1020 SKFALL: b=MES_NORMAL;
1021 if (CC->quickroom.QRflags&QR_ANONONLY) b=MES_ANON;
1022 if (CC->quickroom.QRflags&QR_ANONOPT) {
1023 if (anon_flag==1) b=MES_AN2;
1025 if ((CC->quickroom.QRflags & QR_MAILBOX) == 0) buf[0]=0;
1027 /* If we're only checking the validity of the request, return
1028 * success without creating the message.
1031 cprintf("%d %s\n",OK,buf);
1035 cprintf("%d send message\n",SEND_LISTING);
1036 if (CC->fake_postname[0])
1037 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname, boundary);
1039 if (CC->fake_username[0])
1040 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username, boundary);
1042 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "", boundary);
1043 save_message(CC->temp,buf,mtsflag,e,1);
1044 CC->fake_postname[0]='\0';
1051 * message entry - mode 3 (raw)
1053 void cmd_ent3(char *entargs)
1059 struct usersupp tempUS;
1064 if (CC->internal_pgm == 0) {
1065 cprintf("%d This command is for internal programs only.\n",
1070 /* If we're in Mail, check the recipient */
1071 if (CC->quickroom.QRflags & QR_MAILBOX) {
1072 extract(recp, entargs, 1);
1073 lprintf(9, "aliasing...\n");
1074 e=alias(recp); /* alias and mail type */
1075 lprintf(9,"...type is %d\n", e);
1076 if ((buf[0]==0) || (e==M_ERROR)) {
1077 cprintf("%d Unknown address - cannot send message.\n",
1078 ERROR+NO_SUCH_USER);
1082 a = getuser(&tempUS,recp);
1084 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
1090 /* At this point, message has been approved. */
1091 if (extract_int(entargs, 0) == 0) {
1092 cprintf("%d OK to send\n", OK);
1096 /* open a temp file to hold the message */
1097 fp = fopen(CC->temp, "wb");
1099 cprintf("%d Cannot open %s: %s\n",
1100 ERROR + INTERNAL_ERROR,
1101 CC->temp, strerror(errno) );
1105 msglen = extract_long(entargs, 2);
1106 cprintf("%d %ld\n", SEND_BINARY, msglen);
1107 while(msglen > 0L) {
1108 bloklen = ((msglen >= 255L) ? 255 : msglen);
1109 client_read(buf, (int)bloklen );
1110 fwrite(buf, (int)bloklen, 1, fp);
1111 msglen = msglen - bloklen;
1115 save_message(CC->temp, recp, 0, e, 0);
1120 * Delete message from current room
1122 void cmd_dele(char *delstr)
1127 getuser(&CC->usersupp,CC->curr_user);
1128 if ((CC->usersupp.axlevel < 6)
1129 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1130 cprintf("%d Higher access required.\n",
1131 ERROR+HIGHER_ACCESS_REQUIRED);
1135 delnum = atol(delstr);
1136 if (CC->quickroom.QRflags & QR_MAILBOX) {
1137 cprintf("%d Can't delete mail.\n",ERROR);
1141 /* get room records, obtaining a lock... */
1142 lgetroom(&CC->quickroom,CC->quickroom.QRname);
1143 get_msglist(&CC->quickroom);
1146 if (CC->num_msgs > 0) for (a=0; a<(CC->num_msgs); ++a) {
1147 if (MessageFromList(a) == delnum) {
1148 SetMessageInList(a, 0L);
1153 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1154 CC->quickroom.QRhighest = MessageFromList(CC->num_msgs - 1);
1156 put_msglist(&CC->quickroom);
1157 lputroom(&CC->quickroom,CC->quickroom.QRname);
1159 cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
1160 cprintf("%d Message deleted.\n",OK);
1162 else cprintf("%d No message %ld.\n",ERROR,delnum);
1167 * move a message to another room
1169 void cmd_move(char *args)
1174 struct quickroom qtemp;
1177 num = extract_long(args,0);
1178 extract(targ,args,1);
1180 getuser(&CC->usersupp,CC->curr_user);
1181 if ((CC->usersupp.axlevel < 6)
1182 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1183 cprintf("%d Higher access required.\n",
1184 ERROR+HIGHER_ACCESS_REQUIRED);
1188 if (getroom(&qtemp, targ) != 0) {
1189 cprintf("%d '%s' does not exist.\n",ERROR,targ);
1193 /* yank the message out of the current room... */
1194 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1195 get_msglist(&CC->quickroom);
1198 for (a=0; a<(CC->num_msgs); ++a) {
1199 if (MessageFromList(a) == num) {
1201 SetMessageInList(a, 0L);
1205 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1206 put_msglist(&CC->quickroom);
1207 CC->quickroom.QRhighest = MessageFromList((CC->num_msgs)-1);
1209 lputroom(&CC->quickroom,CC->quickroom.QRname);
1211 cprintf("%d msg %ld does not exist.\n",ERROR,num);
1215 /* put the message into the target room */
1217 cprintf("%d FIX FIX FIX implement this!!!!!\n", ERROR);