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

Finished encoded-character extension.

parent 151cb427
No related branches found
No related tags found
No related merge requests found
...@@ -121,7 +121,7 @@ Extensions and their implementation status: ...@@ -121,7 +121,7 @@ Extensions and their implementation status:
fileinto: full fileinto: full
reject: full reject: full
envelope: full envelope: full
encoded-character: skeleton encoded-character: full
Other RFCs/drafts: Other RFCs/drafts:
subaddress: full subaddress: full
...@@ -193,10 +193,9 @@ TODO ...@@ -193,10 +193,9 @@ TODO
---- ----
Current: Current:
* Implement encoded-character extension * Implement variables extension.
Next (in order of descending priority/precedence): Next (in order of descending priority/precedence):
* Implement variables extension.
* Finish implementing all extensions supported by cmusieve, except notify. * Finish implementing all extensions supported by cmusieve, except notify.
* Limit the maximum number of errors. * Limit the maximum number of errors.
* Verify outgoing mail addresses * Verify outgoing mail addresses
......
require "encoded-character";
require "fileinto";
fileinto "INBOX.${unicode:200000}";
fileinto "INBOX.${Unicode:DF01}";
...@@ -4,6 +4,8 @@ require "reject"; ...@@ -4,6 +4,8 @@ require "reject";
if address :contains "from" "idiot.com" { if address :contains "from" "idiot.com" {
reject "You are an ${hex: 69 64 69 6F 74}."; reject "You are an ${hex: 69 64 69 6F 74}.";
} else { } elsif header :contains "subject" "idiot" {
fileinto "INBOX.${hex: 49 44 49 4F 54}"; fileinto "INBOX.${hex: 49 44 49 4F 54}";
} else {
fileinto "INBOX.${unicode: 0052 00e6}vh${unicode: 00f8 006c}";
} }
...@@ -3,12 +3,13 @@ ...@@ -3,12 +3,13 @@
* *
* Authors: Stephan Bosch * Authors: Stephan Bosch
* Specification: draft-ietf-sieve-3028bis-13.txt * Specification: draft-ietf-sieve-3028bis-13.txt
* Implementation: skeleton * Implementation: full
* Status: under development * Status: experimental, largely untested
* *
*/ */
#include "lib.h" #include "lib.h"
#include "unichar.h"
#include "sieve-extensions.h" #include "sieve-extensions.h"
#include "sieve-commands.h" #include "sieve-commands.h"
...@@ -100,7 +101,7 @@ static bool _parse_hexint ...@@ -100,7 +101,7 @@ static bool _parse_hexint
return ( digit > 0 ); return ( digit > 0 );
} }
static bool _decode_hex static int _decode_hex
(const char **in, const char *inend, string_t *result) (const char **in, const char *inend, string_t *result)
{ {
int values = 0; int values = 0;
...@@ -116,11 +117,12 @@ static bool _decode_hex ...@@ -116,11 +117,12 @@ static bool _decode_hex
values++; values++;
} }
return ( values > 0 ); return ( values > 0 ? 1 : 0 );
} }
static bool _decode_unicode static int _decode_unicode
(const char **in, const char *inend, string_t *result) (struct sieve_validator *validator, struct sieve_command_context *cmd,
const char **in, const char *inend, string_t *result)
{ {
int values = 0; int values = 0;
...@@ -130,19 +132,28 @@ static bool _decode_unicode ...@@ -130,19 +132,28 @@ static bool _decode_unicode
if ( !_skip_whitespace(in, inend) ) return FALSE; if ( !_skip_whitespace(in, inend) ) return FALSE;
if ( !_parse_hexint(in, inend, 6, &unicode_hex) ) break; if ( !_parse_hexint(in, inend, 6, &unicode_hex) ) break;
/* FIXME: unicode is unimplemented */ if ( (unicode_hex <= 0xD7FF) ||
str_append(result, ">>unicode unimplemented<<"); (unicode_hex >= 0xE000 && unicode_hex <= 0x10FFFF) )
uni_ucs4_to_utf8_c((unichar_t) unicode_hex, result);
else {
sieve_command_validate_error(validator, cmd,
"invalid unicode character 0x%08x in encoded character substitution",
unicode_hex);
return -1;
}
values++; values++;
} }
return ( values > 0 ); return ( values > 0 ? 1 : 0 );
} }
bool arg_encoded_string_validate bool arg_encoded_string_validate
(struct sieve_validator *validator ATTR_UNUSED, struct sieve_ast_argument **arg, (struct sieve_validator *validator, struct sieve_ast_argument **arg,
struct sieve_command_context *cmd) struct sieve_command_context *cmd)
{ {
bool result = TRUE;
int ret;
enum { ST_NONE, ST_OPEN, ST_TYPE, ST_CLOSE } enum { ST_NONE, ST_OPEN, ST_TYPE, ST_CLOSE }
state = ST_NONE; state = ST_NONE;
string_t *str = sieve_ast_argument_str(*arg); string_t *str = sieve_ast_argument_str(*arg);
...@@ -156,7 +167,7 @@ bool arg_encoded_string_validate ...@@ -156,7 +167,7 @@ bool arg_encoded_string_validate
p = strval; p = strval;
strstart = p; strstart = p;
while ( p < strend ) { while ( result && p < strend ) {
switch ( state ) { switch ( state ) {
case ST_NONE: case ST_NONE:
if ( *p == '$' ) { if ( *p == '$' ) {
...@@ -186,12 +197,18 @@ bool arg_encoded_string_validate ...@@ -186,12 +197,18 @@ bool arg_encoded_string_validate
str_truncate(tmpstr, 0); str_truncate(tmpstr, 0);
if ( strncasecmp(mark, "hex", p - mark) == 0 ) { if ( strncasecmp(mark, "hex", p - mark) == 0 ) {
p++; p++;
if ( !_decode_hex(&p, strend, tmpstr) ) ret = _decode_hex(&p, strend, tmpstr);
if ( ret <= 0 ) {
state = ST_NONE; state = ST_NONE;
if ( ret < 0 ) result = FALSE;
}
} else if ( strncasecmp(mark, "unicode", p - mark) == 0 ) { } else if ( strncasecmp(mark, "unicode", p - mark) == 0 ) {
p++; p++;
if ( !_decode_unicode(&p, strend, tmpstr) ) ret = _decode_unicode(validator, cmd, &p, strend, tmpstr);
if ( ret <= 0 ) {
state = ST_NONE; state = ST_NONE;
if ( ret < 0 ) result = FALSE;
}
} else { } else {
p++; p++;
state = ST_NONE; state = ST_NONE;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ------------------ * ------------------
* *
* Authors: Stephan Bosch * Authors: Stephan Bosch
* Specification: RFC3028 * Specification: RFC3028, draft-ietf-sieve-3028bis-13.txt
* Implementation: full * Implementation: full
* Status: experimental, largely untested * Status: experimental, largely untested
* *
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ------------------ * ------------------
* *
* Authors: Stephan Bosch * Authors: Stephan Bosch
* Specification: RFC3028 * Specification: RFC3028, draft-ietf-sieve-3028bis-13.txt
* Implementation: full * Implementation: full
* Status: experimental, largely untested * Status: experimental, largely untested
* *
......
...@@ -65,8 +65,7 @@ static struct istream *create_raw_stream(int fd) ...@@ -65,8 +65,7 @@ static struct istream *create_raw_stream(int fd)
input2 = input; input2 = input;
i_stream_ref(input2); i_stream_ref(input2);
} else { } else {
input2 = i_stream_create_limit(input, input->v_offset, input2 = i_stream_create_limit(input, (uoff_t)-1);
(uoff_t)-1);
} }
i_stream_unref(&input); i_stream_unref(&input);
......
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.