aboutsummaryrefslogtreecommitdiff
path: root/mailutils/mail.c
diff options
context:
space:
mode:
Diffstat (limited to 'mailutils/mail.c')
-rw-r--r--mailutils/mail.c72
1 files changed, 2 insertions, 70 deletions
diff --git a/mailutils/mail.c b/mailutils/mail.c
index 8e52a3efc..9b4bebce5 100644
--- a/mailutils/mail.c
+++ b/mailutils/mail.c
@@ -116,16 +116,15 @@ void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol)
116 SRC_BUF_SIZE = 45, /* This *MUST* be a multiple of 3 */ 116 SRC_BUF_SIZE = 45, /* This *MUST* be a multiple of 3 */
117 DST_BUF_SIZE = 4 * ((SRC_BUF_SIZE + 2) / 3), 117 DST_BUF_SIZE = 4 * ((SRC_BUF_SIZE + 2) / 3),
118 }; 118 };
119
120#define src_buf text 119#define src_buf text
120 char src[SRC_BUF_SIZE];
121 FILE *fp = fp; 121 FILE *fp = fp;
122 ssize_t len = len; 122 ssize_t len = len;
123 char dst_buf[DST_BUF_SIZE + 1]; 123 char dst_buf[DST_BUF_SIZE + 1];
124 124
125 if (fname) { 125 if (fname) {
126 fp = (NOT_LONE_DASH(fname)) ? xfopen_for_read(fname) : (FILE *)text; 126 fp = (NOT_LONE_DASH(fname)) ? xfopen_for_read(fname) : (FILE *)text;
127 src_buf = bb_common_bufsiz1; 127 src_buf = src;
128 // N.B. strlen(NULL) segfaults!
129 } else if (text) { 128 } else if (text) {
130 // though we do not call uuencode(NULL, NULL) explicitly 129 // though we do not call uuencode(NULL, NULL) explicitly
131 // still we do not want to break things suddenly 130 // still we do not want to break things suddenly
@@ -161,73 +160,6 @@ void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol)
161#undef src_buf 160#undef src_buf
162} 161}
163 162
164void 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/* 163/*
232 * get username and password from a file descriptor 164 * get username and password from a file descriptor
233 */ 165 */