+
+ 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 */
+ NULL,
+ cs->envelope_to,
+ 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;