103{
104 static const char hex[] = "0123456789ABCDEF";
105 char *s0 = str;
106
107 memcpy(str, "=?", 2);
108 str += 2;
109 memcpy(str, tocode, strlen(tocode));
110 str += strlen(tocode);
111 memcpy(str, "?Q?", 3);
112 str += 3;
113 while (buflen--)
114 {
115 unsigned char c = *buf++;
116 if (c == ' ')
117 *str++ = '_';
118 else if ((c >= 0x7f) || (c < 0x20) || (c ==
'_') || strchr(
MimeSpecials, c))
119 {
120 *str++ = '=';
121 *str++ = hex[(c & 0xf0) >> 4];
122 *str++ = hex[c & 0x0f];
123 }
124 else
125 *str++ = c;
126 }
127 memcpy(str, "?=", 2);
128 str += 2;
129 return str - s0;
130}
const char MimeSpecials[]
Characters that need special treatment in MIME.