-
Notifications
You must be signed in to change notification settings - Fork 29
/
vmodf-encodeurl.c
88 lines (68 loc) · 2.18 KB
/
vmodf-encodeurl.c
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file
*/
#include "lib.h"
#include "str.h"
#include "sieve-common.h"
#include "sieve-code.h"
#include "sieve-ext-variables.h"
#include "ext-enotify-common.h"
/*
* Encodeurl modifier
*/
bool mod_encodeurl_modify(string_t *in, string_t **result);
const struct sieve_variables_modifier_def encodeurl_modifier = {
SIEVE_OBJECT("encodeurl", &encodeurl_operand, 0),
15,
mod_encodeurl_modify
};
/*
* Modifier operand
*/
static const struct sieve_extension_objects ext_enotify_modifiers =
SIEVE_VARIABLES_DEFINE_MODIFIER(encodeurl_modifier);
const struct sieve_operand_def encodeurl_operand = {
.name = "modifier",
.ext_def = &enotify_extension,
.class = &sieve_variables_modifier_operand_class,
.interface = &ext_enotify_modifiers
};
/*
* Modifier implementation
*/
static const char _uri_reserved_lookup[256] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 00
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 10
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, // 20
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, // 30
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 40
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, // 50
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 60
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, // 70
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 80
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 90
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A0
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B0
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C0
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D0
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E0
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // F0
};
bool mod_encodeurl_modify(string_t *in, string_t **result)
{
unsigned int i;
const unsigned char *c;
if ( str_len(in) == 0 ) {
*result = in;
return TRUE;
}
*result = t_str_new(2*str_len(in));
c = str_data(in);
for ( i = 0; i < str_len(in); i++, c++ ) {
if ( (_uri_reserved_lookup[*c] & 0x01) != 0 ) {
str_printfa(*result, "%%%02X", *c);
} else {
str_append_c(*result, *c);
}
}
return TRUE;
}