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");
- // sieve2_getvalue_string(s, "hash"),
- // sieve2_getvalue_int(s, "days") );
+ 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;
+ }
+ }
- /* add hash to list - FIXME only do this on a miss */
+ /* If we get to this point, create a new record.
+ */
vptr = malloc(sizeof(struct sdm_vacation));
vptr->timestamp = time(NULL);
- safestrncpy(vptr->hash, sieve2_getvalue_string(s, "hash"), sizeof vptr->hash);
+ safestrncpy(vptr->fromaddr, cs->sender, sizeof vptr->fromaddr);
vptr->next = cs->u->first_vacation;
cs->u->first_vacation = vptr;
return SIEVE2_OK;
- /* return SIEVE2_ERROR_UNSUPPORTED; */
}
*/
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;
}
else if (!strcasecmp(keyword, "vacation")) {
- vptr = malloc(sizeof(struct sdm_vacation));
- vptr->timestamp = extract_long(c, 1);
- extract_token(vptr->hash, c, 2, '|', sizeof vptr->hash);
- vptr->next = u->first_vacation;
- u->first_vacation = vptr;
+
+ 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 */
free(sptr);
}
- while (u->first_vacation != NULL) {
- if ( (time(NULL) - u->first_vacation->timestamp) < MAX_VACATION) {
- text = realloc(text, strlen(text) + strlen(u->first_vacation->hash) + 256);
- sprintf(&text[strlen(text)], "vacation|%ld|%s" CTDLSIEVECONFIGSEPARATOR,
- u->first_vacation->timestamp,
- u->first_vacation->hash
- );
+ 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);
}
- vptr = u->first_vacation;
- u->first_vacation = u->first_vacation->next;
- free(vptr);
+ sprintf(&text[strlen(text)], CTDLSIEVECONFIGSEPARATOR);
}
/* Save the config */
/* 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 {