1 /*****************************************************************************
2 * HTICK --- FTN Ticker / Request Processor
3 *****************************************************************************
4 * Copyright (C) 1999 by
5 *
6 * Gabriel Plutzar
7 *
8 * Fido: 2:31/1
9 * Internet: gabriel@hit.priv.at
10 *
11 * Vienna, Austria, Europe
12 *
13 * This file is part of HTICK, which is based on HPT by Matthias Tichy,
14 * 2:2432/605.14 2:2433/1245, mtt@tichy.de
15 *
16 * HTICK is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the
18 * Free Software Foundation; either version 2, or (at your option) any
19 * later version.
20 *
21 * HTICK is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with HTICK; see the file COPYING. If not, write to the Free
28 * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 *****************************************************************************
30 * $Id$
31 *****************************************************************************/
32
33 #include <stdlib.h>
34 #include <string.h>
35 #include <time.h>
36
37 #include <smapi/msgapi.h>
38
39 #include <fidoconf/fidoconf.h>
40 #include <fidoconf/common.h>
41 #include <fidoconf/afixcmd.h>
42 #include <huskylib/xstr.h>
43 #include <huskylib/recode.h>
44 #include <huskylib/log.h>
45 #include <areafix/areafix.h>
46
47 #include <fcommon.h>
48 #include <scan.h>
49 #include <global.h>
50 #include <htickafix.h>
51 #include <toss.h>
52
53 char *versionStr;
54
convertMsgHeader(XMSG xmsg,s_message * msg)55 void convertMsgHeader( XMSG xmsg, s_message * msg )
56 {
57 /* convert header */
58 msg->attributes = xmsg.attr;
59
60 msg->origAddr = xmsg.orig;
61 msg->destAddr = xmsg.dest;
62
63 strcpy( ( char * )msg->datetime, ( char * )xmsg.__ftsc_date );
64 xstrcat( &( msg->subjectLine ), ( char * )xmsg.subj );
65 xstrcat( &( msg->toUserName ), ( char * )xmsg.to );
66 xstrcat( &( msg->fromUserName ), ( char * )xmsg.from );
67
68 /* recoding subjectLine to Internal Charset */
69 if( ( !config->recodeMsgBase ) && ( config->outtab != NULL ) )
70 {
71 recodeToInternalCharset( ( char * )msg->subjectLine );
72 recodeToInternalCharset( ( char * )msg->fromUserName );
73 recodeToInternalCharset( ( char * )msg->toUserName );
74 }
75 }
76
convertMsgText(HMSG SQmsg,s_message * msg,hs_addr ourAka)77 void convertMsgText( HMSG SQmsg, s_message * msg, hs_addr ourAka )
78 {
79 char *kludgeLines, viaLine[100];
80 UCHAR *ctrlBuff;
81 UINT32 ctrlLen;
82 time_t tm;
83 struct tm *dt;
84
85 /* get kludge lines */
86 ctrlLen = MsgGetCtrlLen( SQmsg );
87 ctrlBuff = ( unsigned char * )smalloc( ctrlLen + 1 );
88 MsgReadMsg( SQmsg, NULL, 0, 0, NULL, ctrlLen, ctrlBuff );
89 kludgeLines = ( char * )CvtCtrlToKludge( ctrlBuff );
90 free( ctrlBuff );
91
92 /* make text */
93 msg->textLength = MsgGetTextLen( SQmsg );
94
95 time( &tm );
96 dt = gmtime( &tm );
97 sprintf( viaLine, "\001Via %u:%u/%u.%u @%04u%02u%02u.%02u%02u%02u.UTC %s",
98 ourAka.zone, ourAka.net, ourAka.node, ourAka.point,
99 dt->tm_year + 1900, dt->tm_mon + 1, dt->tm_mday, dt->tm_hour, dt->tm_min, dt->tm_sec,
100 versionStr );
101
102 msg->text =
103 ( char * )scalloc( 1, msg->textLength + strlen( kludgeLines ) + strlen( viaLine ) + 1 );
104
105
106 strcpy( msg->text, kludgeLines );
107 /* strcat(msg->text, "\001TID: "); */
108 /* strcat(msg->text, versionStr); */
109 /* strcat(msg->text, "\r"); */
110
111 MsgReadMsg( SQmsg, NULL, 0, msg->textLength, ( unsigned char * )msg->text + strlen( msg->text ),
112 0, NULL );
113
114 strcat( msg->text, viaLine );
115
116 if( ( !config->recodeMsgBase ) && ( config->outtab != NULL ) )
117 recodeToInternalCharset( ( char * )msg->text );
118
119 free( kludgeLines );
120 }
121
scanNMArea(s_area * afixarea)122 void scanNMArea( s_area * afixarea )
123 {
124 HAREA netmail;
125 HMSG msg;
126 unsigned long highMsg, i, j;
127 XMSG xmsg;
128 hs_addr dest;
129 int for_us;
130 s_message filefixmsg;
131 int result = 0;
132
133 memset( &filefixmsg, '\0', sizeof( s_message ) );
134 netmail =
135 MsgOpenArea( ( unsigned char * )afixarea->fileName, MSGAREA_NORMAL,
136 ( word ) afixarea->msgbType );
137 if( netmail != NULL )
138 {
139
140 highMsg = MsgGetHighMsg( netmail );
141 w_log( '1', "Scanning %lu messages of %s", highMsg, afixarea->areaName);
142
143 /* scan all Messages for filefix */
144 for( i = 1; i <= highMsg; i++ )
145 {
146 msg = MsgOpenMsg( netmail, MOPEN_RW, i );
147
148 /* msg does not exist */
149 if( msg == NULL )
150 continue;
151
152 MsgReadMsg( msg, &xmsg, 0, 0, NULL, 0, NULL );
153 dest = xmsg.dest;
154 for_us = 0;
155 for( j = 0; j < config->addrCount; j++ )
156 if( addrComp( dest, config->addr[j] ) == 0 )
157 {
158 for_us = 1;
159 break;
160 }
161
162 /* if for filefix - process it */
163 if( findInStrArray( robot->names, ( char * )xmsg.to ) >= 0 &&
164 for_us && ( xmsg.attr & MSGREAD ) != MSGREAD )
165 {
166 convertMsgHeader( xmsg, &filefixmsg );
167 convertMsgText( msg, &filefixmsg, config->addr[j] );
168
169 result = processFileFix( &filefixmsg );
170 if( result != 2 )
171 {
172 xmsg.attr |= MSGREAD;
173 MsgWriteMsg( msg, 0, &xmsg, NULL, 0, 0, 0, NULL );
174 }
175
176 freeMsgBuffers( &filefixmsg );
177
178 MsgCloseMsg( msg );
179 if( robot->killRequests && result == 1 )
180 {
181 MsgKillMsg( netmail, i );
182 --i;
183 }
184 }
185 else
186 MsgCloseMsg( msg );
187
188 } /* endfor */
189
190 MsgCloseArea( netmail );
191 }
192 else
193 {
194 w_log( '9', "Could not open %s", afixarea->areaName );
195 } /* endif */
196 }
197
scan(void)198 void scan( void )
199 {
200 s_area *afixarea;
201
202 w_log( LL_INFO, "Start filefix scan..." );
203 if( ( afixarea = getNetMailArea( config, config->robotsArea ) ) == NULL )
204 {
205 afixarea = &( config->netMailAreas[0] );
206 }
207
208 scanNMArea( afixarea );
209 }
210