Exemple #1
0
/*
From http://www.ietf.org/internet-drafts/draft-ietf-sieve-vacation-06.txt

   Usage:   vacation [":days" number] [":subject" string]
                     [":from" string] [":addresses" string-list]
                     [":mime"] [":handle" string] <reason: string>

   The parameters that an implementation needs to know about are:
   days, subject, from, mime, handle, reason. Addresses is used
   internally by libSieve implementation to comply with RFCs.

We need to make sure to respect the implementation requirements.
*/
int sort_vacation(sieve2_context_t *s, void *my)
{
	struct sort_context *m = (struct sort_context *)my;
	const char *message, *subject, *fromaddr, *handle;
	const char *rc_to, *rc_from, *rc_handle;
	char *md5_handle = NULL;
	int days, mime;

	days = sieve2_getvalue_int(s, "days");
	mime = sieve2_getvalue_int(s, "mime"); // mime: 1 if message is mime coded. FIXME.
	message = sieve2_getvalue_string(s, "message");
	subject = sieve2_getvalue_string(s, "subject");
	fromaddr = sieve2_getvalue_string(s, "fromaddr"); // From: specified by the script.
	handle = sieve2_getvalue_string(s, "hash");

	/* Default to a week, upper limit of a month.
	 * This is our only loop prevention mechanism! The value must be
	 * greater than 0, else the replycache code will always indicate
	 * that we haven't seen anything since 0 days ago... */
	if (days == 0) days = 7;
	if (days < 1) days = 1;
	if (days > 30) days = 30;

	if (handle) {
		rc_handle = handle;
	} else {
		char *tmp;
		tmp = g_strconcat(subject, message, NULL);
		rc_handle = md5_handle = dm_md5((char * const) tmp);
		g_free(tmp);
	}

	// FIXME: should be validated as a user might try
	// to forge an address from their script.
	rc_from = fromaddr;
	if (!rc_from)
		rc_from = dbmail_message_get_header(m->message, "Delivered-To");
	if (!rc_from)
		rc_from = m->message->envelope_recipient->str;

	rc_to = dbmail_message_get_header(m->message, "Reply-To");
	if (!rc_to)
		rc_to = dbmail_message_get_header(m->message, "Return-Path");

	if (db_replycache_validate(rc_to, rc_from, rc_handle, days) == DM_SUCCESS) {
		if (send_vacation(m->message, rc_to, rc_from, subject, message, rc_handle) == 0)
			db_replycache_register(rc_to, rc_from, rc_handle);
		TRACE(TRACE_INFO, "Sending vacation to [%s] from [%s] handle [%s] repeat days [%d]",
			rc_to, rc_from, rc_handle, days);
	} else {
		TRACE(TRACE_INFO, "Vacation suppressed to [%s] from [%s] handle [%s] repeat days [%d]",
			rc_to, rc_from, rc_handle, days);
	}

	m->result->cancelkeep = 0;
	return SIEVE2_OK;
}
Exemple #2
0
/*
From http://www.ietf.org/internet-drafts/draft-ietf-sieve-notify-07.txt

   Usage:  notify [":from" string] [":importance" <"1" / "2" / "3">]
                  [":options" string-list] [":message" string] <method: string>
*/
int sort_notify(sieve2_context_t *s, void *my)
{
	struct sort_context *m = (struct sort_context *)my;
	const char *message, *fromaddr, *method;
	const char *rc_to, *rc_from;
	int importance;
	char * const * options;

	fromaddr = sieve2_getvalue_string(s, "fromaddr");
	method = sieve2_getvalue_string(s, "method");
	message = sieve2_getvalue_string(s, "message");
	importance = sieve2_getvalue_int(s, "importance");
	options = sieve2_getvalue_stringlist(s, "options");

	// FIXME: should be validated as a user might try
	// to forge an address from their script.
	rc_from = fromaddr;
	if (!rc_from)
		rc_from = dbmail_message_get_header(m->message, "Delivered-To");
	if (!rc_from)
		rc_from = m->message->envelope_recipient->str;

	rc_to = dbmail_message_get_header(m->message, "Reply-To");
	if (!rc_to)
		rc_to = dbmail_message_get_header(m->message, "Return-Path");

//	send_notification(m->message, rc_to, rc_from, method, message);

	TRACE(TRACE_INFO, "Notification from [%s] to [%s] was not sent as notify is not supported in this release.", rc_from, rc_to);

	return SIEVE2_OK;
}
Exemple #3
0
int my_vacation(sieve2_context_t *s, void *my)
{
	struct my_context *m = (struct my_context *)my;
	int yn;

	/* Ask for the message hash, the days parameters, etc. */
	fprintf(stderr, "Have I already responded to '%s' in the past %d days?\n",
		sieve2_getvalue_string(s, "hash"),
		sieve2_getvalue_int(s, "days") );

	yn = getchar();

	/* Check in our 'database' to see if there's a match. */
	if (yn == 'y' || yn == 'Y') {
		printf( "Ok, not sending a vacation response.\n" );
	}

	/* If so, do nothing. If not, send a vacation and log it. */
	printf("echo '%s' | mail -s '%s' '%s' for message '%s'\n",
		sieve2_getvalue_string(s, "message"),
		sieve2_getvalue_string(s, "subject"),
		sieve2_getvalue_string(s, "address"),
		sieve2_getvalue_string(s, "name") );

	m->actiontaken = 1;
	return SIEVE2_OK;
}
Exemple #4
0
int my_debug(sieve2_context_t *s, void *my)
{
	if (debug) {
		printf("Debug: level [%d] module [%s] file [%s] function [%s] message [%s]\n",
			sieve2_getvalue_int(s, "level"),
			sieve2_getvalue_string(s, "module"),
			sieve2_getvalue_string(s, "file"),
			sieve2_getvalue_string(s, "function"),
			sieve2_getvalue_string(s, "message"));
	}
	return SIEVE2_OK;
}
Exemple #5
0
int my_errheader(sieve2_context_t *s, void *my)
{
	struct my_context *m = (struct my_context *)my;

	printf( "Error is HEADER PARSE: " );
	printf( "  Line is %d\n",
		sieve2_getvalue_int(s, "lineno"));
	printf( "  Message is %s\n",
		sieve2_getvalue_string(s, "message"));

	m->error_parse = 1;
	return SIEVE2_OK;
}