1 /*:ts=8*/
2 /*****************************************************************************
3  * FIDOGATE --- Gateway UNIX Mail/News <-> FTN NetMail/EchoMail
4  *
5  * $Id: kludge.c,v 4.10 2004/08/22 20:19:11 n0ll Exp $
6  *
7  * Processing of FTN ^A kludges in message body
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 /*
38  * Process the addressing kludge lines in the message body:
39  * ^ATOPT, ^AFMPT, ^AINTL. Remove these kludges from MsgBody and put
40  * the information in Message.
41  */
kludge_pt_intl(MsgBody * body,Message * msg,int del)42 void kludge_pt_intl(MsgBody *body, Message *msg, int del)
43 {
44     Textline *line;
45     Textlist *list;
46     char *p, *s;
47     Node node;
48 
49     list = &body->kludge;
50 
51     /* ^AINTL */
52     if( (p = kludge_get(list, "INTL", &line)) )
53     {
54 	p = strsave(p);
55 
56 	/* Retrieve addresses from ^AINTL */
57 	if( (s = strtok(p, " \t\r\n")) )	/* Destination */
58 	    if( asc_to_node(s, &node, FALSE) == OK )
59 		msg->node_to = node;
60 	if( (s = strtok(NULL, " \t\r\n")) )	/* Source */
61 	    if( asc_to_node(s, &node, FALSE) == OK )
62 		msg->node_from = node;
63 
64 	xfree(p);
65 
66 	if(del)
67 	    tl_delete(list, line);
68     }
69 
70     /* ^AFMPT */
71     if( (p = kludge_get(list, "FMPT", &line)) )
72     {
73 	msg->node_from.point = atoi(p);
74 
75 	if(del)
76 	    tl_delete(list, line);
77     }
78 
79     /* ^ATOPT */
80     if( (p = kludge_get(list, "TOPT", &line)) )
81     {
82 	msg->node_to.point = atoi(p);
83 
84 	if(del)
85 	    tl_delete(list, line);
86     }
87 }
88 
89 
90 
91 /*
92  * Get first next kludge line
93  */
kludge_getn(Textlist * tl,char * name,Textline ** ptline,int first)94 char *kludge_getn(Textlist *tl, char *name, Textline **ptline, int first)
95 {
96     static Textline *last_kludge;
97     char *s, *r;
98     int len;
99 
100     len = strlen(name);
101 
102     if(first)
103 	last_kludge = tl->first;
104 
105     while(last_kludge)
106     {
107 	s = last_kludge->line;
108 	if(s[0] == '\001'                     &&
109 	   !strnicmp(s+1, name, len)          &&
110 	   ( s[len+1]==' ' || s[len+1]==':' )    )	/* Found it */
111 	{
112 	    r = s + 1 + len;
113 	    /* Skip ':' and white space */
114 	    if(*r == ':')
115 		r++;
116 	    while( is_space(*r) )
117 		r++;
118 	    if(ptline)
119 		*ptline = last_kludge;
120 	    last_kludge = last_kludge->next;
121 
122 	    return r;
123 	}
124 
125 	last_kludge = last_kludge->next;
126     }
127 
128     /* Not found */
129     if(ptline)
130 	*ptline = NULL;
131     return NULL;
132 }
133 
134 
135 
136 /*
137  * Get first kludge line from a Textlist of all kludge lines.
138  */
kludge_get(Textlist * tl,char * name,Textline ** ptline)139 char *kludge_get(Textlist *tl, char *name, Textline **ptline)
140 {
141     return kludge_getn(tl, name, ptline, TRUE);
142 }
143