dovecot-1.1: Added %T = trim modifier.

dovecot at dovecot.org dovecot at dovecot.org
Fri May 16 12:10:08 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/15ddb7513e2d
changeset: 7523:15ddb7513e2d
user:      Timo Sirainen <tss at iki.fi>
date:      Fri May 16 12:09:44 2008 +0300
description:
Added %T = trim modifier.

diffstat:

1 file changed, 17 insertions(+), 2 deletions(-)
src/lib/var-expand.c |   19 +++++++++++++++++--

diffs (57 lines):

diff -r abb4d2011b52 -r 15ddb7513e2d src/lib/var-expand.c
--- a/src/lib/var-expand.c	Thu May 15 09:54:03 2008 +0300
+++ b/src/lib/var-expand.c	Fri May 16 12:09:44 2008 +0300
@@ -10,6 +10,7 @@
 #include "var-expand.h"
 
 #include <stdlib.h>
+#include <ctype.h>
 
 struct var_expand_context {
 	int offset;
@@ -81,7 +82,8 @@ static const char *m_str_hash(const char
 	return str_c(hash);
 }
 
-static const char *m_str_md5(const char *str, struct var_expand_context *ctx ATTR_UNUSED)
+static const char *
+m_str_md5(const char *str, struct var_expand_context *ctx ATTR_UNUSED)
 {
 	unsigned char digest[16];
 
@@ -90,7 +92,8 @@ static const char *m_str_md5(const char 
 	return binary_to_hex(digest, sizeof(digest));
 }
 
-static const char *m_str_ldap_dn(const char *str, struct var_expand_context *ctx ATTR_UNUSED)
+static const char *
+m_str_ldap_dn(const char *str, struct var_expand_context *ctx ATTR_UNUSED)
 {
 	string_t *ret = t_str_new(256);
 
@@ -103,6 +106,17 @@ static const char *m_str_ldap_dn(const c
 	}
 
 	return str_free_without_data(&ret);
+}
+
+static const char *
+m_str_trim(const char *str, struct var_expand_context *ctx ATTR_UNUSED)
+{
+	unsigned int len;
+
+	len = strlen(str);
+	while (len > 0 && i_isspace(str[len-1]))
+		len--;
+	return t_strndup(str, len);
 }
 
 #define MAX_MODIFIER_COUNT 10
@@ -115,6 +129,7 @@ static const struct var_expand_modifier 
 	{ 'H', m_str_hash },
 	{ 'M', m_str_md5 },
 	{ 'D', m_str_ldap_dn },
+	{ 'T', m_str_trim },
 	{ '\0', NULL }
 };
 


More information about the dovecot-cvs mailing list