/*
- * $Id$
- *
* This module glues libSieve to the Citadel server in order to implement
* the Sieve mailbox filtering language (RFC 3028).
*
- * Copyright (c) 2007-2009 by the citadel.org team
+ * Copyright (c) 1987-2010 by the citadel.org team
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "sysdep.h"
#include "citserver.h"
#include "support.h"
#include "config.h"
-#include "policy.h"
#include "database.h"
#include "msgbase.h"
#include "internet_addressing.h"
/* Yes, we actually have to go there */
CtdlUserGoto(NULL, 0, 0, NULL, NULL);
- c = CtdlSaveMsgPointersInRoom(NULL, &cs->msgnum, 1, 0, NULL);
+ c = CtdlSaveMsgPointersInRoom(NULL, &cs->msgnum, 1, 0, NULL, 0);
/* Go back to the room we came from */
if (strcasecmp(original_room_name, CC->room.QRname)) {
}
sprintf(vacamsg_text,
- "Content-type: text/plain\n"
+ "Content-type: text/plain charset=utf-8\n"
"\n"
"%s\n"
"\n"
/* If we get to this point, create a new record.
*/
vptr = malloc(sizeof(struct sdm_vacation));
+ memset(vptr, 0, sizeof(struct sdm_vacation));
vptr->timestamp = time(NULL);
safestrncpy(vptr->fromaddr, cs->sender, sizeof vptr->fromaddr);
vptr->next = cs->u->first_vacation;
* Grab the message headers so we can feed them to libSieve.
* Use HEADERS_ONLY rather than HEADERS_FAST in order to include second-level headers.
*/
- CC->redirect_buffer = malloc(SIZ);
- CC->redirect_len = 0;
- CC->redirect_alloc = SIZ;
+ CC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ONLY, 0, 1, 0);
- my.rfc822headers = CC->redirect_buffer;
- headers_len = CC->redirect_len;
- CC->redirect_buffer = NULL;
- CC->redirect_len = 0;
- CC->redirect_alloc = 0;
+ headers_len = StrLength(CC->redirect_buffer);
+ my.rfc822headers = SmashStrBuf(&CC->redirect_buffer);
/*
* libSieve clobbers the stack if it encounters badly formed
* otherwise it just frees the data structures.)
*/
void rewrite_ctdl_sieve_config(struct sdm_userdata *u, int yes_write_to_disk) {
- char *text;
+ StrBuf *text;
struct sdm_script *sptr;
struct sdm_vacation *vptr;
- size_t tsize;
-
- text = malloc(1024);
- tsize = 1024;
- snprintf(text, 1024,
- "Content-type: application/x-citadel-sieve-config\n"
- "\n"
- CTDLSIEVECONFIGSEPARATOR
- "lastproc|%ld"
- CTDLSIEVECONFIGSEPARATOR
- ,
- u->lastproc
- );
+
+ text = NewStrBufPlain(NULL, SIZ);
+ StrBufPrintf(text,
+ "Content-type: application/x-citadel-sieve-config\n"
+ "\n"
+ CTDLSIEVECONFIGSEPARATOR
+ "lastproc|%ld"
+ CTDLSIEVECONFIGSEPARATOR
+ ,
+ u->lastproc
+ );
while (u->first_script != NULL) {
- size_t tlen;
- tlen = strlen(text);
- tsize = tlen + strlen(u->first_script->script_content) +256;
- text = realloc(text, tsize);
- sprintf(&text[strlen(text)], "script|%s|%d|%s" CTDLSIEVECONFIGSEPARATOR,
- u->first_script->script_name,
- u->first_script->script_active,
- u->first_script->script_content
- );
+ StrBufAppendPrintf(text,
+ "script|%s|%d|%s" CTDLSIEVECONFIGSEPARATOR,
+ u->first_script->script_name,
+ u->first_script->script_active,
+ u->first_script->script_content
+ );
sptr = u->first_script;
u->first_script = u->first_script->next;
free(sptr->script_content);
if (u->first_vacation != NULL) {
- tsize = strlen(text) + 256;
- for (vptr = u->first_vacation; vptr != NULL; vptr = vptr->next) {
- tsize += strlen(vptr->fromaddr + 32);
- }
- text = realloc(text, tsize);
-
- sprintf(&text[strlen(text)], "vacation|\n");
+ StrBufAppendPrintf(text, "vacation|\n");
while (u->first_vacation != NULL) {
if ( (time(NULL) - u->first_vacation->timestamp) < (MAX_VACATION * 86400)) {
- sprintf(&text[strlen(text)], "%s|%ld\n",
- u->first_vacation->fromaddr,
- u->first_vacation->timestamp
- );
+ StrBufAppendPrintf(text, "%s|%ld\n",
+ u->first_vacation->fromaddr,
+ u->first_vacation->timestamp
+ );
}
vptr = u->first_vacation;
u->first_vacation = u->first_vacation->next;
free(vptr);
}
- sprintf(&text[strlen(text)], CTDLSIEVECONFIGSEPARATOR);
+ StrBufAppendPrintf(text, CTDLSIEVECONFIGSEPARATOR);
}
if (yes_write_to_disk)
{
/* Save the config */
quickie_message("Citadel", NULL, NULL, u->config_roomname,
- text,
+ ChrPtr(text),
4,
"Sieve configuration"
);
}
}
- free (text);
+ FreeStrBuf (&text);
}
}
+void cleanup_sieve(void)
+{
+ struct RoomProcList *ptr, *ptr2;
+
+ if (msiv_extensions != NULL)
+ free(msiv_extensions);
+ msiv_extensions = NULL;
+
+ begin_critical_section(S_SIEVELIST);
+ ptr=sieve_list;
+ while (ptr != NULL) {
+ ptr2 = ptr->next;
+ free(ptr);
+ ptr = ptr2;
+ }
+ sieve_list = NULL;
+ end_critical_section(S_SIEVELIST);
+}
+
int serv_sieve_room(struct ctdlroom *room)
{
if (!strcasecmp(&room->QRname[11], MAILROOM)) {
CtdlRegisterProtoHook(cmd_msiv, "MSIV", "Manage Sieve scripts");
CtdlRegisterRoomHook(serv_sieve_room);
CtdlRegisterSessionHook(perform_sieve_processing, EVT_HOUSE);
+ CtdlRegisterCleanupHook(cleanup_sieve);
}
/* return our Subversion id for the Log */
- return "$Id$";
+ return "sieve";
}