# endif
#endif
+
#include <ctype.h>
#include <string.h>
#include <syslog.h>
int alias(char *name)
{ /* process alias and routing info for mail */
FILE *fp;
- int a, b;
- char aaa[300], bbb[300];
+ int a, i;
+ char aaa[SIZ], bbb[SIZ];
+ char *ignetcfg = NULL;
+ char *ignetmap = NULL;
+ int at = 0;
+ char node[SIZ];
+ char testnode[SIZ];
+ char buf[SIZ];
remove_any_whitespace_to_the_left_or_right_of_at_symbol(name);
fp = fopen("network/mail.aliases", "r");
- if (fp == NULL)
+ if (fp == NULL) {
fp = fopen("/dev/null", "r");
- if (fp == NULL)
+ }
+ if (fp == NULL) {
return (MES_ERROR);
+ }
strcpy(aaa, "");
strcpy(bbb, "");
while (fgets(aaa, sizeof aaa, fp) != NULL) {
}
/* determine local or remote type, see citadel.h */
- for (a = 0; a < strlen(name); ++a)
- if (name[a] == '!')
- return (MES_INTERNET);
- for (a = 0; a < strlen(name); ++a)
- if (name[a] == '@')
- for (b = a; b < strlen(name); ++b)
- if (name[b] == '.')
- return (MES_INTERNET);
- b = 0;
- for (a = 0; a < strlen(name); ++a)
- if (name[a] == '@')
- ++b;
- if (b > 1) {
- lprintf(7, "Too many @'s in address\n");
- return (MES_ERROR);
+
+ at = haschar(name, '@');
+ if (at == 0) return(MES_LOCAL); /* no @'s - local address */
+ if (at > 1) return(MES_ERROR); /* >1 @'s - invalid address */
+ remove_any_whitespace_to_the_left_or_right_of_at_symbol(name);
+
+ /* figure out the delivery mode */
+
+ extract_token(node, name, 1, '@');
+
+ /* If there are one or more dots in the nodename, we assume that it
+ * is an FQDN and will attempt SMTP delivery to the Internet.
+ */
+ if (haschar(node, '.') > 0) {
+ return(MES_INTERNET);
}
- if (b == 1) {
- for (a = 0; a < strlen(name); ++a)
- if (name[a] == '@')
- strcpy(bbb, &name[a + 1]);
- while (bbb[0] == 32)
- strcpy(bbb, &bbb[1]);
- fp = fopen("network/mail.sysinfo", "r");
- if (fp == NULL)
- return (MES_ERROR);
-GETSN: do {
- a = getstring(fp, aaa);
- } while ((a >= 0) && (strcasecmp(aaa, bbb)));
- a = getstring(fp, aaa);
- if (!strncmp(aaa, "use ", 4)) {
- strcpy(bbb, &aaa[4]);
- fseek(fp, 0L, 0);
- goto GETSN;
+
+ /* Otherwise we look in the IGnet maps for a valid Citadel node.
+ * Try directly-connected nodes first...
+ */
+ ignetcfg = CtdlGetSysConfig(IGNETCFG);
+ for (i=0; i<num_tokens(ignetcfg, '\n'); ++i) {
+ extract_token(buf, ignetcfg, i, '\n');
+ extract_token(testnode, buf, 0, '|');
+ if (!strcasecmp(node, testnode)) {
+ phree(ignetcfg);
+ return(MES_IGNET);
}
- fclose(fp);
- if (!strncmp(aaa, "uum", 3)) {
- strcpy(bbb, name);
- for (a = 0; a < strlen(bbb); ++a) {
- if (bbb[a] == '@')
- bbb[a] = 0;
- if (bbb[a] == ' ')
- bbb[a] = '_';
- }
- while (bbb[strlen(bbb) - 1] == '_')
- bbb[strlen(bbb) - 1] = 0;
- sprintf(name, &aaa[4], bbb);
- lprintf(9, "returning MES_INTERNET\n");
- return (MES_INTERNET);
- }
- if (!strncmp(aaa, "bin", 3)) {
- strcpy(aaa, name);
- strcpy(bbb, name);
- while (aaa[strlen(aaa) - 1] != '@')
- aaa[strlen(aaa) - 1] = 0;
- aaa[strlen(aaa) - 1] = 0;
- while (aaa[strlen(aaa) - 1] == ' ')
- aaa[strlen(aaa) - 1] = 0;
- while (bbb[0] != '@')
- strcpy(bbb, &bbb[1]);
- strcpy(bbb, &bbb[1]);
- while (bbb[0] == ' ')
- strcpy(bbb, &bbb[1]);
- sprintf(name, "%s @%s", aaa, bbb);
- lprintf(9, "returning MES_BINARY\n");
- return (MES_BINARY);
+ }
+ phree(ignetcfg);
+
+ /*
+ * Then try nodes that are two or more hops away.
+ */
+ ignetmap = CtdlGetSysConfig(IGNETMAP);
+ for (i=0; i<num_tokens(ignetmap, '\n'); ++i) {
+ extract_token(buf, ignetmap, i, '\n');
+ extract_token(testnode, buf, 0, '|');
+ if (!strcasecmp(node, testnode)) {
+ phree(ignetmap);
+ return(MES_IGNET);
}
- return (MES_ERROR);
}
- lprintf(9, "returning MES_LOCAL\n");
- return (MES_LOCAL);
+ phree(ignetmap);
+
+ /* If we get to this point it's an invalid node name */
+ return (MES_ERROR);
}
}
/* nhdr=yes means that we're only displaying headers, no body */
- if ((TheMessage->cm_anon_type == MES_ANON) && (mode == MT_CITADEL)) {
+ if ((TheMessage->cm_anon_type == MES_ANONONLY) && (mode == MT_CITADEL)) {
if (do_proto) cprintf("nhdr=yes\n");
}
if (TheMessage->cm_fields['A']) {
strcpy(buf, TheMessage->cm_fields['A']);
PerformUserHooks(buf, (-1L), EVT_OUTPUTMSG);
- if (TheMessage->cm_anon_type == MES_ANON)
+ if (TheMessage->cm_anon_type == MES_ANONONLY) {
strcpy(display_name, "****");
- else if (TheMessage->cm_anon_type == MES_AN2)
+ }
+ else if (TheMessage->cm_anon_type == MES_ANONOPT) {
strcpy(display_name, "anonymous");
- else
+ }
+ else {
strcpy(display_name, buf);
+ }
if ((is_room_aide())
- && ((TheMessage->cm_anon_type == MES_ANON)
- || (TheMessage->cm_anon_type == MES_AN2))) {
+ && ((TheMessage->cm_anon_type == MES_ANONONLY)
+ || (TheMessage->cm_anon_type == MES_ANONOPT))) {
sprintf(&display_name[strlen(display_name)],
" [%s]", buf);
}
* Message base operation to send a message to the master file
* (returns new message number)
*
- * This is the back end for CtdlSaveMsg() and should not be directly
+ * This is the back end for CtdlSubmitMsg() and should not be directly
* called by server-side modules.
*
*/
/*
- * Save a message to disk
+ * Save a message to disk and submit it into the delivery system.
*/
-long CtdlSaveMsg(struct CtdlMessage *msg, /* message to save */
- char *rec, /* Recipient (mail) */
- char *force, /* force a particular room? */
- int supplied_mailtype) /* local or remote type */
-{
- char aaa[100];
+long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */
+ struct recptypes *recps, /* recipients (if mail) */
+ char *force /* force a particular room? */
+) {
+ char aaa[SIZ];
char hold_rm[ROOMNAMELEN];
char actual_rm[ROOMNAMELEN];
char force_room[ROOMNAMELEN];
long newmsgid;
char *mptr = NULL;
struct usersupp userbuf;
- int a;
+ int a, i;
struct MetaData smi;
FILE *network_fp = NULL;
static int seqnum = 1;
- struct CtdlMessage *imsg;
+ struct CtdlMessage *imsg = NULL;
char *instr;
- int mailtype;
+ struct ser_ret smr;
+ char *hold_R, *hold_D;
- lprintf(9, "CtdlSaveMsg() called\n");
+ lprintf(9, "CtdlSubmitMsg() called\n");
if (is_valid_message(msg) == 0) return(-1); /* self check */
- mailtype = supplied_mailtype;
/* If this message has no timestamp, we take the liberty of
* giving it one, right now.
strcpy(force_room, force);
- /* Strip non-printable characters out of the recipient name */
- lprintf(9, "Checking recipient (if present)\n");
- strcpy(recipient, rec);
- for (a = 0; a < strlen(recipient); ++a)
- if (!isprint(recipient[a]))
- strcpy(&recipient[a], &recipient[a + 1]);
-
- /* Change "user @ xxx" to "user" if xxx is an alias for this host */
- for (a=0; a<strlen(recipient); ++a) {
- if (recipient[a] == '@') {
- if (CtdlHostAlias(&recipient[a+1])
- == hostalias_localhost) {
- recipient[a] = 0;
- lprintf(7, "Changed to <%s>\n", recipient);
- mailtype = MES_LOCAL;
- }
- }
- }
-
- lprintf(9, "Recipient is <%s>\n", recipient);
-
/* Learn about what's inside, because it's what's inside that counts */
lprintf(9, "Learning what's inside\n");
if (msg->cm_fields['M'] == NULL) {
lprintf(9, "Switching rooms\n");
strcpy(hold_rm, CC->quickroom.QRname);
strcpy(actual_rm, CC->quickroom.QRname);
+ if (recps != NULL) {
+ strcpy(actual_rm, SENTITEMS);
+ }
/* If the user is a twit, move to the twit room for posting */
lprintf(9, "Handling twit stuff\n");
lprintf(9, "Performing replication checks\n");
if (ReplicationChecks(msg) > 0) return(-1);
- /* Network mail - send a copy to the network program. */
- if ((strlen(recipient) > 0) && (mailtype == MES_BINARY)) {
- lprintf(9, "Sending network spool\n");
- sprintf(aaa, "./network/spoolin/netmail.%04lx.%04x.%04x",
- (long) getpid(), CC->cs_pid, ++seqnum);
- lprintf(9, "Saving a copy to %s\n", aaa);
- network_fp = fopen(aaa, "ab+");
- if (network_fp == NULL)
- lprintf(2, "ERROR: %s\n", strerror(errno));
- }
-
/* Save it to disk */
lprintf(9, "Saving to disk\n");
- newmsgid = send_message(msg, network_fp);
- if (network_fp != NULL) {
- fclose(network_fp);
- /* FIXME start a network run here */
- }
-
+ newmsgid = send_message(msg, NULL);
if (newmsgid <= 0L) return(-1);
/* Write a supplemental message info record. This doesn't have to
* message, we want to BYPASS saving the sender's copy (because there
* is no local sender; it would otherwise go to the Trashcan).
*/
- if ((!CC->internal_pgm) || (strlen(recipient) == 0)) {
+ if ((!CC->internal_pgm) || (recps == NULL)) {
if (CtdlSaveMsgPointerInRoom(actual_rm, newmsgid, 0) != 0) {
lprintf(3, "ERROR saving message pointer!\n");
CtdlSaveMsgPointerInRoom(AIDEROOM, newmsgid, 0);
}
/* For internet mail, drop a copy in the outbound queue room */
- if (mailtype == MES_INTERNET) {
+ if (recps != NULL)
+ if (recps->num_internet > 0) {
CtdlSaveMsgPointerInRoom(SMTP_SPOOLOUT_ROOM, newmsgid, 0);
}
+ /* If other rooms are specified, drop them there too. */
+ if (recps != NULL)
+ if (recps->num_room > 0)
+ for (i=0; i<num_tokens(recps->recp_room, '|'); ++i) {
+ extract(recipient, recps->recp_room, i);
+ lprintf(9, "Delivering to local room <%s>\n", recipient);
+ CtdlSaveMsgPointerInRoom(recipient, newmsgid, 0);
+ }
+
/* Bump this user's messages posted counter. */
lprintf(9, "Updating user\n");
lgetuser(&CC->usersupp, CC->curr_user);
/* If this is private, local mail, make a copy in the
* recipient's mailbox and bump the reference count.
*/
- if ((strlen(recipient) > 0) && (mailtype == MES_LOCAL)) {
+ if (recps != NULL)
+ if (recps->num_local > 0)
+ for (i=0; i<num_tokens(recps->recp_local, '|'); ++i) {
+ extract(recipient, recps->recp_local, i);
+ lprintf(9, "Delivering private local mail to <%s>\n",
+ recipient);
if (getuser(&userbuf, recipient) == 0) {
- lprintf(9, "Delivering private mail\n");
MailboxName(actual_rm, &userbuf, MAILROOM);
CtdlSaveMsgPointerInRoom(actual_rm, newmsgid, 0);
}
else {
- lprintf(9, "No user <%s>, saving in %s> instead\n",
- recipient, AIDEROOM);
+ lprintf(9, "No user <%s>\n", recipient);
CtdlSaveMsgPointerInRoom(AIDEROOM, newmsgid, 0);
}
}
lprintf(9, "Performing after-save hooks\n");
PerformMessageHooks(msg, EVT_AFTERSAVE);
- /* */
+ /* For IGnet mail, we have to save a new copy into the spooler for
+ * each recipient, with the R and D fields set to the recipient and
+ * destination-node. This has two ugly side effects: all other
+ * recipients end up being unlisted in this recipient's copy of the
+ * message, and it has to deliver multiple messages to the same
+ * node. We'll revisit this again in a year or so when everyone has
+ * a network spool receiver that can handle the new style messages.
+ */
+ if (recps != NULL)
+ if (recps->num_ignet > 0)
+ for (i=0; i<num_tokens(recps->recp_ignet, '|'); ++i) {
+ extract(recipient, recps->recp_ignet, i);
+
+ hold_R = msg->cm_fields['R'];
+ hold_D = msg->cm_fields['D'];
+ msg->cm_fields['R'] = mallok(SIZ);
+ msg->cm_fields['D'] = mallok(SIZ);
+ extract_token(msg->cm_fields['R'], recipient, 0, '@');
+ extract_token(msg->cm_fields['D'], recipient, 1, '@');
+
+ serialize_message(&smr, msg);
+ if (smr.len > 0) {
+ sprintf(aaa,
+ "./network/spoolin/netmail.%04lx.%04x.%04x",
+ (long) getpid(), CC->cs_pid, ++seqnum);
+ network_fp = fopen(aaa, "wb+");
+ if (network_fp != NULL) {
+ fwrite(smr.ser, smr.len, 1, network_fp);
+ fclose(network_fp);
+ }
+ phree(smr.ser);
+ }
+
+ phree(msg->cm_fields['R']);
+ phree(msg->cm_fields['D']);
+ msg->cm_fields['R'] = hold_R;
+ msg->cm_fields['D'] = hold_D;
+ }
+
+ /* Go back to the room we started from */
lprintf(9, "Returning to original room\n");
if (strcasecmp(hold_rm, CC->quickroom.QRname))
getroom(&CC->quickroom, hold_rm);
- /* For internet mail, generate delivery instructions
- * (Yes, this is recursive! Deal with it!)
+ /* For internet mail, generate delivery instructions.
+ * Yes, this is recursive. Deal with it. Infinite recursion does
+ * not happen because the delivery instructions message does not
+ * contain a recipient.
*/
- if (mailtype == MES_INTERNET) {
+ if (recps != NULL)
+ if (recps->num_internet > 0) {
lprintf(9, "Generating delivery instructions\n");
- instr = mallok(2048);
+ instr = mallok(SIZ * 2);
sprintf(instr,
"Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n"
- "bounceto|%s@%s\n"
- "remote|%s|0||\n",
+ "bounceto|%s@%s\n",
SPOOLMIME, newmsgid, (long)time(NULL),
- msg->cm_fields['A'], msg->cm_fields['N'],
- recipient );
+ msg->cm_fields['A'], msg->cm_fields['N']
+ );
+
+ for (i=0; i<num_tokens(recps->recp_internet, '|'); ++i) {
+ extract(recipient, recps->recp_internet, i);
+ sprintf(&instr[strlen(instr)],
+ "remote|%s|0||\n", recipient);
+ }
imsg = mallok(sizeof(struct CtdlMessage));
memset(imsg, 0, sizeof(struct CtdlMessage));
imsg->cm_format_type = FMT_RFC822;
imsg->cm_fields['A'] = strdoop("Citadel");
imsg->cm_fields['M'] = instr;
- CtdlSaveMsg(imsg, "", SMTP_SPOOLOUT_ROOM, MES_LOCAL);
+ CtdlSubmitMsg(imsg, NULL, SMTP_SPOOLOUT_ROOM);
CtdlFreeMessage(imsg);
}
msg->cm_fields['R'] = strdoop(to);
msg->cm_fields['M'] = strdoop(text);
- CtdlSaveMsg(msg, "", room, MES_LOCAL);
+ CtdlSubmitMsg(msg, NULL, room);
CtdlFreeMessage(msg);
syslog(LOG_NOTICE, text);
}
m = reallok(exist, strlen(exist) + 4096);
if (m == NULL) phree(exist);
}
+
+ /* flush the input if we have nowhere to store it */
if (m == NULL) {
while ( (client_gets(buf)>0) && strcmp(buf, terminator) ) ;;
return(NULL);
- } else {
+ }
+
+ /* otherwise read it into memory */
+ else {
buffer_len = 4096;
m[0] = 0;
message_len = 0;
}
}
- /* Add the new line to the buffer. We avoid using strcat()
- * because that would involve traversing the entire message
- * after each line, and this function needs to run fast.
+ /* Add the new line to the buffer. NOTE: this loop must avoid
+ * using functions like strcat() and strlen() because they
+ * traverse the entire buffer upon every call, and doing that
+ * for a multi-megabyte message slows it down beyond usability.
*/
strcpy(&m[message_len], buf);
m[message_len + linelen] = '\n';
char *recipient, /* NULL if it's not mail */
char *room, /* room where it's going */
int type, /* see MES_ types in header file */
- int net_type, /* see MES_ types in header file */
- int format_type, /* local or remote (see citadel.h) */
- char *fake_name) /* who we're masquerading as */
-{
-
- int a;
- char dest_node[32];
+ int format_type, /* variformat, plain text, MIME... */
+ char *fake_name /* who we're masquerading as */
+) {
+ char dest_node[SIZ];
char buf[SIZ];
struct CtdlMessage *msg;
/* Don't confuse the poor folks if it's not routed mail. */
strcpy(dest_node, "");
- /* If net_type is MES_BINARY, split out the destination node. */
- if (net_type == MES_BINARY) {
- strcpy(dest_node, NODENAME);
- for (a = 0; a < strlen(recipient); ++a) {
- if (recipient[a] == '@') {
- recipient[a] = 0;
- strcpy(dest_node, &recipient[a + 1]);
- }
- }
- }
-
- /* if net_type is MES_INTERNET, set the dest node to 'internet' */
- if (net_type == MES_INTERNET) {
- strcpy(dest_node, "internet");
- }
-
- while (isspace(recipient[strlen(recipient) - 1]))
- recipient[strlen(recipient) - 1] = 0;
+ striplt(recipient);
sprintf(buf, "cit%ld", author->usernum); /* Path */
msg->cm_fields['P'] = strdoop(buf);
else
msg->cm_fields['A'] = strdoop(author->fullname);
- if (CC->quickroom.QRflags & QR_MAILBOX) /* room */
+ if (CC->quickroom.QRflags & QR_MAILBOX) { /* room */
msg->cm_fields['O'] = strdoop(&CC->quickroom.QRname[11]);
- else
+ }
+ else {
msg->cm_fields['O'] = strdoop(CC->quickroom.QRname);
+ }
msg->cm_fields['N'] = strdoop(NODENAME); /* nodename */
msg->cm_fields['H'] = strdoop(HUMANNODE); /* hnodename */
- if (recipient[0] != 0)
+ if (recipient[0] != 0) {
msg->cm_fields['R'] = strdoop(recipient);
- if (dest_node[0] != 0)
+ }
+ if (dest_node[0] != 0) {
msg->cm_fields['D'] = strdoop(dest_node);
-
+ }
msg->cm_fields['M'] = CtdlReadMessageBody("000",
config.c_maxmsglen, NULL);
-
return(msg);
}
}
+/*
+ * Validate recipients, count delivery types and errors, and handle aliasing
+ * FIXME check for dupes!!!!!
+ */
+struct recptypes *validate_recipients(char *recipients) {
+ struct recptypes *ret;
+ char this_recp[SIZ];
+ char append[SIZ];
+ int num_recps;
+ int i;
+ int mailtype;
+ int invalid;
+ struct usersupp tempUS;
+
+ /* Initialize */
+ ret = (struct recptypes *) malloc(sizeof(struct recptypes));
+ if (ret == NULL) return(NULL);
+ memset(ret, 0, sizeof(struct recptypes));
+
+ ret->num_local = 0;
+ ret->num_internet = 0;
+ ret->num_ignet = 0;
+ ret->num_error = 0;
+
+ if (recipients == NULL) {
+ num_recps = 0;
+ }
+ else if (strlen(recipients) == 0) {
+ num_recps = 0;
+ }
+ else {
+ /* Change all valid separator characters to commas */
+ for (i=0; i<strlen(recipients); ++i) {
+ if ((recipients[i] == ';') || (recipients[i] == '|')) {
+ recipients[i] = ',';
+ }
+ }
+
+ /* Count 'em up */
+ num_recps = num_tokens(recipients, ',');
+ }
+
+ if (num_recps > 0) for (i=0; i<num_recps; ++i) {
+ extract_token(this_recp, recipients, i, ',');
+ striplt(this_recp);
+ lprintf(9, "Evaluating recipient #%d <%s>\n", i, this_recp);
+ mailtype = alias(this_recp);
+ invalid = 0;
+ switch(mailtype) {
+ case MES_LOCAL:
+ if (!strcasecmp(this_recp, "sysop")) {
+ ++ret->num_room;
+ strcpy(this_recp, AIDEROOM);
+ if (strlen(ret->recp_room) > 0) {
+ strcat(ret->recp_room, "|");
+ }
+ strcat(ret->recp_room, this_recp);
+ }
+ else if (getuser(&tempUS, this_recp) == 0) {
+ ++ret->num_local;
+ strcpy(this_recp, tempUS.fullname);
+ if (strlen(ret->recp_local) > 0) {
+ strcat(ret->recp_local, "|");
+ }
+ strcat(ret->recp_local, this_recp);
+ }
+ else {
+ ++ret->num_error;
+ invalid = 1;
+ }
+ break;
+ case MES_INTERNET:
+ ++ret->num_internet;
+ if (strlen(ret->recp_internet) > 0) {
+ strcat(ret->recp_internet, "|");
+ }
+ strcat(ret->recp_internet, this_recp);
+ break;
+ case MES_IGNET:
+ ++ret->num_ignet;
+ if (strlen(ret->recp_ignet) > 0) {
+ strcat(ret->recp_ignet, "|");
+ }
+ strcat(ret->recp_ignet, this_recp);
+ break;
+ case MES_ERROR:
+ ++ret->num_error;
+ invalid = 1;
+ break;
+ }
+ if (invalid) {
+ if (strlen(ret->errormsg) == 0) {
+ sprintf(append,
+ "Invalid recipient: %s",
+ this_recp);
+ }
+ else {
+ sprintf(append,
+ ", %s", this_recp);
+ }
+ if ( (strlen(ret->errormsg) + strlen(append)) < SIZ) {
+ strcat(ret->errormsg, append);
+ }
+ }
+ else {
+ if (strlen(ret->display_recp) == 0) {
+ strcpy(append, this_recp);
+ }
+ else {
+ sprintf(append, ", %s", this_recp);
+ }
+ if ( (strlen(ret->display_recp)+strlen(append)) < SIZ) {
+ strcat(ret->display_recp, append);
+ }
+ }
+ }
+
+ if ((ret->num_local + ret->num_internet + ret->num_ignet +
+ ret->num_room + ret->num_error) == 0) {
+ ++ret->num_error;
+ strcpy(ret->errormsg, "No recipients specified.");
+ }
+
+ return(ret);
+}
+
/*
void cmd_ent0(char *entargs)
{
int post = 0;
- char recipient[SIZ];
+ char recp[SIZ];
+ char masquerade_as[SIZ];
int anon_flag = 0;
int format_type = 0;
char newusername[SIZ];
struct CtdlMessage *msg;
- int a, b;
- int e = 0;
- int mtsflag = 0;
- struct usersupp tempUS;
- char buf[SIZ];
+ int anonymous = 0;
+ char errmsg[SIZ];
int err = 0;
+ struct recptypes *valid = NULL;
post = extract_int(entargs, 0);
- extract(recipient, entargs, 1);
+ extract(recp, entargs, 1);
anon_flag = extract_int(entargs, 2);
format_type = extract_int(entargs, 3);
/* first check to make sure the request is valid. */
- err = CtdlDoIHavePermissionToPostInThisRoom(buf);
+ err = CtdlDoIHavePermissionToPostInThisRoom(errmsg);
if (err) {
- cprintf("%d %s\n", err, buf);
+ cprintf("%d %s\n", err, errmsg);
return;
}
/* Check some other permission type things. */
if (post == 2) {
- if (CC->usersupp.axlevel < 6) {
+ if (CC->usersupp.axlevel < 6) {
cprintf("%d You don't have permission to masquerade.\n",
ERROR + HIGHER_ACCESS_REQUIRED);
return;
}
extract(newusername, entargs, 4);
- memset(CC->fake_postname, 0, 32);
- strcpy(CC->fake_postname, newusername);
- cprintf("%d Ok\n", OK);
+ memset(CC->fake_postname, 0, sizeof(CC->fake_postname) );
+ safestrncpy(CC->fake_postname, newusername,
+ sizeof(CC->fake_postname) );
+ cprintf("%d ok\n", OK);
return;
}
CC->cs_flags |= CS_POSTING;
- buf[0] = 0;
if (CC->quickroom.QRflags & QR_MAILBOX) {
- if (CC->usersupp.axlevel >= 2) {
- strcpy(buf, recipient);
- } else
- strcpy(buf, "sysop");
- e = alias(buf); /* alias and mail type */
- if ((buf[0] == 0) || (e == MES_ERROR)) {
- cprintf("%d Unknown address - cannot send message.\n",
- ERROR + NO_SUCH_USER);
+ if (CC->usersupp.axlevel < 2) {
+ strcpy(recp, "sysop");
+ }
+
+ valid = validate_recipients(recp);
+ if (valid->num_error > 0) {
+ cprintf("%d %s\n",
+ ERROR + NO_SUCH_USER, valid->errormsg);
+ phree(valid);
return;
}
- if ((e != MES_LOCAL) && (CC->usersupp.axlevel < 4)) {
- cprintf("%d Net privileges required for network mail.\n",
+
+ if ( ( (valid->num_internet + valid->num_ignet) > 0)
+ && (CC->usersupp.axlevel < 4) ) {
+ cprintf("%d Higher access required for network mail.\n",
ERROR + HIGHER_ACCESS_REQUIRED);
+ phree(valid);
return;
}
- if ((RESTRICT_INTERNET == 1) && (e == MES_INTERNET)
+
+ if ((RESTRICT_INTERNET == 1) && (valid->num_internet > 0)
&& ((CC->usersupp.flags & US_INTERNET) == 0)
&& (!CC->internal_pgm)) {
cprintf("%d You don't have access to Internet mail.\n",
ERROR + HIGHER_ACCESS_REQUIRED);
+ phree(valid);
return;
}
- if (!strcasecmp(buf, "sysop")) {
- mtsflag = 1;
- }
- else if (e == MES_LOCAL) { /* don't search local file */
- if (!strcasecmp(buf, CC->usersupp.fullname)) {
- cprintf("%d Can't send mail to yourself!\n",
- ERROR + NO_SUCH_USER);
- return;
- }
- /* Check to make sure the user exists; also get the correct
- * upper/lower casing of the name.
- */
- a = getuser(&tempUS, buf);
- if (a != 0) {
- cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
- return;
- }
- strcpy(buf, tempUS.fullname);
- }
+
}
- b = MES_NORMAL;
- if (CC->quickroom.QRflags & QR_ANONONLY)
- b = MES_ANON;
+ /* Is this a room which has anonymous-only or anonymous-option? */
+ anonymous = MES_NORMAL;
+ if (CC->quickroom.QRflags & QR_ANONONLY) {
+ anonymous = MES_ANONONLY;
+ }
if (CC->quickroom.QRflags & QR_ANONOPT) {
- if (anon_flag == 1)
- b = MES_AN2;
+ if (anon_flag == 1) { /* only if the user requested it */
+ anonymous = MES_ANONOPT;
+ }
+ }
+
+ if ((CC->quickroom.QRflags & QR_MAILBOX) == 0) {
+ recp[0] = 0;
}
- if ((CC->quickroom.QRflags & QR_MAILBOX) == 0)
- buf[0] = 0;
/* If we're only checking the validity of the request, return
* success without creating the message.
*/
if (post == 0) {
- cprintf("%d %s\n", OK, buf);
+ cprintf("%d %s\n", OK,
+ ((valid != NULL) ? valid->display_recp : "") );
+ phree(valid);
return;
}
- cprintf("%d send message\n", SEND_LISTING);
+ /* Handle author masquerading */
+ if (CC->fake_postname[0]) {
+ strcpy(masquerade_as, CC->fake_postname);
+ }
+ else if (CC->fake_username[0]) {
+ strcpy(masquerade_as, CC->fake_username);
+ }
+ else {
+ strcpy(masquerade_as, "");
+ }
/* Read in the message from the client. */
- if (CC->fake_postname[0])
- msg = make_message(&CC->usersupp, buf,
- CC->quickroom.QRname, b, e, format_type,
- CC->fake_postname);
- else if (CC->fake_username[0])
- msg = make_message(&CC->usersupp, buf,
- CC->quickroom.QRname, b, e, format_type,
- CC->fake_username);
- else
- msg = make_message(&CC->usersupp, buf,
- CC->quickroom.QRname, b, e, format_type, "");
+ cprintf("%d send message\n", SEND_LISTING);
+ msg = make_message(&CC->usersupp, recp,
+ CC->quickroom.QRname, anonymous, format_type, masquerade_as);
- if (msg != NULL)
- CtdlSaveMsg(msg, buf, (mtsflag ? AIDEROOM : ""), e);
+ if (msg != NULL) {
+ CtdlSubmitMsg(msg, valid, "");
CtdlFreeMessage(msg);
+ }
CC->fake_postname[0] = '\0';
+ phree(valid);
return;
}
-/*
- * message entry - mode 3 (raw)
- */
-void cmd_ent3(char *entargs)
-{
- char recp[SIZ];
- int a;
- int e = 0;
- int valid_msg = 1;
- unsigned char ch, which_field;
- struct usersupp tempUS;
- long msglen;
- struct CtdlMessage *msg;
- char *tempbuf;
-
- if (CC->internal_pgm == 0) {
- cprintf("%d This command is for internal programs only.\n",
- ERROR);
- return;
- }
-
- /* See if there's a recipient, but make sure it's a real one */
- extract(recp, entargs, 1);
- for (a = 0; a < strlen(recp); ++a)
- if (!isprint(recp[a]))
- strcpy(&recp[a], &recp[a + 1]);
- while (isspace(recp[0]))
- strcpy(recp, &recp[1]);
- while (isspace(recp[strlen(recp) - 1]))
- recp[strlen(recp) - 1] = 0;
-
- /* If we're in Mail, check the recipient */
- if (strlen(recp) > 0) {
- e = alias(recp); /* alias and mail type */
- if ((recp[0] == 0) || (e == MES_ERROR)) {
- cprintf("%d Unknown address - cannot send message.\n",
- ERROR + NO_SUCH_USER);
- return;
- }
- if (e == MES_LOCAL) {
- a = getuser(&tempUS, recp);
- if (a != 0) {
- cprintf("%d No such user.\n",
- ERROR + NO_SUCH_USER);
- return;
- }
- }
- }
-
- /* At this point, message has been approved. */
- if (extract_int(entargs, 0) == 0) {
- cprintf("%d OK to send\n", OK);
- return;
- }
-
- msglen = extract_long(entargs, 2);
- msg = mallok(sizeof(struct CtdlMessage));
- if (msg == NULL) {
- cprintf("%d Out of memory\n", ERROR+INTERNAL_ERROR);
- return;
- }
-
- memset(msg, 0, sizeof(struct CtdlMessage));
- tempbuf = mallok(msglen);
- if (tempbuf == NULL) {
- cprintf("%d Out of memory\n", ERROR+INTERNAL_ERROR);
- phree(msg);
- return;
- }
-
- cprintf("%d %ld\n", SEND_BINARY, msglen);
-
- client_read((char*)&ch, 1); /* 0xFF magic number */
- msg->cm_magic = CTDLMESSAGE_MAGIC;
- client_read((char*)&ch, 1); /* anon type */
- msg->cm_anon_type = ch;
- client_read((char*)&ch, 1); /* format type */
- msg->cm_format_type = ch;
- msglen = msglen - 3;
-
- while (msglen > 0) {
- client_read((char*)&which_field, 1);
- if (!isalpha(which_field)) valid_msg = 0;
- --msglen;
- tempbuf[0] = 0;
- do {
- client_read((char*)&ch, 1);
- --msglen;
- a = strlen(tempbuf);
- tempbuf[a+1] = 0;
- tempbuf[a] = ch;
- } while ( (ch != 0) && (msglen > 0) );
- if (valid_msg)
- msg->cm_fields[which_field] = strdoop(tempbuf);
- }
-
- msg->cm_flags = CM_SKIP_HOOKS;
- if (valid_msg) CtdlSaveMsg(msg, recp, "", e);
- CtdlFreeMessage(msg);
- phree(tempbuf);
-}
-
-
/*
* API function to delete messages which match a set of criteria
* (returns the actual number of messages deleted)
/* Now delete the message from the source room,
* if this is a 'move' rather than a 'copy' operation.
*/
- if (is_copy == 0) CtdlDeleteMessages(CC->quickroom.QRname, num, "");
+ if (is_copy == 0) {
+ CtdlDeleteMessages(CC->quickroom.QRname, num, "");
+ }
cprintf("%d Message %s.\n", OK, (is_copy ? "copied" : "moved") );
}
{
long TheIndex;
- /* Use the negative of the message number for its supp record index */
+ /* Use the negative of the message number for the metadata db index */
TheIndex = (0L - smibuf->meta_msgnum);
- lprintf(9, "PuttMetaData(%ld) - ref count is %d\n",
+ lprintf(9, "PutMetaData(%ld) - ref count is %d\n",
smibuf->meta_msgnum, smibuf->meta_refcount);
cdb_store(CDB_MSGMAIN,
lprintf(9, "Deleting message <%ld>\n", msgnum);
delnum = msgnum;
cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
+
+ /* We have to delete the metadata record too! */
delnum = (0L - msgnum);
cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
}
CtdlDeleteMessages(roomname, 0L, content_type));
}
/* Now write the data */
- CtdlSaveMsg(msg, "", roomname, MES_LOCAL);
+ CtdlSubmitMsg(msg, NULL, roomname);
CtdlFreeMessage(msg);
}