Commit 05abf257 05abf2570ef2d796a3178fab9298bf2b8868a972 by Sergey Poznyakoff

Vacation: improve compatibility with the Sendmail utility.

* libmu_sieve/extensions/vacation.c (match_addresses): Change arguments:
take primary email address as well as a list of aliases.
(vacation_reply): Reply if the primary email or one of alias emails are
listed in recipient list of the original message.  New tag "always_reply"
reverts to the old behavior: reply regardless of whether the message is
destined for us.
Use the current user email as the sender address of the vacation message.
New tag "return_address" sets the sender address explicitly.
* sieve/tests/vacation.at: Add new tests.
1 parent 9a908ba5
......@@ -26,6 +26,8 @@
[:database <path: string>]
[:file]
[:mime]
[:always_reply]
[:return_address <email: string>]
<reply: string>
*/
......@@ -162,8 +164,8 @@ _compare (void *item, void *data)
of the originating mail. Return non-zero if so and store a pointer
to the matching address in *MY_ADDRESS. */
static int
match_addresses (mu_header_t hdr, mu_sieve_value_t *addresses,
char **my_address)
match_addresses (mu_header_t hdr, char *email, mu_sieve_value_t *addresses,
char const **my_address)
{
int match = 0;
const char *str;
......@@ -174,6 +176,9 @@ match_addresses (mu_header_t hdr, mu_sieve_value_t *addresses,
{
if (!mu_address_create (&ad.addr, str))
{
if (_compare (email, &ad))
match = 1;
else if (addresses)
match += mu_sieve_vlist_do (addresses, _compare, &ad);
mu_address_destroy (&ad.addr);
}
......@@ -183,6 +188,9 @@ match_addresses (mu_header_t hdr, mu_sieve_value_t *addresses,
{
if (!mu_address_create (&ad.addr, str))
{
if (_compare (email, &ad))
match = 1;
else if (addresses)
match += mu_sieve_vlist_do (addresses, _compare, &ad);
mu_address_destroy (&ad.addr);
}
......@@ -528,7 +536,7 @@ vacation_subject (mu_sieve_machine_t mach, mu_list_t tags,
/* Generate and send the reply message */
static int
vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg,
char *text, char *to, char *from)
char const *text, char const *to, char const *from)
{
mu_mime_t mime = NULL;
mu_message_t newmsg;
......@@ -629,10 +637,11 @@ sieve_action_vacation (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
{
int rc;
char *text, *from;
char const *return_address;
mu_sieve_value_t *val;
mu_message_t msg;
mu_header_t hdr;
char *my_address = mu_sieve_get_daemon_email (mach);
char *my_address;
if (diag (mach))
return 0;
......@@ -669,20 +678,35 @@ sieve_action_vacation (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
mu_sieve_abort (mach);
}
if (mu_sieve_tag_lookup (tags, "aliases", &val)
&& match_addresses (hdr, val, &my_address) == 0)
my_address = mu_get_user_email (NULL);
if (mu_sieve_tag_lookup (tags, "always_reply", NULL))
return_address = my_address;
else
{
val = NULL;
mu_sieve_tag_lookup (tags, "aliases", &val);
if (match_addresses (hdr, my_address, val, &return_address) == 0)
{
free (my_address);
return 0;
}
}
if (noreply_address_p (mach, tags, from)
|| bulk_precedence_p (hdr)
|| check_db (mach, tags, from))
{
free (from);
free (my_address);
return 0;
}
rc = vacation_reply (mach, tags, msg, text, from, my_address);
if (mu_sieve_tag_lookup (tags, "return_address", &val))
return_address = val->v.string;
rc = vacation_reply (mach, tags, msg, text, from, return_address);
free (from);
free (my_address);
if (rc == -1)
mu_sieve_abort (mach);
return rc;
......@@ -700,6 +724,8 @@ static mu_sieve_tag_def_t vacation_tags[] = {
{"database", SVT_STRING},
{"mime", SVT_VOID},
{"file", SVT_VOID},
{"always_reply", SVT_VOID},
{"return_address", SVT_STRING},
{NULL}
};
......
......@@ -29,7 +29,38 @@ export MTA_DIAG MTA_APPEND
sieve MUT_SIEVE_CMDLINE MUT_SIEVE_OPTIONS -f ./mailbox prog || exit 1
cat ./mta.diag
],
[ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
[ENVELOPE FROM: foobar@nonexistent.net
ENVELOPE TO: <bar@dontmailme.org>
0: References: <200112232808.fERKR9N16790@dontmailme.org>
1: In-Reply-To: Your message of Fri, 28 Dec 2001 23:28:08 +0200
2: <200112232808.fERKR9N16790@dontmailme.org>
3: Subject: =?UTF-8?Q?Re:_Coffee?=
4: To: bar@dontmailme.org
5: Content-Transfer-Encoding: 8bit
6: Content-Type: text/plain;charset=UTF-8
7: MIME-Version: 1.0
8:
9: I'm on vacation
END OF MESSAGE
],
[VACATION on msg uid 1
VACATION on msg uid 2
VACATION on msg uid 3
])
MUT_SIEVE_EXT_TEST([aliases],[vac01],
[require "vacation";
vacation :database "vacation.db" :aliases [[ "roadrunner@acme.example.com" ]] "I'm on vacation";
],
[MUT_MBCOPY($abs_top_srcdir/testsuite/spool/sieve.mbox,mailbox)
MTA_DIAG=`pwd`/mta.diag
MTA_APPEND=1
export MTA_DIAG MTA_APPEND
sieve MUT_SIEVE_CMDLINE MUT_SIEVE_OPTIONS -f ./mailbox prog || exit 1
cat ./mta.diag
],
[ENVELOPE FROM: roadrunner@acme.example.com
ENVELOPE TO: <coyote@desert.example.org>
0: In-Reply-To: Your message of Sun May 6 22:16:47 2001
1: Subject: =?UTF-8?Q?Re:_I_have_a_present_for_you?=
......@@ -40,7 +71,49 @@ ENVELOPE TO: <coyote@desert.example.org>
6:
7: I'm on vacation
END OF MESSAGE
ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
ENVELOPE FROM: foobar@nonexistent.net
ENVELOPE TO: <bar@dontmailme.org>
0: References: <200112232808.fERKR9N16790@dontmailme.org>
1: In-Reply-To: Your message of Fri, 28 Dec 2001 23:28:08 +0200
2: <200112232808.fERKR9N16790@dontmailme.org>
3: Subject: =?UTF-8?Q?Re:_Coffee?=
4: To: bar@dontmailme.org
5: Content-Transfer-Encoding: 8bit
6: Content-Type: text/plain;charset=UTF-8
7: MIME-Version: 1.0
8:
9: I'm on vacation
END OF MESSAGE
],
[VACATION on msg uid 1
VACATION on msg uid 2
VACATION on msg uid 3
])
MUT_SIEVE_EXT_TEST([always_reply],[vac02],
[require "vacation";
vacation :database "vacation.db" :always_reply "I'm on vacation";
],
[MUT_MBCOPY($abs_top_srcdir/testsuite/spool/sieve.mbox,mailbox)
MTA_DIAG=`pwd`/mta.diag
MTA_APPEND=1
export MTA_DIAG MTA_APPEND
sieve MUT_SIEVE_CMDLINE MUT_SIEVE_OPTIONS -f ./mailbox prog || exit 1
cat ./mta.diag
],
[ENVELOPE FROM: foobar@nonexistent.net
ENVELOPE TO: <coyote@desert.example.org>
0: In-Reply-To: Your message of Sun May 6 22:16:47 2001
1: Subject: =?UTF-8?Q?Re:_I_have_a_present_for_you?=
2: To: coyote@desert.example.org
3: Content-Transfer-Encoding: 8bit
4: Content-Type: text/plain;charset=UTF-8
5: MIME-Version: 1.0
6:
7: I'm on vacation
END OF MESSAGE
ENVELOPE FROM: foobar@nonexistent.net
ENVELOPE TO: <b1ff@de.res.example.com>
0: In-Reply-To: Your message of TBD
1: Subject: =?UTF-8?Q?Re:_$$$_YOU,_TOO,_CAN_BE_A_MILLIONAIRE!_$$$?=
......@@ -51,7 +124,7 @@ ENVELOPE TO: <b1ff@de.res.example.com>
6:
7: I'm on vacation
END OF MESSAGE
ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
ENVELOPE FROM: foobar@nonexistent.net
ENVELOPE TO: <bar@dontmailme.org>
0: References: <200112232808.fERKR9N16790@dontmailme.org>
1: In-Reply-To: Your message of Fri, 28 Dec 2001 23:28:08 +0200
......@@ -70,10 +143,10 @@ VACATION on msg uid 2
VACATION on msg uid 3
])
MUT_SIEVE_EXT_TEST([database matching],[vac01],
MUT_SIEVE_EXT_TEST([database matching],[vac03],
[require "vacation";
vacation :database "vacation.db" "I'm on vacation";
vacation :database "vacation.db" :always_reply "I'm on vacation";
],
[MUT_MBCOPY($abs_top_srcdir/testsuite/spool/sieve.mbox,mailbox)
MTA_DIAG=`pwd`/mta.diag
......@@ -83,7 +156,7 @@ sieve MUT_SIEVE_CMDLINE MUT_SIEVE_OPTIONS -f ./mailbox prog || exit 1
sieve MUT_SIEVE_CMDLINE MUT_SIEVE_OPTIONS -f ./mailbox prog || exit 1
cat ./mta.diag
],
[ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
[ENVELOPE FROM: foobar@nonexistent.net
ENVELOPE TO: <coyote@desert.example.org>
0: In-Reply-To: Your message of Sun May 6 22:16:47 2001
1: Subject: =?UTF-8?Q?Re:_I_have_a_present_for_you?=
......@@ -94,7 +167,7 @@ ENVELOPE TO: <coyote@desert.example.org>
6:
7: I'm on vacation
END OF MESSAGE
ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
ENVELOPE FROM: foobar@nonexistent.net
ENVELOPE TO: <b1ff@de.res.example.com>
0: In-Reply-To: Your message of TBD
1: Subject: =?UTF-8?Q?Re:_$$$_YOU,_TOO,_CAN_BE_A_MILLIONAIRE!_$$$?=
......@@ -105,7 +178,7 @@ ENVELOPE TO: <b1ff@de.res.example.com>
6:
7: I'm on vacation
END OF MESSAGE
ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
ENVELOPE FROM: foobar@nonexistent.net
ENVELOPE TO: <bar@dontmailme.org>
0: References: <200112232808.fERKR9N16790@dontmailme.org>
1: In-Reply-To: Your message of Fri, 28 Dec 2001 23:28:08 +0200
......@@ -127,10 +200,10 @@ VACATION on msg uid 2
VACATION on msg uid 3
])
MUT_SIEVE_EXT_TEST([mime],[vac02],
MUT_SIEVE_EXT_TEST([mime],[vac04],
[require "vacation";
vacation :database "vacation.db" :mime "I'm on vacation.";
vacation :database "vacation.db" :always_reply :mime "I'm on vacation.";
],
[MUT_MBCOPY($abs_top_srcdir/testsuite/spool/sieve.mbox,mailbox)
MTA_DIAG=`pwd`/mta.diag
......@@ -139,7 +212,7 @@ export MTA_DIAG MTA_APPEND
sieve MUT_SIEVE_CMDLINE MUT_SIEVE_OPTIONS -f ./mailbox prog || exit 1
cat ./mta.diag
],
[ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
[ENVELOPE FROM: foobar@nonexistent.net
ENVELOPE TO: <coyote@desert.example.org>
0: In-Reply-To: Your message of Sun May 6 22:16:47 2001
1: Subject: =?UTF-8?Q?Re:_I_have_a_present_for_you?=
......@@ -150,7 +223,7 @@ ENVELOPE TO: <coyote@desert.example.org>
6:
7: SSdtIG9uIHZhY2F0aW9uLg==
END OF MESSAGE
ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
ENVELOPE FROM: foobar@nonexistent.net
ENVELOPE TO: <b1ff@de.res.example.com>
0: In-Reply-To: Your message of TBD
1: Subject: =?UTF-8?Q?Re:_$$$_YOU,_TOO,_CAN_BE_A_MILLIONAIRE!_$$$?=
......@@ -161,7 +234,7 @@ ENVELOPE TO: <b1ff@de.res.example.com>
6:
7: SSdtIG9uIHZhY2F0aW9uLg==
END OF MESSAGE
ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
ENVELOPE FROM: foobar@nonexistent.net
ENVELOPE TO: <bar@dontmailme.org>
0: References: <200112232808.fERKR9N16790@dontmailme.org>
1: In-Reply-To: Your message of Fri, 28 Dec 2001 23:28:08 +0200
......@@ -180,10 +253,10 @@ VACATION on msg uid 2
VACATION on msg uid 3
])
MUT_SIEVE_EXT_TEST([reply from file],[vac03],
MUT_SIEVE_EXT_TEST([reply from file],[vac05],
[require "vacation";
vacation :database "vacation.db" :file "reply";
vacation :database "vacation.db" :always_reply :file "reply";
],
[AT_DATA([reply],[X-Mail-Processor: sieve
......@@ -200,7 +273,7 @@ export MTA_DIAG MTA_APPEND
sieve MUT_SIEVE_CMDLINE MUT_SIEVE_OPTIONS -f ./mailbox prog || exit 1
cat ./mta.diag
],
[ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
[ENVELOPE FROM: foobar@nonexistent.net
ENVELOPE TO: <coyote@desert.example.org>
0: In-Reply-To: Your message of Sun May 6 22:16:47 2001
1: Subject: =?UTF-8?Q?Re:_I_have_a_present_for_you?=
......@@ -213,7 +286,7 @@ ENVELOPE TO: <coyote@desert.example.org>
8: Best regards,
9: Ty Coon
END OF MESSAGE
ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
ENVELOPE FROM: foobar@nonexistent.net
ENVELOPE TO: <b1ff@de.res.example.com>
0: In-Reply-To: Your message of TBD
1: Subject: =?UTF-8?Q?Re:_$$$_YOU,_TOO,_CAN_BE_A_MILLIONAIRE!_$$$?=
......@@ -226,7 +299,7 @@ ENVELOPE TO: <b1ff@de.res.example.com>
8: Best regards,
9: Ty Coon
END OF MESSAGE
ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
ENVELOPE FROM: foobar@nonexistent.net
ENVELOPE TO: <bar@dontmailme.org>
0: References: <200112232808.fERKR9N16790@dontmailme.org>
1: In-Reply-To: Your message of Fri, 28 Dec 2001 23:28:08 +0200
......