* This module glues libSieve to the Citadel server in order to implement
* the Sieve mailbox filtering language (RFC 3028).
*
- * Copyright (c) 1987-2012 by the citadel.org team
+ * Copyright (c) 1987-2020 by the citadel.org team
*
* This program is open source software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3.
struct RoomProcList *sieve_list = NULL;
char *msiv_extensions = NULL;
-int SieveDebugEnable = 0;
-
-#define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (SieveDebugEnable != 0))
-
-#define SV_syslog(LEVEL, FORMAT, ...) \
- DBGLOG(LEVEL) syslog(LEVEL, \
- "Sieve: " FORMAT, __VA_ARGS__)
-
-#define SVM_syslog(LEVEL, FORMAT) \
- DBGLOG(LEVEL) syslog(LEVEL, \
- "Sieve: " FORMAT);
/*
*/
int ctdl_debug(sieve2_context_t *s, void *my)
{
- SV_syslog(LOG_DEBUG, "%s", sieve2_getvalue_string(s, "message"));
+ syslog(LOG_DEBUG, "%s", sieve2_getvalue_string(s, "message"));
return SIEVE2_OK;
}
*/
int ctdl_errparse(sieve2_context_t *s, void *my)
{
- SV_syslog(LOG_WARNING, "Error in script, line %d: %s",
+ syslog(LOG_WARNING, "Error in script, line %d: %s",
sieve2_getvalue_int(s, "lineno"),
sieve2_getvalue_string(s, "message")
);
*/
int ctdl_errexec(sieve2_context_t *s, void *my)
{
- SV_syslog(LOG_WARNING, "Error executing script: %s",
+ syslog(LOG_WARNING, "Error executing script: %s",
sieve2_getvalue_string(s, "message")
);
return SIEVE2_OK;
safestrncpy(recp, sieve2_getvalue_string(s, "address"), sizeof recp);
- SV_syslog(LOG_DEBUG, "Action is REDIRECT, recipient <%s>", recp);
+ syslog(LOG_DEBUG, "Action is REDIRECT, recipient <%s>", recp);
valid = validate_recipients(recp, NULL, 0);
if (valid == NULL) {
- SV_syslog(LOG_WARNING, "REDIRECT failed: bad recipient <%s>", recp);
+ syslog(LOG_WARNING, "REDIRECT failed: bad recipient <%s>", recp);
return SIEVE2_ERROR_BADARGS;
}
if (valid->num_error > 0) {
- SV_syslog(LOG_WARNING, "REDIRECT failed: bad recipient <%s>", recp);
+ syslog(LOG_WARNING, "REDIRECT failed: bad recipient <%s>", recp);
free_recipients(valid);
return SIEVE2_ERROR_BADARGS;
}
- msg = CtdlFetchMessage(cs->msgnum, 1);
+ msg = CtdlFetchMessage(cs->msgnum, 1, 1);
if (msg == NULL) {
- SV_syslog(LOG_WARNING, "REDIRECT failed: unable to fetch msg %ld", cs->msgnum);
+ syslog(LOG_WARNING, "REDIRECT failed: unable to fetch msg %ld", cs->msgnum);
free_recipients(valid);
return SIEVE2_ERROR_BADARGS;
}
{
struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
- SVM_syslog(LOG_DEBUG, "Action is KEEP");
+ syslog(LOG_DEBUG, "Action is KEEP");
cs->keep = 1;
cs->cancel_implicit_keep = 1;
char foldername[256];
char original_room_name[ROOMNAMELEN];
- SV_syslog(LOG_DEBUG, "Action is FILEINTO, destination is <%s>", dest_folder);
+ syslog(LOG_DEBUG, "Action is FILEINTO, destination is <%s>", dest_folder);
/* FILEINTO 'INBOX' is the same thing as KEEP */
if ( (!strcasecmp(dest_folder, "INBOX")) || (!strcasecmp(dest_folder, MAILROOM)) ) {
}
if (c != 0) {
- SV_syslog(LOG_WARNING, "FILEINTO failed: target <%s> does not exist", dest_folder);
+ syslog(LOG_WARNING, "FILEINTO failed: target <%s> does not exist", dest_folder);
return SIEVE2_ERROR_BADARGS;
}
{
struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
- SVM_syslog(LOG_DEBUG, "Action is DISCARD");
+ syslog(LOG_DEBUG, "Action is DISCARD");
/* Cancel the implicit keep. That's all there is to it. */
cs->cancel_implicit_keep = 1;
}
-
/*
* Callback function to indicate that a message should be rejected
*/
struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
char *reject_text = NULL;
- SVM_syslog(LOG_DEBUG, "Action is REJECT");
+ syslog(LOG_DEBUG, "Action is REJECT");
/* If we don't know who sent the message, do a DISCARD instead. */
if (IsEmptyStr(cs->sender)) {
- SVM_syslog(LOG_INFO, "Unknown sender. Doing DISCARD instead of REJECT.");
+ syslog(LOG_INFO, "Unknown sender. Doing DISCARD instead of REJECT.");
return ctdl_discard(s, my);
}
}
-
/*
* Callback function to indicate that a vacation message should be generated
*/
char *vacamsg_text = NULL;
char vacamsg_subject[1024];
- SVM_syslog(LOG_DEBUG, "Action is VACATION");
+ syslog(LOG_DEBUG, "Action is VACATION");
message = sieve2_getvalue_string(s, "message");
if (message == NULL) return SIEVE2_ERROR_BADARGS;
for (vptr = cs->u->first_vacation; vptr != NULL; vptr = vptr->next) {
if (!strcasecmp(vptr->fromaddr, cs->sender)) {
if ( (time(NULL) - vptr->timestamp) < (days * 86400) ) {
- SV_syslog(LOG_DEBUG, "Already alerted <%s> recently.", cs->sender);
+ syslog(LOG_DEBUG, "Already alerted <%s> recently.", cs->sender);
return SIEVE2_OK;
}
}
}
+#if 0
/*
* Callback function to parse addresses per local system convention
* It is disabled because we don't support subaddresses.
*/
-#if 0
int ctdl_getsubaddress(sieve2_context_t *s, void *my)
{
struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
{
struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
- SVM_syslog(LOG_DEBUG, "Action is GETENVELOPE");
- SV_syslog(LOG_DEBUG, "EnvFrom: %s", cs->envelope_from);
- SV_syslog(LOG_DEBUG, "EnvTo: %s", cs->envelope_to);
+ syslog(LOG_DEBUG, "Action is GETENVELOPE");
+ syslog(LOG_DEBUG, "EnvFrom: %s", cs->envelope_from);
+ syslog(LOG_DEBUG, "EnvTo: %s", cs->envelope_to);
if (cs->envelope_from != NULL) {
if ((cs->envelope_from[0] != '@')&&(cs->envelope_from[strlen(cs->envelope_from)-1] != '@')) {
}
+#if 0
/*
* Callback function to fetch message body
* (Uncomment the code if we implement this extension)
*
+ */
int ctdl_getbody(sieve2_context_t *s, void *my)
{
return SIEVE2_ERROR_UNSUPPORTED;
}
- *
- */
+#endif
/*
for (sptr=u->first_script; sptr!=NULL; sptr=sptr->next) {
if (sptr->script_active > 0) {
- SV_syslog(LOG_DEBUG, "get_active_script() is using script '%s'", sptr->script_name);
+ syslog(LOG_DEBUG, "get_active_script() is using script '%s'", sptr->script_name);
return(sptr->script_content);
}
}
- SVM_syslog(LOG_DEBUG, "get_active_script() found no active script");
+ syslog(LOG_DEBUG, "get_active_script() found no active script");
return(NULL);
}
return SIEVE2_ERROR_GETSCRIPT;
}
+
/*
* Callback function to retrieve message headers
*/
struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
- SVM_syslog(LOG_DEBUG, "ctdl_getheaders() was called");
+ syslog(LOG_DEBUG, "ctdl_getheaders() was called");
sieve2_setvalue_string(s, "allheaders", cs->rfc822headers);
return SIEVE2_OK;
}
-
/*
* Add a room to the list of those rooms which potentially require sieve processing
*/
ptr->next = sieve_list;
sieve_list = ptr;
end_critical_section(S_SIEVELIST);
- SV_syslog(LOG_DEBUG, "<%s> queued for Sieve processing", which_room->QRname);
+ syslog(LOG_DEBUG, "<%s> queued for Sieve processing", which_room->QRname);
}
-
/*
* Perform sieve processing for one message (called by sieve_do_room() for each message)
*/
size_t headers_len = 0;
int len = 0;
- if (u == NULL)
- {
- SV_syslog(LOG_EMERG, "Can't process message <%ld> without userdata!", msgnum);
+ if (u == NULL) {
+ syslog(LOG_ERR, "Can't process message <%ld> without userdata!", msgnum);
return;
}
sieve2_context = u->sieve2_context;
- SV_syslog(LOG_DEBUG, "Performing sieve processing on msg <%ld>", msgnum);
+ syslog(LOG_DEBUG, "Performing sieve processing on msg <%ld>", msgnum);
/*
* Make sure you include message body so you can get those second-level headers ;)
*/
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) return;
/*
if (!CM_IsEmpty(msg, erFc822Addr)) {
safestrncpy(my.sender, msg->cm_fields[erFc822Addr], sizeof my.sender);
}
- else if ( (!CM_IsEmpty(msg, eAuthor)) && (!CM_IsEmpty(msg, eNodeName)) ) {
- snprintf(my.sender, sizeof my.sender, "%s@%s", msg->cm_fields[eAuthor], msg->cm_fields[eNodeName]);
- }
else if (!CM_IsEmpty(msg, eAuthor)) {
safestrncpy(my.sender, msg->cm_fields[eAuthor], sizeof my.sender);
}
}
if (haschar(my.envelope_from, '@') == 0) {
strcat(my.envelope_from, "@");
- strcat(my.envelope_from, config.c_fqdn);
+ strcat(my.envelope_from, CtdlGetConfigStr("c_fqdn"));
}
/* Keep track of the envelope-to address (use body-to if not found) */
}
else if (!CM_IsEmpty(msg, eRecipient)) {
safestrncpy(my.envelope_to, msg->cm_fields[eRecipient], sizeof my.envelope_to);
- if (!CM_IsEmpty(msg, eDestination)) {
- strcat(my.envelope_to, "@");
- strcat(my.envelope_to, msg->cm_fields[eDestination]);
- }
stripallbut(my.envelope_to, '<', '>');
}
else {
}
if (haschar(my.envelope_to, '@') == 0) {
strcat(my.envelope_to, "@");
- strcat(my.envelope_to, config.c_fqdn);
+ strcat(my.envelope_to, CtdlGetConfigStr("c_fqdn"));
}
CM_Free(msg);
- SVM_syslog(LOG_DEBUG, "Calling sieve2_execute()");
+ syslog(LOG_DEBUG, "Calling sieve2_execute()");
res = sieve2_execute(sieve2_context, &my);
if (res != SIEVE2_OK) {
- SV_syslog(LOG_CRIT, "sieve2_execute() returned %d: %s", res, sieve2_errstr(res));
+ syslog(LOG_ERR, "sieve2_execute() returned %d: %s", res, sieve2_errstr(res));
}
free(my.rfc822headers);
* if no other action was successfully taken.
*/
if ( (!my.keep) && (my.cancel_implicit_keep) ) {
- SVM_syslog(LOG_DEBUG, "keep is 0 -- deleting message from inbox");
+ syslog(LOG_DEBUG, "keep is 0 -- deleting message from inbox");
CtdlDeleteMessages(CC->room.QRname, &msgnum, 1, "");
}
- SV_syslog(LOG_DEBUG, "Completed sieve processing on msg <%ld>", msgnum);
+ syslog(LOG_DEBUG, "Completed sieve processing on msg <%ld>", msgnum);
u->lastproc = msgnum;
return;
long conflen;
u->config_msgnum = msgnum;
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) {
u->config_msgnum = (-1) ;
return;
*/
snprintf(u.config_roomname, sizeof u.config_roomname, "%010ld.%s", atol(roomname), USERCONFIGROOM);
if (CtdlGetRoom(&CC->room, u.config_roomname) != 0) {
- SV_syslog(LOG_DEBUG, "<%s> does not exist. No processing is required.", u.config_roomname);
+ syslog(LOG_DEBUG, "<%s> does not exist. No processing is required.", u.config_roomname);
return;
}
get_sieve_config_backend, (void *)&u );
if (u.config_msgnum < 0) {
- SVM_syslog(LOG_DEBUG, "No Sieve rules exist. No processing is required.");
+ syslog(LOG_DEBUG, "No Sieve rules exist. No processing is required.");
return;
}
(get_active_script(&u) == NULL)
|| (strchr(get_active_script(&u), ';') == NULL)
) {
- SVM_syslog(LOG_DEBUG, "Sieve script is empty. No processing is required.");
+ syslog(LOG_DEBUG, "Sieve script is empty. No processing is required.");
return;
}
- SV_syslog(LOG_DEBUG, "Rules found. Performing Sieve processing for <%s>", roomname);
+ syslog(LOG_DEBUG, "Rules found. Performing Sieve processing for <%s>", roomname);
if (CtdlGetRoom(&CC->room, roomname) != 0) {
- SV_syslog(LOG_CRIT, "ERROR: cannot load <%s>", roomname);
+ syslog(LOG_ERR, "ERROR: cannot load <%s>", roomname);
return;
}
res = sieve2_alloc(&sieve2_context);
if (res != SIEVE2_OK) {
- SV_syslog(LOG_CRIT, "sieve2_alloc() returned %d: %s", res, sieve2_errstr(res));
+ syslog(LOG_ERR, "sieve2_alloc() returned %d: %s", res, sieve2_errstr(res));
return;
}
res = sieve2_callbacks(sieve2_context, ctdl_sieve_callbacks);
if (res != SIEVE2_OK) {
- SV_syslog(LOG_CRIT, "sieve2_callbacks() returned %d: %s", res, sieve2_errstr(res));
+ syslog(LOG_ERR, "sieve2_callbacks() returned %d: %s", res, sieve2_errstr(res));
goto BAIL;
}
my.u = &u;
res = sieve2_validate(sieve2_context, &my);
if (res != SIEVE2_OK) {
- SV_syslog(LOG_CRIT, "sieve2_validate() returned %d: %s", res, sieve2_errstr(res));
+ syslog(LOG_ERR, "sieve2_validate() returned %d: %s", res, sieve2_errstr(res));
goto BAIL;
}
BAIL:
res = sieve2_free(&sieve2_context);
if (res != SIEVE2_OK) {
- SV_syslog(LOG_CRIT, "sieve2_free() returned %d: %s", res, sieve2_errstr(res));
+ syslog(LOG_ERR, "sieve2_free() returned %d: %s", res, sieve2_errstr(res));
}
/* Rewrite the config if we have to */
struct RoomProcList *ptr = NULL;
if (sieve_list != NULL) {
- SVM_syslog(LOG_DEBUG, "Begin Sieve processing");
+ syslog(LOG_DEBUG, "Begin Sieve processing");
while (sieve_list != NULL) {
char spoolroomname[ROOMNAMELEN];
safestrncpy(spoolroomname, sieve_list->name, sizeof spoolroomname);
extract_token(script_name, argbuf, 1, '|', sizeof script_name);
if (!IsEmptyStr(script_name)) {
cprintf("%d Transmit script now\n", SEND_LISTING);
- script_content = CtdlReadMessageBody(HKEY("000"), config.c_maxmsglen, NULL, 0, 0);
+ script_content = CtdlReadMessageBody(HKEY("000"), CtdlGetConfigLong("c_maxmsglen"), NULL, 0);
msiv_putscript(&u, script_name, script_content);
changes_made = 1;
}
strcpy(&cred[55], "...");
}
- SV_syslog(LOG_INFO, "%s",cred);
+ syslog(LOG_INFO, "%s",cred);
free(cred);
/* Briefly initialize a Sieve parser instance just so we can list the
*/
res = sieve2_alloc(&sieve2_context);
if (res != SIEVE2_OK) {
- SV_syslog(LOG_CRIT, "sieve2_alloc() returned %d: %s", res, sieve2_errstr(res));
+ syslog(LOG_ERR, "sieve2_alloc() returned %d: %s", res, sieve2_errstr(res));
return;
}
res = sieve2_callbacks(sieve2_context, ctdl_sieve_callbacks);
if (res != SIEVE2_OK) {
- SV_syslog(LOG_CRIT, "sieve2_callbacks() returned %d: %s", res, sieve2_errstr(res));
+ syslog(LOG_ERR, "sieve2_callbacks() returned %d: %s", res, sieve2_errstr(res));
goto BAIL;
}
msiv_extensions = strdup(sieve2_listextensions(sieve2_context));
- SV_syslog(LOG_INFO, "Extensions: %s", msiv_extensions);
+ syslog(LOG_INFO, "Extensions: %s", msiv_extensions);
BAIL: res = sieve2_free(&sieve2_context);
if (res != SIEVE2_OK) {
- SV_syslog(LOG_CRIT, "sieve2_free() returned %d: %s", res, sieve2_errstr(res));
+ syslog(LOG_ERR, "sieve2_free() returned %d: %s", res, sieve2_errstr(res));
}
}
+
void cleanup_sieve(void)
{
struct RoomProcList *ptr, *ptr2;
end_critical_section(S_SIEVELIST);
}
+
int serv_sieve_room(struct ctdlroom *room)
{
if (!strcasecmp(&room->QRname[11], MAILROOM)) {
return 0;
}
-void LogSieveDebugEnable(const int n)
-{
- SieveDebugEnable = n;
-}
+
CTDL_MODULE_INIT(sieve)
{
if (!threading)
{
- CtdlRegisterDebugFlagHook(HKEY("sieve"), LogSieveDebugEnable, &SieveDebugEnable);
ctdl_sieve_init();
CtdlRegisterProtoHook(cmd_msiv, "MSIV", "Manage Sieve scripts");
CtdlRegisterRoomHook(serv_sieve_room);
/* return our module name for the log */
return "sieve";
}
-