aboutsummaryrefslogtreecommitdiffstats
path: root/signature.c
blob: 458812696ac05e34ab33dac131600e9c0142f8a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdlib.h>
#include "antispam-plugin.h"
#include "signature.h"
#include "mail-storage-private.h"

static char *signature_hdr = "X-DSPAM-Signature";

void signature_init(void)
{
	char *tmp = getenv("ANTISPAM_SIGNATURE");
	if (tmp)
		signature_hdr = tmp;
	debug("antispam: signature header line is \"%s\"\n", signature_hdr);
}

int signature_extract(struct mailbox_transaction_context *t,
		      struct mail *mail, struct siglist **list,
		      bool from_spam)
{
	const char *signature;
	struct siglist *item;

	signature = mail_get_first_header(mail, signature_hdr);
	if (!signature || !signature[0]) {
		mail_storage_set_error(t->box->storage,
				       "antispam signature not found");
		return -1;
	}

	item = i_new(struct siglist, 1);
	item->next = *list;
	item->from_spam = from_spam;
	item->sig = i_strdup(signature);

	*list = item;

	return 0;
}

void signature_list_free(struct siglist **list)
{
	struct siglist *item, *next;

	i_assert(list);

	item = *list;

	while (item) {
		next = item->next;
		i_free(item->sig);
		i_free(item);
		item = next;
		if (item)
			next = item->next;
	}
}