18 #include "sysdep_decls.h"
22 #include "dynloader.h"
31 extern struct config config;
35 * Aliasing for network mail.
36 * (Error messages have been commented out, because this is a server.)
38 int alias(char *name) /* process alias and routing info for mail */
42 char aaa[300],bbb[300];
44 fp=fopen("network/mail.aliases","r");
45 if (fp==NULL) fp=fopen("/dev/null","r");
46 if (fp==NULL) return(M_ERROR);
47 GNA: strcpy(aaa,""); strcpy(bbb,"");
70 if (strcasecmp(name,aaa)) goto GNA;
73 lprintf(7, "Mail is being forwarded to %s\n", name);
75 DETYPE: /* determine local or remote type, see citadel.h */
76 for (a=0; a<strlen(name); ++a) if (name[a]=='!') return(M_INTERNET);
77 for (a=0; a<strlen(name); ++a)
79 for (b=a; b<strlen(name); ++b)
80 if (name[b]=='.') return(M_INTERNET);
81 b=0; for (a=0; a<strlen(name); ++a) if (name[a]=='@') ++b;
83 lprintf(7, "Too many @'s in address\n");
87 for (a=0; a<strlen(name); ++a)
88 if (name[a]=='@') strcpy(bbb,&name[a+1]);
89 while (bbb[0]==32) strcpy(bbb,&bbb[1]);
90 fp = fopen("network/mail.sysinfo","r");
91 if (fp==NULL) return(M_ERROR);
94 } while ((a>=0)&&(strcasecmp(aaa,bbb)));
96 if (!strncmp(aaa,"use ",4)) {
102 if (!strncmp(aaa,"uum",3)) {
104 for (a=0; a<strlen(bbb); ++a) {
105 if (bbb[a]=='@') bbb[a]=0;
106 if (bbb[a]==' ') bbb[a]='_';
108 while(bbb[strlen(bbb)-1]=='_') bbb[strlen(bbb)-1]=0;
109 sprintf(name,&aaa[4],bbb);
112 if (!strncmp(aaa,"bin",3)) {
113 strcpy(aaa,name); strcpy(bbb,name);
114 while (aaa[strlen(aaa)-1]!='@') aaa[strlen(aaa)-1]=0;
115 aaa[strlen(aaa)-1]=0;
116 while (aaa[strlen(aaa)-1]==' ') aaa[strlen(aaa)-1]=0;
117 while (bbb[0]!='@') strcpy(bbb,&bbb[1]);
119 while (bbb[0]==' ') strcpy(bbb,&bbb[1]);
120 sprintf(name,"%s @%s",aaa,bbb);
132 fp=fopen("citadel.control","r");
133 fread((char *)&CitControl,sizeof(struct CitControl),1,fp);
138 * cmd_msgs() - get list of message #'s in this room
140 void cmd_msgs(char *cmdbuf)
149 extract(which,cmdbuf,0);
153 if (!strncasecmp(which,"OLD",3)) mode = MSGS_OLD;
154 if (!strncasecmp(which,"NEW",3)) mode = MSGS_NEW;
155 if (!strncasecmp(which,"FIRST",5)) {
157 cm_howmany = extract_int(cmdbuf,1);
159 if (!strncasecmp(which,"LAST",4)) {
161 cm_howmany = extract_int(cmdbuf,1);
163 if (!strncasecmp(which,"GT",2)) {
165 cm_gt = extract_long(cmdbuf,1);
168 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
169 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
173 get_msglist(&CC->quickroom);
174 getuser(&CC->usersupp,CC->curr_user);
175 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
177 cprintf("%d Message list...\n",LISTING_FOLLOWS);
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) <= vbuf.v_lastseen))
185 || ((mode==MSGS_NEW) && (MessageFromList(a) > vbuf.v_lastseen))
186 || ((mode==MSGS_NEW) && (MessageFromList(a) >= vbuf.v_lastseen)
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 */
255 strcpy(aaa,""); old=255;
257 c=1; /* c is the current pos */
260 while (ch=*mptr, ((ch!=0) && (strlen(buffer)<126) )) {
262 buffer[strlen(buffer)+1] = 0;
263 buffer[strlen(buffer)] = ch;
266 if (buffer[0]=='^') do_help_subst(buffer);
268 buffer[strlen(buffer)+1] = 0;
270 strcpy(buffer,&buffer[1]);
277 if (ch<=0) goto FMTEND;
279 if ( ((ch==13)||(ch==10)) && (old!=13) && (old!=10) ) ch=32;
280 if ( ((old==13)||(old==10)) && (isspace(real)) ) {
284 if (ch>126) goto FMTA;
287 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
288 { cprintf("\n%s",aaa); c=strlen(aaa); aaa[0]=0;
290 b=strlen(aaa); aaa[b]=ch; aaa[b+1]=0; }
292 if ((strlen(aaa)+c)>(width-5)) {
296 cprintf("%s ",aaa); ++c; c=c+strlen(aaa);
300 if ((ch==13)||(ch==10)) {
308 FMTEND: cprintf("\n");
313 * Get a message off disk. (return value is the message's timestamp)
316 time_t output_message(char *msgid, int mode,
317 int headers_only, int desired_section) {
321 CIT_UBYTE format_type,anon_flag;
325 char boundary[256]; /* attachment boundary */
326 char current_section = 0; /* section currently being parsed */
327 int has_attachments = 0;
329 struct cdbdata *dmsgtext;
332 /* buffers needed for RFC822 translation */
341 strcpy(boundary, "");
342 msg_num = atol(msgid);
345 if ((!(CC->logged_in))&&(!(CC->internal_pgm))&&(mode!=MT_DATE)) {
346 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
350 /* We used to need to check in the current room's message list
351 * to determine where the message's disk position. We no longer need
352 * to do this, but we do it anyway as a security measure, in order to
353 * prevent rogue clients from reading messages not in the current room.
357 if (CC->num_msgs > 0) {
358 for (a=0; a<CC->num_msgs; ++a) {
359 if (MessageFromList(a) == msg_num) {
367 cprintf("%d Message %ld is not in this room.\n",
373 dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
375 if (dmsgtext == NULL) {
377 cprintf("%d Can't find message %ld\n",
378 ERROR+INTERNAL_ERROR);
382 msg_len = (long) dmsgtext->len;
383 mptr = dmsgtext->ptr;
385 /* this loop spews out the whole message if we're doing raw format */
386 if (mode == MT_RAW) {
387 cprintf("%d %ld\n", BINARY_FOLLOWS, msg_len);
388 client_write(dmsgtext->ptr, (int) msg_len);
393 /* Otherwise, we'll start parsing it field by field... */
396 cprintf("%d Illegal message format on disk\n",
397 ERROR+INTERNAL_ERROR);
403 format_type = *mptr++;
405 /* Are we just looking for the message date? */
406 if (mode == MT_DATE) while(ch = *mptr++, (ch!='M' && ch!=0)) {
409 buf[strlen(buf)+1] = 0;
411 buf[strlen(buf)] = rch;
422 /* now for the user-mode message reading loops */
423 cprintf("%d Message %ld:\n",LISTING_FOLLOWS,msg_num);
425 if (mode == MT_CITADEL) cprintf("type=%d\n",format_type);
427 if ( (anon_flag == MES_ANON) && (mode == MT_CITADEL) ) {
428 cprintf("nhdr=yes\n");
431 /* begin header processing loop for Citadel message format */
433 if (mode == MT_CITADEL) while(ch = *mptr++, (ch!='M' && ch!=0)) {
436 buf[strlen(buf)+1] = 0;
438 buf[strlen(buf)] = rch;
442 PerformUserHooks(buf, (-1L), EVT_OUTPUTMSG);
443 if (anon_flag==MES_ANON) cprintf("from=****");
444 else if (anon_flag==MES_AN2) cprintf("from=anonymous");
445 else cprintf("from=%s",buf);
446 if ((is_room_aide()) && ((anon_flag == MES_ANON)
447 || (anon_flag == MES_AN2)))
448 cprintf(" [%s]",buf);
453 sprintf(boundary, "--%s", buf);
455 else if (ch=='P') cprintf("path=%s\n",buf);
456 else if (ch=='U') cprintf("subj=%s\n",buf);
457 else if (ch=='I') cprintf("msgn=%s\n",buf);
458 else if (ch=='H') cprintf("hnod=%s\n",buf);
459 else if (ch=='O') cprintf("room=%s\n",buf);
460 else if (ch=='N') cprintf("node=%s\n",buf);
461 else if (ch=='R') cprintf("rcpt=%s\n",buf);
462 else if (ch=='T') cprintf("time=%s\n",buf);
463 /* else cprintf("fld%c=%s\n",ch,buf); */
466 /* begin header processing loop for RFC822 transfer format */
470 strcpy(snode, NODENAME);
471 strcpy(lnode, HUMANNODE);
472 if (mode == MT_RFC822) while(ch = *mptr++, (ch!='M' && ch!=0)) {
475 buf[strlen(buf)+1] = 0;
477 buf[strlen(buf)] = rch;
480 if (ch=='A') strcpy(luser, buf);
482 cprintf("Path: %s\n",buf);
483 for (a=0; a<strlen(buf); ++a) {
485 strcpy(buf,&buf[a+1]);
491 else if (ch=='U') cprintf("Subject: %s\n",buf);
492 else if (ch=='I') strcpy(mid, buf);
493 else if (ch=='H') strcpy(lnode, buf);
494 else if (ch=='O') cprintf("X-Citadel-Room: %s\n",buf);
495 else if (ch=='N') strcpy(snode, buf);
496 else if (ch=='R') cprintf("To: %s\n",buf);
499 cprintf("Date: %s", asctime(localtime(&xtime)));
503 if (mode == MT_RFC822) {
504 if (!strcasecmp(snode, NODENAME)) {
507 cprintf("Message-ID: <%s@%s>\n", mid, snode);
508 PerformUserHooks(luser, (-1L), EVT_OUTPUTMSG);
509 cprintf("From: %s@%s (%s)\n",
510 suser, snode, luser);
511 cprintf("Organization: %s\n", lnode);
514 /* end header processing loop ... at this point, we're in the text */
517 cprintf("text\n*** ?Message truncated\n000\n");
523 /* give 'em a length */
525 while(ch = *mptr++, ch>0) {
528 cprintf("mlen=%ld\n", msg_len);
534 /* signify start of msg text */
535 if (mode == MT_CITADEL) cprintf("text\n");
536 if (mode == MT_RFC822) cprintf("\n");
538 /* If the format type on disk is 1 (fixed-format), then we want
539 * everything to be output completely literally ... regardless of
540 * what message transfer format is in use.
542 if (format_type == 1) {
544 while(ch = *mptr++, ch>0) {
545 if (ch == 13) ch = 10;
546 if ( (ch == 10) || (strlen(buf)>250) ) {
547 if (has_attachments) if (!strncmp(buf, boundary, strlen(boundary))) {
550 if (current_section == desired_section) {
551 if ( (has_attachments == 0) || (strncmp(buf, boundary, strlen(boundary)))) {
552 cprintf("%s\n", buf);
558 buf[strlen(buf)+1] = 0;
559 buf[strlen(buf)] = ch;
562 if (strlen(buf)>0) cprintf("%s\n", buf);
564 /* If the message on disk is format 0 (Citadel vari-format), we
565 * output using the formatter at 80 columns. This is the final output
566 * form if the transfer format is RFC822, but if the transfer format
567 * is Citadel proprietary, it'll still work, because the indentation
568 * for new paragraphs is correct and the client will reformat the
569 * message to the reader's screen width.
571 if (format_type == 0) {
584 * display a message (mode 0 - Citadel proprietary)
586 void cmd_msg0(char *cmdbuf)
589 int headers_only = 0;
590 int desired_section = 0;
592 extract(msgid,cmdbuf,0);
593 headers_only = extract_int(cmdbuf, 1);
594 desired_section = extract_int(cmdbuf, 2);
596 output_message(msgid,MT_CITADEL, headers_only, desired_section);
602 * display a message (mode 2 - RFC822)
604 void cmd_msg2(char *cmdbuf)
607 int headers_only = 0;
609 extract(msgid,cmdbuf,0);
610 headers_only = extract_int(cmdbuf,1);
612 output_message(msgid,MT_RFC822,headers_only,0);
616 * display a message (mode 3 - IGnet raw format - internal programs only)
618 void cmd_msg3(char *cmdbuf)
621 int headers_only = 0;
623 if (CC->internal_pgm == 0) {
624 cprintf("%d This command is for internal programs only.\n",
629 extract(msgid,cmdbuf,0);
630 headers_only = extract_int(cmdbuf,1);
632 output_message(msgid,MT_RAW,headers_only,0);
638 * Message base operation to send a message to the master file
639 * (returns new message number)
641 long send_message(char *message_in_memory, /* pointer to buffer */
642 size_t message_length, /* length of buffer */
643 int generate_id) { /* 1 to generate an I field */
647 /* Get a new message number */
648 newmsgid = get_new_message_number();
650 /* Write our little bundle of joy into the message base */
652 begin_critical_section(S_MSGMAIN);
653 if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
654 message_in_memory, message_length) < 0 ) {
655 lprintf(2, "Can't store message\n");
656 end_critical_section(S_MSGMAIN);
659 end_critical_section(S_MSGMAIN);
661 /* Finally, return the pointers */
668 * this is a simple file copy routine.
670 void copy_file(char *from, char *to)
676 if (ffp==NULL) return;
682 while (a=getc(ffp), a>=0) {
693 * message base operation to save a message and install its pointers
695 void save_message(char *mtmp, /* file containing proper message */
696 char *rec, /* Recipient (if mail) */
697 char mtsflag, /* 0 for normal, 1 to force Aide> room */
698 int mailtype, /* local or remote type, see citadel.h */
699 int generate_id) /* set to 1 to generate an 'I' field */
702 char hold_rm[ROOMNAMELEN];
703 char actual_rm[ROOMNAMELEN];
706 char *message_in_memory;
710 struct usersupp userbuf;
712 /* Measure the message */
713 stat(mtmp, &statbuf);
714 templen = statbuf.st_size;
716 /* Now read it into memory */
717 message_in_memory = (char *) malloc(templen);
718 if (message_in_memory == NULL) {
719 lprintf(2, "Can't allocate memory to save message!\n");
723 fp = fopen(mtmp, "rb");
724 fread(message_in_memory, templen, 1, fp);
727 newmsgid = send_message(message_in_memory, templen, generate_id);
728 free(message_in_memory);
729 if (newmsgid <= 0L) return;
731 strcpy(actual_rm, CC->quickroom.QRname);
733 strcpy(recipient, rec);
735 /* If the user is a twit, move to the twit room for posting... */
736 if (TWITDETECT) if (CC->usersupp.axlevel==2) {
737 strcpy(hold_rm, actual_rm);
738 strcpy(actual_rm, config.c_twitroom);
741 /* ...or if this is a private message, go to the target mailbox. */
742 if (strlen(recipient) > 0) {
743 mailtype = alias(recipient);
744 if (mailtype == M_LOCAL) {
745 if (getuser(&userbuf, recipient)!=0) {
746 mtsflag = 1; /* User not found, goto Aide */
749 strcpy(hold_rm, actual_rm);
750 MailboxName(actual_rm, &userbuf, MAILROOM);
755 /* ...or if this message is destined for Aide> then go there. */
757 strcpy(hold_rm, actual_rm);
758 strcpy(actual_rm, AIDEROOM);
762 /* This call to usergoto() changes rooms if necessary. It also
763 * causes the latest message list to be read into memory.
765 usergoto(actual_rm, 0);
767 /* read in the quickroom record, obtaining a lock... */
768 lgetroom(&CC->quickroom, actual_rm);
770 /* Fix an obscure bug */
771 if (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) {
772 CC->quickroom.QRflags = CC->quickroom.QRflags & ~QR_MAILBOX;
775 /* Add the message pointer to the room */
776 AddMessageToRoom(&CC->quickroom, newmsgid);
778 /* update quickroom */
779 CC->quickroom.QRhighest = newmsgid;
780 lputroom(&CC->quickroom, actual_rm);
782 /* Bump this user's messages posted counter. */
783 lgetuser(&CC->usersupp, CC->curr_user);
784 CC->usersupp.posted = CC->usersupp.posted + 1;
785 lputuser(&CC->usersupp, CC->curr_user);
787 /* Network mail - send a copy to the network program. */
788 if ( (strlen(recipient)>0) && (mailtype != M_LOCAL) ) {
789 sprintf(aaa,"./network/spoolin/nm.%d",getpid());
791 system("exec nohup ./netproc >/dev/null 2>&1 &");
794 /* If we've posted in a room other than the current room, then we
795 * have to now go back to the current room...
797 if (strlen(hold_rm) > 0) {
798 usergoto(hold_rm, 0);
800 unlink(mtmp); /* delete the temporary file */
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 e=alias(buf); /* alias and mail type */
977 if ((buf[0]==0) || (e==M_ERROR)) {
978 cprintf("%d Unknown address - cannot send message.\n",
982 if ((e!=M_LOCAL)&&(CC->usersupp.axlevel<4)) {
983 cprintf("%d Net privileges required for network mail.\n",
984 ERROR+HIGHER_ACCESS_REQUIRED);
987 if ((RESTRICT_INTERNET==1)&&(e==M_INTERNET)
988 &&((CC->usersupp.flags&US_INTERNET)==0)
989 &&(!CC->internal_pgm) ) {
990 cprintf("%d You don't have access to Internet mail.\n",
991 ERROR+HIGHER_ACCESS_REQUIRED);
994 if (!strcasecmp(buf,"sysop")) {
998 if (e!=M_LOCAL) goto SKFALL; /* don't search local file */
999 if (!strcasecmp(buf,CC->usersupp.fullname)) {
1000 cprintf("%d Can't send mail to yourself!\n",
1001 ERROR+NO_SUCH_USER);
1005 /* Check to make sure the user exists; also get the correct
1006 * upper/lower casing of the name.
1008 a = getuser(&tempUS,buf);
1010 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
1013 strcpy(buf,tempUS.fullname);
1016 SKFALL: b=MES_NORMAL;
1017 if (CC->quickroom.QRflags&QR_ANONONLY) b=MES_ANON;
1018 if (CC->quickroom.QRflags&QR_ANONOPT) {
1019 if (anon_flag==1) b=MES_AN2;
1021 if ((CC->quickroom.QRflags & QR_MAILBOX) == 0) buf[0]=0;
1023 /* If we're only checking the validity of the request, return
1024 * success without creating the message.
1027 cprintf("%d %s\n",OK,buf);
1031 cprintf("%d send message\n",SEND_LISTING);
1032 if (CC->fake_postname[0])
1033 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname, boundary);
1035 if (CC->fake_username[0])
1036 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username, boundary);
1038 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "", boundary);
1039 save_message(CC->temp,buf,mtsflag,e,1);
1040 CC->fake_postname[0]='\0';
1047 * message entry - mode 3 (raw)
1049 void cmd_ent3(char *entargs)
1055 struct usersupp tempUS;
1060 if (CC->internal_pgm == 0) {
1061 cprintf("%d This command is for internal programs only.\n",
1066 /* If we're in Mail, check the recipient */
1067 if (CC->quickroom.QRflags & QR_MAILBOX) {
1068 extract(recp, entargs, 1);
1069 e=alias(recp); /* alias and mail type */
1070 if ((buf[0]==0) || (e==M_ERROR)) {
1071 cprintf("%d Unknown address - cannot send message.\n",
1072 ERROR+NO_SUCH_USER);
1076 a = getuser(&tempUS,recp);
1078 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
1084 /* At this point, message has been approved. */
1085 if (extract_int(entargs, 0) == 0) {
1086 cprintf("%d OK to send\n", OK);
1090 /* open a temp file to hold the message */
1091 fp = fopen(CC->temp, "wb");
1093 cprintf("%d Cannot open %s: %s\n",
1094 ERROR + INTERNAL_ERROR,
1095 CC->temp, strerror(errno) );
1099 msglen = extract_long(entargs, 2);
1100 cprintf("%d %ld\n", SEND_BINARY, msglen);
1101 while(msglen > 0L) {
1102 bloklen = ((msglen >= 255L) ? 255 : msglen);
1103 client_read(buf, (int)bloklen );
1104 fwrite(buf, (int)bloklen, 1, fp);
1105 msglen = msglen - bloklen;
1109 save_message(CC->temp, recp, 0, e, 0);
1114 * Delete message from current room
1116 void cmd_dele(char *delstr)
1121 getuser(&CC->usersupp,CC->curr_user);
1122 if ((CC->usersupp.axlevel < 6)
1123 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1124 cprintf("%d Higher access required.\n",
1125 ERROR+HIGHER_ACCESS_REQUIRED);
1129 delnum = atol(delstr);
1130 if (CC->quickroom.QRflags & QR_MAILBOX) {
1131 cprintf("%d Can't delete mail.\n",ERROR);
1135 /* get room records, obtaining a lock... */
1136 lgetroom(&CC->quickroom,CC->quickroom.QRname);
1137 get_msglist(&CC->quickroom);
1140 if (CC->num_msgs > 0) for (a=0; a<(CC->num_msgs); ++a) {
1141 if (MessageFromList(a) == delnum) {
1142 SetMessageInList(a, 0L);
1147 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1148 CC->quickroom.QRhighest = MessageFromList(CC->num_msgs - 1);
1150 put_msglist(&CC->quickroom);
1151 lputroom(&CC->quickroom,CC->quickroom.QRname);
1153 cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
1154 cprintf("%d Message deleted.\n",OK);
1156 else cprintf("%d No message %ld.\n",ERROR,delnum);
1161 * move a message to another room
1163 void cmd_move(char *args)
1168 struct quickroom qtemp;
1171 num = extract_long(args,0);
1172 extract(targ,args,1);
1174 getuser(&CC->usersupp,CC->curr_user);
1175 if ((CC->usersupp.axlevel < 6)
1176 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1177 cprintf("%d Higher access required.\n",
1178 ERROR+HIGHER_ACCESS_REQUIRED);
1182 if (getroom(&qtemp, targ) != 0) {
1183 cprintf("%d '%s' does not exist.\n",ERROR,targ);
1187 /* yank the message out of the current room... */
1188 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1189 get_msglist(&CC->quickroom);
1192 for (a=0; a<(CC->num_msgs); ++a) {
1193 if (MessageFromList(a) == num) {
1195 SetMessageInList(a, 0L);
1199 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1200 put_msglist(&CC->quickroom);
1201 CC->quickroom.QRhighest = MessageFromList((CC->num_msgs)-1);
1203 lputroom(&CC->quickroom,CC->quickroom.QRname);
1205 cprintf("%d msg %ld does not exist.\n",ERROR,num);
1209 /* put the message into the target room */
1210 lgetroom(&qtemp, targ);
1211 AddMessageToRoom(&qtemp, num);
1212 lputroom(&qtemp, targ);
1214 cprintf("%d Message moved.\n", OK);