extern struct config config;
long config_msgnum;
+
+/*
+ * This really belongs in serv_network.c, but I don't know how to export
+ * symbols between modules.
+ */
+struct FilterList *filterlist = NULL;
+
+
+/*
+ * These are the four-character field headers we use when outputting
+ * messages in Citadel format (as opposed to RFC822 format).
+ */
char *msgkeys[] = {
- "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "",
- "",
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL,
"from",
- "", "", "",
+ NULL, NULL, NULL,
"exti",
"rfca",
- "",
+ NULL,
"hnod",
"msgn",
- "", "", "",
+ NULL, NULL, NULL,
"text",
"node",
"room",
"path",
- "",
+ NULL,
"rcpt",
"spec",
"time",
"subj",
- "",
- "",
- "",
- "",
- ""
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
};
/*
char testnode[SIZ];
char buf[SIZ];
+ striplt(name);
remove_any_whitespace_to_the_left_or_right_of_at_symbol(name);
fp = fopen("network/mail.aliases", "r");
strcpy(name, bbb);
}
fclose(fp);
+
+ /* Hit the Global Address Book */
+ if (CtdlDirectoryLookup(aaa, name) == 0) {
+ strcpy(name, aaa);
+ }
+
lprintf(7, "Mail is being forwarded to %s\n", name);
/* Change "user @ xxx" to "user" if xxx is an alias for this host */
}
/* determine local or remote type, see citadel.h */
-
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
{
int i;
- lprintf(9, "CtdlFreeMessage() called\n");
if (is_valid_message(msg) == 0) return;
for (i = 0; i < 256; ++i)
char display_name[SIZ];
char *mptr;
char *nl; /* newline string */
+ int suppress_f = 0;
/* buffers needed for RFC822 translation */
char suser[SIZ];
}
}
+ /* Don't show Internet address for users on the
+ * local Citadel network.
+ */
+ suppress_f = 0;
+ if (TheMessage->cm_fields['N'] != NULL)
+ if (strlen(TheMessage->cm_fields['N']) > 0)
+ if (haschar(TheMessage->cm_fields['N'], '.') == 0) {
+ suppress_f = 1;
+ }
+
+ /* Now spew the header fields in the order we like them. */
strcpy(allkeys, FORDER);
for (i=0; i<strlen(allkeys); ++i) {
k = (int) allkeys[i];
if (k != 'M') {
- if (TheMessage->cm_fields[k] != NULL) {
+ if ( (TheMessage->cm_fields[k] != NULL)
+ && (msgkeys[k] != NULL) ) {
if (k == 'A') {
if (do_proto) cprintf("%s=%s\n",
msgkeys[k],
display_name);
}
+ else if ((k == 'F') && (suppress_f)) {
+ /* do nothing */
+ }
+ /* Masquerade display name if needed */
else {
if (do_proto) cprintf("%s=%s\n",
msgkeys[k],
else if (i == 'U')
cprintf("Subject: %s%s", mptr, nl);
else if (i == 'I')
- strcpy(mid, mptr);
+ safestrncpy(mid, mptr, sizeof mid);
else if (i == 'H')
- strcpy(lnode, mptr);
+ safestrncpy(lnode, mptr, sizeof lnode);
+ else if (i == 'F')
+ safestrncpy(fuser, mptr, sizeof fuser);
else if (i == 'O')
cprintf("X-Citadel-Room: %s%s",
mptr, nl);
else if (i == 'N')
- strcpy(snode, mptr);
+ safestrncpy(snode, mptr, sizeof snode);
else if (i == 'R')
cprintf("To: %s%s", mptr, nl);
else if (i == 'T') {
- datestring(datestamp, atol(mptr),
+ datestring(datestamp, sizeof datestamp, atol(mptr),
DATESTRING_RFC822 );
cprintf("Date: %s%s", datestamp, nl);
}
* 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);
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);
+ lprintf(9, "Delivering to local room <%s>\n", recipient);
CtdlSaveMsgPointerInRoom(recipient, newmsgid, 0);
}
}
else {
lprintf(9, "No user <%s>\n", recipient);
+ CtdlSaveMsgPointerInRoom(AIDEROOM, newmsgid, 0);
}
}
if (exist == NULL) {
m = mallok(4096);
+ m[0] = 0;
+ buffer_len = 4096;
+ message_len = 0;
}
else {
- m = reallok(exist, strlen(exist) + 4096);
- if (m == NULL) phree(exist);
+ message_len = strlen(exist);
+ buffer_len = message_len + 4096;
+ m = reallok(exist, buffer_len);
+ if (m == NULL) {
+ phree(exist);
+ return m;
+ }
}
/* flush the input if we have nowhere to store it */
return(NULL);
}
- /* otherwise read it into memory */
- else {
- buffer_len = 4096;
- m[0] = 0;
- message_len = 0;
- }
/* read in the lines of message text one by one */
while ( (client_gets(buf)>0) && strcmp(buf, terminator) ) {
char *room, /* room where it's going */
int type, /* see MES_ types in header file */
int format_type, /* variformat, plain text, MIME... */
- char *fake_name /* who we're masquerading as */
+ char *fake_name, /* who we're masquerading as */
+ char *subject /* Subject (optional) */
) {
char dest_node[SIZ];
char buf[SIZ];
msg->cm_fields['D'] = strdoop(dest_node);
}
+ if ( (author == &CC->usersupp) && (CC->cs_inet_email != NULL) ) {
+ msg->cm_fields['F'] = strdoop(CC->cs_inet_email);
+ }
+
+ if (subject != NULL) {
+ striplt(subject);
+ if (strlen(subject) > 0) {
+ msg->cm_fields['U'] = strdoop(subject);
+ }
+ }
+
msg->cm_fields['M'] = CtdlReadMessageBody("000",
config.c_maxmsglen, NULL);
struct recptypes *validate_recipients(char *recipients) {
struct recptypes *ret;
char this_recp[SIZ];
+ char this_recp_cooked[SIZ];
char append[SIZ];
int num_recps;
- int i;
+ int i, j;
int mailtype;
int invalid;
struct usersupp tempUS;
+ struct quickroom tempQR;
/* Initialize */
ret = (struct recptypes *) malloc(sizeof(struct recptypes));
ret->num_internet = 0;
ret->num_ignet = 0;
ret->num_error = 0;
+ ret->num_room = 0;
if (recipients == NULL) {
num_recps = 0;
striplt(this_recp);
lprintf(9, "Evaluating recipient #%d <%s>\n", i, this_recp);
mailtype = alias(this_recp);
+ mailtype = alias(this_recp);
+ mailtype = alias(this_recp);
+ for (j=0; j<=strlen(this_recp); ++j) {
+ if (this_recp[j]=='_') {
+ this_recp_cooked[j] = ' ';
+ }
+ else {
+ this_recp_cooked[j] = this_recp[j];
+ }
+ }
invalid = 0;
switch(mailtype) {
case MES_LOCAL:
- if (getuser(&tempUS, this_recp) == 0) {
+ 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, this_recp);
}
+ else if (getuser(&tempUS, this_recp_cooked) == 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 if ( (!strncasecmp(this_recp, "room_", 5))
+ && (!getroom(&tempQR, &this_recp_cooked[5])) ) {
+ ++ret->num_room;
+ if (strlen(ret->recp_room) > 0) {
+ strcat(ret->recp_room, "|");
+ }
+ strcat(ret->recp_room, &this_recp_cooked[5]);
+ }
else {
++ret->num_error;
invalid = 1;
strcpy(ret->errormsg, "No recipients specified.");
}
+ lprintf(9, "validate_recipients()\n");
+ lprintf(9, " local: %d <%s>\n", ret->num_local, ret->recp_local);
+ lprintf(9, " room: %d <%s>\n", ret->num_room, ret->recp_room);
+ lprintf(9, " inet: %d <%s>\n", ret->num_internet, ret->recp_internet);
+ lprintf(9, " ignet: %d <%s>\n", ret->num_ignet, ret->recp_ignet);
+ lprintf(9, " error: %d <%s>\n", ret->num_error, ret->errormsg);
+
return(ret);
}
char newusername[SIZ];
struct CtdlMessage *msg;
int anonymous = 0;
- int mtsflag = 0;
char errmsg[SIZ];
int err = 0;
struct recptypes *valid = NULL;
+ char subject[SIZ];
post = extract_int(entargs, 0);
extract(recp, entargs, 1);
anon_flag = extract_int(entargs, 2);
format_type = extract_int(entargs, 3);
+ extract(subject, entargs, 4);
/* first check to make sure the request is valid. */
}
CC->cs_flags |= CS_POSTING;
- if (CC->quickroom.QRflags & QR_MAILBOX) {
+ /* In the Mail> room we have to behave a little differently --
+ * make sure the user has specified at least one recipient. Then
+ * validate the recipient(s).
+ */
+ if ( (CC->quickroom.QRflags & QR_MAILBOX)
+ && (!strcasecmp(&CC->quickroom.QRname[11], MAILROOM)) ) {
+
if (CC->usersupp.axlevel < 2) {
strcpy(recp, "sysop");
}
return;
}
- if (!strcasecmp(recp, "sysop")) {
- mtsflag = 1;
- }
}
/* Is this a room which has anonymous-only or anonymous-option? */
/* Read in the message from the client. */
cprintf("%d send message\n", SEND_LISTING);
msg = make_message(&CC->usersupp, recp,
- CC->quickroom.QRname, anonymous, format_type, masquerade_as);
+ CC->quickroom.QRname, anonymous, format_type,
+ masquerade_as, subject);
if (msg != NULL) {
- CtdlSubmitMsg(msg, valid, (mtsflag ? AIDEROOM : "") );
+ CtdlSubmitMsg(msg, valid, "");
CtdlFreeMessage(msg);
}
CC->fake_postname[0] = '\0';
struct quickroom qrbuf;
struct cdbdata *cdbfr;
long *msglist = NULL;
+ long *dellist = NULL;
int num_msgs = 0;
int i;
int num_deleted = 0;
if (cdbfr != NULL) {
msglist = mallok(cdbfr->len);
+ dellist = mallok(cdbfr->len);
memcpy(msglist, cdbfr->ptr, cdbfr->len);
num_msgs = cdbfr->len / sizeof(long);
cdb_free(cdbfr);
/* Delete message only if all bits are set */
if (delete_this == 0x03) {
- AdjRefCount(msglist[i], -1);
+ dellist[num_deleted++] = msglist[i];
msglist[i] = 0L;
- ++num_deleted;
}
}
msglist, (num_msgs * sizeof(long)));
qrbuf.QRhighest = msglist[num_msgs - 1];
- phree(msglist);
}
lputroom(&qrbuf);
+
+ /* Go through the messages we pulled out of the index, and decrement
+ * their reference counts by 1. If this is the only room the message
+ * was in, the reference count will reach zero and the message will
+ * automatically be deleted from the database. We do this in a
+ * separate pass because there might be plug-in hooks getting called,
+ * and we don't want that happening during an S_QUICKROOM critical
+ * section.
+ */
+ if (num_deleted) for (i=0; i<num_deleted; ++i) {
+ PerformDeleteHooks(qrbuf.QRname, dellist[i]);
+ AdjRefCount(dellist[i], -1);
+ }
+
+ /* Now free the memory we used, and go away. */
+ if (msglist != NULL) phree(msglist);
+ if (dellist != NULL) phree(dellist);
lprintf(9, "%d message(s) deleted.\n", num_deleted);
return (num_deleted);
}
targ[ROOMNAMELEN - 1] = 0;
is_copy = extract_int(args, 2);
+ if (getroom(&qtemp, targ) != 0) {
+ cprintf("%d '%s' does not exist.\n", ERROR, targ);
+ return;
+ }
+
getuser(&CC->usersupp, CC->curr_user);
+ /* Aides can move/copy */
if ((CC->usersupp.axlevel < 6)
- && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
+ /* Roomaides can move/copy */
+ && (CC->usersupp.usernum != CC->quickroom.QRroomaide)
+ /* Permit move/copy to/from personal rooms */
+ && (!((CC->quickroom.QRflags & QR_MAILBOX)
+ && (qtemp.QRflags & QR_MAILBOX)))
+ /* Permit only copy from public to personal room */
+ && (!(is_copy && !(CC->quickroom.QRflags & QR_MAILBOX)
+ && (qtemp.QRflags & QR_MAILBOX)))) {
cprintf("%d Higher access required.\n",
ERROR + HIGHER_ACCESS_REQUIRED);
return;
}
- if (getroom(&qtemp, targ) != 0) {
- cprintf("%d '%s' does not exist.\n", ERROR, targ);
- return;
- }
-
err = CtdlCopyMsgToRoom(num, targ);
if (err != 0) {
cprintf("%d Cannot store message in %s: error %d\n",