- 论坛徽章:
- 0
|
- char charset[16] = {0};
- // =?UTF-8?B?5o6i57Si56We5puy6ZqQ6JeP5Zyo6IOM5ZCO55qE56eY5a+G?=
- bool decode_subject(char *subject)
- {
- static char *iconvob = NULL;
- static iconv_t cd = (iconv_t)-1;
- char *p1, *p2;
- size_t insz, outsz;
- if(!strstr(subject, "=?"))
- return true;
- p1 = strchr(subject + 2, '?');
- memcpy(charset, subject + 2, p1 - subject - 2);
- charset[p1 - subject - 2] = 0;
- #ifdef DEBUG
- fprintf(stderr, "charset: %s\n", charset);
- #endif
- p1 += 3;
- p2 = strrchr(p1, '?');
- if(cd == (iconv_t)-1) {
- cd = iconv_open("UTF-8", charset);
- if(cd == (iconv_t)-1) {
- perror("iconv_open()");
- return false;
- }
- }
- if(!iconvob) {
- iconvob = (char *)malloc(256);
- if(!iconvob) {
- fprintf(stderr, "malloc() failed\n");
- return false;
- }
- }
- memset(iconvob, 0, 256);
- insz = p2 - p1;
- if(iconv(cd, &p1, &insz, &iconvob, &outsz) == (size_t)-1) {
- iconv_close(cd);
- perror("iconv()");
- return false;
- }
- strcpy(subject, iconvob);
- return true;
- }
复制代码 参数subject意指email的标题,形如“=?UTF-8?B?5o6i57Si56We5puy6ZqQ6JeP5Zyo6IOM5ZCO55qE56eY5a+G?=”,根据MIME,“=?UTF-8?B?”和结尾的“?=”都是固定的部分。
decode_subject函数,想解析出编码(如UTF-8),并把经iconv转换后的数据(NULL-terminated C string)再存入subject参数所指的空间。
错误是:
Program terminated with signal 6, Aborted.
#0 0xb7719424 in __kernel_vsyscall ()
以上的函数,有什么问题呢?我看不出来。bt看,一定是这个函数的问题,但不单步的话,也定位不了问题 |
|