}
+
+/*
+ * Retrieve the "seen" message list for the current room.
+ */
+void CtdlGetSeen(char *buf) {
+ struct visit vbuf;
+
+ /* Learn about the user and room in question */
+ CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
+
+ safestrncpy(buf, vbuf.v_seen, SIZ);
+}
+
+
+
/*
* Manipulate the "seen msgs" string.
*/
int num_msgs = 0;
/* Learn about the user and room in question */
- get_mm();
- getuser(&CC->usersupp, CC->curr_user);
CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
/* Load the message list */
* current room. (Returns the number of messages processed.)
*/
int CtdlForEachMessage(int mode, long ref,
- int moderation_level,
char *content_type,
struct CtdlMessage *compare,
void (*CallBack) (long, void *),
* Now begin the traversal.
*/
if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
- GetMetaData(&smi, msglist[a]);
-
- /* Filter out messages that are moderated below the level
- * currently being viewed at.
- */
- if (smi.meta_mod < moderation_level) {
- msglist[a] = 0L;
- }
/* If the caller is looking for a specific MIME type, filter
* out all messages which are not of the type requested.
*/
if (content_type != NULL) if (strlen(content_type) > 0) {
+
+ /* This call to GetMetaData() sits inside this loop
+ * so that we only do the extra database read per msg
+ * if we need to. Doing the extra read all the time
+ * really kills the server. If we ever need to use
+ * metadata for another search criterion, we need to
+ * move the read somewhere else -- but still be smart
+ * enough to only do the read if the caller has
+ * specified something that will need it.
+ */
+ GetMetaData(&smi, msglist[a]);
+
if (strcasecmp(smi.meta_content_type, content_type)) {
msglist[a] = 0L;
}
}
CtdlForEachMessage(mode, cm_ref,
- CC->usersupp.moderation_filter,
NULL, template, simple_listing, NULL);
if (template != NULL) CtdlFreeMessage(template);
cprintf("000\n");
name, filename, partnum, disp, cbtype, (long)length);
}
+/*
+ * Callback function for multipart prefix
+ */
+void list_this_pref(char *name, char *filename, char *partnum, char *disp,
+ void *content, char *cbtype, size_t length, char *encoding,
+ void *cbuserdata)
+{
+ cprintf("pref=%s|%s\n", partnum, cbtype);
+}
+
+/*
+ * Callback function for multipart sufffix
+ */
+void list_this_suff(char *name, char *filename, char *partnum, char *disp,
+ void *content, char *cbtype, size_t length, char *encoding,
+ void *cbuserdata)
+{
+ cprintf("suff=%s|%s\n", partnum, cbtype);
+}
+
/*
* Callback function for mime parser that opens a section for downloading
{
lprintf(9, "fixed_output_pre() type=<%s>\n", cbtype);
if (!strcasecmp(cbtype, "multipart/alternative")) {
- ma->is_ma = 1;
+ ++ma->is_ma;
ma->did_print = 0;
return;
}
{
lprintf(9, "fixed_output_post() type=<%s>\n", cbtype);
if (!strcasecmp(cbtype, "multipart/alternative")) {
- ma->is_ma = 0;
+ --ma->is_ma;
ma->did_print = 0;
return;
}
char *ptr;
char *wptr;
size_t wlen;
- CIT_UBYTE ch = 0;
lprintf(9, "fixed_output() type=<%s>\n", cbtype);
if ( (!strcasecmp(cbtype, "text/plain"))
|| (strlen(cbtype)==0) ) {
- wlen = length;
wptr = content;
- while (wlen--) {
- ch = *wptr++;
- /**********
- if (ch==10) cprintf("\r\n");
- else cprintf("%c", ch);
- **********/
- cprintf("%c", ch);
+ if (length > 0) {
+ client_write(wptr, length);
+ if (wptr[length-1] != '\n') {
+ cprintf("\n");
+ }
}
- if (ch != '\n') cprintf("\n");
}
else if (!strcasecmp(cbtype, "text/html")) {
ptr = html_to_ascii(content, 80, 0);
wlen = strlen(ptr);
- wptr = ptr;
- while (wlen--) {
- ch = *wptr++;
- if (ch==10) cprintf("\r\n");
- else cprintf("%c", ch);
+ client_write(ptr, wlen);
+ if (ptr[wlen-1] != '\n') {
+ cprintf("\n");
}
phree(ptr);
}
}
}
+/*
+ * The client is elegant and sophisticated and wants to be choosy about
+ * MIME content types, so figure out which multipart/alternative part
+ * we're going to send.
+ */
+void choose_preferred(char *name, char *filename, char *partnum, char *disp,
+ void *content, char *cbtype, size_t length, char *encoding,
+ void *cbuserdata)
+{
+ char buf[SIZ];
+ int i;
+
+ if (ma->is_ma > 0) {
+ for (i=0; i<num_tokens(CC->preferred_formats, '|'); ++i) {
+ extract(buf, CC->preferred_formats, i);
+ if (!strcasecmp(buf, cbtype)) {
+ strcpy(ma->chosen_part, partnum);
+ }
+ }
+ }
+}
+
+/*
+ * Now that we've chosen our preferred part, output it.
+ */
+void output_preferred(char *name, char *filename, char *partnum, char *disp,
+ void *content, char *cbtype, size_t length, char *encoding,
+ void *cbuserdata)
+{
+ int i;
+ char buf[SIZ];
+ int add_newline = 0;
+ char *text_content;
+
+ /* This is not the MIME part you're looking for... */
+ if (strcasecmp(partnum, ma->chosen_part)) return;
+
+ /* If the content-type of this part is in our preferred formats
+ * list, we can simply output it verbatim.
+ */
+ for (i=0; i<num_tokens(CC->preferred_formats, '|'); ++i) {
+ extract(buf, CC->preferred_formats, i);
+ if (!strcasecmp(buf, cbtype)) {
+ /* Yeah! Go! W00t!! */
+
+ text_content = (char *)content;
+ if (text_content[length-1] != '\n') {
+ ++add_newline;
+ }
+
+ cprintf("Content-type: %s\n", cbtype);
+ cprintf("Content-length: %d\n",
+ length + add_newline);
+ cprintf("Content-transfer-encoding: %s\n", encoding);
+ cprintf("\n");
+ client_write(content, length);
+ if (add_newline) cprintf("\n");
+ return;
+ }
+ }
+
+ /* No translations required or possible: output as text/plain */
+ cprintf("Content-type: text/plain\n\n");
+ fixed_output(name, filename, partnum, disp, content, cbtype,
+ length, encoding, cbuserdata);
+}
+
/*
* Get a message off disk. (returns om_* values found in msgbase.h)
*/
/*
- * Fetch the message from disk
+ * Fetch the message from disk. We also keep the most recently
+ * read message in memory, in case we want to read it again, or fetch
+ * MIME parts out of it, or whatever.
*/
- TheMessage = CtdlFetchMessage(msg_num);
+ if ( (CC->cached_msg != NULL) && (CC->cached_msgnum == msg_num) ) {
+ TheMessage = CC->cached_msg;
+ }
+ else {
+ TheMessage = CtdlFetchMessage(msg_num);
+ if (CC->cached_msg != NULL) {
+ phree(CC->cached_msg); /* FIXME efence? */
+ }
+ CC->cached_msg = TheMessage;
+ CC->cached_msgnum = msg_num;
+ }
+
if (TheMessage == NULL) {
if (do_proto) cprintf("%d Can't locate msg %ld on disk\n",
ERROR, msg_num);
TheMessage, msg_num, mode,
headers_only, do_proto, crlf);
- CtdlFreeMessage(TheMessage);
+ /* don't free the memory; we're keeping it in the cache */
+ /* CtdlFreeMessage(TheMessage); */
+
return(retcode);
}
return((CC->download_fp != NULL) ? om_ok : om_mime_error);
}
+ /* Does the caller want to skip the headers? */
+ if (headers_only == HEADERS_NONE) goto START_TEXT;
+
/* now for the user-mode message reading loops */
if (do_proto) cprintf("%d Message %ld:\n", LISTING_FOLLOWS, msg_num);
- /* Tell the client which format type we're using. If this is a
- * MIME message, *lie* about it and tell the user it's fixed-format.
- */
- if (mode == MT_CITADEL) {
- if (TheMessage->cm_format_type == FMT_RFC822) {
- if (do_proto) cprintf("type=1\n");
- }
- else {
- if (do_proto) cprintf("type=%d\n",
- TheMessage->cm_format_type);
- }
+ /* Tell the client which format type we're using. */
+ if ( (mode == MT_CITADEL) && (do_proto) ) {
+ cprintf("type=%d\n", TheMessage->cm_format_type);
}
/* nhdr=yes means that we're only displaying headers, no body */
- if ((TheMessage->cm_anon_type == MES_ANONONLY) && (mode == MT_CITADEL)) {
- if (do_proto) cprintf("nhdr=yes\n");
+ if ( (TheMessage->cm_anon_type == MES_ANONONLY)
+ && (mode == MT_CITADEL)
+ && (do_proto)
+ ) {
+ cprintf("nhdr=yes\n");
}
/* begin header processing loop for Citadel message format */
else if (i == 'R')
cprintf("To: %s%s", mptr, nl);
else if (i == 'T') {
- datestring(datestamp, sizeof datestamp, atol(mptr),
- DATESTRING_RFC822 );
+ datestring(datestamp, sizeof datestamp,
+ atol(mptr), DATESTRING_RFC822);
cprintf("Date: %s%s", datestamp, nl);
}
}
}
/* end header processing loop ... at this point, we're in the text */
-
+START_TEXT:
mptr = TheMessage->cm_fields['M'];
/* Tell the client about the MIME parts in this message */
if (TheMessage->cm_format_type == FMT_RFC822) {
- if (mode == MT_CITADEL) {
+ if ( (mode == MT_CITADEL) || (mode == MT_MIME) ) {
mime_parser(mptr, NULL,
- *list_this_part, NULL, NULL,
+ *list_this_part,
+ *list_this_pref,
+ *list_this_suff,
NULL, 0);
}
- else if (mode == MT_MIME) { /* list parts only */
- mime_parser(mptr, NULL,
- *list_this_part, NULL, NULL,
- NULL, 0);
- if (do_proto) cprintf("000\n");
- return(om_ok);
- }
else if (mode == MT_RFC822) { /* unparsed RFC822 dump */
/* FIXME ... we have to put some code in here to avoid
* printing duplicate header information when both
}
}
- if (headers_only) {
+ if (headers_only == HEADERS_ONLY) {
if (do_proto) cprintf("000\n");
return(om_ok);
}
/* signify start of msg text */
- if (mode == MT_CITADEL)
+ if ( (mode == MT_CITADEL) || (mode == MT_MIME) ) {
if (do_proto) cprintf("text\n");
+ }
if (mode == MT_RFC822) {
if (TheMessage->cm_fields['U'] == NULL) {
cprintf("Subject: (no subject)%s", nl);
* what message transfer format is in use.
*/
if (TheMessage->cm_format_type == FMT_FIXED) {
+ if (mode == MT_MIME) {
+ cprintf("Content-type: text/plain\n\n");
+ }
strcpy(buf, "");
while (ch = *mptr++, ch > 0) {
if (ch == 13)
* message to the reader's screen width.
*/
if (TheMessage->cm_format_type == FMT_CITADEL) {
+ if (mode == MT_MIME) {
+ cprintf("Content-type: text/x-citadel-variformat\n\n");
+ }
memfmout(80, mptr, 0, nl);
}
if (TheMessage->cm_format_type == FMT_RFC822) {
CtdlAllocUserData(SYM_MA_INFO, sizeof(struct ma_info));
memset(ma, 0, sizeof(struct ma_info));
- mime_parser(mptr, NULL,
- *fixed_output, *fixed_output_pre, *fixed_output_post,
- NULL, 0);
+
+ if (mode == MT_MIME) {
+ strcpy(ma->chosen_part, "1");
+ mime_parser(mptr, NULL,
+ *choose_preferred, *fixed_output_pre,
+ *fixed_output_post, NULL, 0);
+ mime_parser(mptr, NULL,
+ *output_preferred, NULL, NULL, NULL, 0);
+ }
+ else {
+ mime_parser(mptr, NULL,
+ *fixed_output, *fixed_output_pre,
+ *fixed_output_post, NULL, 0);
+ }
}
/* now we're done */
void cmd_msg0(char *cmdbuf)
{
long msgid;
- int headers_only = 0;
+ int headers_only = HEADERS_ALL;
msgid = extract_long(cmdbuf, 0);
headers_only = extract_int(cmdbuf, 1);
void cmd_msg2(char *cmdbuf)
{
long msgid;
- int headers_only = 0;
+ int headers_only = HEADERS_ALL;
msgid = extract_long(cmdbuf, 0);
headers_only = extract_int(cmdbuf, 1);
/*
- * display a message (mode 4 - MIME) (FIXME ... still evolving, not complete)
+ * Display a message using MIME content types
*/
void cmd_msg4(char *cmdbuf)
{
CtdlOutputMsg(msgid, MT_MIME, 0, 1, 0);
}
+
+
+/*
+ * Client tells us its preferred message format(s)
+ */
+void cmd_msgp(char *cmdbuf)
+{
+ safestrncpy(CC->preferred_formats, cmdbuf,
+ sizeof(CC->preferred_formats));
+ cprintf("%d ok\n", CIT_OK);
+}
+
+
/*
* Open a component of a MIME message as a download file
*/
memset(template, 0, sizeof(struct CtdlMessage));
template->cm_fields['E'] = strdoop(msg->cm_fields['E']);
- CtdlForEachMessage(MSGS_ALL, 0L, (-127), NULL, template,
- check_repl, NULL);
+ CtdlForEachMessage(MSGS_ALL, 0L, NULL, template, check_repl, NULL);
/* If a newer message exists with the same Extended ID, abort
* this save.
}
}
- strcpy(force_room, force);
+ if (force == NULL) {
+ strcpy(force_room, "");
+ }
+ else {
+ strcpy(force_room, force);
+ }
/* Learn about what's inside, because it's what's inside that counts */
lprintf(9, "Learning what's inside\n");
if ((!CC->internal_pgm) || (recps == NULL)) {
if (CtdlSaveMsgPointerInRoom(actual_rm, newmsgid, 0) != 0) {
lprintf(3, "ERROR saving message pointer!\n");
- CtdlSaveMsgPointerInRoom(AIDEROOM, newmsgid, 0);
+ CtdlSaveMsgPointerInRoom(config.c_aideroom, newmsgid, 0);
}
}
if (getuser(&userbuf, recipient) == 0) {
MailboxName(actual_rm, sizeof actual_rm, &userbuf, MAILROOM);
CtdlSaveMsgPointerInRoom(actual_rm, newmsgid, 0);
+ BumpNewMailCounter(userbuf.usernum);
}
else {
lprintf(9, "No user <%s>\n", recipient);
- CtdlSaveMsgPointerInRoom(AIDEROOM, newmsgid, 0);
+ CtdlSaveMsgPointerInRoom(config.c_aideroom, newmsgid, 0);
}
}
/*
* Convenience function for generating small administrative messages.
*/
-void quickie_message(char *from, char *to, char *room, char *text)
+void quickie_message(char *from, char *to, char *room, char *text,
+ int format_type, char *subject)
{
struct CtdlMessage *msg;
+ struct recptypes *recp = NULL;
msg = mallok(sizeof(struct CtdlMessage));
memset(msg, 0, sizeof(struct CtdlMessage));
msg->cm_magic = CTDLMESSAGE_MAGIC;
msg->cm_anon_type = MES_NORMAL;
- msg->cm_format_type = 0;
+ msg->cm_format_type = format_type;
msg->cm_fields['A'] = strdoop(from);
- msg->cm_fields['O'] = strdoop(room);
+ if (room != NULL) msg->cm_fields['O'] = strdoop(room);
msg->cm_fields['N'] = strdoop(NODENAME);
- if (to != NULL)
+ if (to != NULL) {
msg->cm_fields['R'] = strdoop(to);
+ recp = validate_recipients(to);
+ }
+ if (subject != NULL) {
+ msg->cm_fields['U'] = strdoop(subject);
+ }
msg->cm_fields['M'] = strdoop(text);
- CtdlSubmitMsg(msg, NULL, room);
+ CtdlSubmitMsg(msg, recp, room);
CtdlFreeMessage(msg);
- syslog(LOG_NOTICE, text);
+ if (recp != NULL) phree(recp);
}
case MES_LOCAL:
if (!strcasecmp(this_recp, "sysop")) {
++ret->num_room;
- strcpy(this_recp, AIDEROOM);
+ strcpy(this_recp, config.c_aideroom);
if (strlen(ret->recp_room) > 0) {
strcat(ret->recp_room, "|");
}
/* We want the last (and probably only) config in this room */
begin_critical_section(S_CONFIG);
config_msgnum = (-1L);
- CtdlForEachMessage(MSGS_LAST, 1, (-127), sysconfname, NULL,
+ CtdlForEachMessage(MSGS_LAST, 1, sysconfname, NULL,
CtdlGetSysConfigBackend, NULL);
msgnum = config_msgnum;
end_critical_section(S_CONFIG);