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
};
/*
}
if ( ((is_seen == 0) && (was_seen == 1))
|| ((is_seen == 1) && (i == num_msgs-1)) ) {
+ size_t tmp;
+
if ( (strlen(newseen) + 20) > SIZ) {
strcpy(newseen, &newseen[20]);
newseen[0] = '*';
}
- if (strlen(newseen) > 0) strcat(newseen, ",");
+ tmp = strlen(newseen);
+ if (tmp > 0) {
+ strcat(newseen, ",");
+ tmp++;
+ }
if (lo == hi) {
- sprintf(&newseen[strlen(newseen)], "%ld", lo);
+ snprintf(&newseen[tmp], sizeof newseen - tmp,
+ "%ld", lo);
}
else {
- sprintf(&newseen[strlen(newseen)], "%ld:%ld",
- lo, hi);
+ snprintf(&newseen[tmp], sizeof newseen - tmp,
+ "%ld:%ld", lo, hi);
}
lo = (-1L);
hi = (-1L);
help_subst(buffer, "^humannode", config.c_humannode);
help_subst(buffer, "^fqdn", config.c_fqdn);
help_subst(buffer, "^username", CC->usersupp.fullname);
- sprintf(buf2, "%ld", CC->usersupp.usernum);
+ snprintf(buf2, sizeof buf2, "%ld", CC->usersupp.usernum);
help_subst(buffer, "^usernum", buf2);
help_subst(buffer, "^sysadm", config.c_sysadm);
help_subst(buffer, "^variantname", CITADEL);
- sprintf(buf2, "%d", config.c_maxsessions);
+ snprintf(buf2, sizeof buf2, "%d", config.c_maxsessions);
help_subst(buffer, "^maxsessions", buf2);
}
char display_name[SIZ];
char *mptr;
char *nl; /* newline string */
+ int suppress_f = 0;
/* buffers needed for RFC822 translation */
char suser[SIZ];
char datestamp[SIZ];
/* */
- sprintf(mid, "%ld", msg_num);
+ snprintf(mid, sizeof mid, "%ld", msg_num);
nl = (crlf ? "\r\n" : "\n");
if (!is_valid_message(TheMessage)) {
if ((is_room_aide())
&& ((TheMessage->cm_anon_type == MES_ANONONLY)
|| (TheMessage->cm_anon_type == MES_ANONOPT))) {
- sprintf(&display_name[strlen(display_name)],
- " [%s]", buf);
+ size_t tmp = strlen(display_name);
+ snprintf(&display_name[tmp],
+ sizeof display_name - tmp,
+ " [%s]", buf);
}
}
+ /* 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);
}
- /* Don't show Internet address for
- * local users
- */
- else if (k == 'F') {
- if (do_proto) if (TheMessage->cm_fields['N'] != NULL) if (strcasecmp(TheMessage->cm_fields['N'], config.c_nodename)) {
- cprintf("%s=%s\n",
- msgkeys[k],
- TheMessage->cm_fields[k]
- );
-
- }
+ else if ((k == 'F') && (suppress_f)) {
+ /* do nothing */
}
/* Masquerade display name if needed */
else {
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);
}
/* Get a new message number */
newmsgid = get_new_message_number();
- sprintf(msgidbuf, "%ld@%s", newmsgid, config.c_fqdn);
+ snprintf(msgidbuf, sizeof msgidbuf, "%ld@%s", newmsgid, config.c_fqdn);
/* Generate an ID if we don't have one already */
if (msg->cm_fields['I']==NULL) {
*/
if (msg->cm_fields['T'] == NULL) {
lprintf(9, "Generating timestamp\n");
- sprintf(aaa, "%ld", (long)time(NULL));
+ snprintf(aaa, sizeof aaa, "%ld", (long)time(NULL));
msg->cm_fields['T'] = strdoop(aaa);
}
lprintf(9, "Delivering private local mail to <%s>\n",
recipient);
if (getuser(&userbuf, recipient) == 0) {
- MailboxName(actual_rm, &userbuf, MAILROOM);
+ MailboxName(actual_rm, sizeof actual_rm, &userbuf, MAILROOM);
CtdlSaveMsgPointerInRoom(actual_rm, newmsgid, 0);
}
else {
serialize_message(&smr, msg);
if (smr.len > 0) {
- sprintf(aaa,
+ snprintf(aaa, sizeof aaa,
"./network/spoolin/netmail.%04lx.%04x.%04x",
(long) getpid(), CC->cs_pid, ++seqnum);
network_fp = fopen(aaa, "wb+");
if (recps->num_internet > 0) {
lprintf(9, "Generating delivery instructions\n");
instr = mallok(SIZ * 2);
- sprintf(instr,
+ snprintf(instr, SIZ * 2,
"Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n"
"bounceto|%s@%s\n",
SPOOLMIME, newmsgid, (long)time(NULL),
);
for (i=0; i<num_tokens(recps->recp_internet, '|'); ++i) {
+ size_t tmp = strlen(instr);
extract(recipient, recps->recp_internet, i);
- sprintf(&instr[strlen(instr)],
- "remote|%s|0||\n", recipient);
+ snprintf(&instr[tmp], SIZ * 2 - tmp,
+ "remote|%s|0||\n", recipient);
}
imsg = mallok(sizeof(struct CtdlMessage));
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];
striplt(recipient);
- sprintf(buf, "cit%ld", author->usernum); /* Path */
+ snprintf(buf, sizeof buf, "cit%ld", author->usernum); /* Path */
msg->cm_fields['P'] = strdoop(buf);
- sprintf(buf, "%ld", (long)time(NULL)); /* timestamp */
+ snprintf(buf, sizeof buf, "%ld", (long)time(NULL)); /* timestamp */
msg->cm_fields['T'] = strdoop(buf);
if (fake_name[0]) /* author */
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);
* room. Returns a *CITADEL ERROR CODE* and puts a message in errmsgbuf, or
* returns 0 on success.
*/
-int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf) {
+int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf, size_t n) {
if (!(CC->logged_in)) {
- sprintf(errmsgbuf, "Not logged in.");
+ snprintf(errmsgbuf, n, "Not logged in.");
return (ERROR + NOT_LOGGED_IN);
}
if ((CC->usersupp.axlevel < 2)
&& ((CC->quickroom.QRflags & QR_MAILBOX) == 0)) {
- sprintf(errmsgbuf, "Need to be validated to enter "
+ snprintf(errmsgbuf, n, "Need to be validated to enter "
"(except in %s> to sysop)", MAILROOM);
return (ERROR + HIGHER_ACCESS_REQUIRED);
}
if ((CC->usersupp.axlevel < 4)
&& (CC->quickroom.QRflags & QR_NETWORK)) {
- sprintf(errmsgbuf, "Need net privileges to enter here.");
+ snprintf(errmsgbuf, n, "Need net privileges to enter here.");
return (ERROR + HIGHER_ACCESS_REQUIRED);
}
if ((CC->usersupp.axlevel < 6)
&& (CC->quickroom.QRflags & QR_READONLY)) {
- sprintf(errmsgbuf, "Sorry, this is a read-only room.");
+ snprintf(errmsgbuf, n, "Sorry, this is a read-only room.");
return (ERROR + HIGHER_ACCESS_REQUIRED);
}
}
if (invalid) {
if (strlen(ret->errormsg) == 0) {
- sprintf(append,
- "Invalid recipient: %s",
- this_recp);
+ snprintf(append, sizeof append,
+ "Invalid recipient: %s",
+ this_recp);
}
else {
- sprintf(append,
- ", %s", this_recp);
+ snprintf(append, sizeof append,
+ ", %s", this_recp);
}
if ( (strlen(ret->errormsg) + strlen(append)) < SIZ) {
strcat(ret->errormsg, append);
strcpy(append, this_recp);
}
else {
- sprintf(append, ", %s", this_recp);
+ snprintf(append, sizeof append, ", %s",
+ this_recp);
}
if ( (strlen(ret->display_recp)+strlen(append)) < SIZ) {
strcat(ret->display_recp, append);
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. */
- err = CtdlDoIHavePermissionToPostInThisRoom(errmsg);
+ err = CtdlDoIHavePermissionToPostInThisRoom(errmsg, sizeof errmsg);
if (err) {
cprintf("%d %s\n", err, errmsg);
return;
memset(CC->fake_postname, 0, sizeof(CC->fake_postname) );
safestrncpy(CC->fake_postname, newusername,
sizeof(CC->fake_postname) );
- cprintf("%d ok\n", OK);
+ cprintf("%d ok\n", CIT_OK);
return;
}
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");
}
* success without creating the message.
*/
if (post == 0) {
- cprintf("%d %s\n", OK,
+ cprintf("%d %s\n", CIT_OK,
((valid != NULL) ? valid->display_recp : "") );
phree(valid);
return;
/* 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, "");
num_deleted = CtdlDeleteMessages(CC->quickroom.QRname, delnum, "");
if (num_deleted) {
- cprintf("%d %d message%s deleted.\n", OK,
+ cprintf("%d %d message%s deleted.\n", CIT_OK,
num_deleted, ((num_deleted != 1) ? "s" : ""));
} else {
cprintf("%d Message %ld not found.\n", ERROR, delnum);
CtdlDeleteMessages(CC->quickroom.QRname, num, "");
}
- cprintf("%d Message %s.\n", OK, (is_copy ? "copied" : "moved") );
+ cprintf("%d Message %s.\n", CIT_OK, (is_copy ? "copied" : "moved") );
}
size_t len;
if (is_mailbox != NULL)
- MailboxName(roomname, is_mailbox, req_room);
+ MailboxName(roomname, sizeof roomname, is_mailbox, req_room);
else
safestrncpy(roomname, req_room, sizeof(roomname));
lprintf(9, "CtdlWriteObject() to <%s> (flags=%d)\n", roomname, flags);
fprintf(fp, "Content-transfer-encoding: base64\n\n");
fclose(tempfp);
fclose(fp);
- sprintf(cmdbuf, "./base64 -e <%s >>%s",
+ snprintf(cmdbuf, sizeof cmdbuf, "./base64 -e <%s >>%s",
tempfilename, filename);
system(cmdbuf);
}