static int ctdl_libsieve_debug = 0;
if (ctdl_libsieve_debug) {
+/*
lprintf(CTDL_DEBUG, "Sieve: level [%d] module [%s] file [%s] function [%s]\n",
sieve2_getvalue_int(s, "level"),
sieve2_getvalue_string(s, "module"),
sieve2_getvalue_string(s, "file"),
sieve2_getvalue_string(s, "function"));
- lprintf(CTDL_DEBUG, " message [%s]\n",
+ */
+ lprintf(CTDL_DEBUG, "Sieve: %s\n",
sieve2_getvalue_string(s, "message"));
}
return SIEVE2_OK;
);
quickie_message( /* This delivers the message */
- "Citadel",
+ "Citadel", /* FIXME make it myself */
cs->sender,
NULL,
reject_text,
/*
* Callback function to indicate that a vacation message should be generated
- * FIXME implement this
*/
int ctdl_vacation(sieve2_context_t *s, void *my)
{
+ struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
+ struct sdm_vacation *vptr;
+ int days = 1;
+ const char *message;
+ char *vacamsg_text = NULL;
+ char vacamsg_subject[1024];
+
lprintf(CTDL_DEBUG, "Action is VACATION\n");
- return SIEVE2_ERROR_UNSUPPORTED;
+
+ message = sieve2_getvalue_string(s, "message");
+ if (message == NULL) return SIEVE2_ERROR_BADARGS;
+
+ if (sieve2_getvalue_string(s, "subject") != NULL) {
+ safestrncpy(vacamsg_subject, sieve2_getvalue_string(s, "subject"), sizeof vacamsg_subject);
+ }
+ else {
+ snprintf(vacamsg_subject, sizeof vacamsg_subject, "Re: %s", cs->subject);
+ }
+
+ days = sieve2_getvalue_int(s, "days");
+ if (days < 1) days = 1;
+ if (days > MAX_VACATION) days = MAX_VACATION;
+
+ /* Check to see whether we've already alerted this sender that we're on vacation. */
+ for (vptr = cs->u->first_vacation; vptr != NULL; vptr = vptr->next) {
+ if (!strcasecmp(vptr->fromaddr, cs->sender)) {
+ if ( (time(NULL) - vptr->timestamp) < (days * 86400) ) {
+ lprintf(CTDL_DEBUG, "Already alerted <%s> recently.\n", cs->sender);
+ return SIEVE2_OK;
+ }
+ }
+ }
+
+ /* Assemble the reject message. */
+ vacamsg_text = malloc(strlen(message) + 1024);
+ if (vacamsg_text == NULL) {
+ return SIEVE2_ERROR_FAIL;
+ }
+
+ sprintf(vacamsg_text,
+ "Content-type: text/plain\n"
+ "\n"
+ "%s\n"
+ "\n"
+ ,
+ message
+ );
+
+ quickie_message( /* This delivers the message */
+ "Citadel", /* FIXME make it myself */
+ cs->sender,
+ NULL,
+ vacamsg_text,
+ FMT_RFC822,
+ vacamsg_subject
+ );
+
+ free(vacamsg_text);
+
+ /* Now update the list to reflect the fact that we've alerted this sender.
+ * If they're already in the list, just update the timestamp.
+ */
+ for (vptr = cs->u->first_vacation; vptr != NULL; vptr = vptr->next) {
+ if (!strcasecmp(vptr->fromaddr, cs->sender)) {
+ vptr->timestamp = time(NULL);
+ return SIEVE2_OK;
+ }
+ }
+
+ /* If we get to this point, create a new record.
+ */
+ vptr = malloc(sizeof(struct sdm_vacation));
+ vptr->timestamp = time(NULL);
+ safestrncpy(vptr->fromaddr, cs->sender, sizeof vptr->fromaddr);
+ vptr->next = cs->u->first_vacation;
+ cs->u->first_vacation = vptr;
+
+ return SIEVE2_OK;
}
/*
* Callback function to parse message envelope
*/
-#if 0
int ctdl_getenvelope(sieve2_context_t *s, void *my)
{
- return SIEVE2_ERROR_UNSUPPORTED;
+ 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);
+ return SIEVE2_OK;
}
-#endif
/*
else {
strcpy(my.subject, "");
}
-
+
+ /* 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);
+ }
+ else if (msg->cm_fields['F'] != NULL) {
+ safestrncpy(my.envelope_from, msg->cm_fields['F'], sizeof my.envelope_from);
+ }
+ else {
+ strcpy(my.envelope_from, "");
+ }
+
+ /* Keep track of the envelope-to address */
+ if (msg->cm_fields['V'] != NULL) {
+ safestrncpy(my.envelope_to, msg->cm_fields['V'], sizeof my.envelope_to);
+ }
+ else {
+ strcpy(my.envelope_to, "");
+ }
free(msg);
*/
void parse_sieve_config(char *conf, struct sdm_userdata *u) {
char *ptr;
- char *c;
+ char *c, *vacrec;
char keyword[256];
struct sdm_script *sptr;
+ struct sdm_vacation *vptr;
ptr = conf;
while (c = ptr, ptr = bmstrcasestr(ptr, CTDLSIEVECONFIGSEPARATOR), ptr != NULL) {
u->first_script = sptr;
}
+ else if (!strcasecmp(keyword, "vacation")) {
+
+ if (c != NULL) while (vacrec=c, c=strchr(c, '\n'), (c != NULL)) {
+
+ *c = 0;
+ ++c;
+
+ if (strncasecmp(vacrec, "vacation|", 9)) {
+ vptr = malloc(sizeof(struct sdm_vacation));
+ extract_token(vptr->fromaddr, vacrec, 0, '|', sizeof vptr->fromaddr);
+ vptr->timestamp = extract_long(vacrec, 1);
+ vptr->next = u->first_vacation;
+ u->first_vacation = vptr;
+ }
+ }
+ }
+
/* ignore unknown keywords */
}
}
void rewrite_ctdl_sieve_config(struct sdm_userdata *u) {
char *text;
struct sdm_script *sptr;
+ struct sdm_vacation *vptr;
text = malloc(1024);
free(sptr);
}
+ if (u->first_vacation != NULL) {
+
+ size_t realloc_len = strlen(text) + 256;
+ for (vptr = u->first_vacation; vptr != NULL; vptr = vptr->next) {
+ realloc_len += strlen(vptr->fromaddr + 32);
+ }
+ text = realloc(text, realloc_len);
+
+ sprintf(&text[strlen(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
+ );
+ }
+ vptr = u->first_vacation;
+ u->first_vacation = u->first_vacation->next;
+ free(vptr);
+ }
+ sprintf(&text[strlen(text)], CTDLSIEVECONFIGSEPARATOR);
+ }
+
/* Save the config */
quickie_message("Citadel", NULL, u->config_roomname,
text,
{ SIEVE2_DEBUG_TRACE, ctdl_debug },
{ SIEVE2_MESSAGE_GETALLHEADERS, ctdl_getheaders },
{ SIEVE2_MESSAGE_GETSIZE, ctdl_getsize },
+ { SIEVE2_MESSAGE_GETENVELOPE, ctdl_getenvelope },
/*
* These actions are unsupported by Citadel so we don't declare them.
*
{ SIEVE2_ACTION_NOTIFY, ctdl_notify },
{ SIEVE2_MESSAGE_GETSUBADDRESS, ctdl_getsubaddress },
- { SIEVE2_MESSAGE_GETENVELOPE, ctdl_getenvelope },
{ SIEVE2_MESSAGE_GETBODY, ctdl_getbody },
*
*/
/* See if the user who owns this 'mailbox' has any Sieve scripts that
* require execution.
*/
- snprintf(u.config_roomname, sizeof u.config_roomname, "%010ld.%s", atol(roomname), SIEVERULES);
+ snprintf(u.config_roomname, sizeof u.config_roomname, "%010ld.%s", atol(roomname), USERCONFIGROOM);
if (getroom(&CC->room, u.config_roomname) != 0) {
lprintf(CTDL_DEBUG, "<%s> does not exist. No processing is required.\n", u.config_roomname);
return;
strcpy(hold_rm, CC->room.QRname); /* save current room */
/* Take a spin through the user's personal address book */
- if (getroom(&CC->room, SIEVERULES) == 0) {
+ if (getroom(&CC->room, USERCONFIGROOM) == 0) {
u->config_msgnum = (-1);
strcpy(u->config_roomname, CC->room.QRname);
extract_token(script_name, argbuf, 1, '|', sizeof script_name);
script_content = msiv_getscript(&u, script_name);
if (script_content != NULL) {
- cprintf("%d Script:\n", SEND_LISTING);
+ cprintf("%d Script:\n", LISTING_FOLLOWS);
cprintf("%s000\n", script_content);
}
else {