}
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);
+ }
+
}
}
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
);
}
}
+/*
+ * 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;
+}
/*
void generate_uuid(char *buf);
char *bmstrcasestr(char *text, char *pattern);
void CtdlMakeTempFileName(char *name, int len);
+char *rfc2047encode(char *line, long length);