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