FreeCalypso > hg > falcon-mail-tools
comparison f-demime/initconv.c @ 0:7e0d08176f32
f-demime starting code
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 06 May 2023 06:14:03 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7e0d08176f32 |
---|---|
1 /* | |
2 * This module contains functions that implement initiation of various | |
3 * conversions performed by f-demime. | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 #include <unistd.h> | |
11 #include "defs.h" | |
12 | |
13 extern enum msg_state msg_state; | |
14 extern char cont_te_buf[HDR_BUF_SIZE]; | |
15 extern int got_cont_type, got_cont_te; | |
16 extern char *att_filename_base; | |
17 extern int qpdec_err_flag; | |
18 | |
19 void (*dec_outf)(); | |
20 FILE *tempfile; | |
21 int text_is_utf8; | |
22 | |
23 static int | |
24 create_tempfile() | |
25 { | |
26 char template[16]; | |
27 int fd; | |
28 | |
29 strcpy(template, "/tmp/fdemXXXXXX"); | |
30 fd = mkstemp(template); | |
31 if (fd < 0) { | |
32 perror("mkstemp"); | |
33 return(-1); | |
34 } | |
35 unlink(template); | |
36 tempfile = fdopen(fd, "r+w"); | |
37 if (!tempfile) { | |
38 perror("fdopen"); | |
39 close(fd); | |
40 return(-1); | |
41 } | |
42 return(0); | |
43 } | |
44 | |
45 static int | |
46 init_tempfile() | |
47 { | |
48 int rc; | |
49 | |
50 rc = create_tempfile(); | |
51 if (!rc) | |
52 return(0); | |
53 if (got_cont_te) | |
54 fputs(cont_te_buf, stdout); | |
55 puts("X-Fdemime-Error: unable to create temp file for conversion"); | |
56 putchar('\n'); | |
57 msg_state = MSG_STATE_BODY_PASS; | |
58 return(-1); | |
59 } | |
60 | |
61 static void | |
62 implicit_text_plain() | |
63 { | |
64 if (!got_cont_type) | |
65 puts("Content-Type: text/plain (f-demime implied)"); | |
66 } | |
67 | |
68 static void | |
69 grok_charset_attr(csa) | |
70 char *csa; | |
71 { | |
72 text_is_utf8 = !strcasecmp(csa, "UTF-8") || !strcmp(csa, "csUTF8"); | |
73 } | |
74 | |
75 void | |
76 init_base64_text_plain(charset_attr) | |
77 char *charset_attr; | |
78 { | |
79 implicit_text_plain(); | |
80 if (init_tempfile() < 0) | |
81 return; | |
82 grok_charset_attr(charset_attr); | |
83 base64_dec_init(); | |
84 ptext_conv_init(); | |
85 msg_state = MSG_STATE_PTEXT_B64; | |
86 } | |
87 | |
88 void | |
89 init_qp_text_plain(charset_attr) | |
90 char *charset_attr; | |
91 { | |
92 implicit_text_plain(); | |
93 if (init_tempfile() < 0) | |
94 return; | |
95 grok_charset_attr(charset_attr); | |
96 qpdec_err_flag = 0; | |
97 ptext_conv_init(); | |
98 msg_state = MSG_STATE_PTEXT_QP; | |
99 } | |
100 | |
101 void | |
102 init_base64_text_other() | |
103 { | |
104 if (init_tempfile() < 0) | |
105 return; | |
106 base64_dec_init(); | |
107 b2q_conv_init(); | |
108 msg_state = MSG_STATE_B64_TO_QP; | |
109 } | |
110 | |
111 void | |
112 init_base64_nontext() | |
113 { | |
114 fputs(cont_te_buf, stdout); | |
115 if (init_attach_out() < 0) { | |
116 puts("X-Fdemime-Error: unable to create save file"); | |
117 putchar('\n'); | |
118 msg_state = MSG_STATE_BODY_PASS; | |
119 return; | |
120 } | |
121 printf("X-Fdemime-Saved: %s\n", att_filename_base); | |
122 base64_dec_init(); | |
123 msg_state = MSG_STATE_BLOB_B64; | |
124 } |