diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-16 17:51:13 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-16 17:51:13 +0200 |
commit | 9fe98f701d40835db32baa12c94b661d40231ea4 (patch) | |
tree | 781c9c71519f3eb79082eac54e0cc545e16b2fd1 /mailutils/mail.c | |
parent | 52e460b7440ed5b85e4125a4eccf1e665d92c0ff (diff) | |
download | busybox-w32-9fe98f701d40835db32baa12c94b661d40231ea4.tar.gz busybox-w32-9fe98f701d40835db32baa12c94b661d40231ea4.tar.bz2 busybox-w32-9fe98f701d40835db32baa12c94b661d40231ea4.zip |
libbb: merge mail and uudecode's base64 decoders
function old new delta
read_base64 - 378 +378
uudecode_main 306 315 +9
parse 953 958 +5
read_stduu 250 254 +4
base64_main 217 219 +2
read_base64 358 - -358
decode_base64 371 - -371
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 4/0 up/down: 398/-729) Total: -331 bytes
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'mailutils/mail.c')
-rw-r--r-- | mailutils/mail.c | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/mailutils/mail.c b/mailutils/mail.c index 8e52a3efc..89db66166 100644 --- a/mailutils/mail.c +++ b/mailutils/mail.c | |||
@@ -161,73 +161,6 @@ void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol) | |||
161 | #undef src_buf | 161 | #undef src_buf |
162 | } | 162 | } |
163 | 163 | ||
164 | void FAST_FUNC decode_base64(FILE *src_stream, FILE *dst_stream) | ||
165 | { | ||
166 | int term_count = 1; | ||
167 | |||
168 | while (1) { | ||
169 | char translated[4]; | ||
170 | int count = 0; | ||
171 | |||
172 | while (count < 4) { | ||
173 | char *table_ptr; | ||
174 | int ch; | ||
175 | |||
176 | /* Get next _valid_ character. | ||
177 | * global vector bb_uuenc_tbl_base64[] contains this string: | ||
178 | * "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n" | ||
179 | */ | ||
180 | do { | ||
181 | ch = fgetc(src_stream); | ||
182 | if (ch == EOF) { | ||
183 | bb_error_msg_and_die(bb_msg_read_error); | ||
184 | } | ||
185 | // - means end of MIME section | ||
186 | if ('-' == ch) { | ||
187 | // push it back | ||
188 | ungetc(ch, src_stream); | ||
189 | return; | ||
190 | } | ||
191 | table_ptr = strchr(bb_uuenc_tbl_base64, ch); | ||
192 | } while (table_ptr == NULL); | ||
193 | |||
194 | /* Convert encoded character to decimal */ | ||
195 | ch = table_ptr - bb_uuenc_tbl_base64; | ||
196 | |||
197 | if (*table_ptr == '=') { | ||
198 | if (term_count == 0) { | ||
199 | translated[count] = '\0'; | ||
200 | break; | ||
201 | } | ||
202 | term_count++; | ||
203 | } else if (*table_ptr == '\n') { | ||
204 | /* Check for terminating line */ | ||
205 | if (term_count == 5) { | ||
206 | return; | ||
207 | } | ||
208 | term_count = 1; | ||
209 | continue; | ||
210 | } else { | ||
211 | translated[count] = ch; | ||
212 | count++; | ||
213 | term_count = 0; | ||
214 | } | ||
215 | } | ||
216 | |||
217 | /* Merge 6 bit chars to 8 bit */ | ||
218 | if (count > 1) { | ||
219 | fputc(translated[0] << 2 | translated[1] >> 4, dst_stream); | ||
220 | } | ||
221 | if (count > 2) { | ||
222 | fputc(translated[1] << 4 | translated[2] >> 2, dst_stream); | ||
223 | } | ||
224 | if (count > 3) { | ||
225 | fputc(translated[2] << 6 | translated[3], dst_stream); | ||
226 | } | ||
227 | } | ||
228 | } | ||
229 | |||
230 | |||
231 | /* | 164 | /* |
232 | * get username and password from a file descriptor | 165 | * get username and password from a file descriptor |
233 | */ | 166 | */ |