]> code.citadel.org Git - citadel.git/blobdiff - citadel/internet_addressing.c
Implemented RFC2919, the 'List-ID' field for mailing
[citadel.git] / citadel / internet_addressing.c
index 53924ba809785c049db3cbe91dd5a4e961da2dee..8661d70fa12cfae5f734e1affdb24dfd02d9530d 100644 (file)
@@ -77,11 +77,10 @@ iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
        return(ic);
 }
 
-
-
-inline char *FindNextEnd (char *bptr)
+#if 0
+/* This is the non-define version in case of s.b. needing to debug */
+inline void FindNextEnd (char *bptr, char *end)
 {
-       char * end;
        /* Find the next ?Q? */
        end = strchr(bptr + 2, '?');
        if (end == NULL) return NULL;
@@ -93,7 +92,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, "?="); \
+       } \
 }
 
 /*
@@ -157,13 +165,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 +211,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);
@@ -280,6 +289,9 @@ void utf8ify_rfc822_string(char *buf) {
                 */
                ++passes;
                if (passes > 20) return;
+
+               start = strstr(buf, "=?");
+               FindNextEnd((start != NULL)? start : buf, end);
        }
 
 }
@@ -326,11 +338,11 @@ int CtdlHostAlias(char *fqdn) {
                        return(hostalias_localhost);
 
                if ( (!strcasecmp(type, "directory"))
-                  && (!strcasecmp(&fqdn[strlen(fqdn)-strlen(host)], host)))
+                  && (!strcasecmp(fqdn, host)))
                        return(hostalias_directory);
 
                if ( (!strcasecmp(type, "masqdomain"))
-                  && (!strcasecmp(&fqdn[strlen(fqdn)-strlen(host)], host)))
+                  && (!strcasecmp(fqdn, host)))
                        return(hostalias_masq);
 
        }
@@ -588,6 +600,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);
@@ -998,7 +1016,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) ) {