#include "room_ops.h"
#include "user_ops.h"
#include "file_ops.h"
+#include "config.h"
#include "control.h"
#include "tools.h"
#include "mime_parser.h"
#include "html.h"
#include "genstamp.h"
#include "internet_addressing.h"
+#include "serv_fulltext.h"
-extern struct config config;
long config_msgnum;
striplt(name);
remove_any_whitespace_to_the_left_or_right_of_at_symbol(name);
- fp = fopen("network/mail.aliases", "r");
+ fp = fopen(
+#ifndef HAVE_ETG_DIR
+ "network/"
+#else
+ ETC_DIR
+#endif
+ "mail.aliases", "r");
if (fp == NULL) {
fp = fopen("/dev/null", "r");
}
fclose(fp);
/* Hit the Global Address Book */
- if (CtdlDirectoryLookup(aaa, name) == 0) {
+ if (CtdlDirectoryLookup(aaa, name, sizeof aaa) == 0) {
strcpy(name, aaa);
}
{
FILE *fp;
- fp = fopen("citadel.control", "r");
+ fp = fopen(
+#ifndef HAVE_RUN_DIR
+ "."
+#else
+ RUN_DIR
+#endif
+ "/citadel.control", "r");
if (fp == NULL) {
lprintf(CTDL_CRIT, "Cannot open citadel.control: %s\n",
strerror(errno));
}
-
+/*
+ * Back end for the MSGS command: output message number only.
+ */
void simple_listing(long msgnum, void *userdata)
{
cprintf("%ld\n", msgnum);
+/*
+ * Back end for the MSGS command: output header summary.
+ */
+void headers_listing(long msgnum, void *userdata)
+{
+ struct CtdlMessage *msg;
+
+ msg = CtdlFetchMessage(msgnum, 0);
+ if (msg < 0L) {
+ cprintf("%ld|0|||||\n", msgnum);
+ return;
+ }
+
+ cprintf("%ld|%s|%s|%s|%s|%s|\n",
+ msgnum,
+ (msg->cm_fields['T'] ? msg->cm_fields['T'] : "0"),
+ (msg->cm_fields['A'] ? msg->cm_fields['A'] : ""),
+ (msg->cm_fields['N'] ? msg->cm_fields['N'] : ""),
+ (msg->cm_fields['F'] ? msg->cm_fields['F'] : ""),
+ (msg->cm_fields['U'] ? msg->cm_fields['U'] : "")
+ );
+ CtdlFreeMessage(msg);
+}
+
+
+
/* Determine if a given message matches the fields in a message template.
* Return 0 for a successful match.
*/
/*
* Manipulate the "seen msgs" string (or other message set strings)
*/
-void CtdlSetSeen(long target_msgnum, int target_setting, int which_set) {
+void CtdlSetSeen(long target_msgnum, int target_setting, int which_set,
+ struct ctdluser *which_user, struct ctdlroom *which_room) {
struct cdbdata *cdbfr;
- int i;
+ int i, j;
int is_seen = 0;
- int was_seen = 1;
+ int was_seen = 0;
long lo = (-1L);
long hi = (-1L);
+ long t = (-1L);
+ int trimming = 0;
struct visit vbuf;
long *msglist;
int num_msgs = 0;
int num_sets;
int s;
char setstr[SIZ], lostr[SIZ], histr[SIZ];
+ size_t tmp;
lprintf(CTDL_DEBUG, "CtdlSetSeen(%ld, %d, %d)\n",
target_msgnum, target_setting, which_set);
/* Learn about the user and room in question */
- CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
+ CtdlGetRelationship(&vbuf,
+ ((which_user != NULL) ? which_user : &CC->user),
+ ((which_room != NULL) ? which_room : &CC->room)
+ );
/* Load the message list */
cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
memset(is_set, 0, (num_msgs * sizeof(char)) );
/* Decide which message set we're manipulating */
- if (which_set == ctdlsetseen_seen) safestrncpy(vset, vbuf.v_seen, sizeof vset);
- if (which_set == ctdlsetseen_answered) safestrncpy(vset, vbuf.v_answered, sizeof vset);
+ switch(which_set) {
+ case ctdlsetseen_seen:
+ safestrncpy(vset, vbuf.v_seen, sizeof vset);
+ break;
+ case ctdlsetseen_answered:
+ safestrncpy(vset, vbuf.v_answered, sizeof vset);
+ break;
+ }
- lprintf(CTDL_DEBUG, "before optimize: %s\n", vset);
+ /* lprintf(CTDL_DEBUG, "before optimize: %s\n", vset); */
/* Translate the existing sequence set into an array of booleans */
num_sets = num_tokens(vset, ',');
/* Now translate the array of booleans back into a sequence set */
strcpy(vset, "");
+ lo = (-1L);
+ hi = (-1L);
for (i=0; i<num_msgs; ++i) {
is_seen = 0;
is_seen = target_setting;
}
else {
- if (is_set[i]) {
- is_seen = 1;
- }
+ is_seen = is_set[i];
}
- if (is_seen == 1) {
+ if (is_seen) {
if (lo < 0L) lo = msglist[i];
hi = msglist[i];
}
+
if ( ((is_seen == 0) && (was_seen == 1))
|| ((is_seen == 1) && (i == num_msgs-1)) ) {
- size_t tmp;
- if ( (strlen(vset) + 20) > sizeof vset) {
- strcpy(vset, &vset[20]);
- vset[0] = '*';
+ /* begin trim-o-matic code */
+ j=9;
+ trimming = 0;
+ while ( (strlen(vset) + 20) > sizeof vset) {
+ remove_token(vset, 0, ',');
+ trimming = 1;
+ if (j--) break; /* loop no more than 9 times */
+ }
+ if ( (trimming) && (which_set == ctdlsetseen_seen) ) {
+ t = atol(vset);
+ if (t<2) t=2;
+ --t;
+ snprintf(lostr, sizeof lostr,
+ "1:%ld,%s", t, vset);
+ safestrncpy(vset, lostr, sizeof vset);
}
+ /* end trim-o-matic code */
+
tmp = strlen(vset);
if (tmp > 0) {
strcat(vset, ",");
- tmp++;
+ ++tmp;
}
if (lo == hi) {
- snprintf(&vset[tmp], sizeof vset - tmp,
+ snprintf(&vset[tmp], (sizeof vset) - tmp,
"%ld", lo);
}
else {
- snprintf(&vset[tmp], sizeof vset - tmp,
+ snprintf(&vset[tmp], (sizeof vset) - tmp,
"%ld:%ld", lo, hi);
}
lo = (-1L);
}
/* Decide which message set we're manipulating */
- if (which_set == ctdlsetseen_seen) safestrncpy(vbuf.v_seen, vset, sizeof vbuf.v_seen);
- if (which_set == ctdlsetseen_answered) safestrncpy(vbuf.v_answered, vset, sizeof vbuf.v_answered);
+ switch (which_set) {
+ case ctdlsetseen_seen:
+ safestrncpy(vbuf.v_seen, vset, sizeof vbuf.v_seen);
+ break;
+ case ctdlsetseen_answered:
+ safestrncpy(vbuf.v_answered, vset,
+ sizeof vbuf.v_answered);
+ break;
+ }
free(is_set);
- lprintf(CTDL_DEBUG, " after optimize: %s\n", vset);
+ /* lprintf(CTDL_DEBUG, " after optimize: %s\n", vset); */
free(msglist);
- CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
+ CtdlSetRelationship(&vbuf,
+ ((which_user != NULL) ? which_user : &CC->user),
+ ((which_room != NULL) ? which_room : &CC->room)
+ );
}
long thismsg;
struct MetaData smi;
struct CtdlMessage *msg;
- int is_seen;
+ int is_seen = 0;
long lastold = 0L;
int printed_lastold = 0;
if (num_msgs > 0)
for (a = 0; a < num_msgs; ++a) {
thismsg = msglist[a];
- is_seen = is_msg_in_sequence_set(vbuf.v_seen, thismsg);
- if (is_seen) lastold = thismsg;
+ if (mode == MSGS_ALL) {
+ is_seen = 0;
+ }
+ else {
+ is_seen = is_msg_in_sequence_set(
+ vbuf.v_seen, thismsg);
+ if (is_seen) lastold = thismsg;
+ }
if ((thismsg > 0L)
&& (
int i;
int with_template = 0;
struct CtdlMessage *template = NULL;
+ int with_headers = 0;
extract_token(which, cmdbuf, 0, '|', sizeof which);
cm_ref = extract_int(cmdbuf, 1);
with_template = extract_int(cmdbuf, 2);
+ with_headers = extract_int(cmdbuf, 3);
mode = MSGS_ALL;
strcat(which, " ");
buffer_output();
}
else {
- cprintf("%d Message list...\n", LISTING_FOLLOWS);
+ cprintf("%d \n", LISTING_FOLLOWS);
}
- CtdlForEachMessage(mode, cm_ref,
- NULL, template, simple_listing, NULL);
+ CtdlForEachMessage(mode,
+ cm_ref,
+ NULL,
+ template,
+ (with_headers ? headers_listing : simple_listing),
+ NULL
+ );
if (template != NULL) CtdlFreeMessage(template);
cprintf("000\n");
}
* Callback function for mime parser that simply lists the part
*/
void list_this_part(char *name, char *filename, char *partnum, char *disp,
- void *content, char *cbtype, size_t length, char *encoding,
+ void *content, char *cbtype, char *cbcharset, size_t length, char *encoding,
void *cbuserdata)
{
* 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 *content, char *cbtype, char *cbcharset, 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 *content, char *cbtype, char *cbcharset, 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
*/
void mime_download(char *name, char *filename, char *partnum, char *disp,
- void *content, char *cbtype, size_t length, char *encoding,
- void *cbuserdata)
+ void *content, char *cbtype, char *cbcharset, size_t length,
+ char *encoding, void *cbuserdata)
{
/* Silently go away if there's already a download open... */
*
*/
void fixed_output_pre(char *name, char *filename, char *partnum, char *disp,
- void *content, char *cbtype, size_t length, char *encoding,
+ void *content, char *cbtype, char *cbcharset, size_t length, char *encoding,
void *cbuserdata)
{
struct ma_info *ma;
* Post callback function for multipart/alternative
*/
void fixed_output_post(char *name, char *filename, char *partnum, char *disp,
- void *content, char *cbtype, size_t length, char *encoding,
+ void *content, char *cbtype, char *cbcharset, size_t length, char *encoding,
void *cbuserdata)
{
struct ma_info *ma;
* Inline callback function for mime parser that wants to display text
*/
void fixed_output(char *name, char *filename, char *partnum, char *disp,
- void *content, char *cbtype, size_t length, char *encoding,
+ void *content, char *cbtype, char *cbcharset, size_t length, char *encoding,
void *cbuserdata)
{
char *ptr;
* 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 *content, char *cbtype, char *cbcharset, size_t length, char *encoding,
void *cbuserdata)
{
char buf[1024];
* 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 *content, char *cbtype, char *cbcharset, size_t length, char *encoding,
void *cbuserdata)
{
int i;
++add_newline;
}
- cprintf("Content-type: %s\n", cbtype);
- cprintf("Content-length: %d\n",
+ cprintf("Content-type: %s", cbtype);
+ if (strlen(cbcharset) > 0) {
+ cprintf("; charset=%s", cbcharset);
+ }
+ cprintf("\nContent-length: %d\n",
(int)(length + add_newline) );
if (strlen(encoding) > 0) {
cprintf("Content-transfer-encoding: %s\n", encoding);
/* No translations required or possible: output as text/plain */
cprintf("Content-type: text/plain\n\n");
- fixed_output(name, filename, partnum, disp, content, cbtype,
+ fixed_output(name, filename, partnum, disp, content, cbtype, cbcharset,
length, encoding, cbuserdata);
}
*/
void check_repl(long msgnum, void *userdata) {
lprintf(CTDL_DEBUG, "check_repl() replacing message %ld\n", msgnum);
- CtdlDeleteMessages(CC->room.QRname, msgnum, "");
+ CtdlDeleteMessages(CC->room.QRname, msgnum, "", 0);
}
lprintf(CTDL_DEBUG, "Final selection: %s\n", actual_rm);
if (strcasecmp(actual_rm, CC->room.QRname)) {
- getroom(&CC->room, actual_rm);
+ /* getroom(&CC->room, actual_rm); */
+ usergoto(actual_rm, 0, 1, NULL, NULL);
}
/*
serialize_message(&smr, msg);
if (smr.len > 0) {
snprintf(submit_filename, sizeof submit_filename,
- "./network/spoolin/netmail.%04lx.%04x.%04x",
- (long) getpid(), CC->cs_pid, ++seqnum);
+#ifndef HAVE_SPOOL_DIR
+ "."
+#else
+ SPOOL_DIR
+#endif
+ "/network/spoolin/netmail.%04lx.%04x.%04x",
+ (long) getpid(), CC->cs_pid, ++seqnum);
network_fp = fopen(submit_filename, "wb+");
if (network_fp != NULL) {
fwrite(smr.ser, smr.len, 1, network_fp);
/* Go back to the room we started from */
lprintf(CTDL_DEBUG, "Returning to original room %s\n", hold_rm);
if (strcasecmp(hold_rm, CC->room.QRname))
- getroom(&CC->room, hold_rm);
+ /* getroom(&CC->room, hold_rm); */
+ usergoto(hold_rm, 0, 1, NULL, NULL);
/* For internet mail, generate delivery instructions.
* Yes, this is recursive. Deal with it. Infinite recursion does
* (returns the actual number of messages deleted)
*/
int CtdlDeleteMessages(char *room_name, /* which room */
- long dmsgnum, /* or "0" for any */
- char *content_type /* or "" for any */
+ long dmsgnum, /* or "0" for any */
+ char *content_type, /* or "" for any */
+ int deferred /* let TDAP sweep it later */
)
{
int delete_this;
struct MetaData smi;
- lprintf(CTDL_DEBUG, "CtdlDeleteMessages(%s, %ld, %s)\n",
- room_name, dmsgnum, content_type);
+ lprintf(CTDL_DEBUG, "CtdlDeleteMessages(%s, %ld, %s, %d)\n",
+ room_name, dmsgnum, content_type, deferred);
/* get room record, obtaining a lock... */
if (lgetroom(&qrbuf, room_name) != 0) {
}
lputroom(&qrbuf);
+ /*
+ * If the delete operation is "deferred" (and technically, any delete
+ * operation not performed by THE DREADED AUTO-PURGER ought to be
+ * a deferred delete) then we save a pointer to the message in the
+ * DELETED_MSGS_ROOM. This will cause the reference count to remain
+ * at least 1, which will save the user from having to synchronously
+ * wait for various disk-intensive operations to complete.
+ */
+ if ( (deferred) && (num_deleted) ) {
+ for (i=0; i<num_deleted; ++i) {
+ CtdlCopyMsgToRoom(dellist[i], DELETED_MSGS_ROOM);
+ }
+ }
+
/* 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
}
delnum = extract_long(delstr, 0);
- num_deleted = CtdlDeleteMessages(CC->room.QRname, delnum, "");
+ num_deleted = CtdlDeleteMessages(CC->room.QRname, delnum, "", 1);
if (num_deleted) {
cprintf("%d %d message%s deleted.\n", CIT_OK,
* if this is a 'move' rather than a 'copy' operation.
*/
if (is_copy == 0) {
- CtdlDeleteMessages(CC->room.QRname, num, "");
+ CtdlDeleteMessages(CC->room.QRname, num, "", 0);
}
cprintf("%d Message %s.\n", CIT_OK, (is_copy ? "copied" : "moved") );
*/
begin_critical_section(S_SUPPMSGMAIN);
GetMetaData(&smi, msgnum);
- lprintf(CTDL_DEBUG, "Ref count for message <%ld> before write is <%d>\n",
- msgnum, smi.meta_refcount);
smi.meta_refcount += incr;
PutMetaData(&smi);
end_critical_section(S_SUPPMSGMAIN);
- lprintf(CTDL_DEBUG, "Ref count for message <%ld> after write is <%d>\n",
- msgnum, smi.meta_refcount);
+ lprintf(CTDL_DEBUG, "msg %ld ref count incr %d, is now %d\n",
+ msgnum, incr, smi.meta_refcount);
/* If the reference count is now zero, delete the message
* (and its supplementary record as well).
+ * FIXME ... defer this so it doesn't keep the user waiting.
*/
if (smi.meta_refcount == 0) {
lprintf(CTDL_DEBUG, "Deleting message <%ld>\n", msgnum);
+
+ /* Remove from fulltext index */
+ if (config.c_enable_fulltext) {
+ ft_index_message(msgnum, 0);
+ }
+
+ /* Remove from message base */
delnum = msgnum;
cdb_delete(CDB_MSGMAIN, &delnum, (int)sizeof(long));
cdb_delete(CDB_BIGMSGS, &delnum, (int)sizeof(long));
- /* We have to delete the metadata record too! */
+ /* Remove metadata record */
delnum = (0L - msgnum);
cdb_delete(CDB_MSGMAIN, &delnum, (int)sizeof(long));
}
*/
if (is_unique) {
lprintf(CTDL_DEBUG, "Deleted %d other msgs of this type\n",
- CtdlDeleteMessages(roomname, 0L, content_type));
+ CtdlDeleteMessages(roomname, 0L, content_type, 0)
+ );
}
/* Now write the data */
CtdlSubmitMsg(msg, NULL, roomname);