17 #include "sysdep_decls.h"
29 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 /* cprintf("*** 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 /* cprintf("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)
147 extract(which,cmdbuf,0);
151 if (!strncasecmp(which,"OLD",3)) mode = MSGS_OLD;
152 if (!strncasecmp(which,"NEW",3)) mode = MSGS_NEW;
153 if (!strncasecmp(which,"FIRST",5)) {
155 cm_howmany = extract_int(cmdbuf,1);
157 if (!strncasecmp(which,"LAST",4)) {
159 cm_howmany = extract_int(cmdbuf,1);
161 if (!strncasecmp(which,"GT",2)) {
163 cm_gt = extract_long(cmdbuf,1);
166 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
167 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
170 if (CC->curr_rm < 0) {
171 cprintf("%d no room\n",ERROR);
175 get_msglist(CC->curr_rm);
176 getuser(&CC->usersupp,CC->curr_user);
177 cprintf("%d %d messages...\n",LISTING_FOLLOWS, CC->num_msgs);
178 if (CC->num_msgs != 0) {
179 for (a=0; a<(CC->num_msgs); ++a)
180 if ((MessageFromList(a) >=0)
184 || ((mode==MSGS_OLD) && (MessageFromList(a) <= CC->usersupp.lastseen[CC->curr_rm]))
185 || ((mode==MSGS_NEW) && (MessageFromList(a) > CC->usersupp.lastseen[CC->curr_rm]))
186 || ((mode==MSGS_NEW) && (MessageFromList(a) >= CC->usersupp.lastseen[CC->curr_rm])
187 && (CC->usersupp.flags & US_LASTOLD))
188 || ((mode==MSGS_LAST)&& (a>=(CC->num_msgs-cm_howmany)))
189 || ((mode==MSGS_FIRST)&&(a<cm_howmany))
190 || ((mode==MSGS_GT) && (MessageFromList(a) > cm_gt))
194 cprintf("%ld\n", MessageFromList(a));
203 * help_subst() - support routine for help file viewer
205 void help_subst(char *strbuf, char *source, char *dest)
210 while (p=pattern2(strbuf,source), (p>=0)) {
211 strcpy(workbuf,&strbuf[p+strlen(source)]);
212 strcpy(&strbuf[p],dest);
213 strcat(strbuf,workbuf);
218 void do_help_subst(char *buffer)
222 help_subst(buffer,"^nodename",config.c_nodename);
223 help_subst(buffer,"^humannode",config.c_humannode);
224 help_subst(buffer,"^fqdn",config.c_fqdn);
225 help_subst(buffer,"^username",CC->usersupp.fullname);
226 sprintf(buf2,"%ld",CC->usersupp.usernum);
227 help_subst(buffer,"^usernum",buf2);
228 help_subst(buffer,"^sysadm",config.c_sysadm);
229 help_subst(buffer,"^variantname",CITADEL);
230 sprintf(buf2,"%d",config.c_maxsessions);
231 help_subst(buffer,"^maxsessions",buf2);
237 * memfmout() - Citadel text formatter and paginator.
238 * Although the original purpose of this routine was to format
239 * text to the reader's screen width, all we're really using it
240 * for here is to format text out to 80 columns before sending it
241 * to the client. The client software may reformat it again.
243 void memfmout(int width, char *mptr, char subst)
244 /* screen width to use */
245 /* where are we going to get our text from? */
246 /* nonzero if we should use hypertext mode */
253 strcpy(aaa,""); old=255;
255 c=1; /* c is the current pos */
258 while (ch=*mptr, ((ch!=0) && (strlen(buffer)<126) )) {
260 buffer[strlen(buffer)+1] = 0;
261 buffer[strlen(buffer)] = ch;
264 if (buffer[0]=='^') do_help_subst(buffer);
266 buffer[strlen(buffer)+1] = 0;
268 strcpy(buffer,&buffer[1]);
275 if (ch<=0) goto FMTEND;
277 if ( ((ch==13)||(ch==10)) && (old!=13) && (old!=10) ) ch=32;
278 if ( ((old==13)||(old==10)) && (isspace(real)) ) {
282 if (ch>126) goto FMTA;
285 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
286 { cprintf("\n%s",aaa); c=strlen(aaa); aaa[0]=0;
288 b=strlen(aaa); aaa[b]=ch; aaa[b+1]=0; }
290 if ((strlen(aaa)+c)>(width-5)) {
294 cprintf("%s ",aaa); ++c; c=c+strlen(aaa);
298 if ((ch==13)||(ch==10)) {
306 FMTEND: cprintf("\n");
311 * get a message off disk.
314 void output_message(char *msgid, int mode, int headers_only)
319 CIT_UBYTE format_type,anon_flag;
324 struct cdbdata *dmsgtext;
327 /* buffers needed for RFC822 translation */
336 msg_num = atol(msgid);
339 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
340 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
343 if (CC->curr_rm < 0) {
344 cprintf("%d No room selected.\n",ERROR);
348 /* We used to need to check in the current room's message list
349 * to determine where the message's disk position. We no longer need
350 * to do this, but we do it anyway as a security measure, in order to
351 * prevent rogue clients from reading messages not in the current room.
355 if (CC->num_msgs > 0) {
356 for (a=0; a<CC->num_msgs; ++a) {
357 if (MessageFromList(a) == msg_num) {
364 cprintf("%d Message %ld is not in this room.\n",
370 dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
372 if (dmsgtext == NULL) {
373 cprintf("%d Can't find message %ld\n", ERROR+INTERNAL_ERROR);
377 msg_len = (long) dmsgtext->len;
378 mptr = dmsgtext->ptr;
379 lprintf(9, "Returned message length is %ld\n", msg_len);
381 /* this loop spews out the whole message if we're doing raw format */
382 if (mode == MT_RAW) {
383 cprintf("%d %ld\n", BINARY_FOLLOWS, msg_len);
384 client_write(dmsgtext->ptr, (int) msg_len);
389 /* Otherwise, we'll start parsing it field by field... */
392 cprintf("%d Illegal message format on disk\n",
393 ERROR+INTERNAL_ERROR);
399 format_type = *mptr++;
401 /* now for the user-mode message reading loops */
402 cprintf("%d Message %ld:\n",LISTING_FOLLOWS,msg_num);
404 if (mode == MT_CITADEL) cprintf("type=%d\n",format_type);
406 if ( (anon_flag == MES_ANON) && (mode == MT_CITADEL) ) {
407 cprintf("nhdr=yes\n");
410 /* begin header processing loop for Citadel message format */
412 if (mode == MT_CITADEL) while(ch = *mptr++, (ch!='M' && ch!=0)) {
415 buf[strlen(buf)+1] = 0;
417 buf[strlen(buf)] = rch;
421 if (anon_flag==MES_ANON) cprintf("from=****");
422 else if (anon_flag==MES_AN2) cprintf("from=anonymous");
423 else cprintf("from=%s",buf);
424 if ((is_room_aide()) && ((anon_flag == MES_ANON)
425 || (anon_flag == MES_AN2)))
426 cprintf(" [%s]",buf);
429 else if (ch=='P') cprintf("path=%s\n",buf);
430 else if (ch=='U') cprintf("subj=%s\n",buf);
431 else if (ch=='I') cprintf("msgn=%s\n",buf);
432 else if (ch=='H') cprintf("hnod=%s\n",buf);
433 else if (ch=='O') cprintf("room=%s\n",buf);
434 else if (ch=='N') cprintf("node=%s\n",buf);
435 else if (ch=='R') cprintf("rcpt=%s\n",buf);
436 else if (ch=='T') cprintf("time=%s\n",buf);
437 /* else cprintf("fld%c=%s\n",ch,buf); */
440 /* begin header processing loop for RFC822 transfer format */
444 strcpy(snode, NODENAME);
445 strcpy(lnode, HUMANNODE);
446 if (mode == MT_RFC822) while(ch = *mptr++, (ch!='M' && ch!=0)) {
449 buf[strlen(buf)+1] = 0;
451 buf[strlen(buf)] = rch;
454 if (ch=='A') strcpy(luser, buf);
456 cprintf("Path: %s\n",buf);
457 for (a=0; a<strlen(buf); ++a) {
459 strcpy(buf,&buf[a+1]);
465 else if (ch=='U') cprintf("Subject: %s\n",buf);
466 else if (ch=='I') strcpy(mid, buf);
467 else if (ch=='H') strcpy(lnode, buf);
468 else if (ch=='O') cprintf("X-Citadel-Room: %s\n",buf);
469 else if (ch=='N') strcpy(snode, buf);
470 else if (ch=='R') cprintf("To: %s\n",buf);
473 cprintf("Date: %s", asctime(localtime(&xtime)));
477 if (mode == MT_RFC822) {
478 if (!strcasecmp(snode, NODENAME)) {
481 cprintf("Message-ID: <%s@%s>\n", mid, snode);
482 cprintf("From: %s@%s (%s)\n",
483 suser, snode, luser);
484 cprintf("Organization: %s\n", lnode);
487 /* end header processing loop ... at this point, we're in the text */
490 cprintf("text\n*** ?Message truncated\n000\n");
496 /* give 'em a length */
498 while(och=ch, ch = *mptr++, ch>0) {
501 cprintf("mlen=%ld\n", msg_len);
507 /* signify start of msg text */
508 if (mode == MT_CITADEL) cprintf("text\n");
509 if (mode == MT_RFC822) cprintf("\n");
511 /* If the format type on disk is 1 (fixed-format), then we want
512 * everything to be output completely literally ... regardless of
513 * what message transfer format is in use.
515 if (format_type == 1) {
518 while(och=ch, ch = *mptr++, ch>0) {
519 if (ch == 13) ch = 10;
521 /* if ((ch!=10)||(och!=10)) { */
527 /* cprintf("%c", ch); */
531 if (len!=0) cprintf("%c", 10);
533 /* If the message on disk is format 0 (Citadel vari-format), we
534 * output using the formatter at 80 columns. This is the final output
535 * form if the transfer format is RFC822, but if the transfer format
536 * is Citadel proprietary, it'll still work, because the indentation
537 * for new paragraphs is correct and the client will reformat the
538 * message to the reader's screen width.
540 if (format_type == 0) {
552 * display a message (mode 0 - Citadel proprietary)
554 void cmd_msg0(char *cmdbuf)
557 int headers_only = 0;
559 extract(msgid,cmdbuf,0);
560 headers_only = extract_int(cmdbuf,1);
562 output_message(msgid,MT_CITADEL,headers_only);
567 * display a message (mode 2 - RFC822)
569 void cmd_msg2(char *cmdbuf)
572 int headers_only = 0;
574 extract(msgid,cmdbuf,0);
575 headers_only = extract_int(cmdbuf,1);
577 output_message(msgid,MT_RFC822,headers_only);
581 * display a message (mode 3 - IGnet raw format - internal programs only)
583 void cmd_msg3(char *cmdbuf)
586 int headers_only = 0;
588 if (CC->internal_pgm == 0) {
589 cprintf("%d This command is for internal programs only.\n",
594 extract(msgid,cmdbuf,0);
595 headers_only = extract_int(cmdbuf,1);
597 output_message(msgid,MT_RAW,headers_only);
603 * Message base operation to send a message to the master file
604 * (returns new message number)
606 long send_message(char *message_in_memory, /* pointer to buffer */
607 size_t message_length, /* length of buffer */
608 int generate_id) { /* 1 to generate an I field */
612 /* Get a new message number */
613 newmsgid = get_new_message_number();
615 /* Write our little bundle of joy into the message base */
617 lprintf(9, "Storing message %ld\n", newmsgid);
618 begin_critical_section(S_MSGMAIN);
619 if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
620 message_in_memory, message_length) < 0 ) {
621 lprintf(2, "Can't store message\n");
622 end_critical_section(S_MSGMAIN);
625 end_critical_section(S_MSGMAIN);
627 /* Finally, return the pointers */
636 void loadtroom(void) {
637 struct quickroom qrbuf;
641 /* first try to locate the twit room */
642 for (a=0; a<MAXROOMS; ++a) {
644 if (!strcasecmp(qrbuf.QRname,config.c_twitroom)) {
650 /* if not found, try to create it - put it in the last slot */
651 twitroom = get_free_room_slot(-1);
653 newflags = create_room(twitroom,config.c_twitroom,0,"",0);
657 /* as a last resort, point to Aide> */
663 * this is a simple file copy routine.
665 void copy_file(char *from, char *to)
671 if (ffp==NULL) return;
677 while (a=getc(ffp), a>=0) {
688 * message base operation to save a message and install its pointers
690 void save_message(char *mtmp, /* file containing proper message */
691 char *rec, /* Recipient (if mail) */
692 char mtsflag, /* 0 for normal, 1 to force Aide> room */
693 int mailtype, /* local or remote type, see citadel.h */
694 int generate_id) /* set to 1 to generate an 'I' field */
696 struct usersupp tempUS;
699 struct cdbdata *cdbmb;
703 char *message_in_memory;
708 /* Measure the message */
709 lprintf(9, "Measuring the message\n");
710 stat(mtmp, &statbuf);
711 templen = statbuf.st_size;
713 /* Now read it into memory */
714 lprintf(9, "Allocating %ld bytes\n", templen);
715 message_in_memory = (char *) malloc(templen);
716 if (message_in_memory == NULL) {
717 lprintf(2, "Can't allocate memory to save message!\n");
721 lprintf(9, "Reading it into memory\n");
722 fp = fopen(mtmp, "rb");
723 fread(message_in_memory, templen, 1, fp);
726 newmsgid = send_message(message_in_memory, templen, generate_id);
727 free(message_in_memory);
728 if (newmsgid <= 0L) return;
731 /* If the user is a twit, move to the twit room for posting... */
732 if (TWITDETECT) if (CC->usersupp.axlevel==2) {
733 if (twitroom<0) loadtroom();
735 CC->curr_rm=twitroom;
738 /* ...or if this message is destined for Aide> then go there. */
744 /* This call to usergoto() changes rooms if necessary. It also
745 * causes the latest message list to be read into memory.
747 usergoto(CC->curr_rm,0);
749 /* Store the message pointer, but NOT for sent mail! */
750 if (CC->curr_rm != 1) {
752 /* read in the quickroom record, obtaining a lock... */
753 lgetroom(&CC->quickroom,CC->curr_rm);
754 get_msglist(CC->curr_rm);
756 /* FIX here's where we have to to 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 put_msglist(CC->curr_rm);
770 /* update quickroom */
771 CC->quickroom.QRhighest = newmsgid;
772 lputroom(&CC->quickroom,CC->curr_rm);
775 /* Bump this user's messages posted counter. Also, if the user is a
776 * twit, give them access to the twit room.
778 lgetuser(&CC->usersupp,CC->curr_user);
779 CC->usersupp.posted = CC->usersupp.posted + 1;
780 if (CC->curr_rm==twitroom) {
781 CC->usersupp.generation[twitroom] = CC->quickroom.QRgen;
783 lputuser(&CC->usersupp, CC->curr_user);
785 /* If mail, there's still more to do, if not, skip it. */
786 if ((CC->curr_rm!=1)||(mtsflag)) goto ENTFIN;
788 /* Network mail - send a copy to the network program. */
789 if (mailtype!=M_LOCAL) {
790 sprintf(aaa,"./network/spoolin/nm.%d",getpid());
792 system("exec nohup ./netproc >/dev/null 2>&1 &");
795 /* Local mail - put a copy in the recipient's mailbox. */
796 /* FIX here's where we have to handle expiry, stuffed boxes, etc. */
797 if (mailtype == M_LOCAL) {
798 if (lgetuser(&tempUS,rec)==0) {
800 cdbmb = cdb_fetch(CDB_MAILBOXES,
801 &tempUS.usernum, sizeof(long));
803 memcpy(dmailbox, cdbmb->ptr, cdbmb->len);
804 dnum_mails = cdbmb->len / sizeof(long);
813 if (dmailbox == NULL) {
814 dmailbox = malloc(sizeof(long) * dnum_mails);
817 dmailbox = realloc(dmailbox,
818 sizeof(long) * dnum_mails);
821 dmailbox[dnum_mails - 1] = newmsgid;
822 cdb_store(CDB_MAILBOXES, &tempUS.usernum, sizeof(long),
823 dmailbox, (dnum_mails * sizeof(long)) );
824 lputuser(&tempUS,rec);
829 /* If we've posted in a room other than the current room, then we
830 * have to now go back to the current room...
832 ENTFIN: if (hold_rm!=(-1)) {
835 unlink(mtmp); /* delete the temporary file */
840 * Generate an administrative message and post it in the Aide> room.
842 void aide_message(char *text)
848 fp=fopen(CC->temp,"wb");
849 fprintf(fp,"%c%c%c",255,MES_NORMAL,0);
850 fprintf(fp,"Psysop%c",0);
851 fprintf(fp,"T%ld%c",now,0);
852 fprintf(fp,"ACitadel%c",0);
853 fprintf(fp,"OAide%c",0);
854 fprintf(fp,"N%s%c",NODENAME,0);
855 fprintf(fp,"M%s\n%c",text,0);
857 save_message(CC->temp,"",1,M_LOCAL,1);
858 syslog(LOG_NOTICE,text);
864 * Build a binary message to be saved on disk.
866 void make_message(char *filename, struct usersupp *author, char *recipient, char *room, int type, int net_type, int format_type, char *fake_name)
867 /* temporary file name */
868 /* author's usersupp structure */
869 /* NULL if it's not mail */
870 /* room where it's going */
871 /* see MES_ types in header file */
872 /* local or remote type, see citadel.h */
873 /* format type (see citadel.h) */
881 /* Don't confuse the poor folks if it's not routed mail. */
882 strcpy(dest_node, "");
884 /* If net_type is M_BINARY, split out the destination node. */
885 if (net_type == M_BINARY) {
886 strcpy(dest_node,NODENAME);
887 for (a=0; a<strlen(recipient); ++a) {
888 if (recipient[a]=='@') {
890 strcpy(dest_node,&recipient[a+1]);
895 /* if net_type is M_INTERNET, set the dest node to 'internet' */
896 if (net_type == M_INTERNET) {
897 strcpy(dest_node,"internet");
900 while (isspace(recipient[strlen(recipient)-1]))
901 recipient[strlen(recipient)-1] = 0;
904 fp=fopen(filename,"w");
906 putc(type,fp); /* Normal or anonymous, see MES_ flags */
907 putc(format_type,fp); /* Formatted or unformatted */
908 fprintf(fp,"Pcit%ld%c",author->usernum,0); /* path */
909 fprintf(fp,"T%ld%c",now,0); /* date/time */
911 fprintf(fp,"A%s%c",fake_name,0);
913 fprintf(fp,"A%s%c",author->fullname,0); /* author */
914 fprintf(fp,"O%s%c",CC->quickroom.QRname,0); /* room */
915 fprintf(fp,"N%s%c",NODENAME,0); /* nodename */
916 fprintf(fp,"H%s%c",HUMANNODE,0); /* human nodename */
918 if (recipient[0]!=0) fprintf(fp,"R%s%c",recipient,0);
919 if (dest_node[0]!=0) fprintf(fp,"D%s%c",dest_node,0);
923 while (client_gets(buf), strcmp(buf,"000"))
925 fprintf(fp,"%s\n",buf);
927 syslog(LOG_INFO, "Closing message");
937 * message entry - mode 0 (normal) <bc>
939 void cmd_ent0(char *entargs)
945 char newusername[256]; /* <bc> */
949 struct usersupp tempUS;
952 post = extract_int(entargs,0);
953 extract(recipient,entargs,1);
954 anon_flag = extract_int(entargs,2);
955 format_type = extract_int(entargs,3);
957 /* first check to make sure the request is valid. */
959 if (!(CC->logged_in)) {
960 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
963 if (CC->curr_rm < 0) {
964 cprintf("%d No room selected.\n",ERROR);
967 if ((CC->usersupp.axlevel<2)&&(CC->curr_rm!=1)) {
968 cprintf("%d Need to be validated to enter (except in Mail> to sysop)\n",
969 ERROR+HIGHER_ACCESS_REQUIRED);
972 if ((CC->usersupp.axlevel<4)&&(CC->quickroom.QRflags&QR_NETWORK)) {
973 cprintf("%d Need net privileges to enter here.\n",
974 ERROR+HIGHER_ACCESS_REQUIRED);
977 if ((CC->usersupp.axlevel<6)&&(CC->quickroom.QRflags&QR_READONLY)) {
978 cprintf("%d Sorry, this is a read-only room.\n",
979 ERROR+HIGHER_ACCESS_REQUIRED);
986 if (post==2) { /* <bc> */
987 if (CC->usersupp.axlevel<6)
989 cprintf("%d\nYou don't have sufficient permission to do an aide post.\n", ERROR+HIGHER_ACCESS_REQUIRED);
992 extract(newusername,entargs,4);
993 bzero(CC->fake_postname, 32);
994 strcpy(CC->fake_postname, newusername);
995 cprintf("%d Ok\n",OK);
999 CC->cs_flags |= CS_POSTING;
1002 if (CC->curr_rm==1) {
1003 if (CC->usersupp.axlevel>=2) {
1004 strcpy(buf,recipient);
1006 else strcpy(buf,"sysop");
1007 lprintf(9, "aliasing...\n");
1008 e=alias(buf); /* alias and mail type */
1009 lprintf(9,"...type is %d\n", e);
1010 if ((buf[0]==0) || (e==M_ERROR)) {
1011 cprintf("%d Unknown address - cannot send message.\n",
1012 ERROR+NO_SUCH_USER);
1015 if ((e!=M_LOCAL)&&(CC->usersupp.axlevel<4)) {
1016 cprintf("%d Net privileges required for network mail.\n",
1017 ERROR+HIGHER_ACCESS_REQUIRED);
1020 if ((RESTRICT_INTERNET==1)&&(e==M_INTERNET)
1021 &&((CC->usersupp.flags&US_INTERNET)==0)
1022 &&(!CC->internal_pgm) ) {
1023 cprintf("%d You don't have access to Internet mail.\n",
1024 ERROR+HIGHER_ACCESS_REQUIRED);
1027 if (!strcasecmp(buf,"sysop")) {
1031 if (e!=M_LOCAL) goto SKFALL; /* don't search local file */
1032 if (!strcasecmp(buf,CC->usersupp.fullname)) {
1033 cprintf("%d Can't send mail to yourself!\n",
1034 ERROR+NO_SUCH_USER);
1038 /* Check to make sure the user exists; also get the correct
1039 * upper/lower casing of the name.
1041 lprintf(9, "checking validity of %s\n", buf);
1042 a = getuser(&tempUS,buf);
1043 lprintf(9, "getuser() returned %d\n", a);
1045 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
1048 strcpy(buf,tempUS.fullname);
1051 SKFALL: b=MES_NORMAL;
1052 if (CC->quickroom.QRflags&QR_ANONONLY) b=MES_ANON;
1053 if (CC->quickroom.QRflags&QR_ANON2) {
1054 if (anon_flag==1) b=MES_AN2;
1056 if (CC->curr_rm!=1) buf[0]=0;
1058 /* If we're only checking the validity of the request, return
1059 * success without creating the message.
1062 cprintf("%d %s\n",OK,buf);
1066 cprintf("%d send message\n",SEND_LISTING);
1067 if (CC->fake_postname[0])
1068 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname);
1070 if (CC->fake_username[0])
1071 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username);
1073 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "");
1074 save_message(CC->temp,buf,mtsflag,e,1);
1075 CC->fake_postname[0]='\0';
1082 * message entry - mode 3 (raw)
1084 void cmd_ent3(char *entargs)
1089 struct usersupp tempUS;
1094 if (CC->internal_pgm == 0) {
1095 cprintf("%d This command is for internal programs only.\n",
1100 if (CC->curr_rm < 0) {
1101 cprintf("%d No room selected.\n",ERROR);
1105 if (CC->curr_rm == 1) { /* If we're in Mail, check the recipient */
1106 extract(recp, entargs, 1);
1107 lprintf(9, "aliasing...\n");
1108 e=alias(recp); /* alias and mail type */
1109 lprintf(9,"...type is %d\n", e);
1110 if ((buf[0]==0) || (e==M_ERROR)) {
1111 cprintf("%d Unknown address - cannot send message.\n",
1112 ERROR+NO_SUCH_USER);
1116 a = getuser(&tempUS,recp);
1118 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
1124 /* At this point, message has been approved. */
1125 if (extract_int(entargs, 0) == 0) {
1126 cprintf("%d OK to send\n", OK);
1130 /* open a temp file to hold the message */
1131 fp = fopen(CC->temp, "wb");
1133 cprintf("%d Cannot open %s: %s\n",
1134 ERROR + INTERNAL_ERROR,
1135 CC->temp, strerror(errno) );
1139 msglen = extract_long(entargs, 2);
1140 cprintf("%d %ld\n", SEND_BINARY, msglen);
1141 while(msglen > 0L) {
1142 bloklen = ((msglen >= 255L) ? 255 : msglen);
1143 client_read(buf, (int)bloklen );
1144 fwrite(buf, (int)bloklen, 1, fp);
1145 msglen = msglen - bloklen;
1149 save_message(CC->temp, recp, 0, e, 0);
1154 * Delete message from current room
1156 void cmd_dele(char *delstr)
1161 getuser(&CC->usersupp,CC->curr_user);
1162 if ((CC->usersupp.axlevel < 6)
1163 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1164 cprintf("%d Higher access required.\n",
1165 ERROR+HIGHER_ACCESS_REQUIRED);
1169 delnum = atol(delstr);
1170 if (CC->curr_rm==1) {
1171 cprintf("%d Can't delete mail.\n",ERROR);
1175 /* get room records, obtaining a lock... */
1176 lgetroom(&CC->quickroom,CC->curr_rm);
1177 get_msglist(CC->curr_rm);
1180 if (CC->num_msgs > 0) for (a=0; a<(CC->num_msgs); ++a) {
1181 if (MessageFromList(a) == delnum) {
1182 SetMessageInList(a, 0L);
1187 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1188 CC->quickroom.QRhighest = MessageFromList(CC->num_msgs - 1);
1190 put_msglist(CC->curr_rm);
1191 lputroom(&CC->quickroom,CC->curr_rm);
1193 cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
1194 cprintf("%d Message deleted.\n",OK);
1196 else cprintf("%d No message %ld.\n",ERROR,delnum);
1201 * move a message to another room
1203 void cmd_move(char *args)
1209 struct quickroom qtemp;
1211 struct cdbdata *cdbtarg;
1215 num = extract_long(args,0);
1216 extract(targ,args,1);
1218 if (CC->curr_rm < 0) {
1219 cprintf("%d no room\n",ERROR);
1223 getuser(&CC->usersupp,CC->curr_user);
1224 if ((CC->usersupp.axlevel < 6)
1225 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1226 cprintf("%d Higher access required.\n",
1227 ERROR+HIGHER_ACCESS_REQUIRED);
1232 for (a=0; a<MAXROOMS; ++a) {
1234 if (!strcasecmp(qtemp.QRname,targ)) {
1239 if (targ_slot < 0) {
1240 cprintf("%d '%s' does not exist.\n",ERROR,targ);
1244 /* yank the message out of the current room... */
1245 lgetroom(&CC->quickroom,CC->curr_rm);
1246 get_msglist(CC->curr_rm);
1249 for (a=0; a<(CC->num_msgs); ++a) {
1250 if (MessageFromList(a) == num) {
1252 SetMessageInList(a, 0L);
1256 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1257 put_msglist(CC->curr_rm);
1258 CC->quickroom.QRhighest = MessageFromList((CC->num_msgs)-1);
1260 lputroom(&CC->quickroom,CC->curr_rm);
1262 cprintf("%d msg %ld does not exist.\n",ERROR,num);
1266 /* put the message into the target room */
1267 lgetroom(&qtemp,targ_slot);
1268 cdbtarg = cdb_fetch(CDB_MSGLISTS, &targ_slot, sizeof(int));
1269 if (cdbtarg != NULL) {
1270 targmsgs = malloc(cdbtarg->len);
1271 memcpy(targmsgs, cdbtarg->ptr, cdbtarg->len);
1272 targ_count = cdbtarg->len / sizeof(long);
1281 targmsgs = realloc(targmsgs, ((CC->num_msgs) * sizeof(long)));
1282 targmsgs[targ_count - 1] = num;
1283 targ_count = sort_msglist(targmsgs, targ_count);
1284 qtemp.QRhighest = targmsgs[targ_count - 1];
1285 cdb_store(CDB_MSGLISTS, &targ_slot, sizeof(int),
1286 targmsgs, targ_count * sizeof(long));
1288 lputroom(&qtemp,targ_slot);
1289 cprintf("%d ok\n",OK);