-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_post.c
253 lines (240 loc) · 6.49 KB
/
load_post.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*
* Copyright (C) 1992 by Rush Record
* Copyright (C) 1993 by Charles Sandmann (sandmann@clio.rice.edu)
*
* This file is part of ED.
*
* ED is free software; you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation.
*
* ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with ED
* (see the file COPYING). If not, write to the Free Software Foundation, 675
* Mass Ave, Cambridge, MA 02139, USA.
*/
#include "opsys.h"
#ifndef NO_NEWS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "unistd.h"
#include "memory.h"
#include "rec.h"
#include "window.h"
#include "ed_dec.h" /* global data */
extern Char *get_servername();
extern Char *version();
/******************************************************************************\
|Routine: count_equals
|Callby: load_post
|Purpose: Returns a count of how many '='s precede a subject entry.
|Arguments:
| rec is the record being examined.
\******************************************************************************/
Int count_equals(rec)
rec_ptr rec;
{
Char *p,*q;
p = q = rec->data + 42;
while(*q++ == '=');
return(--q - p);
}
/******************************************************************************\
|Routine: get_post_info
|Callby: load_post
|Purpose: Returns the username and host.
|Arguments:
| user is the returned user name.
| host is the returned host name.
| hostsize is the size of host.
\******************************************************************************/
void get_post_info(user,host,hostsize)
Char *user,*host;
Int hostsize;
{
Char *p;
#ifdef CUSERID_ENV
strcpy(user,getenv(CUSERID_ENV));
#else
strcpy(user,cuserid(NULL));
#endif
gethostname(host,hostsize);
if(!strchr(host,'.'))
{
#ifdef UCX
if((p = getenv("UCX$BIND_DOMAIN")))
{
strcat(host,".");
strcat(host,p);
}
#else
#ifdef WOLLONGONG
if((p = getenv("INET_DOMAIN_NAME")))
{
strcat(host,".");
strcat(host,p);
}
#else
/* getdomainname(domain,domainsize); */
#endif
#endif
}
}
/******************************************************************************\
|Routine: load_post_string
|Callby: load_post
|Purpose: Creates a new records, loads a string, appends to a buffer.
|Arguments:
| base is the base of the buffer that receives the new record.
| string is the string to append.
\******************************************************************************/
void load_post_string(base,string)
rec_ptr base;
Char *string;
{
rec_ptr new;
new = (rec_ptr)imalloc(sizeof(rec_node));
new->data = (Char *)imalloc((new->length = strlen(string)) + 1);
strcpy(new->data,string);
new->recflags = 1;
insq(new,base->prev);
}
/******************************************************************************\
|Routine: load_post
|Callby: edit
|Purpose: Loads the headers of a news posting.
|Arguments:
| base is the base of the buffer that receives the headers.
| subject is the subject of the posting.
\******************************************************************************/
void load_post(base,subject)
rec_ptr base;
Char *subject;
{
Char buf[512],subjbuf[512],resp[512],user[128],host[128],email[256],name[256];
Char *p,*q,*msg,*tmp,*m,*new;
rec_ptr r;
FILE *fp;
time_t t;
#ifdef VMS
Char wdy[8],mon[8];
Int day,hour,min,sec,year;
#endif
Int artnum,i;
/* get the identifying information */
get_post_info(user,host,sizeof(host));
/* try to get the real name from the passwd file */
name[0] = '\0';
if((fp = fopen("/etc/passwd","r")))
{
while(fgets(buf,sizeof(buf),fp))
if((p = strchr(buf,':')))
{
*p = '\0';
if(!strcmp(user,buf))
if((p = strchr(++p,':')))
if((p = strchr(++p,':')))
if((p = strchr(++p,':')))
if((q = strchr(++p,':')))
{
*q = '\0';
strcpy(name,p);
break;
}
}
fclose(fp);
}
sprintf(email,"%s@%s",user,host);
sprintf(buf,"Relay-Version: version ED-%s; site %s",version(),host);
load_post_string(base,buf);
sprintf(buf,"Posting-Version: version ED-%s; site %s",version(),host);
load_post_string(base,buf);
if(name[0] != '\0')
sprintf(buf,"From: %s <%s>",name,email);
else
sprintf(buf,"From: <%s>",email);
load_post_string(base,buf);
t = time(0);
#ifdef VMS
/*Sun Sep 16 01:03:52 1973\n\0*/
my_sscanf(ctime(&t),"%s%s%d%d:%d:%d%d",wdy,mon,&day,&hour,&min,&sec,&year);
sprintf(buf,"Date: %s, %2d %s %4d %2d:%2d:%2d",wdy,day,mon,year,hour,min,sec);
#else
strftime(buf,sizeof(buf),"Date: %a, %d %b %Y %T %Z",localtime(&t));
#endif
load_post_string(base,buf);
sprintf(buf,"Newsgroups: %s",WINDOW[CURWINDOW].filename);
load_post_string(base,buf);
sprintf(buf,"Message-ID: <%08x.%s>",time(NULL),email);
load_post_string(base,buf);
sprintf(buf,"Path: %s!%s",get_servername(),user);
load_post_string(base,buf);
/* handle posting references */
if(CURREC != BASE)
{
if(strncmp(subject,"Re: ",4) && strncmp(subject,"re: ",4))
{
sprintf(subjbuf,"Re: %s",subject);
subject = subjbuf;
}
r = CURREC;
msg = NULL;
while(1)
{
my_sscanf(r->data,"%d",&artnum);
sprintf(buf,"STAT %d",artnum);
news_command(buf);
news_response(resp,sizeof(resp));
if(resp[0] == '2')
{
news_command("HEAD");
news_response(resp,sizeof(resp));
if(resp[0] == '2')
while(1)
{
news_response(resp,sizeof(resp));
if(!strcmp(resp,"."))
break;
if(!strncmp(resp,"Message-ID: ",strlen("Message-ID: ")))
if((m = strchr(resp,'<')))
if(!msg)
{
msg = (Char *)imalloc(strlen(m) + 1);
strcpy(msg,m);
}
else
{
new = (Char *)imalloc(strlen(msg) + 1 + strlen(m) + 1);
sprintf(new,"%s %s",m,msg);
ifree(msg);
msg = new;
}
}
}
/* new back up to record with one less '=' */
if(!(i = count_equals(r)))
break;
do
{
if((r = r->prev) == BASE)
break;
} while(count_equals(r) != i - 1);
}
tmp = (Char *)imalloc(strlen("References: ") + strlen(msg) + 1);
sprintf(tmp,"References: %s",msg);
load_post_string(base,tmp);
ifree(msg);
ifree(tmp);
}
sprintf(buf,"Subject: %s",subject);
load_post_string(base,buf);
sprintf(buf,"Reply-To: %s",email);
load_post_string(base,buf);
buf[0] = '\0';
load_post_string(base,buf);
}
#endif