| 1 | /************************************************* |
| 2 | * Exim - an Internet mail transport agent * |
| 3 | *************************************************/ |
| 4 | |
| 5 | /* Copyright (c) Tom Kistner <tom@duncanthrax.net> 2003-???? */ |
| 6 | /* License: GPL */ |
| 7 | |
| 8 | /* demime defines */ |
| 9 | |
| 10 | #ifdef WITH_OLD_DEMIME |
| 11 | |
| 12 | #define MIME_DEMUX_MODE_SCANNING 0 |
| 13 | #define MIME_DEMUX_MODE_MIME_HEADERS 1 |
| 14 | #define MIME_DEMUX_MODE_BASE64 2 |
| 15 | #define MIME_DEMUX_MODE_QP 3 |
| 16 | #define MIME_DEMUX_MODE_PLAIN 4 |
| 17 | |
| 18 | #define MIME_UU_MODE_OFF 0 |
| 19 | #define MIME_UU_MODE_UNCONFIRMED 1 |
| 20 | #define MIME_UU_MODE_CONFIRMED 2 |
| 21 | |
| 22 | #define MIME_MAX_EXTENSION 128 |
| 23 | |
| 24 | #define MIME_READ_LINE_EOF 0 |
| 25 | #define MIME_READ_LINE_OK 1 |
| 26 | #define MIME_READ_LINE_OVERFLOW 2 |
| 27 | |
| 28 | #define MIME_SANITY_MAX_LINE_LENGTH 131071 |
| 29 | #define MIME_SANITY_MAX_FILENAME 512 |
| 30 | #define MIME_SANITY_MAX_HEADER_OPTION_VALUE 1024 |
| 31 | #define MIME_SANITY_MAX_B64_LINE_LENGTH 76 |
| 32 | #define MIME_SANITY_MAX_BOUNDARY_LENGTH 1024 |
| 33 | #define MIME_SANITY_MAX_DUMP_FILES 1024 |
| 34 | |
| 35 | |
| 36 | |
| 37 | /* MIME errorlevel settings */ |
| 38 | |
| 39 | #define MIME_ERRORLEVEL_LONG_LINE 3,US"line length in message or single header size exceeds %u bytes",MIME_SANITY_MAX_LINE_LENGTH |
| 40 | #define MIME_ERRORLEVEL_TOO_MANY_PARTS 3,US"too many MIME parts (max %u)",MIME_SANITY_MAX_DUMP_FILES |
| 41 | #define MIME_ERRORLEVEL_MESSAGE_PARTIAL 3,US"'message/partial' MIME type" |
| 42 | #define MIME_ERRORLEVEL_FILENAME_LENGTH 3,US"proposed filename exceeds %u characters",MIME_SANITY_MAX_FILENAME |
| 43 | #define MIME_ERRORLEVEL_BOUNDARY_LENGTH 3,US"boundary length exceeds %u characters",MIME_SANITY_MAX_BOUNDARY_LENGTH |
| 44 | #define MIME_ERRORLEVEL_DOUBLE_HEADERS 2,US"double headers (content-type, content-disposition or content-transfer-encoding)" |
| 45 | #define MIME_ERRORLEVEL_UU_MISALIGNED 1,US"uuencoded line length is not a multiple of 4 characters" |
| 46 | #define MIME_ERRORLEVEL_UU_LINE_LENGTH 1,US"uuencoded line length does not match advertised number of bytes" |
| 47 | #define MIME_ERRORLEVEL_B64_LINE_LENGTH 1,US"base64 line length exceeds %u characters",MIME_SANITY_MAX_B64_LINE_LENGTH |
| 48 | #define MIME_ERRORLEVEL_B64_ILLEGAL_CHAR 2,US"base64 line contains illegal character" |
| 49 | #define MIME_ERRORLEVEL_B64_MISALIGNED 1,US"base64 line length is not a multiple of 4 characters" |
| 50 | #define MIME_ERRORLEVEL_QP_ILLEGAL_CHAR 1,US"quoted-printable encoding contains illegal character" |
| 51 | |
| 52 | |
| 53 | /* demime structures */ |
| 54 | |
| 55 | typedef struct mime_part { |
| 56 | /* true if there was a content-type header */ |
| 57 | int seen_content_type; |
| 58 | /* true if there was a content-transfer-encoding header |
| 59 | contains the encoding type */ |
| 60 | int seen_content_transfer_encoding; |
| 61 | /* true if there was a content-disposition header */ |
| 62 | int seen_content_disposition; |
| 63 | /* pointer to a buffer with the proposed file extension */ |
| 64 | uschar *extension; |
| 65 | } mime_part; |
| 66 | |
| 67 | typedef struct boundary { |
| 68 | struct boundary *next; |
| 69 | uschar *boundary_string; |
| 70 | } boundary; |
| 71 | |
| 72 | typedef struct file_extension { |
| 73 | struct file_extension *next; |
| 74 | uschar *file_extension_string; |
| 75 | } file_extension; |
| 76 | |
| 77 | /* demime.c prototypes */ |
| 78 | |
| 79 | unsigned int mime_hstr_i(uschar *); |
| 80 | uschar *mime_decode_qp(uschar *, int *); |
| 81 | int mime_get_dump_file(uschar *, FILE **, uschar *); |
| 82 | int mime_header_find(uschar *, uschar *, uschar **); |
| 83 | int mime_read_line(FILE *, int, uschar *, long *); |
| 84 | int mime_check_boundary(uschar *, struct boundary *); |
| 85 | int mime_check_uu_start(uschar *, uschar *, int *); |
| 86 | long uu_decode_line(uschar *, uschar **, long, uschar *); |
| 87 | long mime_decode_line(int ,uschar *, uschar **, long, uschar *); |
| 88 | void mime_trigger_error(int, uschar *, ...); |
| 89 | int mime_demux(FILE *, uschar *); |
| 90 | |
| 91 | |
| 92 | |
| 93 | /* BASE64 decoder matrix */ |
| 94 | static unsigned char b64[256]={ |
| 95 | /* 0 */ 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 96 | /* 16 */ 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 97 | /* 32 */ 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 62, 128, 128, 128, 63, |
| 98 | /* 48 */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 128, 128, 128, 255, 128, 128, |
| 99 | /* 64 */ 128, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, |
| 100 | /* 80 */ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 128, 128, 128, 128, 128, |
| 101 | /* 96 */ 128, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, |
| 102 | 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 128, 128, 128, 128, 128, |
| 103 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 104 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 105 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 106 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 107 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 108 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 109 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 110 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 |
| 111 | }; |
| 112 | |
| 113 | |
| 114 | /* Microsoft-Style uudecode matrix */ |
| 115 | static unsigned char uudec[256]={ |
| 116 | /* 0 */ 0, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, |
| 117 | /* 16 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, |
| 118 | /* 32 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, |
| 119 | /* 48 */ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
| 120 | /* 64 */ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, |
| 121 | /* 80 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, |
| 122 | /* 96 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, |
| 123 | /* 112 */ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
| 124 | /* 128 */ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, |
| 125 | /* 144 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, |
| 126 | /* 160 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, |
| 127 | /* 176 */ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
| 128 | /* 192 */ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, |
| 129 | /* 208 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, |
| 130 | /* 224 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, |
| 131 | /* 240 */ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 |
| 132 | }; |
| 133 | |
| 134 | #endif |