Skip to content
Snippets Groups Projects
Commit f940ef27 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Implemented address part execution support.

parent 0b1a8c86
No related branches found
No related tags found
No related merge requests found
if address :comparator "i;ascii-casemap" :localpart "from" "STEPHAN" {
if address :comparator "i;octet" :domain "from" "STEPHAN" {
discard;
if address :domain :comparator "i;octet" "from" "drunksnipers.com" {
......
......@@ -2,8 +2,10 @@
#include "lib.h"
#include "compat.h"
#include "mempool.h"
#include "hash.h"
#include "array.h"
#include "message-address.h"
#include "sieve-extensions.h"
#include "sieve-code.h"
......@@ -256,6 +258,44 @@ static bool tag_address_part_generate
return TRUE;
}
/*
* Address Matching
*/
bool sieve_address_stringlist_match
(struct sieve_address_part *addrp, struct sieve_coded_stringlist *key_list,
struct sieve_comparator *cmp, const char *data)
{
bool matched = FALSE;
const struct message_address *addr;
t_push();
addr = message_address_parse
(unsafe_data_stack_pool, (const unsigned char *) data,
strlen(data), 256, FALSE);
while (!matched && addr != NULL) {
if (addr->domain != NULL) {
/* mailbox@domain */
const char *part;
i_assert(addr->mailbox != NULL);
part = addrp->extract_from(addr);
if ( sieve_stringlist_match(key_list, part, cmp) )
matched = TRUE;
}
addr = addr->next;
}
t_pop();
return matched;
}
/*
* Core address-part modifiers
*/
......@@ -267,25 +307,46 @@ const struct sieve_argument address_domain_tag =
const struct sieve_argument address_all_tag =
{ "all", tag_address_part_validate, tag_address_part_generate };
static const char *addrp_all_extract_from
(const struct message_address *address)
{
return t_strconcat(address->mailbox, "@", address->domain, NULL);
}
static const char *addrp_domain_extract_from
(const struct message_address *address)
{
return address->domain;
}
static const char *addrp_localpart_extract_from
(const struct message_address *address)
{
return address->mailbox;
}
const struct sieve_address_part all_address_part = {
"all",
&address_all_tag,
SIEVE_ADDRESS_PART_ALL,
NULL
NULL,
addrp_all_extract_from
};
const struct sieve_address_part local_address_part = {
"localpart",
&address_localpart_tag,
SIEVE_ADDRESS_PART_LOCAL,
NULL
NULL,
addrp_localpart_extract_from
};
const struct sieve_address_part domain_address_part = {
"domain",
&address_domain_tag,
SIEVE_ADDRESS_PART_DOMAIN,
NULL
NULL,
addrp_domain_extract_from
};
const struct sieve_address_part *sieve_core_address_parts[] = {
......
#ifndef __SIEVE_ADDRESS_PARTS_H
#define __SIEVE_ADDRESS_PARTS_H
#include "message-address.h"
#include "sieve-common.h"
enum sieve_address_part_code {
SIEVE_ADDRESS_PART_ALL,
SIEVE_ADDRESS_PART_LOCAL,
......@@ -14,6 +18,8 @@ struct sieve_address_part {
enum sieve_address_part_code code;
const struct sieve_extension *extension;
const char *(*extract_from)(const struct message_address *address);
};
void sieve_address_parts_link_tags
......@@ -38,6 +44,8 @@ const struct sieve_address_part *sieve_opr_address_part_read
bool sieve_opr_address_part_dump
(struct sieve_binary *sbin, sieve_size_t *address);
void sieve_address_parts_init_registry(struct sieve_interpreter *interp);
bool sieve_address_stringlist_match
(struct sieve_address_part *addrp, struct sieve_coded_stringlist *key_list,
struct sieve_comparator *cmp, const char *data);
#endif /* __SIEVE_ADDRESS_PARTS_H */
......@@ -188,7 +188,7 @@ static bool tst_address_opcode_execute
int i;
for ( i = 0; !matched && headers[i] != NULL; i++ ) {
if ( sieve_stringlist_match(key_list, headers[i], cmp) )
if ( sieve_address_stringlist_match(addrp, key_list, cmp, headers[i]) )
matched = TRUE;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.