- /* read data linewise and dump it to the file,
- while looking for the current boundary */
- while(fgets(CS buffer, MIME_MAX_LINE_LENGTH, mime_stream) != NULL) {
- uschar *decoded_line = NULL;
- int decoded_line_length = 0;
-
- if (mime_current_boundary != NULL) {
- /* boundary line must start with 2 dashes */
- if (Ustrncmp(buffer,"--",2) == 0) {
- if (Ustrncmp((buffer+2),mime_current_boundary,Ustrlen(mime_current_boundary)) == 0)
- break;
- };
- };
-
- decoded_line = mime_parse_line(buffer, decode_buffer, mime_content_transfer_encoding, &decoded_line_length);
-
- /* write line to decode file */
- if (fwrite(decoded_line, 1, decoded_line_length, decode_file) < decoded_line_length) {
- /* error/short write */
- clearerr(mime_stream);
- fseek(mime_stream,f_pos,SEEK_SET);
- return DEFER;
- };
- size_counter += decoded_line_length;
-
- if (size_counter > 1023) {
- if ((mime_content_size + (size_counter / 1024)) < 65535)
- mime_content_size += (size_counter / 1024);
- else
- mime_content_size = 65535;
- size_counter = (size_counter % 1024);
- };
-
- }
+ /* decode according to mime type */
+ if (mime_content_transfer_encoding == NULL)
+ /* no encoding, dump as-is */
+ decode_function = mime_decode_asis;
+ else if (Ustrcmp(mime_content_transfer_encoding, "base64") == 0)
+ decode_function = mime_decode_base64;
+ else if (Ustrcmp(mime_content_transfer_encoding, "quoted-printable") == 0)
+ decode_function = mime_decode_qp;
+ else
+ /* unknown encoding type, just dump as-is */
+ decode_function = mime_decode_asis;