|
Lines 28-40
Link Here
|
| 28 |
#include "codeconv.h" |
28 |
#include "codeconv.h" |
| 29 |
#include "base64.h" |
29 |
#include "base64.h" |
| 30 |
#include "quoted-printable.h" |
30 |
#include "quoted-printable.h" |
|
|
31 |
#include "utils.h" |
| 31 |
|
32 |
|
| 32 |
#define ENCODED_WORD_BEGIN "=?" |
33 |
#define ENCODED_WORD_BEGIN "=?" |
| 33 |
#define ENCODED_WORD_END "?=" |
34 |
#define ENCODED_WORD_END "?=" |
| 34 |
|
35 |
|
| 35 |
/* Decodes headers based on RFC2045 and RFC2047. */ |
36 |
/* Decodes headers based on RFC2045 and RFC2047. */ |
| 36 |
|
37 |
|
| 37 |
void unmime_header(gchar *out, const gchar *str) |
38 |
void unmime_header(gchar *out, gint outlen, const gchar *str) |
| 38 |
{ |
39 |
{ |
| 39 |
const gchar *p = str; |
40 |
const gchar *p = str; |
| 40 |
gchar *outp = out; |
41 |
gchar *outp = out; |
|
Lines 50-77
Link Here
|
| 50 |
|
51 |
|
| 51 |
eword_begin_p = strstr(p, ENCODED_WORD_BEGIN); |
52 |
eword_begin_p = strstr(p, ENCODED_WORD_BEGIN); |
| 52 |
if (!eword_begin_p) { |
53 |
if (!eword_begin_p) { |
| 53 |
strcpy(outp, p); |
54 |
strncpy2(outp, p, outlen); |
| 54 |
return; |
55 |
return; |
| 55 |
} |
56 |
} |
| 56 |
encoding_begin_p = strchr(eword_begin_p + 2, '?'); |
57 |
encoding_begin_p = strchr(eword_begin_p + 2, '?'); |
| 57 |
if (!encoding_begin_p) { |
58 |
if (!encoding_begin_p) { |
| 58 |
strcpy(outp, p); |
59 |
strncpy2(outp, p, outlen); |
| 59 |
return; |
60 |
return; |
| 60 |
} |
61 |
} |
| 61 |
text_begin_p = strchr(encoding_begin_p + 1, '?'); |
62 |
text_begin_p = strchr(encoding_begin_p + 1, '?'); |
| 62 |
if (!text_begin_p) { |
63 |
if (!text_begin_p) { |
| 63 |
strcpy(outp, p); |
64 |
strncpy2(outp, p, outlen); |
| 64 |
return; |
65 |
return; |
| 65 |
} |
66 |
} |
| 66 |
eword_end_p = strstr(text_begin_p + 1, ENCODED_WORD_END); |
67 |
eword_end_p = strstr(text_begin_p + 1, ENCODED_WORD_END); |
| 67 |
if (!eword_end_p) { |
68 |
if (!eword_end_p) { |
| 68 |
strcpy(outp, p); |
69 |
strncpy2(outp, p, outlen); |
| 69 |
return; |
70 |
return; |
| 70 |
} |
71 |
} |
| 71 |
|
72 |
|
| 72 |
if (p == str) { |
73 |
if (p == str) { |
|
|
74 |
if (eword_begin_p - p > outlen - 1) { |
| 75 |
strncpy2(outp, p, outlen); |
| 76 |
return; |
| 77 |
} |
| 73 |
memcpy(outp, p, eword_begin_p - p); |
78 |
memcpy(outp, p, eword_begin_p - p); |
| 74 |
outp += eword_begin_p - p; |
79 |
outp += eword_begin_p - p; |
|
|
80 |
outlen -= eword_begin_p - p; |
| 75 |
p = eword_begin_p; |
81 |
p = eword_begin_p; |
| 76 |
} else { |
82 |
} else { |
| 77 |
/* ignore spaces between encoded words */ |
83 |
/* ignore spaces between encoded words */ |
|
Lines 79-86
Link Here
|
| 79 |
|
85 |
|
| 80 |
for (sp = p; sp < eword_begin_p; sp++) { |
86 |
for (sp = p; sp < eword_begin_p; sp++) { |
| 81 |
if (!isspace(*(const guchar *)sp)) { |
87 |
if (!isspace(*(const guchar *)sp)) { |
|
|
88 |
if (eword_begin_p - p > outlen - 1) { |
| 89 |
strncpy2(outp, p, outlen); |
| 90 |
return; |
| 91 |
} |
| 82 |
memcpy(outp, p, eword_begin_p - p); |
92 |
memcpy(outp, p, eword_begin_p - p); |
| 83 |
outp += eword_begin_p - p; |
93 |
outp += eword_begin_p - p; |
|
|
94 |
outlen -= eword_begin_p - p; |
| 84 |
p = eword_begin_p; |
95 |
p = eword_begin_p; |
| 85 |
break; |
96 |
break; |
| 86 |
} |
97 |
} |
|
Lines 106-113
Link Here
|
| 106 |
(decoded_text, text_begin_p + 1, |
117 |
(decoded_text, text_begin_p + 1, |
| 107 |
eword_end_p - (text_begin_p + 1)); |
118 |
eword_end_p - (text_begin_p + 1)); |
| 108 |
} else { |
119 |
} else { |
|
|
120 |
if (eword_end_p + 2 - p > outlen - 1) { |
| 121 |
strncpy2(outp, p, outlen); |
| 122 |
return; |
| 123 |
} |
| 109 |
memcpy(outp, p, eword_end_p + 2 - p); |
124 |
memcpy(outp, p, eword_end_p + 2 - p); |
| 110 |
outp += eword_end_p + 2 - p; |
125 |
outp += eword_end_p + 2 - p; |
|
|
126 |
outlen -= eword_end_p + 2 - p; |
| 111 |
p = eword_end_p + 2; |
127 |
p = eword_end_p + 2; |
| 112 |
continue; |
128 |
continue; |
| 113 |
} |
129 |
} |
|
Lines 116-128
Link Here
|
| 116 |
conv_str = conv_codeset_strdup(decoded_text, charset, NULL); |
132 |
conv_str = conv_codeset_strdup(decoded_text, charset, NULL); |
| 117 |
if (conv_str) { |
133 |
if (conv_str) { |
| 118 |
len = strlen(conv_str); |
134 |
len = strlen(conv_str); |
|
|
135 |
if (len > outlen - 1) { |
| 136 |
strncpy2(outp, conv_str, outlen); |
| 137 |
g_free(conv_str); |
| 138 |
g_free(decoded_text); |
| 139 |
return; |
| 140 |
} |
| 119 |
memcpy(outp, conv_str, len); |
141 |
memcpy(outp, conv_str, len); |
| 120 |
g_free(conv_str); |
142 |
g_free(conv_str); |
| 121 |
} else { |
143 |
} else { |
| 122 |
len = strlen(decoded_text); |
144 |
len = strlen(decoded_text); |
|
|
145 |
if (len > outlen - 1) { |
| 146 |
conv_localetodisp(outp, outlen, decoded_text); |
| 147 |
g_free(decoded_text); |
| 148 |
return; |
| 149 |
} |
| 123 |
conv_localetodisp(outp, len + 1, decoded_text); |
150 |
conv_localetodisp(outp, len + 1, decoded_text); |
| 124 |
} |
151 |
} |
| 125 |
outp += len; |
152 |
outp += len; |
|
|
153 |
outlen -= len; |
| 126 |
|
154 |
|
| 127 |
g_free(decoded_text); |
155 |
g_free(decoded_text); |
| 128 |
|
156 |
|