#include <sys/wait.h>
#include <string.h>
#include <limits.h>
+#include <libcitadel.h>
#include "citadel.h"
#include "server.h"
#include "citserver.h"
#include "database.h"
#include "msgbase.h"
#include "internet_addressing.h"
-#include "tools.h"
-
-
#include "ctdl_module.h"
-
-
-#ifdef HAVE_LIBSIEVE
-
#include "serv_sieve.h"
struct RoomProcList *sieve_list = NULL;
lprintf(CTDL_DEBUG, "Action is REDIRECT, recipient <%s>\n", recp);
- valid = validate_recipients(recp);
+ valid = validate_recipients(recp, NULL, 0);
if (valid == NULL) {
lprintf(CTDL_WARNING, "REDIRECT failed: bad recipient <%s>\n", recp);
return SIEVE2_ERROR_BADARGS;
lprintf(CTDL_DEBUG, "Action is REJECT\n");
/* If we don't know who sent the message, do a DISCARD instead. */
- if (strlen(cs->sender) == 0) {
+ if (IsEmptyStr(cs->sender)) {
lprintf(CTDL_INFO, "Unknown sender. Doing DISCARD instead of REJECT.\n");
return ctdl_discard(s, my);
}
{
struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
- lprintf(CTDL_DEBUG, "Action is GETENVELOPE\n");
- sieve2_setvalue_string(s, "to", cs->envelope_to);
- sieve2_setvalue_string(s, "from", cs->envelope_from);
+ lprintf(CTDL_DEBUG, "Action is GETENVELOPE\nEnvFrom: %s\n EnvTo: %s\n",
+ cs->envelope_from, cs->envelope_to);
+
+ if (cs->envelope_from != NULL) {
+ if ((cs->envelope_from[0] != '@')&&(cs->envelope_from[strlen(cs->envelope_from)-1] != '@')) {
+ sieve2_setvalue_string(s, "from", cs->envelope_from);
+ }
+ else {
+ sieve2_setvalue_string(s, "from", "invalid_envelope_from@example.org");
+ }
+ }
+ else {
+ sieve2_setvalue_string(s, "from", "null_envelope_from@example.org");
+ }
+
+
+ if (cs->envelope_to != NULL) {
+ if ((cs->envelope_to[0] != '@') && (cs->envelope_to[strlen(cs->envelope_to)-1] != '@')) {
+ sieve2_setvalue_string(s, "to", cs->envelope_to);
+ }
+ else {
+ sieve2_setvalue_string(s, "to", "invalid_envelope_to@example.org");
+ }
+ }
+ else {
+ sieve2_setvalue_string(s, "to", "null_envelope_to@example.org");
+ }
+
return SIEVE2_OK;
}
*/
void sieve_do_msg(long msgnum, void *userdata) {
struct sdm_userdata *u = (struct sdm_userdata *) userdata;
- sieve2_context_t *sieve2_context = u->sieve2_context;
+ sieve2_context_t *sieve2_context;
struct ctdl_sieve my;
int res;
struct CtdlMessage *msg;
size_t headers_len = 0;
int len = 0;
+ if (userdata == NULL)
+ {
+ lprintf(CTDL_EMERG, "Cant process Message <%ld>without Userdata!\n", msgnum);
+ return;
+ }
+
+ sieve2_context = u->sieve2_context;
+
lprintf(CTDL_DEBUG, "Performing sieve processing on msg <%ld>\n", msgnum);
msg = CtdlFetchMessage(msgnum, 0);
/* Keep track of the envelope-from address (use body-from if not found) */
if (msg->cm_fields['P'] != NULL) {
safestrncpy(my.envelope_from, msg->cm_fields['P'], sizeof my.envelope_from);
+ stripallbut(my.envelope_from, '<', '>');
}
else if (msg->cm_fields['F'] != NULL) {
safestrncpy(my.envelope_from, msg->cm_fields['F'], sizeof my.envelope_from);
+ stripallbut(my.envelope_from, '<', '>');
}
else {
strcpy(my.envelope_from, "");
/* Keep track of the envelope-to address (use body-to if not found) */
if (msg->cm_fields['V'] != NULL) {
safestrncpy(my.envelope_to, msg->cm_fields['V'], sizeof my.envelope_to);
+ stripallbut(my.envelope_to, '<', '>');
}
else if (msg->cm_fields['R'] != NULL) {
safestrncpy(my.envelope_to, msg->cm_fields['R'], sizeof my.envelope_to);
strcat(my.envelope_to, "@");
strcat(my.envelope_to, msg->cm_fields['D']);
}
+ stripallbut(my.envelope_to, '<', '>');
}
else {
strcpy(my.envelope_to, "");
sprintf(&text[strlen(text)], CTDLSIEVECONFIGSEPARATOR);
}
- /* Save the config */
- quickie_message("Citadel", NULL, NULL, u->config_roomname,
- text,
- 4,
- "Sieve configuration"
- );
-
- free (text);
- /* And delete the old one */
- if (u->config_msgnum > 0) {
- CtdlDeleteMessages(u->config_roomname, &u->config_msgnum, 1, "");
+ if (yes_write_to_disk)
+ {
+ /* Save the config */
+ quickie_message("Citadel", NULL, NULL, u->config_roomname,
+ text,
+ 4,
+ "Sieve configuration"
+ );
+
+ /* And delete the old one */
+ if (u->config_msgnum > 0) {
+ CtdlDeleteMessages(u->config_roomname, &u->config_msgnum, 1, "");
+ }
}
+ free (text);
+
}
/* First see if the supplied value is ok */
- if (strlen(script_name) == 0) {
+ if (IsEmptyStr(script_name)) {
ok = 1;
}
else {
if (!strcasecmp(subcmd, "putscript")) {
extract_token(script_name, argbuf, 1, '|', sizeof script_name);
- if (strlen(script_name) > 0) {
+ if (!IsEmptyStr(script_name)) {
cprintf("%d Transmit script now\n", SEND_LISTING);
- script_content = CtdlReadMessageBody("000", config.c_maxmsglen, NULL, 0);
+ script_content = CtdlReadMessageBody("000", config.c_maxmsglen, NULL, 0, 0);
msiv_putscript(&u, script_name, script_content);
changes_made = 1;
}
return 0;
}
-#endif /* HAVE_LIBSIEVE */
-
CTDL_MODULE_INIT(sieve)
{
+ if (!threading)
+ {
-#ifdef HAVE_LIBSIEVE
-
- ctdl_sieve_init();
- CtdlRegisterProtoHook(cmd_msiv, "MSIV", "Manage Sieve scripts");
-
- CtdlRegisterRoomHook(serv_sieve_room);
-
- CtdlRegisterSessionHook(perform_sieve_processing, EVT_HOUSE);
-
-#else /* HAVE_LIBSIEVE */
-
- lprintf(CTDL_INFO, "This server is missing libsieve. Mailbox filtering will be disabled.\n");
-
-#endif /* HAVE_LIBSIEVE */
-
+ ctdl_sieve_init();
+ CtdlRegisterProtoHook(cmd_msiv, "MSIV", "Manage Sieve scripts");
+ CtdlRegisterRoomHook(serv_sieve_room);
+ CtdlRegisterSessionHook(perform_sieve_processing, EVT_HOUSE);
+ }
+
/* return our Subversion id for the Log */
return "$Id$";
}