1 /* Emailpkt: Husky e-mailer
2  *
3  * (C) Copyleft Stas Degteff 2:5080/102@FIDOnet, g@grumbler.org
4  * (c) Copyleft Husky developers team http://husky.sorceforge.net/team.html
5  *
6  * $Id$
7  * Common declarations
8  *
9  * For latest version see http://husky.sorceforge.net/emailpkt
10  *
11  * This file is part of EMAILPKT, module of The HUSKY Fidonet Software.
12  *
13  * EMAILPKT is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation; either
16  * version 2 of the License, or (at your option) any later version.
17  *
18  * EMAILPKT is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public
24  * License along with this library; see file COPYING. If not, write to the Free
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  *
27  * See also http://www.gnu.org, license may be found here.
28  *****************************************************************************
29  */
30 
31 #ifndef __ECOMMON_H
32 #define __ECOMMON_H
33 
34 /***** Default configuretion *****/
35 
36 #ifndef LOGFILE
37 # define LOGFILE "emailpkt.log"
38 #endif
39 
40 #define DEFAULT_FROMNAME "EmailPkt"
41 #define DEFAULT_FPOMADDR "unknown@fidonet.org"
42 #define DEFAULT_SUBJECT  "FTNbundle"
43 
44 /* String to put in the body of the message if no one is found */
45 #ifndef DEFAULTBODY
46 #define DEFAULTBODY "This message contains a FTN bundle.\nDecode attachment and save file into FTN inbound directory."
47 /* "(Latest version of emailpkt available at http://husky.physcip.uni-stuttgart.de)\n" */
48 #endif
49 /* MIME booundary string */
50 #ifndef MIMEBOUNDARY
51 #define MIMEBOUNDARY   "emailpkt_boundary"
52 #endif
53 
54 /* Sub-directory names in temporary inbound, outbound & etc */
55 #define TempSubDir     "emailpkt"
56 /*#define TEMPEXT "eml"*/
57 #define SECTIONS_SUBDIR "sections"
58 #define TempInSubDir   "hereceive"
59 #define TempOutSubDir  "hesend"
60 #define UnknownFileExt "unk" /* suffix for received files without names */
61 
62 /* First chars of SEAT special lines */
63 #define SEAT_HEADER_SIGNATURE "Ftn-"
64 
65 #define AMODE    0644    /* mode (see chmod(1)) for create file */
66 #define TempMODE 0600    /* mode (see chmod(1)) for create temp file */
67 #define TempDIRMODE 0700 /* mode (see chmod(1)) for create temp directory */
68 
69 /**** Do not change after this line *****************************/
70 #include <fidoconf/dirlayer.h>
71 #include <fidoconf/fidoconf.h>
72 #include <fidoconf/common.h>
73 #include <limits.h>
74 
75 #if defined (_MSC_VER) || defined (__CYGWIN__) || defined (__MINGW32__) || defined (_WIN32)
76 /*#  include <stdint.h>*/
77 #else
78 #  include <inttypes.h>
79 #endif
80 
81 #ifndef DIRSEP
82 # if ((OSTYPE==UNIX)  || defined(__UNIX__))
83 #  define DIRSEP '/'
84 # else
85 #  define DIRSEP '\\'
86 # endif
87 #endif
88 
89 #ifndef PATH_MAX
90 # define PATH_MAX 80
91 #endif
92 #ifndef NAME_MAX
93 # define NAME_MAX 13
94 #endif
95 
96 #define ADRS_MAX 31  /* Max. length of FTN address string: "zzzz:nnnnn/nnnnn.ppppp@dddddddd" */
97 
98 /* Types */
99 
100 /* for processMIMESection() */
101 enum contents{ con_Unknown, con_TextPlain, con_TextHtml, con_Text, con_File };
102 enum encodings{ en_Unknown, en_None, en_UUE, en_BASE64, en_QUOTED };
103 
104 struct s_msgHeader{
105 	char *from_, *From, *To, *Subject, *Date, *XMailer, *MessageID;
106 	char *Organization, *MimeVersion, *ContentType;
107 	char *ContentTransferEncoding, *ContentDisposition;
108 	char *XConfirmTo;     /* LuckyGate's confirmation address */
109 	char *fromaddr;       /* sender's email */
110         char *boundary;       /* MIME boundary string */
111         char *endboundary;    /* MIME boundary string: message end */
112 	char **other;         /* other (unknown) lines */
113 	unsigned othercount;  /* other lines count */
114         unsigned short isbad; /* Bad message (duplicate kludges)*/
115         char *XFTNattachVersion;  /* X-FTNattach-Version: 1.0 */
116         unsigned char f_multipart_mixed;      /* MIME multipart/mixed */
117         unsigned char f_multipart_alternative;/* MIME multipart/alternative */
118         unsigned char f_LuckyGate; /* Flag: detected LuckyGate */
119         unsigned char f_IREX;      /* Flag: detected Internet REX */
120         unsigned char f_SEAT;      /* Flag: detected SEAT (RFC-0015) message */
121 };
122 
123 struct s_SEAT_header{
124         char *FileID;          /* Ftn-File-ID:   */
125         UINT32 Crc32;          /* Ftn-Crc32:     */
126         unsigned short SegNo, SegCount; /* Ftn-Seg:       */
127         UINT32 SegCrc32;       /* Ftn-Seg-Crc32: */
128         char *SegID;           /* Ftn-Seg-ID:    */
129 };
130 
131 /* misc.c vars */
132 extern char *program_name;
133 
134 /* misc.c funcs */
135 
136 #ifndef sstr
137 /* safety string: not return NULL */
138 #define sstr(sss) (sss ? sss : "(-null-)")
139 #endif
140 
141 void  dispose_SEAT_header(struct s_SEAT_header);
142 int   truncat(const char *path);
143 int   delete(const char *path);
144 char *snprintaddr(char *string, const int size,const hs_addr addr);
145 int   setOutboundFilenames(s_link *link, e_flavour prio);
146 FILE *createbsy(s_link link);
147 int   removebsy(s_link link);
148 int   testfile(const char *filename);
149 char *stripCRLF(char *s);
150 char *version();
151 
152 /* Create new file (exclusive sharing mode) with access mode 'AMODE'
153  * in file mode 'fmode'
154  * Return values:
155  * OK:     file descriptor
156  * error:  NULL
157  */
158 FILE *createFileExcl(char *filename, const char *fmode);
159 
160 
161 /* Concatenate files
162  * Parameters:
163  *   path to files (directory name), slash ('/' or '\\') at end is mandatory!
164  *   array of directory entries (NULL-terminated)
165  *   output filename.
166  * Return 0 if success
167  */
168 int concat_files( const char *path, struct dirent **ls, const char *dstfilename);
169 
170 /* Move file into inbound, if file exist - change name:
171  * if *.pkt then change before point char else increment last chars
172  * Return 0 if success
173  */
174 int move_file_to_inbound( const char *from,  const char *to );
175 
176 /* Generate next inbound file name
177  * if *.pkt then change before point char else increment last chars
178  * Return new file name or NULL
179  */
180 char *next_inbound_filename(const char *filename);
181 
182 /* encdec.c funcs ==============================================*/
183 /* decoders *****************************************************/
184 
185 /* Decode uu-string and store into dstbuffer
186  * Return decoded array len
187  */
188 unsigned uudecodeLine( unsigned char **dstbuffer, const unsigned char *line );
189 
190 /* Decode base64-encoded string (store pointer into dstbuffer)
191  * Return length of decoded data or -1 (if error)
192  */
193 int base64DecodeLine( unsigned char **dstbuffer,
194                            const unsigned char * line);
195 
196 /* Decode quoted-printeble line (store into dstbuffer)
197  * Return length of decoded data or -1 (if error)
198  */
199 int quotedPrintableDecodeLine( unsigned char **dstbuffer,
200                                     const unsigned char *line);
201 
202 /* uudecode file
203  * Return values:
204  * OK:               0
205  * Can't open file: -1
206  */
207 int uudecodeFile(char *name, FILE *from);
208 
209 /* Decode base64-encoded file
210  * Return values:
211  * OK:                    0
212  * Can't create file:    -1  display critical error
213  * Can't reopen file:    -2  display critical error
214  * Unexpected EOF:        1  display error
215  * Can't read from file: -3  display error
216  */
217 int base64decodeFile(char *name, FILE *in);
218 
219 
220 /* encoders *****************************************************/
221 
222 /* base64-encoder for file
223  * Return values:
224  * OK: 0
225  * error: errno
226  */
227 int base64encodeFile(FILE *infd, FILE *outfd);
228 
229 /* uu-encoder for file
230  * Return values:
231  * OK: 0
232  * error: errno
233  */
234 int uuencodeFile( FILE *infd, FILE *outfd, const char*filename,
235               const unsigned section, const unsigned sectsize);
236 
237 
238 /* Case-incensitive string compare, return values eq. strncmp()
239  */
240 //int strincmp(const char *str1, const char *str2, unsigned len);
241 
242 
243 /* Create new file (into inbound directory), if file exist increment:
244  * - base part of filename - tic or pkt,
245  * - suffix ("extension") for other.
246  */
247 FILE *createInboundFile(char **pathname);
248 
249 /* Move file into inbound directory. If file exist increment:
250  * - base part of filename - tic or pkt,
251  * - suffix ("extension") for other.
252  * Return 0 if success.
253  */
254 int moveInboundFile( const char *srcfname, const char *dstdir );
255 
256 /* Define module information for config parser (config variables 'module',
257  * 'version'; fill structure sApp).
258  */
259 void  set_module_vars();
260 
261 
262 /* main vars ****************************************************/
263 
264 extern s_fidoconfig *config;
265 
266 
267 #define dirsort(ls) {w_log(LL_ALERT,"dirsort() not implemented yet, sorry");}
268 #define RemoveDirectoryTree(tp) {w_log(LL_ALERT,"RemoveDirectoryTree() not implemented yet, sorry");}
269 
270 #endif
271