dovecot-2.2: lib-fts: Removed unnecessary code from fts-address-...

dovecot at dovecot.org dovecot at dovecot.org
Sat May 9 09:34:40 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/b9f85e125639
changeset: 18566:b9f85e125639
user:      Timo Sirainen <tss at iki.fi>
date:      Sat May 09 12:32:46 2015 +0300
description:
lib-fts: Removed unnecessary code from fts-address-tokenizer.
chars_after_at() was only used to check if local-part was empty, but it was
checked at a state where it never could have been empty.

diffstat:

 src/lib-fts/fts-tokenizer-address.c |  21 ++-------------------
 src/lib-fts/test-fts-tokenizer.c    |  16 ++++++++--------
 2 files changed, 10 insertions(+), 27 deletions(-)

diffs (110 lines):

diff -r adf9eb277499 -r b9f85e125639 src/lib-fts/fts-tokenizer-address.c
--- a/src/lib-fts/fts-tokenizer-address.c	Sat May 09 12:01:42 2015 +0300
+++ b/src/lib-fts/fts-tokenizer-address.c	Sat May 09 12:32:46 2015 +0300
@@ -199,22 +199,6 @@
 	return EMAIL_ADDRESS_PARSER_STATE_NONE;
 }
 
-/* TODO:  might be  nice  if error  was  -1, but  that  requires a  _r
-   param */
-static size_t chars_after_at(struct email_address_fts_tokenizer *tok)
-{
-
-	size_t len = 0;
-	const unsigned char *at;
-	const unsigned char *str;
-
-	str = buffer_get_data(tok->last_word, &len);
-	at = memchr(str, '@', len);
-	if (at == NULL)
-		return 0;
-	return at - str;
-}
-
 /* TODO:
  - allow address literals
  - reject "@..."
@@ -234,7 +218,7 @@
 	}
 	 /* A complete domain name */
 	if ((pos > 1 && pos < size) || /* non-atext after atext in this data*/
-	    (pos < size && chars_after_at(tok) > 0)) { /* non-atext after previous atext */
+	    pos < size) { /* non-atext after previous atext */
 		str_append_n(tok->last_word, data, pos);
 		*skip_r = pos;
 		return EMAIL_ADDRESS_PARSER_STATE_COMPLETE;
@@ -281,8 +265,7 @@
 		if (!tok->no_parent && str_len(tok->parent_data) > 0)
 			return fts_tokenizer_address_parent_data(tok, token_r);
 
-		if (tok->state == EMAIL_ADDRESS_PARSER_STATE_DOMAIN
-		    && chars_after_at(tok) > 0)
+		if (tok->state == EMAIL_ADDRESS_PARSER_STATE_DOMAIN)
 			return fts_tokenizer_address_current_token(tok, token_r);
 	}
 
diff -r adf9eb277499 -r b9f85e125639 src/lib-fts/test-fts-tokenizer.c
--- a/src/lib-fts/test-fts-tokenizer.c	Sat May 09 12:01:42 2015 +0300
+++ b/src/lib-fts/test-fts-tokenizer.c	Sat May 09 12:32:46 2015 +0300
@@ -308,7 +308,7 @@
 static void test_fts_tokenizer_char_address_only(void)
 {
 	static const unsigned char input[] =
-		"abc at example.com, "
+		"@invalid  abc at example.com, "
 		"Bar Baz <bar at example.org>, "
 		"foo at domain";
 	static const char *const expected_output[] = {
@@ -346,7 +346,7 @@
 static void test_fts_tokenizer_rand_address_only(void)
 {
 	static const unsigned char input[] =
-		"Abc Dfg <abc.dfg at example.com>, "
+		"@invalid  Abc Dfg <abc.dfg at example.com>, "
 		"Foo Bar (comment)foo.bar at host.example.org foo ";
 
 	static const char *const expected_output[] = {
@@ -388,11 +388,11 @@
 static void test_fts_tokenizer_address_char(void)
 {
 	static const unsigned char input[] =
-		"abc at example.com, "
+		"@invalid  abc at example.com, "
 		"Bar Baz <bar at example.org>, "
 		"foo at domain";
 	static const char *const expected_output[] = {
-		"abc", "example", "com", "abc at example.com", "Bar", "Baz",
+		"invalid", "abc", "example", "com", "abc at example.com", "Bar", "Baz",
 		"bar", "example", "org", "bar at example.org",
 		"foo", "domain", "foo at domain", NULL
 	};
@@ -430,13 +430,13 @@
 static void test_fts_tokenizer_address_line(void)
 {
 	static const char *const input[] = {
-		"abc at example.com, ",
+		"@invalid  abc at example.com, ",
 		"Bar Baz <bar at example.org>, ",
 		"foo at domain, ",
 		"foo at domain Bar Baz <bar at example.org>, "
 	};
 	static const char *const expected_output[] = {
-		"abc", "example", "com", "abc at example.com", "Bar", "Baz",
+		"invalid", "abc", "example", "com", "abc at example.com", "Bar", "Baz",
 		"bar", "example", "org", "bar at example.org",
 		"foo", "domain", "foo at domain",
 		"foo", "domain", "foo at domain", "Bar", "Baz",
@@ -477,11 +477,11 @@
 static void test_fts_tokenizer_address_rand(void)
 {
 	static const unsigned char input[] =
-		"abc at example.com, "
+		"@invalid  abc at example.com, "
 		"Bar Baz <bar at example.org>, "
 		"foo at domain";
 	static const char *const expected_output[] = {
-		"abc", "example", "com", "abc at example.com", "Bar", "Baz",
+		"invalid", "abc", "example", "com", "abc at example.com", "Bar", "Baz",
 		"bar", "example", "org", "bar at example.org",
 		"foo", "domain", "foo at domain", NULL
 	};


More information about the dovecot-cvs mailing list