Commit 366f4dd9 366f4dd93b53bf414d6dcc8032446570939b75e0 by Sergey Poznyakoff

Use mu_decode_filter.

1 parent b68f2bcb
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
27 #include <mailutils/filter.h> 27 #include <mailutils/filter.h>
28 #include <mailutils/errno.h> 28 #include <mailutils/errno.h>
29 29
30 enum mu_iconv_fallback_mode rfc2047_fallback_mode = mu_fallback_copy_octal;
31
32 int 30 int
33 rfc2047_decode (const char *tocode, const char *input, char **ptostr) 31 rfc2047_decode (const char *tocode, const char *input, char **ptostr)
34 { 32 {
...@@ -71,7 +69,7 @@ rfc2047_decode (const char *tocode, const char *input, char **ptostr) ...@@ -71,7 +69,7 @@ rfc2047_decode (const char *tocode, const char *input, char **ptostr)
71 char *fromcode = NULL; 69 char *fromcode = NULL;
72 char *encoding_type = NULL; 70 char *encoding_type = NULL;
73 char *encoded_text = NULL; 71 char *encoded_text = NULL;
74 stream_t filter = NULL, cvt = NULL; 72 stream_t filter = NULL;
75 stream_t in_stream = NULL; 73 stream_t in_stream = NULL;
76 const char *filter_type = NULL; 74 const char *filter_type = NULL;
77 size_t nbytes = 0, size; 75 size_t nbytes = 0, size;
...@@ -118,44 +116,20 @@ rfc2047_decode (const char *tocode, const char *input, char **ptostr) ...@@ -118,44 +116,20 @@ rfc2047_decode (const char *tocode, const char *input, char **ptostr)
118 116
119 memory_stream_create (&in_stream, 0, 0); 117 memory_stream_create (&in_stream, 0, 0);
120 stream_write (in_stream, encoded_text, size, 0, NULL); 118 stream_write (in_stream, encoded_text, size, 0, NULL);
121 status = filter_create (&filter, in_stream, filter_type, 119 status = mu_decode_filter (&filter, in_stream, filter_type, fromcode,
122 MU_FILTER_DECODE, MU_STREAM_READ); 120 tocode);
123 if (status != 0) 121 if (status != 0)
124 break; 122 break;
125 123
126 status = filter_iconv_create (&cvt, filter, fromcode, tocode, 124 while (stream_sequential_read (filter, buffer + bufpos,
127 MU_STREAM_NO_CLOSE,
128 rfc2047_fallback_mode);
129 if (status)
130 {
131 cvt = filter;
132 /* Note: the filter stream is already open! */
133 }
134 else
135 {
136 if (stream_open (cvt))
137 {
138 stream_destroy (&cvt, stream_get_owner (cvt));
139 cvt = filter;
140 }
141 else
142 {
143 int flags;
144 stream_get_flags (cvt, &flags);
145 flags &= ~MU_STREAM_NO_CLOSE;
146 stream_set_flags (cvt, flags);
147 }
148 }
149
150 while (stream_sequential_read (cvt, buffer + bufpos,
151 bufsize - bufpos, 125 bufsize - bufpos,
152 &nbytes) == 0 && nbytes) 126 &nbytes) == 0 && nbytes)
153 { 127 {
154 bufpos += nbytes; 128 bufpos += nbytes;
155 } 129 }
156 130
157 stream_close (cvt); 131 stream_close (filter);
158 stream_destroy (&cvt, stream_get_owner (cvt)); 132 stream_destroy (&filter, stream_get_owner (filter));
159 133
160 fromstr = sp + 1; 134 fromstr = sp + 1;
161 run_count = 1; 135 run_count = 1;
......