|
Lines 34-40
Link Here
|
| 34 |
|
34 |
|
| 35 |
/* Decodes headers based on RFC2045 and RFC2047. */ |
35 |
/* Decodes headers based on RFC2045 and RFC2047. */ |
| 36 |
|
36 |
|
| 37 |
void unmime_header(gchar *out, const gchar *str) |
37 |
void unmime_header(gchar *out, const gchar *str, size_t outsize) |
| 38 |
{ |
38 |
{ |
| 39 |
const gchar *p = str; |
39 |
const gchar *p = str; |
| 40 |
gchar *outp = out; |
40 |
gchar *outp = out; |
|
Lines 44-77
Link Here
|
| 44 |
gchar encoding; |
44 |
gchar encoding; |
| 45 |
gchar *conv_str; |
45 |
gchar *conv_str; |
| 46 |
gint len; |
46 |
gint len; |
|
|
47 |
size_t cnt; |
| 47 |
|
48 |
|
| 48 |
while (*p != '\0') { |
49 |
cnt = 0; |
|
|
50 |
while (*p != '\0' && cnt < outsize) { |
| 49 |
gchar *decoded_text = NULL; |
51 |
gchar *decoded_text = NULL; |
| 50 |
|
52 |
|
| 51 |
eword_begin_p = strstr(p, ENCODED_WORD_BEGIN); |
53 |
eword_begin_p = strstr(p, ENCODED_WORD_BEGIN); |
| 52 |
if (!eword_begin_p) { |
54 |
if (!eword_begin_p) { |
| 53 |
strcpy(outp, p); |
55 |
strncpy(outp, p, outsize); |
| 54 |
return; |
56 |
return; |
| 55 |
} |
57 |
} |
| 56 |
encoding_begin_p = strchr(eword_begin_p + 2, '?'); |
58 |
encoding_begin_p = strchr(eword_begin_p + 2, '?'); |
| 57 |
if (!encoding_begin_p) { |
59 |
if (!encoding_begin_p) { |
| 58 |
strcpy(outp, p); |
60 |
strncpy(outp, p, outsize); |
| 59 |
return; |
61 |
return; |
| 60 |
} |
62 |
} |
| 61 |
text_begin_p = strchr(encoding_begin_p + 1, '?'); |
63 |
text_begin_p = strchr(encoding_begin_p + 1, '?'); |
| 62 |
if (!text_begin_p) { |
64 |
if (!text_begin_p) { |
| 63 |
strcpy(outp, p); |
65 |
strncpy(outp, p, outsize); |
| 64 |
return; |
66 |
return; |
| 65 |
} |
67 |
} |
| 66 |
eword_end_p = strstr(text_begin_p + 1, ENCODED_WORD_END); |
68 |
eword_end_p = strstr(text_begin_p + 1, ENCODED_WORD_END); |
| 67 |
if (!eword_end_p) { |
69 |
if (!eword_end_p) { |
| 68 |
strcpy(outp, p); |
70 |
strncpy(outp, p, outsize); |
| 69 |
return; |
71 |
return; |
| 70 |
} |
72 |
} |
| 71 |
|
73 |
|
| 72 |
if (p == str) { |
74 |
if (p == str) { |
|
|
75 |
if((eword_begin_p - p) >= outsize) |
| 76 |
return; |
| 73 |
memcpy(outp, p, eword_begin_p - p); |
77 |
memcpy(outp, p, eword_begin_p - p); |
| 74 |
outp += eword_begin_p - p; |
78 |
outp += eword_begin_p - p; |
|
|
79 |
outsize -= (eword_begin_p - p); |
| 75 |
p = eword_begin_p; |
80 |
p = eword_begin_p; |
| 76 |
} else { |
81 |
} else { |
| 77 |
/* ignore spaces between encoded words */ |
82 |
/* ignore spaces between encoded words */ |
|
Lines 79-86
Link Here
|
| 79 |
|
84 |
|
| 80 |
for (sp = p; sp < eword_begin_p; sp++) { |
85 |
for (sp = p; sp < eword_begin_p; sp++) { |
| 81 |
if (!isspace(*(const guchar *)sp)) { |
86 |
if (!isspace(*(const guchar *)sp)) { |
|
|
87 |
if((eword_begin_p - p) >= outsize) |
| 88 |
return; |
| 82 |
memcpy(outp, p, eword_begin_p - p); |
89 |
memcpy(outp, p, eword_begin_p - p); |
| 83 |
outp += eword_begin_p - p; |
90 |
outp += eword_begin_p - p; |
|
|
91 |
outsize -= (eword_begin_p - p); |
| 84 |
p = eword_begin_p; |
92 |
p = eword_begin_p; |
| 85 |
break; |
93 |
break; |
| 86 |
} |
94 |
} |
|
Lines 106-113
Link Here
|
| 106 |
(decoded_text, text_begin_p + 1, |
114 |
(decoded_text, text_begin_p + 1, |
| 107 |
eword_end_p - (text_begin_p + 1)); |
115 |
eword_end_p - (text_begin_p + 1)); |
| 108 |
} else { |
116 |
} else { |
|
|
117 |
if((eword_end_p + 2 - p) >= outsize) |
| 118 |
return; |
| 109 |
memcpy(outp, p, eword_end_p + 2 - p); |
119 |
memcpy(outp, p, eword_end_p + 2 - p); |
| 110 |
outp += eword_end_p + 2 - p; |
120 |
outp += eword_end_p + 2 - p; |
|
|
121 |
outsize -= (eword_end_p + 2 - p); |
| 111 |
p = eword_end_p + 2; |
122 |
p = eword_end_p + 2; |
| 112 |
continue; |
123 |
continue; |
| 113 |
} |
124 |
} |
|
Lines 116-128
Link Here
|
| 116 |
conv_str = conv_codeset_strdup(decoded_text, charset, NULL); |
127 |
conv_str = conv_codeset_strdup(decoded_text, charset, NULL); |
| 117 |
if (conv_str) { |
128 |
if (conv_str) { |
| 118 |
len = strlen(conv_str); |
129 |
len = strlen(conv_str); |
|
|
130 |
if(len >= outsize) |
| 131 |
{ |
| 132 |
g_free(decoded_text); |
| 133 |
g_free(conv_str); |
| 134 |
return; |
| 135 |
} |
| 119 |
memcpy(outp, conv_str, len); |
136 |
memcpy(outp, conv_str, len); |
| 120 |
g_free(conv_str); |
137 |
g_free(conv_str); |
| 121 |
} else { |
138 |
} else { |
| 122 |
len = strlen(decoded_text); |
139 |
len = strlen(decoded_text); |
|
|
140 |
if(len >= outsize) |
| 141 |
{ |
| 142 |
g_free(decoded_text); |
| 143 |
return; |
| 144 |
} |
| 123 |
conv_localetodisp(outp, len + 1, decoded_text); |
145 |
conv_localetodisp(outp, len + 1, decoded_text); |
| 124 |
} |
146 |
} |
| 125 |
outp += len; |
147 |
outp += len; |
|
|
148 |
outsize -= len; |
| 126 |
|
149 |
|
| 127 |
g_free(decoded_text); |
150 |
g_free(decoded_text); |
| 128 |
|
151 |
|