|
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 51-85
void unmime_header(gchar *out, const gch
Link Here
|
| 51 |
|
52 |
|
| 52 |
eword_begin_p = strstr(p, ENCODED_WORD_BEGIN); |
53 |
eword_begin_p = strstr(p, ENCODED_WORD_BEGIN); |
| 53 |
if (!eword_begin_p) { |
54 |
if (!eword_begin_p) { |
| 54 |
strcpy(outp, p); |
55 |
strncpy2(outp, p, outlen); |
| 55 |
return; |
56 |
return; |
| 56 |
} |
57 |
} |
| 57 |
encoding_begin_p = strchr(eword_begin_p + 2, '?'); |
58 |
encoding_begin_p = strchr(eword_begin_p + 2, '?'); |
| 58 |
if (!encoding_begin_p) { |
59 |
if (!encoding_begin_p) { |
| 59 |
strcpy(outp, p); |
60 |
strncpy2(outp, p, outlen); |
| 60 |
return; |
61 |
return; |
| 61 |
} |
62 |
} |
| 62 |
text_begin_p = strchr(encoding_begin_p + 1, '?'); |
63 |
text_begin_p = strchr(encoding_begin_p + 1, '?'); |
| 63 |
if (!text_begin_p) { |
64 |
if (!text_begin_p) { |
| 64 |
strcpy(outp, p); |
65 |
strncpy2(outp, p, outlen); |
| 65 |
return; |
66 |
return; |
| 66 |
} |
67 |
} |
| 67 |
eword_end_p = strstr(text_begin_p + 1, ENCODED_WORD_END); |
68 |
eword_end_p = strstr(text_begin_p + 1, ENCODED_WORD_END); |
| 68 |
if (!eword_end_p) { |
69 |
if (!eword_end_p) { |
| 69 |
strcpy(outp, p); |
70 |
strncpy2(outp, p, outlen); |
| 70 |
return; |
71 |
return; |
| 71 |
} |
72 |
} |
| 72 |
|
73 |
|
| 73 |
if (p == str) { |
74 |
if (p == str) { |
|
|
75 |
if (eword_begin_p - p > outlen - 1) { |
| 76 |
strncpy2(outp, p, outlen); |
| 77 |
return; |
| 78 |
} |
| 74 |
memcpy(outp, p, eword_begin_p - p); |
79 |
memcpy(outp, p, eword_begin_p - p); |
| 75 |
outp += eword_begin_p - p; |
80 |
outp += eword_begin_p - p; |
|
|
81 |
outlen -= eword_begin_p - p; |
| 76 |
p = eword_begin_p; |
82 |
p = eword_begin_p; |
| 77 |
} else { |
83 |
} else { |
| 78 |
/* ignore spaces between encoded words */ |
84 |
/* ignore spaces between encoded words */ |
| 79 |
for (sp = p; sp < eword_begin_p; sp++) { |
85 |
for (sp = p; sp < eword_begin_p; sp++) { |
| 80 |
if (!isspace(*sp)) { |
86 |
if (!isspace(*sp)) { |
|
|
87 |
if (eword_begin_p - p > outlen - 1) { |
| 88 |
strncpy2(outp, p, outlen); |
| 89 |
return; |
| 90 |
} |
| 81 |
memcpy(outp, p, eword_begin_p - p); |
91 |
memcpy(outp, p, eword_begin_p - p); |
| 82 |
outp += eword_begin_p - p; |
92 |
outp += eword_begin_p - p; |
|
|
93 |
outlen -= eword_begin_p - p; |
| 83 |
p = eword_begin_p; |
94 |
p = eword_begin_p; |
| 84 |
break; |
95 |
break; |
| 85 |
} |
96 |
} |
|
Lines 105-112
void unmime_header(gchar *out, const gch
Link Here
|
| 105 |
(decoded_text, text_begin_p + 1, |
116 |
(decoded_text, text_begin_p + 1, |
| 106 |
eword_end_p - (text_begin_p + 1)); |
117 |
eword_end_p - (text_begin_p + 1)); |
| 107 |
} else { |
118 |
} else { |
|
|
119 |
if (eword_end_p + 2 - p > outlen - 1) { |
| 120 |
strncpy2(outp, p, outlen); |
| 121 |
return; |
| 122 |
} |
| 108 |
memcpy(outp, p, eword_end_p + 2 - p); |
123 |
memcpy(outp, p, eword_end_p + 2 - p); |
| 109 |
outp += eword_end_p + 2 - p; |
124 |
outp += eword_end_p + 2 - p; |
|
|
125 |
outlen -= eword_end_p + 2 - p; |
| 110 |
p = eword_end_p + 2; |
126 |
p = eword_end_p + 2; |
| 111 |
continue; |
127 |
continue; |
| 112 |
} |
128 |
} |
|
Lines 115-127
void unmime_header(gchar *out, const gch
Link Here
|
| 115 |
conv_str = conv_codeset_strdup(decoded_text, charset, NULL); |
131 |
conv_str = conv_codeset_strdup(decoded_text, charset, NULL); |
| 116 |
if (conv_str) { |
132 |
if (conv_str) { |
| 117 |
len = strlen(conv_str); |
133 |
len = strlen(conv_str); |
|
|
134 |
if (len > outlen - 1) { |
| 135 |
strncpy2(outp, conv_str, outlen); |
| 136 |
g_free(conv_str); |
| 137 |
g_free(decoded_text); |
| 138 |
return; |
| 139 |
} |
| 118 |
memcpy(outp, conv_str, len); |
140 |
memcpy(outp, conv_str, len); |
| 119 |
g_free(conv_str); |
141 |
g_free(conv_str); |
| 120 |
} else { |
142 |
} else { |
| 121 |
len = strlen(decoded_text); |
143 |
len = strlen(decoded_text); |
|
|
144 |
if (len > outlen - 1) { |
| 145 |
conv_localetodisp(outp, outlen, decoded_text); |
| 146 |
g_free(decoded_text); |
| 147 |
return; |
| 148 |
} |
| 122 |
conv_localetodisp(outp, len + 1, decoded_text); |
149 |
conv_localetodisp(outp, len + 1, decoded_text); |
| 123 |
} |
150 |
} |
| 124 |
outp += len; |
151 |
outp += len; |
|
|
152 |
outlen -= len; |
| 125 |
|
153 |
|
| 126 |
g_free(decoded_text); |
154 |
g_free(decoded_text); |
| 127 |
|
155 |
|