1 /*:ts=8*/
2 /*****************************************************************************
3 * FIDOGATE --- Gateway UNIX Mail/News <-> FIDO NetMail/EchoMail
4 *
5 * $Id: mail.c,v 4.14 2004/08/22 20:19:11 n0ll Exp $
6 *
7 * Create RFC messages in mail/news dir
8 *
9 *****************************************************************************
10 * Copyright (C) 1990-2004
11 * _____ _____
12 * | |___ | Martin Junius <mj.at.n0ll.dot.net>
13 * | | | | | | Radiumstr. 18
14 * |_|_|_|@home| D-51069 Koeln, Germany
15 *
16 * This file is part of FIDOGATE.
17 *
18 * FIDOGATE is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the
20 * Free Software Foundation; either version 2, or (at your option) any
21 * later version.
22 *
23 * FIDOGATE is distributed in the hope that it will be useful, but
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with FIDOGATE; see the file COPYING. If not, write to the Free
30 * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
31 *****************************************************************************/
32
33 #include "fidogate.h"
34
35
36
37 char mail_dir[MAXPATH];
38 char news_dir[MAXPATH];
39
40 static char m_name[MAXPATH];
41 static char m_tmp [MAXPATH];
42 static FILE *m_file = NULL;
43
44 static char n_name[MAXPATH];
45 static char n_tmp [MAXPATH];
46 static FILE *n_file = NULL;
47
48
49
50 /*
51 * Open RFC mail file
52 */
mail_open(int sel)53 int mail_open(int sel)
54 {
55 long n;
56
57 switch(sel)
58 {
59 case 'm':
60 case 'M':
61 n = sequencer(DEFAULT_SEQ_MAIL);
62 str_printf(m_tmp, sizeof(m_tmp), "%s/%08ld.tmp", mail_dir, n);
63 str_printf(m_name, sizeof(m_name), "%s/%08ld.rfc", mail_dir, n);
64 m_file = fopen(m_tmp, W_MODE);
65 if(!m_file) {
66 logit("$Can't create mail file %s", m_tmp);
67 return ERROR;
68 }
69 break;
70
71 case 'n':
72 case 'N':
73 n = sequencer(DEFAULT_SEQ_NEWS);
74 str_printf(n_tmp, sizeof(n_tmp), "%s/%08ld.tmp", news_dir, n);
75 str_printf(n_name, sizeof(n_name), "%s/%08ld.rfc", news_dir, n);
76 n_file = fopen(n_tmp, W_MODE);
77 if(!n_file) {
78 logit("$Can't create mail file %s", n_tmp);
79 return ERROR;
80 }
81 break;
82
83 default:
84 logit("mail_open(%d): illegal value", sel);
85 return ERROR;
86 break;
87 }
88
89 return OK;
90 }
91
92
93
94 /*
95 * Return mail tmp name
96 */
mail_name(int sel)97 char *mail_name(int sel)
98 {
99 switch(sel)
100 {
101 case 'm':
102 case 'M':
103 return m_tmp;
104 break;
105 case 'n':
106 case 'N':
107 return n_tmp;
108 break;
109 }
110
111 return NULL;
112 }
113
114
115
116 /*
117 * Return mail file pointer
118 */
mail_file(int sel)119 FILE *mail_file(int sel)
120 {
121 switch(sel)
122 {
123 case 'm':
124 case 'M':
125 return m_file;
126 break;
127 case 'n':
128 case 'N':
129 return n_file;
130 break;
131 }
132
133 return NULL;
134 }
135
136
137
138 /*
139 * Close mail file
140 */
mail_close(int sel)141 int mail_close(int sel)
142 {
143 int err=ERROR;
144
145 switch(sel)
146 {
147 case 'm':
148 case 'M':
149 fclose(m_file);
150 err = rename(m_tmp, m_name);
151 if(err == ERROR)
152 logit("$Can't rename mail file %s to %s", m_tmp, m_name);
153
154 m_tmp[0] = 0;
155 m_name[0] = 0;
156 m_file = NULL;
157 break;
158
159 case 'n':
160 case 'N':
161 fclose(n_file);
162 err = rename(n_tmp, n_name);
163 if(err == ERROR)
164 logit("$Can't rename mail file %s to %s", n_tmp, n_name);
165
166 n_tmp[0] = 0;
167 n_name[0] = 0;
168 n_file = NULL;
169 break;
170 }
171
172 return err;
173 }
174