18 #include "sysdep_decls.h"
22 #include "dynloader.h"
24 #include "mime_parser.h"
33 extern struct config config;
37 * This function is self explanatory.
38 * (What can I say, I'm in a weird mood today...)
40 void remove_any_whitespace_to_the_left_or_right_of_at_symbol(char *name) {
43 for (i=0; i<strlen(name); ++i) if (name[i]=='@') {
44 if (i>0) if (isspace(name[i-1])) {
45 strcpy(&name[i-1], &name[i]);
48 while (isspace(name[i+1])) {
49 strcpy(&name[i+1], &name[i+2]);
56 * Aliasing for network mail.
57 * (Error messages have been commented out, because this is a server.)
59 int alias(char *name) /* process alias and routing info for mail */
63 char aaa[300],bbb[300];
65 lprintf(9, "alias() called for <%s>\n", name);
67 remove_any_whitespace_to_the_left_or_right_of_at_symbol(name);
69 fp=fopen("network/mail.aliases","r");
70 if (fp==NULL) fp=fopen("/dev/null","r");
71 if (fp==NULL) return(M_ERROR);
72 GNA: strcpy(aaa,""); strcpy(bbb,"");
95 if (strcasecmp(name,aaa)) goto GNA;
98 lprintf(7, "Mail is being forwarded to %s\n", name);
100 DETYPE: /* determine local or remote type, see citadel.h */
101 for (a=0; a<strlen(name); ++a) if (name[a]=='!') return(M_INTERNET);
102 for (a=0; a<strlen(name); ++a)
104 for (b=a; b<strlen(name); ++b)
105 if (name[b]=='.') return(M_INTERNET);
106 b=0; for (a=0; a<strlen(name); ++a) if (name[a]=='@') ++b;
108 lprintf(7, "Too many @'s in address\n");
112 for (a=0; a<strlen(name); ++a)
113 if (name[a]=='@') strcpy(bbb,&name[a+1]);
114 while (bbb[0]==32) strcpy(bbb,&bbb[1]);
115 fp = fopen("network/mail.sysinfo","r");
116 if (fp==NULL) return(M_ERROR);
119 } while ((a>=0)&&(strcasecmp(aaa,bbb)));
121 if (!strncmp(aaa,"use ",4)) {
127 if (!strncmp(aaa,"uum",3)) {
129 for (a=0; a<strlen(bbb); ++a) {
130 if (bbb[a]=='@') bbb[a]=0;
131 if (bbb[a]==' ') bbb[a]='_';
133 while(bbb[strlen(bbb)-1]=='_') bbb[strlen(bbb)-1]=0;
134 sprintf(name,&aaa[4],bbb);
137 if (!strncmp(aaa,"bin",3)) {
138 strcpy(aaa,name); strcpy(bbb,name);
139 while (aaa[strlen(aaa)-1]!='@') aaa[strlen(aaa)-1]=0;
140 aaa[strlen(aaa)-1]=0;
141 while (aaa[strlen(aaa)-1]==' ') aaa[strlen(aaa)-1]=0;
142 while (bbb[0]!='@') strcpy(bbb,&bbb[1]);
144 while (bbb[0]==' ') strcpy(bbb,&bbb[1]);
145 sprintf(name,"%s @%s",aaa,bbb);
157 fp=fopen("citadel.control","r");
158 fread((char *)&CitControl,sizeof(struct CitControl),1,fp);
163 * cmd_msgs() - get list of message #'s in this room
165 void cmd_msgs(char *cmdbuf)
174 extract(which,cmdbuf,0);
178 if (!strncasecmp(which,"OLD",3)) mode = MSGS_OLD;
179 if (!strncasecmp(which,"NEW",3)) mode = MSGS_NEW;
180 if (!strncasecmp(which,"FIRST",5)) {
182 cm_howmany = extract_int(cmdbuf,1);
184 if (!strncasecmp(which,"LAST",4)) {
186 cm_howmany = extract_int(cmdbuf,1);
188 if (!strncasecmp(which,"GT",2)) {
190 cm_gt = extract_long(cmdbuf,1);
193 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
194 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
198 get_msglist(&CC->quickroom);
199 getuser(&CC->usersupp,CC->curr_user);
200 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
202 cprintf("%d Message list...\n",LISTING_FOLLOWS);
203 if (CC->num_msgs != 0) {
204 for (a=0; a<(CC->num_msgs); ++a)
205 if ((MessageFromList(a) >=0)
209 || ((mode==MSGS_OLD) && (MessageFromList(a) <= vbuf.v_lastseen))
210 || ((mode==MSGS_NEW) && (MessageFromList(a) > vbuf.v_lastseen))
211 || ((mode==MSGS_NEW) && (MessageFromList(a) >= vbuf.v_lastseen)
212 && (CC->usersupp.flags & US_LASTOLD))
213 || ((mode==MSGS_LAST)&& (a>=(CC->num_msgs-cm_howmany)))
214 || ((mode==MSGS_FIRST)&&(a<cm_howmany))
215 || ((mode==MSGS_GT) && (MessageFromList(a) > cm_gt))
219 cprintf("%ld\n", MessageFromList(a));
228 * help_subst() - support routine for help file viewer
230 void help_subst(char *strbuf, char *source, char *dest)
235 while (p=pattern2(strbuf,source), (p>=0)) {
236 strcpy(workbuf,&strbuf[p+strlen(source)]);
237 strcpy(&strbuf[p],dest);
238 strcat(strbuf,workbuf);
243 void do_help_subst(char *buffer)
247 help_subst(buffer,"^nodename",config.c_nodename);
248 help_subst(buffer,"^humannode",config.c_humannode);
249 help_subst(buffer,"^fqdn",config.c_fqdn);
250 help_subst(buffer,"^username",CC->usersupp.fullname);
251 sprintf(buf2,"%ld",CC->usersupp.usernum);
252 help_subst(buffer,"^usernum",buf2);
253 help_subst(buffer,"^sysadm",config.c_sysadm);
254 help_subst(buffer,"^variantname",CITADEL);
255 sprintf(buf2,"%d",config.c_maxsessions);
256 help_subst(buffer,"^maxsessions",buf2);
262 * memfmout() - Citadel text formatter and paginator.
263 * Although the original purpose of this routine was to format
264 * text to the reader's screen width, all we're really using it
265 * for here is to format text out to 80 columns before sending it
266 * to the client. The client software may reformat it again.
268 void memfmout(int width, char *mptr, char subst)
269 /* screen width to use */
270 /* where are we going to get our text from? */
271 /* nonzero if we should use hypertext mode */
280 strcpy(aaa,""); old=255;
282 c=1; /* c is the current pos */
285 while (ch=*mptr, ((ch!=0) && (strlen(buffer)<126) )) {
287 buffer[strlen(buffer)+1] = 0;
288 buffer[strlen(buffer)] = ch;
291 if (buffer[0]=='^') do_help_subst(buffer);
293 buffer[strlen(buffer)+1] = 0;
295 strcpy(buffer,&buffer[1]);
302 if (ch<=0) goto FMTEND;
304 if ( ((ch==13)||(ch==10)) && (old!=13) && (old!=10) ) ch=32;
305 if ( ((old==13)||(old==10)) && (isspace(real)) ) {
309 if (ch>126) goto FMTA;
312 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
313 { cprintf("\n%s",aaa); c=strlen(aaa); aaa[0]=0;
315 b=strlen(aaa); aaa[b]=ch; aaa[b+1]=0; }
317 if ((strlen(aaa)+c)>(width-5)) {
321 cprintf("%s ",aaa); ++c; c=c+strlen(aaa);
325 if ((ch==13)||(ch==10)) {
333 FMTEND: cprintf("\n");
340 void part_handler(char *name, char *filename, char *encoding,
341 void *content, char *cbtype, size_t length) {
343 cprintf("part=%s|%s|%s|%s|%d\n",
344 name, filename, encoding, cbtype, length);
350 * Feed MIME-encoded stuff to the mime_parser
352 void output_mime_parts(char *msg) {
353 char content_type[256];
354 int content_length = (-1);
360 strcpy(content_type, "");
367 buf[strlen(buf)+1] = 0;
369 if (strlen(buf)<((sizeof buf)-1))
370 buf[strlen(buf)] = rch;
371 } while ( (rch > 0) && (rch != 10) );
372 if (buf[strlen(buf)-1]==10) {
373 buf[strlen(buf)-1] = 0;
378 if (buf[strlen(buf)-1]==13) buf[strlen(buf)-1]=0;
379 } while (buf[strlen(buf)-1]==';');
380 for (i=0; i<strlen(buf); ++i) if (isspace(buf[i])) buf[i]=' ';
381 if (!strncasecmp(buf, "Content-type: ", 14))
382 strcpy(content_type, &buf[14]);
383 if (!strncasecmp(buf, "Content-length: ", 16))
384 content_length = atoi(&buf[16]);
385 if (strlen(buf)==0) {
386 if (content_length < 0) {
389 while (*mptr++ != 0) ++content_length;
391 cprintf("mime=type=%s\n", content_type);
392 cprintf("mime=len=%d\n", content_length);
393 mime_parser(mptr, content_length, content_type,
404 * Get a message off disk. (return value is the message's timestamp)
407 time_t output_message(char *msgid, int mode, int headers_only) {
411 CIT_UBYTE format_type,anon_flag;
416 struct cdbdata *dmsgtext;
419 /* buffers needed for RFC822 translation */
428 msg_num = atol(msgid);
431 if ((!(CC->logged_in))&&(!(CC->internal_pgm))&&(mode!=MT_DATE)) {
432 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
436 /* We used to need to check in the current room's message list
437 * to determine where the message's disk position. We no longer need
438 * to do this, but we do it anyway as a security measure, in order to
439 * prevent rogue clients from reading messages not in the current room.
443 if (CC->num_msgs > 0) {
444 for (a=0; a<CC->num_msgs; ++a) {
445 if (MessageFromList(a) == msg_num) {
453 cprintf("%d Message %ld is not in this room.\n",
459 dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
461 if (dmsgtext == NULL) {
463 cprintf("%d Can't find message %ld\n",
464 ERROR+INTERNAL_ERROR);
468 msg_len = (long) dmsgtext->len;
469 mptr = dmsgtext->ptr;
471 /* this loop spews out the whole message if we're doing raw format */
472 if (mode == MT_RAW) {
473 cprintf("%d %ld\n", BINARY_FOLLOWS, msg_len);
474 client_write(dmsgtext->ptr, (int) msg_len);
479 /* Otherwise, we'll start parsing it field by field... */
482 cprintf("%d Illegal message format on disk\n",
483 ERROR+INTERNAL_ERROR);
489 format_type = *mptr++;
491 /* Are we just looking for the message date? */
492 if (mode == MT_DATE) while(ch = *mptr++, (ch!='M' && ch!=0)) {
495 buf[strlen(buf)+1] = 0;
497 buf[strlen(buf)] = rch;
508 /* now for the user-mode message reading loops */
509 cprintf("%d Message %ld:\n",LISTING_FOLLOWS,msg_num);
511 if (mode == MT_CITADEL) cprintf("type=%d\n", format_type);
513 if ( (anon_flag == MES_ANON) && (mode == MT_CITADEL) ) {
514 cprintf("nhdr=yes\n");
517 /* begin header processing loop for Citadel message format */
519 if ((mode == MT_CITADEL)||(mode == MT_MIME))
520 while(ch = *mptr++, (ch!='M' && ch!=0)) {
523 buf[strlen(buf)+1] = 0;
525 buf[strlen(buf)] = rch;
529 PerformUserHooks(buf, (-1L), EVT_OUTPUTMSG);
530 if (anon_flag==MES_ANON) cprintf("from=****");
531 else if (anon_flag==MES_AN2) cprintf("from=anonymous");
532 else cprintf("from=%s",buf);
533 if ((is_room_aide()) && ((anon_flag == MES_ANON)
534 || (anon_flag == MES_AN2)))
535 cprintf(" [%s]",buf);
538 else if (ch=='P') cprintf("path=%s\n",buf);
539 else if (ch=='U') cprintf("subj=%s\n",buf);
540 else if (ch=='I') cprintf("msgn=%s\n",buf);
541 else if (ch=='H') cprintf("hnod=%s\n",buf);
542 else if (ch=='O') cprintf("room=%s\n",buf);
543 else if (ch=='N') cprintf("node=%s\n",buf);
544 else if (ch=='R') cprintf("rcpt=%s\n",buf);
545 else if (ch=='T') cprintf("time=%s\n",buf);
546 /* else cprintf("fld%c=%s\n",ch,buf); */
549 /* begin header processing loop for RFC822 transfer format */
553 strcpy(snode, NODENAME);
554 strcpy(lnode, HUMANNODE);
555 if (mode == MT_RFC822) while(ch = *mptr++, (ch!='M' && ch!=0)) {
558 buf[strlen(buf)+1] = 0;
560 buf[strlen(buf)] = rch;
563 if (ch=='A') strcpy(luser, buf);
565 cprintf("Path: %s\n",buf);
566 for (a=0; a<strlen(buf); ++a) {
568 strcpy(buf,&buf[a+1]);
574 else if (ch=='U') cprintf("Subject: %s\n",buf);
575 else if (ch=='I') strcpy(mid, buf);
576 else if (ch=='H') strcpy(lnode, buf);
577 else if (ch=='O') cprintf("X-Citadel-Room: %s\n",buf);
578 else if (ch=='N') strcpy(snode, buf);
579 else if (ch=='R') cprintf("To: %s\n",buf);
582 cprintf("Date: %s", asctime(localtime(&xtime)));
586 if (mode == MT_RFC822) {
587 if (!strcasecmp(snode, NODENAME)) {
590 cprintf("Message-ID: <%s@%s>\n", mid, snode);
591 PerformUserHooks(luser, (-1L), EVT_OUTPUTMSG);
592 cprintf("From: %s@%s (%s)\n",
593 suser, snode, luser);
594 cprintf("Organization: %s\n", lnode);
597 /* end header processing loop ... at this point, we're in the text */
600 cprintf("text\n*** ?Message truncated\n000\n");
605 /* do some sort of MIME output */
606 if ( (mode == MT_MIME) && (format_type == 4) ) {
607 output_mime_parts(mptr);
614 /* give 'em a length */
616 while(ch = *mptr++, ch>0) {
619 cprintf("mlen=%ld\n", msg_len);
625 /* signify start of msg text */
626 if (mode == MT_CITADEL) cprintf("text\n");
627 if ( (mode == MT_RFC822) && (format_type != 4) ) cprintf("\n");
629 /* If the format type on disk is 1 (fixed-format), then we want
630 * everything to be output completely literally ... regardless of
631 * what message transfer format is in use. Format type 4 is
632 * temporarily being output this way as well.
634 if ( (format_type == 1) || (format_type == 4)) {
636 while(ch = *mptr++, ch>0) {
637 if (ch == 13) ch = 10;
638 if ( (ch == 10) || (strlen(buf)>250) ) {
639 cprintf("%s\n", buf);
643 buf[strlen(buf)+1] = 0;
644 buf[strlen(buf)] = ch;
647 if (strlen(buf)>0) cprintf("%s\n", buf);
649 /* If the message on disk is format 0 (Citadel vari-format), we
650 * output using the formatter at 80 columns. This is the final output
651 * form if the transfer format is RFC822, but if the transfer format
652 * is Citadel proprietary, it'll still work, because the indentation
653 * for new paragraphs is correct and the client will reformat the
654 * message to the reader's screen width.
656 if (format_type == 0) {
669 * display a message (mode 0 - Citadel proprietary)
671 void cmd_msg0(char *cmdbuf)
674 int headers_only = 0;
676 extract(msgid,cmdbuf,0);
677 headers_only = extract_int(cmdbuf, 1);
679 output_message(msgid, MT_CITADEL, headers_only);
685 * display a message (mode 2 - RFC822)
687 void cmd_msg2(char *cmdbuf)
690 int headers_only = 0;
692 extract(msgid,cmdbuf,0);
693 headers_only = extract_int(cmdbuf,1);
695 output_message(msgid,MT_RFC822,headers_only);
699 * display a message (mode 3 - IGnet raw format - internal programs only)
701 void cmd_msg3(char *cmdbuf)
704 int headers_only = 0;
706 if (CC->internal_pgm == 0) {
707 cprintf("%d This command is for internal programs only.\n",
712 extract(msgid,cmdbuf,0);
713 headers_only = extract_int(cmdbuf,1);
715 output_message(msgid,MT_RAW,headers_only);
719 * display a message (mode 4 - MIME) (FIX ... still evolving, not complete)
721 void cmd_msg4(char *cmdbuf)
725 extract(msgid, cmdbuf, 0);
727 output_message(msgid, MT_MIME, 0);
733 * Message base operation to send a message to the master file
734 * (returns new message number)
736 long send_message(char *message_in_memory, /* pointer to buffer */
737 size_t message_length, /* length of buffer */
738 int generate_id) { /* 1 to generate an I field */
741 char *actual_message;
742 size_t actual_length;
746 /* Get a new message number */
747 newmsgid = get_new_message_number();
750 sprintf(msgidbuf, "I%ld", newmsgid);
751 actual_length = message_length + strlen(msgidbuf) + 1;
752 actual_message = mallok(actual_length);
753 memcpy(actual_message, message_in_memory, 3);
754 memcpy(&actual_message[3], msgidbuf, (strlen(msgidbuf)+1) );
755 memcpy(&actual_message[strlen(msgidbuf)+4],
756 &message_in_memory[3], message_length - 3);
760 actual_message = message_in_memory;
761 actual_length = message_length;
764 /* Write our little bundle of joy into the message base */
765 begin_critical_section(S_MSGMAIN);
766 if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
767 actual_message, actual_length) < 0 ) {
768 lprintf(2, "Can't store message\n");
774 end_critical_section(S_MSGMAIN);
777 phree(actual_message);
780 /* Finally, return the pointers */
787 * this is a simple file copy routine.
789 void copy_file(char *from, char *to)
795 if (ffp==NULL) return;
801 while (a=getc(ffp), a>=0) {
812 * message base operation to save a message and install its pointers
814 void save_message(char *mtmp, /* file containing proper message */
815 char *rec, /* Recipient (if mail) */
816 char *force_room, /* if non-zero length, force a room */
817 int mailtype, /* local or remote type, see citadel.h */
818 int generate_id) /* set to 1 to generate an 'I' field */
821 char hold_rm[ROOMNAMELEN];
822 char actual_rm[ROOMNAMELEN];
825 char *message_in_memory;
829 struct usersupp userbuf;
831 static int seqnum = 0;
833 lprintf(9, "save_message(%s,%s,%s,%d,%d)\n",
834 mtmp, rec, force_room, mailtype, generate_id);
836 /* Strip non-printable characters out of the recipient name */
837 strcpy(recipient, rec);
838 for (a=0; a<strlen(recipient); ++a)
839 if (!isprint(recipient[a]))
840 strcpy(&recipient[a], &recipient[a+1]);
842 /* Measure the message */
843 stat(mtmp, &statbuf);
844 templen = statbuf.st_size;
846 /* Now read it into memory */
847 message_in_memory = (char *) mallok(templen);
848 if (message_in_memory == NULL) {
849 lprintf(2, "Can't allocate memory to save message!\n");
853 fp = fopen(mtmp, "rb");
854 fread(message_in_memory, templen, 1, fp);
857 newmsgid = send_message(message_in_memory, templen, generate_id);
858 phree(message_in_memory);
859 if (newmsgid <= 0L) return;
861 strcpy(actual_rm, CC->quickroom.QRname);
864 /* If the user is a twit, move to the twit room for posting... */
865 if (TWITDETECT) if (CC->usersupp.axlevel==2) {
866 strcpy(hold_rm, actual_rm);
867 strcpy(actual_rm, config.c_twitroom);
870 /* ...or if this is a private message, go to the target mailbox. */
871 if (strlen(recipient) > 0) {
872 /* mailtype = alias(recipient); */
873 if (mailtype == M_LOCAL) {
874 if (getuser(&userbuf, recipient)!=0) {
875 /* User not found, goto Aide */
876 strcpy(force_room, AIDEROOM);
879 strcpy(hold_rm, actual_rm);
880 MailboxName(actual_rm, &userbuf, MAILROOM);
885 /* ...or if this message is destined for Aide> then go there. */
886 if (strlen(force_room) > 0) {
887 strcpy(hold_rm, actual_rm);
888 strcpy(actual_rm, force_room);
891 /* This call to usergoto() changes rooms if necessary. It also
892 * causes the latest message list to be read into memory.
894 usergoto(actual_rm, 0);
896 /* read in the quickroom record, obtaining a lock... */
897 lgetroom(&CC->quickroom, actual_rm);
899 /* Fix an obscure bug */
900 if (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) {
901 CC->quickroom.QRflags = CC->quickroom.QRflags & ~QR_MAILBOX;
904 /* Add the message pointer to the room */
905 CC->quickroom.QRhighest = AddMessageToRoom(&CC->quickroom, newmsgid);
907 /* update quickroom */
908 lputroom(&CC->quickroom, actual_rm);
910 /* Network mail - send a copy to the network program. */
911 if ( (strlen(recipient)>0) && (mailtype != M_LOCAL) ) {
912 sprintf(aaa,"./network/spoolin/netmail.%04x.%04x.%04x",
913 getpid(), CC->cs_pid, ++seqnum);
915 system("exec nohup ./netproc -i >/dev/null 2>&1 &");
918 /* Bump this user's messages posted counter. */
919 lgetuser(&CC->usersupp, CC->curr_user);
920 CC->usersupp.posted = CC->usersupp.posted + 1;
921 lputuser(&CC->usersupp, CC->curr_user);
923 /* If we've posted in a room other than the current room, then we
924 * have to now go back to the current room...
926 if (strlen(hold_rm) > 0) {
927 usergoto(hold_rm, 0);
929 unlink(mtmp); /* delete the temporary file */
934 * Generate an administrative message and post it in the Aide> room.
936 void aide_message(char *text)
940 fp=fopen(CC->temp,"wb");
941 fprintf(fp,"%c%c%c",255,MES_NORMAL,0);
942 fprintf(fp,"Psysop%c",0);
943 fprintf(fp,"T%ld%c", time(NULL), 0);
944 fprintf(fp,"ACitadel%c",0);
945 fprintf(fp,"OAide%c",0);
946 fprintf(fp,"N%s%c",NODENAME,0);
947 fprintf(fp,"M%s\n%c",text,0);
949 save_message(CC->temp,"",AIDEROOM,M_LOCAL,1);
950 syslog(LOG_NOTICE,text);
956 * Build a binary message to be saved on disk.
959 char *filename, /* temporary file name */
960 struct usersupp *author, /* author's usersupp structure */
961 char *recipient, /* NULL if it's not mail */
962 char *room, /* room where it's going */
963 int type, /* see MES_ types in header file */
964 int net_type, /* see MES_ types in header file */
965 int format_type, /* local or remote (see citadel.h) */
966 char *fake_name) { /* who we're masquerading as */
974 /* Don't confuse the poor folks if it's not routed mail. */
975 strcpy(dest_node, "");
978 /* If net_type is M_BINARY, split out the destination node. */
979 if (net_type == M_BINARY) {
980 strcpy(dest_node,NODENAME);
981 for (a=0; a<strlen(recipient); ++a) {
982 if (recipient[a]=='@') {
984 strcpy(dest_node,&recipient[a+1]);
989 /* if net_type is M_INTERNET, set the dest node to 'internet' */
990 if (net_type == M_INTERNET) {
991 strcpy(dest_node,"internet");
994 while (isspace(recipient[strlen(recipient)-1]))
995 recipient[strlen(recipient)-1] = 0;
998 fp=fopen(filename,"w");
1000 putc(type,fp); /* Normal or anonymous, see MES_ flags */
1001 putc(format_type,fp); /* Formatted or unformatted */
1002 fprintf(fp,"Pcit%ld%c",author->usernum,0); /* path */
1003 fprintf(fp,"T%ld%c",now,0); /* date/time */
1005 fprintf(fp,"A%s%c",fake_name,0);
1007 fprintf(fp,"A%s%c",author->fullname,0); /* author */
1009 if (CC->quickroom.QRflags & QR_MAILBOX) { /* room */
1010 fprintf(fp,"O%s%c", &CC->quickroom.QRname[11], 0);
1013 fprintf(fp,"O%s%c",CC->quickroom.QRname,0);
1016 fprintf(fp,"N%s%c",NODENAME,0); /* nodename */
1017 fprintf(fp,"H%s%c",HUMANNODE,0); /* human nodename */
1019 if (recipient[0]!=0) fprintf(fp, "R%s%c", recipient, 0);
1020 if (dest_node[0]!=0) fprintf(fp, "D%s%c", dest_node, 0);
1024 while (client_gets(buf), strcmp(buf,"000"))
1026 fprintf(fp,"%s\n",buf);
1028 syslog(LOG_INFO, "Closing message");
1038 * message entry - mode 0 (normal) <bc>
1040 void cmd_ent0(char *entargs)
1043 char recipient[256];
1045 int format_type = 0;
1046 char newusername[256]; /* <bc> */
1051 struct usersupp tempUS;
1054 post = extract_int(entargs,0);
1055 extract(recipient,entargs,1);
1056 anon_flag = extract_int(entargs,2);
1057 format_type = extract_int(entargs,3);
1059 /* first check to make sure the request is valid. */
1061 if (!(CC->logged_in)) {
1062 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1065 if ((CC->usersupp.axlevel<2)&&((CC->quickroom.QRflags&QR_MAILBOX)==0)) {
1066 cprintf("%d Need to be validated to enter ",
1067 ERROR+HIGHER_ACCESS_REQUIRED);
1068 cprintf("(except in %s> to sysop)\n", MAILROOM);
1071 if ((CC->usersupp.axlevel<4)&&(CC->quickroom.QRflags&QR_NETWORK)) {
1072 cprintf("%d Need net privileges to enter here.\n",
1073 ERROR+HIGHER_ACCESS_REQUIRED);
1076 if ((CC->usersupp.axlevel<6)&&(CC->quickroom.QRflags&QR_READONLY)) {
1077 cprintf("%d Sorry, this is a read-only room.\n",
1078 ERROR+HIGHER_ACCESS_REQUIRED);
1085 if (post==2) { /* <bc> */
1086 if (CC->usersupp.axlevel<6)
1088 cprintf("%d You don't have permission to do an aide post.\n",
1089 ERROR+HIGHER_ACCESS_REQUIRED);
1092 extract(newusername,entargs,4);
1093 bzero(CC->fake_postname, 32);
1094 strcpy(CC->fake_postname, newusername);
1095 cprintf("%d Ok\n",OK);
1099 CC->cs_flags |= CS_POSTING;
1102 if (CC->quickroom.QRflags & QR_MAILBOX) {
1103 if (CC->usersupp.axlevel>=2) {
1104 strcpy(buf,recipient);
1106 else strcpy(buf,"sysop");
1107 e=alias(buf); /* alias and mail type */
1108 if ((buf[0]==0) || (e==M_ERROR)) {
1109 cprintf("%d Unknown address - cannot send message.\n",
1110 ERROR+NO_SUCH_USER);
1113 if ((e!=M_LOCAL)&&(CC->usersupp.axlevel<4)) {
1114 cprintf("%d Net privileges required for network mail.\n",
1115 ERROR+HIGHER_ACCESS_REQUIRED);
1118 if ((RESTRICT_INTERNET==1)&&(e==M_INTERNET)
1119 &&((CC->usersupp.flags&US_INTERNET)==0)
1120 &&(!CC->internal_pgm) ) {
1121 cprintf("%d You don't have access to Internet mail.\n",
1122 ERROR+HIGHER_ACCESS_REQUIRED);
1125 if (!strcasecmp(buf,"sysop")) {
1129 if (e!=M_LOCAL) goto SKFALL; /* don't search local file */
1130 if (!strcasecmp(buf,CC->usersupp.fullname)) {
1131 cprintf("%d Can't send mail to yourself!\n",
1132 ERROR+NO_SUCH_USER);
1136 /* Check to make sure the user exists; also get the correct
1137 * upper/lower casing of the name.
1139 a = getuser(&tempUS,buf);
1141 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
1144 strcpy(buf,tempUS.fullname);
1147 SKFALL: b=MES_NORMAL;
1148 if (CC->quickroom.QRflags&QR_ANONONLY) b=MES_ANON;
1149 if (CC->quickroom.QRflags&QR_ANONOPT) {
1150 if (anon_flag==1) b=MES_AN2;
1152 if ((CC->quickroom.QRflags & QR_MAILBOX) == 0) buf[0]=0;
1154 /* If we're only checking the validity of the request, return
1155 * success without creating the message.
1158 cprintf("%d %s\n",OK,buf);
1162 cprintf("%d send message\n",SEND_LISTING);
1163 if (CC->fake_postname[0])
1164 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname);
1166 if (CC->fake_username[0])
1167 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username);
1169 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "");
1170 save_message(CC->temp,buf, (mtsflag ? AIDEROOM : ""), e,1);
1171 CC->fake_postname[0]='\0';
1178 * message entry - mode 3 (raw)
1180 void cmd_ent3(char *entargs)
1186 struct usersupp tempUS;
1191 if (CC->internal_pgm == 0) {
1192 cprintf("%d This command is for internal programs only.\n",
1197 /* See if there's a recipient, but make sure it's a real one */
1198 extract(recp, entargs, 1);
1199 for (a=0; a<strlen(recp); ++a)
1200 if (!isprint(recp[a]))
1201 strcpy(&recp[a], &recp[a+1]);
1202 while (isspace(recp[0])) strcpy(recp, &recp[1]);
1203 while (isspace(recp[strlen(recp)-1])) recp[strlen(recp)-1] = 0;
1205 /* If we're in Mail, check the recipient */
1206 if (strlen(recp) > 0) {
1207 e=alias(recp); /* alias and mail type */
1208 if ((recp[0]==0) || (e==M_ERROR)) {
1209 cprintf("%d Unknown address - cannot send message.\n",
1210 ERROR+NO_SUCH_USER);
1214 a = getuser(&tempUS,recp);
1216 cprintf("%d No such user.\n",
1217 ERROR+NO_SUCH_USER);
1223 /* At this point, message has been approved. */
1224 if (extract_int(entargs, 0) == 0) {
1225 cprintf("%d OK to send\n", OK);
1229 /* open a temp file to hold the message */
1230 fp = fopen(CC->temp, "wb");
1232 cprintf("%d Cannot open %s: %s\n",
1233 ERROR + INTERNAL_ERROR,
1234 CC->temp, strerror(errno) );
1238 msglen = extract_long(entargs, 2);
1239 cprintf("%d %ld\n", SEND_BINARY, msglen);
1240 while(msglen > 0L) {
1241 bloklen = ((msglen >= 255L) ? 255 : msglen);
1242 client_read(buf, (int)bloklen );
1243 fwrite(buf, (int)bloklen, 1, fp);
1244 msglen = msglen - bloklen;
1248 save_message(CC->temp, recp, "", e, 0);
1253 * Delete message from current room
1255 void cmd_dele(char *delstr)
1260 getuser(&CC->usersupp,CC->curr_user);
1261 if ((CC->usersupp.axlevel < 6)
1262 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)
1263 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0)) {
1264 cprintf("%d Higher access required.\n",
1265 ERROR+HIGHER_ACCESS_REQUIRED);
1269 delnum = extract_long(delstr, 0);
1271 /* get room records, obtaining a lock... */
1272 lgetroom(&CC->quickroom,CC->quickroom.QRname);
1273 get_msglist(&CC->quickroom);
1276 if (CC->num_msgs > 0) for (a=0; a<(CC->num_msgs); ++a) {
1277 if (MessageFromList(a) == delnum) {
1278 SetMessageInList(a, 0L);
1283 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1284 CC->quickroom.QRhighest = MessageFromList(CC->num_msgs - 1);
1286 put_msglist(&CC->quickroom);
1287 lputroom(&CC->quickroom,CC->quickroom.QRname);
1289 cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
1290 cprintf("%d Message deleted.\n",OK);
1292 else cprintf("%d No message %ld.\n",ERROR,delnum);
1297 * move a message to another room
1299 void cmd_move(char *args)
1304 struct quickroom qtemp;
1307 num = extract_long(args,0);
1308 extract(targ,args,1);
1310 getuser(&CC->usersupp,CC->curr_user);
1311 if ((CC->usersupp.axlevel < 6)
1312 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1313 cprintf("%d Higher access required.\n",
1314 ERROR+HIGHER_ACCESS_REQUIRED);
1318 if (getroom(&qtemp, targ) != 0) {
1319 cprintf("%d '%s' does not exist.\n",ERROR,targ);
1323 /* yank the message out of the current room... */
1324 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1325 get_msglist(&CC->quickroom);
1328 for (a=0; a<(CC->num_msgs); ++a) {
1329 if (MessageFromList(a) == num) {
1331 SetMessageInList(a, 0L);
1335 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1336 put_msglist(&CC->quickroom);
1337 CC->quickroom.QRhighest = MessageFromList((CC->num_msgs)-1);
1339 lputroom(&CC->quickroom,CC->quickroom.QRname);
1341 cprintf("%d msg %ld does not exist.\n",ERROR,num);
1345 /* put the message into the target room */
1346 lgetroom(&qtemp, targ);
1347 qtemp.QRhighest = AddMessageToRoom(&qtemp, num);
1348 lputroom(&qtemp, targ);
1350 cprintf("%d Message moved.\n", OK);