]> code.citadel.org Git - citadel.git/blobdiff - citadel/internet_addressing.c
* Found and removed a large section of the old LDAP connector.
[citadel.git] / citadel / internet_addressing.c
index 0ae938c7c4497ef651553f11f185a965c016eb6f..caca0806603056ada966702e8931edff4ce4613d 100644 (file)
 #ifdef HAVE_ICONV
 #include <iconv.h>
 
-/*
- * Wrapper around iconv_open()
- * Our version adds aliases for non-standard Microsoft charsets
- * such as 'MS950', aliasing them to names like 'CP950'
- *
- * tocode      Target encoding
- * fromcode    Source encoding
- */
-iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
+#if 0
+/* This is the non-define version in case of s.b. needing to debug */
+inline void FindNextEnd (char *bptr, char *end)
 {
-       iconv_t ic = (iconv_t)(-1) ;
-       ic = iconv_open(tocode, fromcode);
-       if (ic == (iconv_t)(-1) ) {
-               char alias_fromcode[64];
-               if ( (strlen(fromcode) == 5) && (!strncasecmp(fromcode, "MS", 2)) ) {
-                       safestrncpy(alias_fromcode, fromcode, sizeof alias_fromcode);
-                       alias_fromcode[0] = 'C';
-                       alias_fromcode[1] = 'P';
-                       ic = iconv_open(tocode, alias_fromcode);
-               }
-       }
-       return(ic);
-}
-
-
-
-inline char *FindNextEnd (char *bptr)
-{
-       char * end;
        /* Find the next ?Q? */
        end = strchr(bptr + 2, '?');
        if (end == NULL) return NULL;
@@ -93,7 +68,16 @@ inline char *FindNextEnd (char *bptr)
        else
                /* sort of half valid encoding, try to find an end. */
                end = strstr(bptr, "?=");
-       return end;
+}
+#endif
+
+#define FindNextEnd(bptr, end) { \
+       end = strchr(bptr + 2, '?'); \
+       if (end != NULL) { \
+               if (((*(end + 1) == 'B') || (*(end + 1) == 'Q')) && (*(end + 2) == '?')) { \
+                       end = strstr(end + 3, "?="); \
+               } else end = strstr(bptr, "?="); \
+       } \
 }
 
 /*
@@ -133,7 +117,7 @@ void utf8ify_rfc822_string(char *buf) {
        if (illegal_non_rfc2047_encoding) {
                const char *default_header_charset = "iso-8859-1";
                if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
-                       ic = ctdl_iconv_open("UTF-8", default_header_charset);
+                       ctdl_iconv_open("UTF-8", default_header_charset, &ic);
                        if (ic != (iconv_t)(-1) ) {
                                ibuf = malloc(1024);
                                isav = ibuf;
@@ -157,13 +141,13 @@ void utf8ify_rfc822_string(char *buf) {
        len = strlen(buf);
        start = strstr(buf, "=?");
        if (start != NULL) 
-               end = FindNextEnd (start);
+               FindNextEnd (start, end);
 
        while ((start != NULL) && (end != NULL))
        {
                next = strstr(end, "=?");
                if (next != NULL)
-                       nextend = FindNextEnd(next);
+                       FindNextEnd(next, nextend);
                if (nextend == NULL)
                        next = NULL;
 
@@ -203,8 +187,9 @@ void utf8ify_rfc822_string(char *buf) {
        /* Now we handle foreign character sets properly encoded
         * in RFC2047 format.
         */
-       while (start=strstr(buf, "=?"), end=FindNextEnd((start != NULL)? start : buf),
-               ((start != NULL) && (end != NULL) && (end > start)) )
+       start = strstr(buf, "=?");
+       FindNextEnd((start != NULL)? start : buf, end);
+       while (start != NULL && end != NULL && end > start)
        {
                extract_token(charset, start, 1, '?', sizeof charset);
                extract_token(encoding, start, 2, '?', sizeof encoding);
@@ -234,7 +219,7 @@ void utf8ify_rfc822_string(char *buf) {
                        ibuflen = strlen(istr);
                }
 
-               ic = ctdl_iconv_open("UTF-8", charset);
+               ctdl_iconv_open("UTF-8", charset, &ic);
                if (ic != (iconv_t)(-1) ) {
                        obuflen = 1024;
                        obuf = (char *) malloc(obuflen);
@@ -280,6 +265,9 @@ void utf8ify_rfc822_string(char *buf) {
                 */
                ++passes;
                if (passes > 20) return;
+
+               start = strstr(buf, "=?");
+               FindNextEnd((start != NULL)? start : buf, end);
        }
 
 }
@@ -307,6 +295,7 @@ int CtdlHostAlias(char *fqdn) {
        int i;
        char buf[256];
        char host[256], type[256];
+       int found = 0;
 
        if (fqdn == NULL) return(hostalias_nomatch);
        if (IsEmptyStr(fqdn)) return(hostalias_nomatch);
@@ -321,18 +310,23 @@ int CtdlHostAlias(char *fqdn) {
                extract_token(host, buf, 0, '|', sizeof host);
                extract_token(type, buf, 1, '|', sizeof type);
 
-               if ( (!strcasecmp(type, "localhost"))
-                  && (!strcasecmp(fqdn, host)))
-                       return(hostalias_localhost);
+               found = 0;
 
-               if ( (!strcasecmp(type, "directory"))
-                  && (!strcasecmp(fqdn, host)))
-                       return(hostalias_directory);
+               /* Process these in a specific order, in case there are multiple matches.
+                * We want directory to override masq, for example.
+                */
 
-               if ( (!strcasecmp(type, "masqdomain"))
-                  && (!strcasecmp(fqdn, host)))
-                       return(hostalias_masq);
+               if ( (!strcasecmp(type, "masqdomain")) && (!strcasecmp(fqdn, host))) {
+                       found = hostalias_masq;
+               }
+               if ( (!strcasecmp(type, "localhost")) && (!strcasecmp(fqdn, host))) {
+                       found = hostalias_localhost;
+               }
+               if ( (!strcasecmp(type, "directory")) && (!strcasecmp(fqdn, host))) {
+                       found = hostalias_directory;
+               }
 
+               if (found) return(found);
        }
 
        return(hostalias_nomatch);
@@ -588,6 +582,12 @@ int convert_field(struct CtdlMessage *msg, int beg, int end) {
                processed = 1;
        }
 
+       else if (!strcasecmp(key, "List-ID")) {
+               if (msg->cm_fields['L'] == NULL)
+                       msg->cm_fields['L'] = strdup(value);
+               processed = 1;
+       }
+
        else if (!strcasecmp(key, "To")) {
                if (msg->cm_fields['R'] == NULL)
                        msg->cm_fields['R'] = strdup(value);
@@ -898,14 +898,10 @@ void CtdlDirectoryInit(void) {
 void CtdlDirectoryAddUser(char *internet_addr, char *citadel_addr) {
        char key[SIZ];
 
-       CtdlLogPrintf(CTDL_DEBUG, "Dir: %s --> %s\n",
-               internet_addr, citadel_addr);
        if (IsDirectory(internet_addr, 0) == 0) return;
-
+       CtdlLogPrintf(CTDL_DEBUG, "Create directory entry: %s --> %s\n", internet_addr, citadel_addr);
        directory_key(key, internet_addr);
-
-       cdb_store(CDB_DIRECTORY, key, strlen(key),
-               citadel_addr, strlen(citadel_addr)+1 );
+       cdb_store(CDB_DIRECTORY, key, strlen(key), citadel_addr, strlen(citadel_addr)+1 );
 }
 
 
@@ -918,6 +914,7 @@ void CtdlDirectoryAddUser(char *internet_addr, char *citadel_addr) {
 void CtdlDirectoryDelUser(char *internet_addr, char *citadel_addr) {
        char key[SIZ];
 
+       CtdlLogPrintf(CTDL_DEBUG, "Delete directory entry: %s --> %s\n", internet_addr, citadel_addr);
        directory_key(key, internet_addr);
        cdb_delete(CDB_DIRECTORY, key, strlen(key) );
 }
@@ -998,7 +995,8 @@ char *harvest_collected_addresses(struct CtdlMessage *msg) {
                if (msg->cm_fields[field] != NULL) {
                        for (j=0; j<num_tokens(msg->cm_fields[field], ','); ++j) {
                                extract_token(addr, msg->cm_fields[field], j, ',', sizeof addr);
-                               utf8ify_rfc822_string(addr);
+                               if (strstr(addr, "=?") != NULL)
+                                       utf8ify_rfc822_string(addr);
                                process_rfc822_addr(addr, user, node, name);
                                h = CtdlHostAlias(node);
                                if ( (h != hostalias_localhost) && (h != hostalias_directory) ) {