[patch] on LDAP address book
IKEDA Soji <[email protected]>
| Newsgroups | gmane.mail.sqwebmail |
|---|---|
| Message-ID | <[email protected]> |
Hi Attached patch includes some modification on LDAP address book: o Query will be converted to UTF-8 (most LDAP servers support queries encoded by UTF-8, I think). o New query operators "ends with" (*=) and "contains" (*=*). --- nezumi
sqwebmail-cvs20040213-ldap_utf8-1.0.patch
(application/octet-stream, 3.8 KB)
Index: sqwebmail-cvs20040213/sqwebmail/ldaplist.c
===================================================================
RCS file: /cvsroot/courier/courier/webmail/ldaplist.c,v
retrieving revision 1.11
diff -u -r1.11 ldaplist.c
--- sqwebmail-cvs20040213/sqwebmail/ldaplist.c 16 Nov 2003 03:07:43 -0000 1.11
+++ sqwebmail-cvs20040213/sqwebmail/ldaplist.c 13 Feb 2004 09:35:21 -0000
@@ -253,20 +253,64 @@
const char *attrval=getattrn("value", n);
char *buf;
+char *p, *q;
+size_t i;
+
+#if HAVE_SQWEBMAIL_UNICODE
+const char *uattrval=NULL;
+const struct unicode_info *uoptr = unicode_find(sqwebmail_content_charset);
+#endif
if (*attrname == 0 || *attrop == 0 || *attrval == 0) return (0);
- buf=malloc(strlen(attrname)+strlen(attrop)+strlen(attrval)+40);
+#if HAVE_SQWEBMAIL_UNICODE
+ if (uoptr && (uattrval=unicode_ctoutf8(uoptr, attrval, NULL)))
+ attrval = uattrval;
+#endif
- if (!buf) return (0);
+ /* compute length of filter string */
+ for (p=attrval, i=0; *p; p++, i++)
+ if (*p == '*' || *p == '(' || *p == ')' || *p == '\\')
+ i+=2;
+ buf=malloc(strlen(attrname)+strlen(attrop)+i+sizeof("()")+1);
+ if (!buf)
+ {
+#if HAVE_SQWEBMAIL_UNICODE
+ if (uattrval)
+ free(uattrval);
+#endif
+ return (0);
+ }
strcpy(buf, "(");
strcat(buf, attrname);
- strcat(buf, strcmp(attrop, "=*") == 0 ? "=":attrop);
- strcat(buf, attrval);
- if (strcmp(attrop, "=*") == 0)
+
+ if (strcmp(attrop, "=*") == 0 || strcmp(attrop, "*=") == 0
+ || strcmp(attrop, "*=*") == 0)
+ strcat(buf, "=");
+ else
+ strcat(buf, attrop);
+ if (strcmp(attrop, "*=") == 0 || strcmp(attrop, "*=*") == 0)
+ strcat(buf, "*");
+
+ for (p=attrval, q=buf+strlen(buf); *p; p++, q++)
+ if (*p == '*' || *p == '(' || *p == ')' || *p == '\\')
+ {
+ sprintf(q, "\\%02X", (unsigned char)(*p));
+ q+=2;
+ }
+ else
+ *q = *p;
+ *q = 0;
+
+ if (strcmp(attrop, "=*") == 0 || strcmp(attrop, "*=*") == 0)
strcat(buf, "*");
strcat(buf, ")");
+
+#if HAVE_SQWEBMAIL_UNICODE
+ if (uattrval)
+ free(uattrval);
+#endif
return (buf);
}
Index: sqwebmail-cvs20040213/sqwebmail/html/en-us/ldaplist.html
===================================================================
RCS file: /cvsroot/courier/courier/webmail/html/en-us/ldaplist.html,v
retrieving revision 1.22
diff -u -r1.22 ldaplist.html
--- sqwebmail-cvs20040213/sqwebmail/html/en-us/ldaplist.html 1 Nov 2003 04:05:03 -0000 1.22
+++ sqwebmail-cvs20040213/sqwebmail/html/en-us/ldaplist.html 13 Feb 2004 09:35:21 -0000
@@ -110,6 +110,8 @@
<option value="=">is </option>
<option value="=*" selected="selected">starts
with </option>
+ <option value="*=">ends with </option>
+ <option value="*=*">contains </option>
<option value="~=">like </option>
</select>
</td>
@@ -133,6 +135,8 @@
<option value="" selected="selected"></option>
<option value="=">is </option>
<option value="=*">starts with </option>
+ <option value="*=">ends with </option>
+ <option value="*=*">contains </option>
<option value="~=">like </option>
</select>
</td>
@@ -156,6 +160,8 @@
<option value="" selected="selected"></option>
<option value="=">is </option>
<option value="=*">starts with </option>
+ <option value="*=">ends with </option>
+ <option value="*=*">contains </option>
<option value="~=">like </option>
</select>
</td>