+/* $Id$ */
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
/*
- * get a message off disk.
+ * Get a message off disk. (return value is the message's timestamp)
*
*/
-void output_message(char *msgid, int mode,
+time_t output_message(char *msgid, int mode,
int headers_only, int desired_section) {
long msg_num;
int a;
char snode[256];
char lnode[256];
char mid[256];
- long xtime;
+ time_t xtime = 0L;
/* */
strcpy(boundary, "");
msg_num = atol(msgid);
- if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
+ if ((!(CC->logged_in))&&(!(CC->internal_pgm))&&(mode!=MT_DATE)) {
cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
- return;
+ return(xtime);
}
/* We used to need to check in the current room's message list
}
if (!msg_ok) {
- cprintf("%d Message %ld is not in this room.\n",
- ERROR, msg_num);
- return;
+ if (mode != MT_DATE)
+ cprintf("%d Message %ld is not in this room.\n",
+ ERROR, msg_num);
+ return(xtime);
}
dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
if (dmsgtext == NULL) {
- cprintf("%d Can't find message %ld\n", ERROR+INTERNAL_ERROR);
- return;
+ if (mode != MT_DATE)
+ cprintf("%d Can't find message %ld\n",
+ ERROR+INTERNAL_ERROR);
+ return(xtime);
}
msg_len = (long) dmsgtext->len;
mptr = dmsgtext->ptr;
- lprintf(9, "Returned message length is %ld\n", msg_len);
/* this loop spews out the whole message if we're doing raw format */
if (mode == MT_RAW) {
cprintf("%d %ld\n", BINARY_FOLLOWS, msg_len);
client_write(dmsgtext->ptr, (int) msg_len);
cdb_free(dmsgtext);
- return;
+ return(xtime);
}
/* Otherwise, we'll start parsing it field by field... */
cprintf("%d Illegal message format on disk\n",
ERROR+INTERNAL_ERROR);
cdb_free(dmsgtext);
- return;
+ return(xtime);
}
anon_flag = *mptr++;
format_type = *mptr++;
+ /* Are we just looking for the message date? */
+ if (mode == MT_DATE) while(ch = *mptr++, (ch!='M' && ch!=0)) {
+ buf[0] = 0;
+ do {
+ buf[strlen(buf)+1] = 0;
+ rch = *mptr++;
+ buf[strlen(buf)] = rch;
+ } while (rch > 0);
+
+ if (ch=='T') {
+ xtime = atol(buf);
+ cdb_free(dmsgtext);
+ return(xtime);
+ }
+ }
+
+
/* now for the user-mode message reading loops */
cprintf("%d Message %ld:\n",LISTING_FOLLOWS,msg_num);
if (ch==0) {
cprintf("text\n*** ?Message truncated\n000\n");
cdb_free(dmsgtext);
- return;
+ return(xtime);
}
if (headers_only) {
cprintf("mlen=%ld\n", msg_len);
cprintf("000\n");
cdb_free(dmsgtext);
- return;
+ return(xtime);
}
/* signify start of msg text */
/* now we're done */
cprintf("000\n");
cdb_free(dmsgtext);
+ return(xtime);
}
desired_section = extract_int(cmdbuf, 2);
output_message(msgid,MT_CITADEL, headers_only, desired_section);
+ return;
}
/* Write our little bundle of joy into the message base */
- lprintf(9, "Storing message %ld\n", newmsgid);
begin_critical_section(S_MSGMAIN);
if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
message_in_memory, message_length) < 0 ) {
struct usersupp userbuf;
/* Measure the message */
- lprintf(9, "Measuring the message\n");
stat(mtmp, &statbuf);
templen = statbuf.st_size;
/* Now read it into memory */
- lprintf(9, "Allocating %ld bytes\n", templen);
message_in_memory = (char *) malloc(templen);
if (message_in_memory == NULL) {
lprintf(2, "Can't allocate memory to save message!\n");
return;
}
- lprintf(9, "Reading it into memory\n");
fp = fopen(mtmp, "rb");
fread(message_in_memory, templen, 1, fp);
fclose(fp);
strcpy(actual_rm, CC->quickroom.QRname);
strcpy(hold_rm, "");
strcpy(recipient, rec);
+ strproc(recipient);
/* If the user is a twit, move to the twit room for posting... */
if (TWITDETECT) if (CC->usersupp.axlevel==2) {
strcpy(actual_rm, AIDEROOM);
}
-
/* This call to usergoto() changes rooms if necessary. It also
* causes the latest message list to be read into memory.
*/
- lprintf(9, "Changing rooms if necessary...\n");
usergoto(actual_rm, 0);
/* read in the quickroom record, obtaining a lock... */
- lprintf(9, "Reading/locking <%s>...\n", actual_rm);
lgetroom(&CC->quickroom, actual_rm);
- lprintf(9, "Fetching message list...\n");
- get_msglist(&CC->quickroom);
-
- /* FIX here's where we have to handle message expiry!! */
- /* Now add the new message */
- CC->num_msgs = CC->num_msgs + 1;
- CC->msglist = realloc(CC->msglist,
- ((CC->num_msgs) * sizeof(long)) );
- if (CC->msglist == NULL) {
- lprintf(3, "ERROR: can't realloc message list!\n");
+ /* Fix an obscure bug */
+ if (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) {
+ CC->quickroom.QRflags = CC->quickroom.QRflags & ~QR_MAILBOX;
}
- SetMessageInList(CC->num_msgs - 1, newmsgid);
- /* Write it back to disk. */
- lprintf(9, "Writing message list...\n");
- put_msglist(&CC->quickroom);
+ /* Add the message pointer to the room */
+ AddMessageToRoom(&CC->quickroom, newmsgid);
/* update quickroom */
CC->quickroom.QRhighest = newmsgid;
- lprintf(9, "Writing/unlocking room <%s>...\n", actual_rm);
lputroom(&CC->quickroom, actual_rm);
- /* Bump this user's messages posted counter. Also, if the user is a
- * twit, give them access to the twit room.
- */
+ /* Bump this user's messages posted counter. */
lgetuser(&CC->usersupp, CC->curr_user);
CC->usersupp.posted = CC->usersupp.posted + 1;
- /* FIX if user is twit, grant access to twitroom here */
lputuser(&CC->usersupp, CC->curr_user);
/* Network mail - send a copy to the network program. */
- if ((strlen(recipient)>0)&&(mailtype != M_LOCAL)) {
+ if ( (strlen(recipient)>0) && (mailtype != M_LOCAL) ) {
sprintf(aaa,"./network/spoolin/nm.%d",getpid());
copy_file(mtmp,aaa);
system("exec nohup ./netproc >/dev/null 2>&1 &");
* have to now go back to the current room...
*/
if (strlen(hold_rm) > 0) {
- lprintf(9, "Returning to <%s>\n", hold_rm);
usergoto(hold_rm, 0);
}
- lprintf(9, "Deleting temporary file\n");
unlink(mtmp); /* delete the temporary file */
- lprintf(9, "Finished with save_message()\n");
}
*/
void aide_message(char *text)
{
- long now;
+ time_t now;
FILE *fp;
time(&now);
FILE *fp;
int a;
- long now;
+ time_t now;
char dest_node[32];
char buf[256];
/* Don't confuse the poor folks if it's not routed mail. */
strcpy(dest_node, "");
+
/* If net_type is M_BINARY, split out the destination node. */
if (net_type == M_BINARY) {
strcpy(dest_node,NODENAME);
fprintf(fp,"A%s%c",fake_name,0);
else
fprintf(fp,"A%s%c",author->fullname,0); /* author */
- fprintf(fp,"O%s%c",CC->quickroom.QRname,0); /* room */
+
+ if (CC->quickroom.QRflags & QR_MAILBOX) { /* room */
+ fprintf(fp,"O%s%c", &CC->quickroom.QRname[11], 0);
+ }
+ else {
+ fprintf(fp,"O%s%c",CC->quickroom.QRname,0);
+ }
+
fprintf(fp,"N%s%c",NODENAME,0); /* nodename */
fprintf(fp,"H%s%c",HUMANNODE,0); /* human nodename */
strcpy(buf,recipient);
}
else strcpy(buf,"sysop");
- lprintf(9, "aliasing...\n");
e=alias(buf); /* alias and mail type */
- lprintf(9,"...type is %d\n", e);
if ((buf[0]==0) || (e==M_ERROR)) {
cprintf("%d Unknown address - cannot send message.\n",
ERROR+NO_SUCH_USER);
/* Check to make sure the user exists; also get the correct
* upper/lower casing of the name.
*/
- lprintf(9, "checking validity of %s\n", buf);
a = getuser(&tempUS,buf);
- lprintf(9, "getuser() returned %d\n", a);
if (a != 0) {
cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
return;
/* If we're in Mail, check the recipient */
if (CC->quickroom.QRflags & QR_MAILBOX) {
extract(recp, entargs, 1);
- lprintf(9, "aliasing...\n");
e=alias(recp); /* alias and mail type */
- lprintf(9,"...type is %d\n", e);
if ((buf[0]==0) || (e==M_ERROR)) {
cprintf("%d Unknown address - cannot send message.\n",
ERROR+NO_SUCH_USER);
}
/* put the message into the target room */
+ lgetroom(&qtemp, targ);
+ AddMessageToRoom(&qtemp, num);
+ lputroom(&qtemp, targ);
- cprintf("%d FIX FIX FIX implement this!!!!!\n", ERROR);
+ cprintf("%d Message moved.\n", OK);
}