]> code.citadel.org Git - citadel.git/commitdiff
* encode message subjects in rfc2047 style if they contain non ascii
authorWilfried Göesgens <willi@citadel.org>
Sat, 30 Dec 2006 18:12:43 +0000 (18:12 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 30 Dec 2006 18:12:43 +0000 (18:12 +0000)
* add content type utf-8 to our calendaring mails

citadel/msgbase.c
citadel/serv_calendar.c
citadel/tools.c
citadel/tools.h

index a1a51e6e817b2e68f99ba5598a4442c1e3350b97..03260b31f1603c22535d33d81a5664b3242d1675 100644 (file)
@@ -2933,9 +2933,24 @@ struct CtdlMessage *CtdlMakeMessage(
        }
 
        if (subject != NULL) {
+               long length;
                striplt(subject);
-               if (strlen(subject) > 0) {
-                       msg->cm_fields['U'] = strdup(subject);
+               length = strlen(subject);
+               if (length > 0) {
+                       long i;
+                       long IsAscii;
+                       IsAscii = -1;
+                       i = 0;
+                       while ((subject[i] != '\0') &&
+                              (IsAscii = isascii(subject[i]) != 0 ))
+                               i++;
+                       if (IsAscii != 0)
+                               msg->cm_fields['U'] = strdup(subject);
+                       else /* ok, we've got utf8 in the string. */
+                       {
+                               msg->cm_fields['U'] = rfc2047encode(subject, length);
+                       }
+
                }
        }
 
index cbb3f84c44af6b378b5bbce5c3a29bcc6bed9ca9..41e5990db8dca4ee8905f978eb86e017200d4f1b 100644 (file)
@@ -310,7 +310,7 @@ void ical_send_a_reply(icalcomponent *request, char *action) {
        reply_message_text = malloc(strlen(serialized_reply) + SIZ);
        if (reply_message_text != NULL) {
                sprintf(reply_message_text,
-                       "Content-type: text/calendar\r\n\r\n%s\r\n",
+                       "Content-type: text/calendar charset=\"utf-8\"\r\n\r\n%s\r\n",
                        serialized_reply
                );
 
index e8a1abc9798e04e57db37accbd21a087468dc4e0..4927e18d4d72a1c87d089f22b385f39034771c4b 100644 (file)
@@ -328,6 +328,34 @@ int CtdlDecodeBase64(char *dest, const char *source, size_t length)
     }
 }
 
+/*
+ * if we send out non ascii subjects, we encode it this way.
+ */
+char *rfc2047encode(char *line, long length)
+{
+       char *AlreadyEncoded;
+       char *result;
+       long end;
+#define UTF8_HEADER "=?UTF-8?B?"
+
+       /* check if we're already done */
+       AlreadyEncoded = strstr(line, "=?");
+       if ((AlreadyEncoded != NULL) &&
+           ((strstr(AlreadyEncoded, "?B?") != NULL)||
+            (strstr(AlreadyEncoded, "?Q?") != NULL)))
+       {
+               return strdup(line);
+       }
+
+       result = (char*) malloc(strlen(UTF8_HEADER) + 4 + length * 2);
+       strncpy (result, UTF8_HEADER, strlen (UTF8_HEADER));
+       CtdlEncodeBase64(result + strlen(UTF8_HEADER), line, length);
+       end = strlen (result);
+        result[end]='?';
+       result[end+1]='=';
+       result[end+2]='\0';
+       return result;
+}
 
 
 /*
index 01c196b2b3f36ad9d0d8f45e5757c2ecde2884dd..c1666f8c6ef92009238f3a28c00f0cc36e43e9e1 100644 (file)
@@ -33,3 +33,4 @@ char *ascmonths[12];
 void generate_uuid(char *buf);
 char *bmstrcasestr(char *text, char *pattern);
 void CtdlMakeTempFileName(char *name, int len);
+char *rfc2047encode(char *line, long length);