]> git.pld-linux.org Git - packages/mutt.git/blob - mutt-nntp.patch
- up to 1.4.2.1
[packages/mutt.git] / mutt-nntp.patch
1 diff -uNr mutt-1.4.orig/ChangeLog.nntp mutt-1.4/ChangeLog.nntp
2 --- mutt-1.4.orig/ChangeLog.nntp        Thu Jan  1 01:00:00 1970
3 +++ mutt-1.4/ChangeLog.nntp     Sun Nov  3 21:57:20 2002
4 @@ -0,0 +1,422 @@
5 +* Wed May 29 2002 Vsevolod Volkov <vvv@mutt.org.ua>
6 +- update to 1.4
7 +
8 +* Thu May  2 2002 Vsevolod Volkov <vvv@mutt.org.ua>
9 +- update to 1.3.99
10 +
11 +* Wed Mar 13 2002 Vsevolod Volkov <vvv@mutt.org.ua>
12 +- update to 1.3.28
13 +- fixed SIGSEGV in <get-message>, <get-parent>, <get-children>,
14 +  <reconstruct-thread> functions
15 +- fixed message about nntp reconnect
16 +- fixed <attach-news-message> function using browser
17 +- added support of Followup-To: poster
18 +- added %n (new articles) in group_index_format
19 +- posting articles without inews by default
20 +
21 +* Wed Jan 23 2002 Vsevolod Volkov <vvv@mutt.org.ua>
22 +- update to 1.3.27
23 +
24 +* Fri Jan 18 2002 Vsevolod Volkov <vvv@mutt.org.ua>
25 +- update to 1.3.26
26 +
27 +* Thu Jan  3 2002 Vsevolod Volkov <vvv@mutt.org.ua>
28 +- update to 1.3.25
29 +- accelerated speed of access to news->newsgroups hash (by <gul@gul.kiev.ua>)
30 +- added default content disposition
31 +
32 +* Mon Dec  3 2001 Vsevolod Volkov <vvv@mutt.org.ua>
33 +- update to 1.3.24
34 +
35 +* Fri Nov  9 2001 Vsevolod Volkov <vvv@mutt.org.ua>
36 +- update to 1.3.23.2
37 +- fixed segfault if mutt_conn_find() returns null
38 +
39 +* Wed Oct 31 2001 Vsevolod Volkov <vvv@mutt.org.ua>
40 +- update to 1.3.23.1
41 +- added support of LISTGROUP command
42 +- added support for servers with broken overview
43 +- disabled <flag-message> function on news server
44 +- fixed error storing bad authentication information
45 +
46 +* Wed Oct 10 2001 Vsevolod Volkov <vvv@mutt.org.ua>
47 +- update to 1.3.23
48 +- fixed typo in buffy.c
49 +- added substitution of %s parameter in $inews variable
50 +
51 +* Fri Aug 31 2001 Vsevolod Volkov <vvv@mutt.org.ua>
52 +- update to 1.3.22.1
53 +- update to 1.3.22
54 +
55 +* Thu Aug 23 2001 Vsevolod Volkov <vvv@mutt.org.ua>
56 +- update to 1.3.21
57 +
58 +* Wed Jul 25 2001 Vsevolod Volkov <vvv@mutt.org.ua>
59 +- update to 1.3.20
60 +- removed 'server-hook', use 'account-hook' instead
61 +- fixed error opening NNTP server without newsgroup using -f option
62 +
63 +* Fri Jun  8 2001 Vsevolod Volkov <vvv@mutt.org.ua>
64 +- update to 1.3.19
65 +
66 +* Sat May  5 2001 Vsevolod Volkov <vvv@mutt.org.ua>
67 +- update to 1.3.18
68 +- fixed typo in nntp_attempt_features()
69 +- changed algorithm of XGTITLE command testing
70 +- disabled writing of NNTP password in debug file
71 +- fixed reading and writing of long newsrc lines
72 +- changed checking of last line while reading lines from server
73 +- fixed possible buffer overrun in nntp_parse_newsrc_line()
74 +- removed checking of XHDR command
75 +- compare NNTP return codes without trailing space
76 +
77 +* Thu Mar 29 2001 Vsevolod Volkov <vvv@mutt.org.ua>
78 +- update to 1.3.17
79 +- support for 'LIST NEWSGROUPS' command to read descriptions
80 +
81 +* Fri Mar  2 2001 Vsevolod Volkov <vvv@mutt.org.ua>
82 +- update to 1.3.16
83 +
84 +* Wed Feb 14 2001 Vsevolod Volkov <vvv@mutt.org.ua>
85 +- update to 1.3.15
86 +
87 +* Sun Jan 28 2001 Vsevolod Volkov <vvv@mutt.org.ua>
88 +- update to 1.3.14
89 +- show number of tagged messages patch from Felix von Leitner <leitner@fefe.de>
90 +
91 +* Sun Dec 31 2000 Vsevolod Volkov <vvv@mutt.org.ua>
92 +- update to 1.3.13
93 +
94 +* Sat Dec 30 2000 Vsevolod Volkov <vvv@mutt.org.ua>
95 +- Fixed problem if last article in group is deleted
96 +
97 +* Fri Dec 22 2000 Vsevolod Volkov <vvv@mutt.org.ua>
98 +- Fixed checking of XGTITLE command on some servers
99 +
100 +* Mon Dec 18 2000 Vsevolod Volkov <vvv@mutt.org.ua>
101 +- Added \r in AUTHINFO commands
102 +
103 +* Mon Nov 27 2000 Vsevolod Volkov <vvv@mutt.org.ua>
104 +- update to 1.3.12
105 +
106 +* Wed Nov  1 2000 Vsevolod Volkov <vvv@mutt.org.ua>
107 +- update to 1.3.11
108 +- fixed error opening newsgroup from mutt started with -g or -G
109 +
110 +* Thu Oct 12 2000 Vsevolod Volkov <vvv@mutt.org.ua>
111 +- update to 1.3.10
112 +- hotkey 'G' (get-message) replaced with '^G'
113 +
114 +* Thu Sep 21 2000 Vsevolod Volkov <vvv@mutt.org.ua>
115 +- update to 1.3.9
116 +- changed delay displaying error messages from 1 to 2 seconds
117 +- fixed error compiling with nntp and without imap
118 +
119 +* Wed Sep  6 2000 Vsevolod Volkov <vvv@mutt.org.ua>
120 +- fixed catchup in index
121 +- fixed nntp_open_mailbox()
122 +
123 +* Sat Sep  2 2000 Vsevolod Volkov <vvv@mutt.org.ua>
124 +- functions <edit> and <delete-entry> disabled
125 +- format of news mailbox names changed to url form
126 +- option nntp_attempts removed
127 +- option reconnect_news renamed to nntp_reconnect
128 +- default value of nntp_poll changed from 30 to 60
129 +- error handling improved
130 +
131 +* Wed Aug 30 2000 Vsevolod Volkov <vvv@mutt.org.ua>
132 +- update to 1.3.8
133 +- new option show_only_unread
134 +- add newsgroup completion
135 +
136 +* Fri Aug  4 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
137 +- update to 1.3.7
138 +
139 +* Sat Jul 29 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
140 +- update to 1.3.6
141 +
142 +* Sun Jul  9 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
143 +- update to 1.3.5
144 +- authentication code update
145 +- fix for changing to newsgroup from mailbox with read messages
146 +- socket code optimization
147 +
148 +* Wed Jun 21 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
149 +- update to 1.3.4
150 +
151 +* Wed Jun 14 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
152 +- don't substitute current newsgroup with deleted new messages
153 +
154 +* Mon Jun 12 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
155 +- update to 1.3.3
156 +- fix for substitution of newsgroup after reconnection
157 +- fix for loading newsgroups with very long names
158 +- fix for loading more than 32768 newsgroups
159 +
160 +* Wed May 24 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
161 +- update to 1.3.2
162 +
163 +* Sat May 20 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
164 +- update to 1.3.1
165 +
166 +* Fri May 12 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
167 +- update to 1.3
168 +
169 +* Thu May 11 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
170 +- update to 1.2
171 +
172 +* Thu May  4 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
173 +- update to 1.1.14
174 +
175 +* Sun Apr 23 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
176 +- update to 1.1.12
177 +
178 +* Fri Apr  7 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
179 +- add substitution of newsgroup with new messages by default
180 +
181 +* Wed Apr  5 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
182 +- add attach message from newsgroup
183 +- add one-line help in newsreader mode
184 +- disable 'change-dir' command in newsgroups browser
185 +- add -G option
186 +
187 +* Tue Apr  4 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
188 +- get default newsserver name from file /etc/nntpserver
189 +- use case insensitive server names
190 +- add print-style sequence %s to $newsrc
191 +- add -g option
192 +
193 +* Sat Apr  1 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
194 +- remove 'X-FTN-Origin' header processing
195 +
196 +* Thu Mar 30 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
197 +- update to 1.1.11
198 +- update to 1.1.10
199 +
200 +* Thu Mar 23 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
201 +- fix mutt_select_newsserver()
202 +- remove 'toggle-mode' function
203 +- add 'change-newsgroup' function
204 +
205 +* Wed Mar 22 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
206 +- fix server-hook
207 +
208 +* Tue Mar 21 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
209 +- fix error 'bounce' function after 'post'
210 +- add 'forward to newsgroup' function
211 +
212 +* Mon Mar 20 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
213 +- 'forward' function works in newsreader mode
214 +- add 'post' and 'followup' functions to pager and attachment menu
215 +- fix active descriptions and allowed flag reload
216 +
217 +* Tue Mar 14 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
218 +- update to 1.1.9
219 +- remove deleted newsgroups from list
220 +
221 +* Mon Mar 13 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
222 +- update .newsrc in browser
223 +
224 +* Sun Mar 12 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
225 +- reload .newsrc if externally modified
226 +- fix active cache update
227 +
228 +* Sun Mar  5 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
229 +- update to 1.1.8
230 +
231 +* Sat Mar  4 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
232 +- patch *.update_list_file is not required
233 +- count lines when loading descriptions
234 +- remove cache of unsubscribed newsgroups
235 +
236 +* Thu Mar  2 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
237 +- load list of newsgroups from cache faster
238 +
239 +* Wed Mar  1 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
240 +- update to 1.1.7
241 +
242 +* Tue Feb 29 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
243 +- fix unread messages in browser
244 +- fix newsrc_gen_entries()
245 +
246 +* Mon Feb 28 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
247 +- fix mutt_newsgroup_stat()
248 +- fix nntp_delete_cache()
249 +- fix nntp_get_status()
250 +- fix check_children()
251 +- fix nntp_fetch_headers()
252 +
253 +* Fri Feb 25 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
254 +- update to 1.1.5
255 +
256 +* Thu Feb 24 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
257 +- fix updating new messages in cache
258 +
259 +* Mon Feb 21 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
260 +- change default cache filenames
261 +- fix updating new messages in cache
262 +
263 +* Fri Feb 18 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
264 +- fix segmentation fault in news groups browser
265 +
266 +* Tue Feb 15 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
267 +- update to 1.1.4
268 +
269 +* Thu Feb 10 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
270 +- update to 1.1.3
271 +
272 +* Sun Jan 30 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
273 +- add X-Comment-To editing
274 +- add my_hdr support for Newsgroups:, Followup-To: and X-Comment-To: headers
275 +- add variables $ask_followup_to and $ask_x_comment_to
276 +
277 +* Fri Jan 28 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
278 +- update to 1.1.2
279 +
280 +* Wed Aug 23 2000 Andrej Gritsenko <andrej@lucky.net>
281 +- nntp.c: inserted server hook when opened a newsgroup - for
282 +  difference between mail and news reader environment
283 +- parse.c: `X-FTN-Origin:' processed for bad Fido gates
284 +
285 +* Tue Aug 22 2000 Vsevolod Volkov <vvv@mutt.org.ua>
286 +- browser.c, complete.c: newsgroup completion patch
287 +
288 +* Wed Dec 22 1999 Andrej Gritsenko <andrej@lucky.net>
289 +- send.c: fixed bug with `Subject:' on followup
290 +
291 +* Sat Dec 18 1999 Andrej Gritsenko <andrej@lucky.net>
292 +- updated to 1.1.1
293 +
294 +* Tue Oct 26 1999 Andrej Gritsenko <andrej@lucky.net>
295 +- updated to 1.1
296 +
297 +* Mon Jun 14 1999 Andrej Gritsenko <andrej@lucky.net>
298 +- sendlib.c: use $mime_subject for news articles only
299 +
300 +* Fri Jun 11 1999 Edouard G. Parmelan <Edouard.Parmelan@quadratec.fr>
301 +- nntp.c: bugfix with number of new articles
302 +
303 +* Thu Jun 10 1999 Andrej Gritsenko <andrej@lucky.net>
304 +- nntp.c: fixed incomplete creating of index file
305 +
306 +* Wed Jun  9 1999 Andrej Gritsenko <andrej@lucky.net>
307 +- updated to 0.96.3
308 +- doc/manual*: documentation updated
309 +
310 +* Sun Feb 21 1999 Andrej Gritsenko <andrej@lucky.net>
311 +- browser.c, newsrc.c, nntp.c: couple of fixes
312 +
313 +* Wed Dec 16 1998 Andrej Gritsenko <andrej@lucky.net>
314 +- curs_main.c, newsrc.c, nntp.c: fixes on number of read
315 +  articles
316 +
317 +* Tue Dec 15 1998 Vikas Agnihotri <vikasa@att.com>
318 +- nntp.c: fix with gone cache files
319 +
320 +* Tue Dec 15 1998 Andrej Gritsenko <andrej@lucky.net>
321 +- newsrc.c, nntp.c: fixes on number of read articles
322 +
323 +* Mon Dec 14 1998 Andrej Gritsenko <andrej@lucky.net>
324 +- browser.c, newsrc.c, nntp.c, nntp.h: changed then simplified
325 +  nntp_parse_xover()
326 +
327 +* Mon Dec 14 1998 Vikas Agnihotri <vikasa@att.com>
328 +- browser.c: cosmetic patch
329 +- nntp.c: say "Fetching %s from server..."
330 +
331 +* Sun Dec 13 1998 Andrej Gritsenko <andrej@lucky.net>
332 +- commands.c, newsrc.c, nntp.c, nntp.h: don't save newsrc file
333 +  so often (noted by Vikas Agnihotri)
334 +
335 +* Sat Dec 12 1998 Andrej Gritsenko <andrej@lucky.net>
336 +- browser.c, functions.h, nntp.c, nntp.h: fixed incorrect first
337 +  active loading
338 +
339 +* Wed Dec  9 1998 Vikas Agnihotri <vikasa@att.com>
340 +- nntp.c: fixed bug in `reconstruct-thread' function
341 +- curs_main.c, nntp.c: fixed the bug in non-XOVER case of get
342 +  headers
343 +
344 +* Tue Dec  8 1998 Andrej Gritsenko <andrej@lucky.net>
345 +- nntp.c: fixed error in getting status of article
346 +
347 +* Tue Dec  8 1998 Vikas Agnihotri <vikasa@att.com>
348 +- mutt.h, pattern.c: added `~w' search pattern
349 +
350 +* Tue Dec  8 1998 Andrej Gritsenko <andrej@lucky.net>
351 +- nntp.c: bugfix when get children
352 +
353 +* Tue Dec  8 1998 Vikas Agnihotri <vikasa@att.com>
354 +- newsrc.c: bugfix in mutt_newsgroup_catchup()
355 +
356 +* Tue Dec  8 1998 Andrej Gritsenko <andrej@lucky.net>
357 +- browser.c: bugfix in _mutt_select_file()
358 +
359 +* Sat Dec  5 1998 Andrej Gritsenko <andrej@lucky.net>
360 +- browser.c, newsrc.c, nntp.c, nntp.h: fix the sorting of
361 +  newsgroups in browser (from Vikas Agnihotri)
362 +
363 +* Fri Dec  4 1998 Vikas Agnihotri <vikasa@att.com>
364 +- OPS, curs_main.c, functions.h, nntp.c, nntp.h: new functions:
365 +  `get-children' and `reconstruct-thread'
366 +
367 +* Thu Dec  3 1998 Vikas Agnihotri <vikasa@att.com>
368 +- OPS, curs_main.c, functions.h, nntp.c, nntp.h: new functions:
369 +  `get-message' and `get-parent'
370 +
371 +* Wed Dec  2 1998 Vikas Agnihotri <vikasa@att.com>
372 +- OPS, compose.c, curs_main.c, functions.h, parse.c, send.c,
373 +  sendlib.c: added `Followup-To:' field editing
374 +
375 +* Wed Dec  2 1998 Vikas Agnihotri <vikasa@att.com>
376 +- OPS, browser.c, functions.h: new `load-active' function
377 +
378 +* Tue Dec  1 1998 Andrej Gritsenko <andrej@lucky.net>
379 +- browser.c: added option for blank %s in $group_index_format
380 +- hdrline.c, lib.c, mutt.h, parse.c: added %g and %W parameters
381 +  to $pager_format
382 +- hook.c, newsrc.c, nntp.c, sendlib.c: some small bugfixes
383 +
384 +* Mon Nov 30 1998 Andrej Gritsenko <andrej@lucky.net>
385 +- send.c: bugfix in `Followup-To:' field
386 +
387 +* Sun Nov 29 1998 Vikas Agnihotri <vikasa@att.com>
388 +- compose.c, lib.c, parse.c, protos.h: remove white spaces from
389 +  `Newsgroup:' field to prevent a unnecessary rejection of article
390 +
391 +* Sat Nov 28 1998 Vikas Agnihotri <vikasa@att.com>
392 +- newsrc.c: fixed bug in catchup
393 +
394 +* Sat Nov 28 1998 Vikas Agnihotri <vikasa@att.com>
395 +- browser.c: make indicator advance when (un)subscribe
396 +
397 +* Sat Nov 28 1998 Andrej Gritsenko <andrej@lucky.net>
398 +- newsrc.c: fixed segmentation fault in newsrc_update_line()
399 +
400 +* Sat Nov 28 1998 Andrej Gritsenko <andrej@lucky.net>
401 +- OPS, browser.c, functions.h, init.h, mutt.h, mx.c, newsrc.c,
402 +  nntp.c, nntp.h: corrected reading of newsrc file and added new
403 +  `catchup' function
404 +
405 +* Thu Nov 26 1998 Andrej Gritsenko <andrej@lucky.net>
406 +- browser.c, newsrc.c: implementation of `(un)subscribe-pattern'
407 +  functions from Vikas Agnihotri
408 +- globals.h, init.h, nntp.h, nntp.c: added variable $nntp_poll
409 +  to avoid of polling newsserver on each keypressing
410 +
411 +* Thu Nov 26 1998 Andrej Gritsenko <andrej@lucky.net>
412 +- nntp.c, socket.c: fixed parsing of long XOVER lines
413 +- send.c: removed silly ask for newsgroup name (noted by Vikas
414 +  Agnihotri)
415 +
416 +* Wed Nov 25 1998
417 +- commands.c: bugfix in mutt_update_list_file()
418 +
419 +* Wed Nov 25 1998 Andrej Gritsenko <andrej@lucky.net>
420 +- updated to mutt-0.94.17
421 +- init.c, nntp.c, nntp.h, parse.c, send.c: couple of bugfixes
422 +  from Vikas Agnihotri
423 +
424 +* Sat Nov 21 1998 Andrej Gritsenko <andrej@lucky.net>
425 +- [mutt-0.94.13] couple of files: pre-alpha version of patch,
426 +  partially based on code that written by Brandon Long
427 diff -uNr mutt-1.4.orig/Makefile.am mutt-1.4/Makefile.am
428 --- mutt-1.4.orig/Makefile.am   Sun Nov  3 21:42:52 2002
429 +++ mutt-1.4/Makefile.am        Sun Nov  3 21:57:20 2002
430 @@ -68,7 +68,8 @@
431  EXTRA_mutt_SOURCES = account.c md5c.c mutt_sasl.c mutt_socket.c mutt_ssl.c \
432         mutt_tunnel.c pop.c pop_auth.c pop_lib.c pgp.c pgpinvoke.c pgpkey.c \
433         pgplib.c sha1.c pgpmicalg.c gnupgparse.c resize.c dotlock.c remailer.c \
434 -       browser.h mbyte.h remailer.h url.h mutt_ssl_nss.c pgppacket.c 
435 +       browser.h mbyte.h remailer.h url.h mutt_ssl_nss.c pgppacket.c \
436 +       nntp.c newsrc.c
437  
438  EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP TODO configure acconfig.h account.h \
439         attach.h buffy.h charset.h compress.h copy.h dotlock.h functions.h \
440 @@ -77,6 +78,7 @@
441         mutt_regex.h mutt_sasl.h mutt_socket.h mutt_ssl.h mutt_tunnel.h \
442         mx.h pager.h pgp.h pop.h protos.h reldate.h rfc1524.h rfc2047.h \
443         rfc2231.h rfc822.h sha1.h sort.h mime.types VERSION prepare \
444 +       nntp.h ChangeLog.nntp \
445         _regex.h OPS.MIX README.SECURITY remailer.c remailer.h browser.h \
446         mbyte.h lib.h extlib.c pgpewrap.c pgplib.h Muttrc.head Muttrc \
447         makedoc.c stamp-doc-rc README.SSL \
448 diff -uNr mutt-1.4.orig/Muttrc mutt-1.4/Muttrc
449 --- mutt-1.4.orig/Muttrc        Sun Nov  3 21:42:52 2002
450 +++ mutt-1.4/Muttrc     Sun Nov  3 21:57:20 2002
451 @@ -185,6 +185,28 @@
452  # editing the body of an outgoing message.
453  # 
454  # 
455 +# set ask_follow_up=no
456 +#
457 +# Name: ask_follow_up
458 +# Type: boolean
459 +# Default: no
460 +# 
461 +# 
462 +# If set, Mutt will prompt you for follow-up groups before editing
463 +# the body of an outgoing message.
464 +# 
465 +# 
466 +# set ask_x_comment_to=no
467 +#
468 +# Name: ask_x_comment_to
469 +# Type: boolean
470 +# Default: no
471 +# 
472 +# 
473 +# If set, Mutt will prompt you for x-comment-to field before editing
474 +# the body of an outgoing message.
475 +# 
476 +# 
477  # set attach_format="%u%D%I %t%4n %T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] "
478  #
479  # Name: attach_format
480 @@ -308,6 +330,17 @@
481  # bouncing messages.  Postfix users may wish to unset this variable.
482  # 
483  # 
484 +# set catchup_newsgroup=ask-yes
485 +#
486 +# Name: catchup_newsgroup
487 +# Type: quadoption
488 +# Default: ask-yes
489 +# 
490 +# 
491 +# If this variable is set, Mutt will mark all articles in newsgroup
492 +# as read when you quit the newsgroup (catchup newsgroup).
493 +# 
494 +# 
495  # set charset=""
496  #
497  # Name: charset
498 @@ -734,6 +767,19 @@
499  # resulting in two copies of the same email for you.
500  # 
501  # 
502 +# set followup_to_poster=ask-yes
503 +#
504 +# Name: followup_to_poster
505 +# Type: quadoption
506 +# Default: ask-yes
507 +# 
508 +# 
509 +# If this variable is set and the keyword "poster" is present in
510 +# Followup-To header, follow-up to newsgroup function is not
511 +# permitted.  The message will be mailed to the submitter of the
512 +# message via mail.
513 +# 
514 +# 
515  # set force_name=no
516  #
517  # Name: force_name
518 @@ -818,6 +864,28 @@
519  # "Franklin" to "Franklin, Steve".
520  # 
521  # 
522 +# set group_index_format="%4C %M%N %5s  %-45.45f %d"
523 +#
524 +# Name: group_index_format
525 +# Type: string
526 +# Default: "%4C %M%N %5s  %-45.45f %d"
527 +# 
528 +# 
529 +# This variable allows you to customize the newsgroup browser display to
530 +# your personal taste.  This string is similar to ``index_format'', but
531 +# has its own set of printf()-like sequences:
532 +# 
533 +# %C      current newsgroup number
534 +# %d      description of newsgroup (becomes from server)
535 +# %f      newsgroup name
536 +# %M      - if newsgroup not allowed for direct post (moderated for example)
537 +# %N      N if newsgroup is new, u if unsubscribed, blank otherwise
538 +# %n      number of new articles in newsgroup
539 +# %s      number of unread articles in newsgroup
540 +# %>X     right justify the rest of the string and pad with character "X"
541 +# %|X     pad to the end of the line with character "X"
542 +# 
543 +# 
544  # set hdrs=yes
545  #
546  # Name: hdrs
547 @@ -1187,6 +1255,7 @@
548  # %E      number of messages in current thread
549  # %f      entire From: line (address + real name)
550  # %F      author name, or recipient name if the message is from you
551 +# %g      newsgroup name (if compiled with nntp support)
552  # %i      message-id of the current message
553  # %l      number of lines in the message
554  # %L      If an address in the To or CC header field matches an address
555 @@ -1204,6 +1273,7 @@
556  # %T      the appropriate character from the $to_chars string
557  # %u      user (login) name of the author
558  # %v      first name of the author, or the recipient if the message is from you
559 +# %W      name of organization of author (`organization:' field)
560  # %y      `x-label:' field, if present
561  # %Y      `x-label' field, if present, and (1) not at part of a thread tree,
562  #         (2) at the top of a thread, or (3) `x-label' is different from
563 @@ -1227,6 +1297,22 @@
564  # See also: ``$to_chars''.
565  # 
566  # 
567 +# set inews=""
568 +#
569 +# Name: inews
570 +# Type: path
571 +# Default: ""
572 +# 
573 +# 
574 +# If set, specifies the program and arguments used to deliver news posted
575 +# by Mutt.  Otherwise, mutt posts article using current connection to
576 +# news server.  The following printf-style sequence is understood:
577 +# 
578 +# %s      newsserver name
579 +# 
580 +# Example: set inews="/usr/local/bin/inews -hS"
581 +# 
582 +# 
583  # set ispell="/usr/bin/ispell"
584  #
585  # Name: ispell
586 @@ -1496,6 +1582,18 @@
587  # be attached to the newly composed message if this option is set.
588  # 
589  # 
590 +# set mime_subject=yes
591 +#
592 +# Name: mime_subject
593 +# Type: boolean
594 +# Default: yes
595 +# 
596 +# 
597 +# If unset, 8-bit ``subject:'' line in article header will not be
598 +# encoded according to RFC2047 to base64.  This is useful when message
599 +# is Usenet article, because MIME for news is nonstandard feature.
600 +# 
601 +# 
602  # set mix_entry_format="%4n %c %-16s %a"
603  #
604  # Name: mix_entry_format
605 @@ -1550,6 +1648,118 @@
606  # escape sequences see the section on ``$index_format''.
607  # 
608  # 
609 +# set news_cache_dir="~/.mutt"
610 +#
611 +# Name: news_cache_dir
612 +# Type: path
613 +# Default: "~/.mutt"
614 +# 
615 +# 
616 +# This variable pointing to directory where Mutt will save cached news
617 +# articles headers in. If unset, headers will not be saved at all
618 +# and will be reloaded each time when you enter to newsgroup.
619 +# 
620 +# 
621 +# set news_server=""
622 +#
623 +# Name: news_server
624 +# Type: string
625 +# Default: ""
626 +# 
627 +# 
628 +# This variable specifies domain name or address of NNTP server. It
629 +# defaults to the newsserver specified in the environment variable
630 +# $NNTPSERVER or contained in the file /etc/nntpserver.  You can also
631 +# specify username and an alternative port for each newsserver, ie:
632 +# 
633 +# [nntp[s]://][username[:password]@]newsserver[:port]
634 +# 
635 +# 
636 +# set newsrc="~/.newsrc"
637 +#
638 +# Name: newsrc
639 +# Type: path
640 +# Default: "~/.newsrc"
641 +# 
642 +# 
643 +# The file, containing info about subscribed newsgroups - names and
644 +# indexes of read articles.  The following printf-style sequence
645 +# is understood:
646 +# 
647 +# %s      newsserver name
648 +# 
649 +# 
650 +# set nntp_context=1000
651 +#
652 +# Name: nntp_context
653 +# Type: number
654 +# Default: 1000
655 +# 
656 +# 
657 +# This variable defines number of articles which will be in index when
658 +# newsgroup entered.  If active newsgroup have more articles than this
659 +# number, oldest articles will be ignored.  Also controls how many
660 +# articles headers will be saved in cache when you quit newsgroup.
661 +# 
662 +# 
663 +# set nntp_load_description=yes
664 +#
665 +# Name: nntp_load_description
666 +# Type: boolean
667 +# Default: yes
668 +# 
669 +# 
670 +# This variable controls whether or not descriptions for each newsgroup
671 +# must be loaded when newsgroup is added to list (first time list
672 +# loading or new newsgroup adding).
673 +# 
674 +# 
675 +# set nntp_user=""
676 +#
677 +# Name: nntp_user
678 +# Type: string
679 +# Default: ""
680 +# 
681 +# 
682 +# Your login name on the NNTP server.  If unset and NNTP server requires
683 +# authentification, Mutt will prompt you for your account name when you
684 +# connect to newsserver.
685 +# 
686 +# 
687 +# set nntp_pass=""
688 +#
689 +# Name: nntp_pass
690 +# Type: string
691 +# Default: ""
692 +# 
693 +# 
694 +# Your password for NNTP account.
695 +# 
696 +# 
697 +# set nntp_poll=60
698 +#
699 +# Name: nntp_poll
700 +# Type: number
701 +# Default: 60
702 +# 
703 +# 
704 +# The time in seconds until any operations on newsgroup except post new
705 +# article will cause recheck for new news.  If set to 0, Mutt will
706 +# recheck newsgroup on each operation in index (stepping, read article,
707 +# etc.).
708 +# 
709 +# 
710 +# set nntp_reconnect=ask-yes
711 +#
712 +# Name: nntp_reconnect
713 +# Type: quadoption
714 +# Default: ask-yes
715 +# 
716 +# 
717 +# Controls whether or not Mutt will try to reconnect to newsserver when
718 +# connection lost.
719 +# 
720 +# 
721  # set pager="builtin"
722  #
723  # Name: pager
724 @@ -2293,6 +2503,19 @@
725  # string after the inclusion of a message which is being replied to.
726  # 
727  # 
728 +# set post_moderated=ask-yes
729 +#
730 +# Name: post_moderated
731 +# Type: quadoption
732 +# Default: ask-yes
733 +# 
734 +# 
735 +# If set to yes, Mutt will post article to newsgroup that have
736 +# not permissions to posting (e.g. moderated).  Note: if newsserver
737 +# does not support posting to that newsgroup or totally read-only, that
738 +# posting will not have an effect.
739 +# 
740 +# 
741  # set postpone=ask-yes
742  #
743  # Name: postpone
744 @@ -2802,6 +3025,41 @@
745  # shell from /etc/passwd is used.
746  # 
747  # 
748 +# set save_unsubscribed=no
749 +#
750 +# Name: save_unsubscribed
751 +# Type: boolean
752 +# Default: no
753 +# 
754 +# 
755 +# When set, info about unsubscribed newsgroups will be saved into
756 +# ``newsrc'' file and into cache.
757 +# 
758 +# 
759 +# set show_new_news=yes
760 +#
761 +# Name: show_new_news
762 +# Type: boolean
763 +# Default: yes
764 +# 
765 +# 
766 +# If set, newsserver will be asked for new newsgroups on entering
767 +# the browser.  Otherwise, it will be done only once for a newsserver.
768 +# Also controls whether or not number of new articles of subscribed
769 +# newsgroups will be then checked.
770 +# 
771 +# 
772 +# set show_only_unread=no
773 +#
774 +# Name: show_only_unread
775 +# Type: boolean
776 +# Default: no
777 +# 
778 +# 
779 +# If set, only subscribed newsgroups that contain unread articles
780 +# will be displayed in browser.
781 +# 
782 +# 
783  # set sig_dashes=yes
784  #
785  # Name: sig_dashes
786 @@ -3285,6 +3543,18 @@
787  # command.
788  # 
789  # 
790 +# set use_ipv6=yes
791 +#
792 +# Name: use_ipv6
793 +# Type: boolean
794 +# Default: yes
795 +# 
796 +# 
797 +# When set, Mutt will look for IPv6 addresses of hosts it tries to
798 +# contact.  If this option is unset, Mutt will restrict itself to IPv4 addresses.
799 +# Normally, the default should work.
800 +# 
801 +# 
802  # set user_agent=yes
803  #
804  # Name: user_agent
805 @@ -3387,3 +3657,14 @@
806  # messages to be sent.  Exim users may wish to use this.
807  # 
808  # 
809 +# set x_comment_to=no
810 +#
811 +# Name: x_comment_to
812 +# Type: boolean
813 +# Default: no
814 +# 
815 +# 
816 +# If set, Mutt will add ``X-Comment-To:'' field (that contains full
817 +# name of original article author) to article that followuped to newsgroup.
818 +# 
819 +# 
820 diff -uNr mutt-1.4.orig/Muttrc.head mutt-1.4/Muttrc.head
821 --- mutt-1.4.orig/Muttrc.head   Sun Nov  3 21:42:51 2002
822 +++ mutt-1.4/Muttrc.head        Thu Jan  1 01:00:00 1970
823 @@ -1,43 +0,0 @@
824 -#
825 -# System configuration file for Mutt
826 -#
827 -
828 -# default list of header fields to weed when displaying
829 -#
830 -ignore "from " received content- mime-version status x-status message-id
831 -ignore sender references return-path lines
832 -
833 -# imitate the old search-body function
834 -macro index \eb '/~b ' 'search in message bodies'
835 -
836 -# simulate the old url menu
837 -macro index \cb |urlview\n 'call urlview to extract URLs out of a message'
838 -macro pager \cb |urlview\n 'call urlview to extract URLs out of a message'
839 -
840 -# Show documentation when pressing F1
841 -macro generic <f1> "!less /usr/local/doc/mutt/manual.txt\n" "Show Mutt documentation"
842 -macro index   <f1> "!less /usr/local/doc/mutt/manual.txt\n" "Show Mutt documentation"
843 -macro pager   <f1> "!less /usr/local/doc/mutt/manual.txt\n" "Show Mutt documentation"
844 -
845 -# Use folders which match on \\.gz$ as gzipped folders:
846 -# open-hook \\.gz$ "gzip -cd %f > %t"
847 -# close-hook \\.gz$ "gzip -c %t > %f"
848 -# append-hook \\.gz$ "gzip -c %t >> %f"
849 -
850 -# open-hook \\.bz2$ "bzip2 -cd %f > %t"
851 -# close-hook \\.bz2$ "bzip2 -c %t > %f"
852 -# append-hook \\.bz2$ "bzip2 -c %t >> %f"
853 -
854 -# If Mutt is unable to determine your site's domain name correctly, you can
855 -# set the default here.
856 -#
857 -# set hostname=cs.hmc.edu
858 -
859 -# If your sendmail supports the -B8BITMIME flag, enable the following
860 -#
861 -# set use_8bitmime
862 -
863 -##
864 -## More settings
865 -##
866 -
867 diff -uNr mutt-1.4.orig/OPS mutt-1.4/OPS
868 --- mutt-1.4.orig/OPS   Sun Nov  3 21:42:52 2002
869 +++ mutt-1.4/OPS        Sun Nov  3 21:57:20 2002
870 @@ -7,13 +7,15 @@
871  OP_BROWSER_NEW_FILE "select a new file in this directory"
872  OP_BROWSER_VIEW_FILE "view file"
873  OP_BROWSER_TELL "display the currently selected file's name"
874 -OP_BROWSER_SUBSCRIBE "subscribe to current mailbox (IMAP only)"
875 -OP_BROWSER_UNSUBSCRIBE "unsubscribe to current mailbox (IMAP only)"
876 +OP_CATCHUP "mark all articles in newsgroup as read"
877 +OP_BROWSER_SUBSCRIBE "subscribe to current (IMAP/NNTP only)"
878 +OP_BROWSER_UNSUBSCRIBE "unsubscribe to current (IMAP/NNTP only)"
879  OP_BROWSER_TOGGLE_LSUB "toggle view all/subscribed mailboxes (IMAP only)"
880  OP_CHANGE_DIRECTORY "change directories"
881  OP_CHECK_NEW "check mailboxes for new mail"
882  OP_COMPOSE_ATTACH_FILE "attach a file(s) to this message"
883  OP_COMPOSE_ATTACH_MESSAGE "attach message(s) to this message"
884 +OP_COMPOSE_ATTACH_NEWS_MESSAGE "attach newsmessage(s) to this message"
885  OP_COMPOSE_EDIT_BCC "edit the BCC list"
886  OP_COMPOSE_EDIT_CC "edit the CC list"
887  OP_COMPOSE_EDIT_DESCRIPTION "edit attachment description"
888 @@ -24,7 +26,10 @@
889  OP_COMPOSE_EDIT_HEADERS "edit the message with headers"
890  OP_COMPOSE_EDIT_MESSAGE "edit the message"
891  OP_COMPOSE_EDIT_MIME "edit attachment using mailcap entry"
892 +OP_COMPOSE_EDIT_NEWSGROUPS "edit the newsgroups list"
893  OP_COMPOSE_EDIT_REPLY_TO "edit the Reply-To field"
894 +OP_COMPOSE_EDIT_FOLLOWUP_TO "edit the Followup-To field"
895 +OP_COMPOSE_EDIT_X_COMMENT_TO "edit the X-Comment-To field"
896  OP_COMPOSE_EDIT_SUBJECT "edit the subject of this message"
897  OP_COMPOSE_EDIT_TO "edit the TO list"
898  OP_CREATE_MAILBOX "create a new mailbox (IMAP only)"
899 @@ -84,8 +89,13 @@
900  OP_FILTER "filter attachment through a shell command"
901  OP_FIRST_ENTRY "move to the first entry"
902  OP_FLAG_MESSAGE "toggle a message's 'important' flag"
903 +OP_FOLLOWUP "followup to newsgroup"
904 +OP_FORWARD_TO_GROUP "forward to newsgroup"
905  OP_FORWARD_MESSAGE "forward a message with comments"
906  OP_GENERIC_SELECT_ENTRY "select the current entry"
907 +OP_GET_CHILDREN "get all children of the current message"
908 +OP_GET_MESSAGE "get message with Message-Id"
909 +OP_GET_PARENT "get parent of the current message"
910  OP_GROUP_REPLY "reply to all recipients"
911  OP_HALF_DOWN "scroll down 1/2 page"
912  OP_HALF_UP "scroll up 1/2 page"
913 @@ -93,13 +103,17 @@
914  OP_JUMP "jump to an index number"
915  OP_LAST_ENTRY "move to the last entry"
916  OP_LIST_REPLY "reply to specified mailing list"
917 +OP_LOAD_ACTIVE "load active file from NNTP server"
918  OP_MACRO "execute a macro"
919  OP_MAIL "compose a new mail message"
920  OP_MAIN_BREAK_THREAD "break the thread in two"
921  OP_MAIN_CHANGE_FOLDER "open a different folder"
922  OP_MAIN_CHANGE_FOLDER_READONLY "open a different folder in read only mode"
923 +OP_MAIN_CHANGE_GROUP "open a different newsgroup"
924 +OP_MAIN_CHANGE_GROUP_READONLY "open a different newsgroup in read only mode"
925  OP_MAIN_CLEAR_FLAG "clear a status flag from a message"
926  OP_MAIN_DELETE_PATTERN "delete messages matching a pattern"
927 +OP_RECONSTRUCT_THREAD "reconstruct thread containing current message"
928  OP_MAIN_IMAP_FETCH "force retrieval of mail from IMAP server"
929  OP_MAIN_FETCH_MAIL "retrieve mail from POP server"
930  OP_MAIN_FIRST_MESSAGE "move to the first message"
931 @@ -134,6 +148,7 @@
932  OP_PAGER_SKIP_QUOTED "skip beyond quoted text"
933  OP_PAGER_TOP "jump to the top of the message"
934  OP_PIPE "pipe message/attachment to a shell command"
935 +OP_POST "post message to newsgroup"
936  OP_PREV_ENTRY "move to the previous entry"
937  OP_PREV_LINE "scroll up one line"
938  OP_PREV_PAGE "move to the previous page"
939 @@ -159,17 +174,21 @@
940  OP_SIG_SEARCH "search signatures matching a pattern"
941  OP_SORT "sort messages"
942  OP_SORT_REVERSE "sort messages in reverse order"
943 +OP_SUBSCRIBE_PATTERN "subscribe to newsgroups matching a pattern"
944  OP_TAG "tag the current entry"
945  OP_TAG_PREFIX "apply next function to tagged messages"
946  OP_TAG_SUBTHREAD "tag the current subthread"
947  OP_TAG_THREAD "tag the current thread"
948  OP_TOGGLE_NEW "toggle a message's 'new' flag"
949 +OP_TOGGLE_READ "toggle view of read messages"
950  OP_TOGGLE_WRITE "toggle whether the mailbox will be rewritten"
951  OP_TOGGLE_MAILBOXES "toggle whether to browse mailboxes or all files"
952  OP_TOP_PAGE "move to the top of the page"
953 +OP_UNCATCHUP "mark all articles in newsgroup as unread"
954  OP_UNDELETE "undelete the current entry"
955  OP_UNDELETE_THREAD "undelete all messages in thread"
956  OP_UNDELETE_SUBTHREAD "undelete all messages in subthread"
957 +OP_UNSUBSCRIBE_PATTERN "unsubscribe from newsgroups matching a pattern"
958  OP_VERSION "show the Mutt version number and date"
959  OP_VIEW_ATTACH "view attachment using mailcap entry if necessary"
960  OP_VIEW_ATTACHMENTS "show MIME attachments"
961 diff -uNr mutt-1.4.orig/PATCHES mutt-1.4/PATCHES
962 --- mutt-1.4.orig/PATCHES       Sun Nov  3 21:42:52 2002
963 +++ mutt-1.4/PATCHES    Sun Nov  3 21:57:20 2002
964 @@ -1,0 +1,1 @@
965 +vvv.nntp
966 diff -uNr mutt-1.4.orig/acconfig.h mutt-1.4/acconfig.h
967 --- mutt-1.4.orig/acconfig.h    Tue Jan 15 23:08:12 2002
968 +++ mutt-1.4/acconfig.h Sun Nov  3 21:57:20 2002
969 @@ -14,6 +14,9 @@
970   */
971  #undef HOMESPOOL
972  
973 +/* Compiling with newsreading support with NNTP */
974 +#undef USE_NNTP
975 +
976  /* program to use for shell commands */
977  #define EXECSHELL "/bin/sh"
978  
979 diff -uNr mutt-1.4.orig/account.c mutt-1.4/account.c
980 --- mutt-1.4.orig/account.c     Thu Apr 26 15:36:33 2001
981 +++ mutt-1.4/account.c  Sun Nov  3 21:57:20 2002
982 @@ -44,6 +44,11 @@
983      user = PopUser;
984  #endif
985    
986 +#ifdef USE_NNTP
987 +  if (a1->type == M_ACCT_TYPE_NNTP && NntpUser)
988 +    user = NntpUser;
989 +#endif
990 +
991    if (a1->flags & a2->flags & M_ACCT_USER)
992      return (!strcmp (a1->user, a2->user));
993    if (a1->flags & M_ACCT_USER)
994 @@ -113,6 +118,16 @@
995    }
996  #endif
997  
998 +#ifdef USE_NNTP
999 +  if (account->type == M_ACCT_TYPE_NNTP)
1000 +  {
1001 +    if (account->flags & M_ACCT_SSL)
1002 +      url->scheme = U_NNTPS;
1003 +    else
1004 +      url->scheme = U_NNTP;
1005 +  }
1006 +#endif
1007 +
1008    url->host = account->host;
1009    if (account->flags & M_ACCT_PORT)
1010      url->port = account->port;
1011 @@ -138,6 +153,10 @@
1012    else if ((account->type == M_ACCT_TYPE_POP) && PopUser)
1013      strfcpy (account->user, PopUser, sizeof (account->user));
1014  #endif
1015 +#ifdef USE_NNTP
1016 +  else if ((account->type == M_ACCT_TYPE_NNTP) && NntpUser)
1017 +    strfcpy (account->user, NntpUser, sizeof (account->user));
1018 +#endif
1019    /* prompt (defaults to unix username), copy into account->user */
1020    else
1021    {
1022 @@ -167,6 +186,10 @@
1023    else if ((account->type == M_ACCT_TYPE_POP) && PopPass)
1024      strfcpy (account->pass, PopPass, sizeof (account->pass));
1025  #endif
1026 +#ifdef USE_NNTP
1027 +  else if ((account->type == M_ACCT_TYPE_NNTP) && NntpPass)
1028 +    strfcpy (account->pass, NntpPass, sizeof (account->pass));
1029 +#endif
1030    else
1031    {
1032      snprintf (prompt, sizeof (prompt), _("Password for %s@%s: "),
1033 diff -uNr mutt-1.4.orig/account.h mutt-1.4/account.h
1034 --- mutt-1.4.orig/account.h     Tue Jan  2 10:34:30 2001
1035 +++ mutt-1.4/account.h  Sun Nov  3 21:57:20 2002
1036 @@ -28,6 +28,7 @@
1037  {
1038    M_ACCT_TYPE_NONE = 0,
1039    M_ACCT_TYPE_IMAP,
1040 +  M_ACCT_TYPE_NNTP,
1041    M_ACCT_TYPE_POP
1042  };
1043  
1044 diff -uNr mutt-1.4.orig/attach.h mutt-1.4/attach.h
1045 --- mutt-1.4.orig/attach.h      Tue Sep 11 13:20:34 2001
1046 +++ mutt-1.4/attach.h   Sun Nov  3 21:57:20 2002
1047 @@ -30,5 +30,5 @@
1048  
1049  void mutt_attach_bounce (FILE *, HEADER *, ATTACHPTR **, short, BODY *);
1050  void mutt_attach_resend (FILE *, HEADER *, ATTACHPTR **, short, BODY *);
1051 -void mutt_attach_forward (FILE *, HEADER *, ATTACHPTR **, short, BODY *);
1052 +void mutt_attach_forward (FILE *, HEADER *, ATTACHPTR **, short, BODY *, int);
1053  void mutt_attach_reply (FILE *, HEADER *, ATTACHPTR **, short, BODY *, int);
1054 diff -uNr mutt-1.4.orig/browser.c mutt-1.4/browser.c
1055 --- mutt-1.4.orig/browser.c     Sun Nov  3 21:42:52 2002
1056 +++ mutt-1.4/browser.c  Sun Nov  3 22:00:14 2002
1057 @@ -27,6 +27,9 @@
1058  #ifdef USE_IMAP
1059  #include "imap.h"
1060  #endif
1061 +#ifdef USE_NNTP
1062 +#include "nntp.h"
1063 +#endif
1064  
1065  #include <stdlib.h>
1066  #include <dirent.h>
1067 @@ -44,6 +47,19 @@
1068    { NULL }
1069  };
1070  
1071 +#ifdef USE_NNTP
1072 +static struct mapping_t FolderNewsHelp[] = {
1073 +  { N_("Exit"),        OP_EXIT },
1074 +  { N_("List"),        OP_TOGGLE_MAILBOXES },
1075 +  { N_("Subscribe"),   OP_BROWSER_SUBSCRIBE },
1076 +  { N_("Unsubscribe"), OP_BROWSER_UNSUBSCRIBE },
1077 +  { N_("Catchup"),     OP_CATCHUP },
1078 +  { N_("Mask"),        OP_ENTER_MASK },
1079 +  { N_("Help"),        OP_HELP },
1080 +  { NULL }
1081 +};
1082 +#endif
1083 +
1084  typedef struct folder_t
1085  {
1086    struct folder_file *ff;
1087 @@ -109,9 +125,17 @@
1088      case SORT_ORDER:
1089        return;
1090      case SORT_DATE:
1091 +#ifdef USE_NNTP
1092 +      if (option (OPTNEWS))
1093 +       return;
1094 +#endif
1095        f = browser_compare_date;
1096        break;
1097      case SORT_SIZE:
1098 +#ifdef USE_NNTP
1099 +      if (option (OPTNEWS))
1100 +       return;
1101 +#endif
1102        f = browser_compare_size;
1103        break;
1104      case SORT_SUBJECT:
1105 @@ -299,8 +323,106 @@
1106    return (src);
1107  }
1108  
1109 +#ifdef USE_NNTP
1110 +static const char *
1111 +newsgroup_format_str (char *dest, size_t destlen, char op, const char *src,
1112 +                      const char *fmt, const char *ifstring, const char *elsestring,
1113 +                      unsigned long data, format_flag flags)
1114 +{
1115 +  char fn[SHORT_STRING], tmp[SHORT_STRING];
1116 +  FOLDER *folder = (FOLDER *) data;
1117 +
1118 +  switch (op)
1119 +  {
1120 +    case 'C':
1121 +      snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
1122 +      snprintf (dest, destlen, tmp, folder->num + 1);
1123 +      break;
1124 +      
1125 +    case 'f':
1126 +      strncpy (fn, folder->ff->name, sizeof(fn) - 1);
1127 +      snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
1128 +      snprintf (dest, destlen, tmp, fn);
1129 +      break;
1130 +
1131 +    case 'N':
1132 +      snprintf (tmp, sizeof (tmp), "%%%sc", fmt);
1133 +      if (folder->ff->nd->subscribed)
1134 +       snprintf (dest, destlen, tmp, ' ');
1135 +      else
1136 +       snprintf (dest, destlen, tmp, folder->ff->new ? 'N' : 'u');
1137 +      break;
1138 +
1139 +    case 'M':
1140 +      snprintf (tmp, sizeof (tmp), "%%%sc", fmt);
1141 +      if (folder->ff->nd->deleted)
1142 +       snprintf (dest, destlen, tmp, 'D');
1143 +      else
1144 +       snprintf (dest, destlen, tmp, folder->ff->nd->allowed ? ' ' : '-');
1145 +      break;
1146 +
1147 +    case 's':
1148 +      if (flags & M_FORMAT_OPTIONAL)
1149 +      {
1150 +       if (folder->ff->nd->unread != 0)
1151 +         mutt_FormatString (dest, destlen, ifstring, newsgroup_format_str,
1152 +               data, flags);
1153 +       else
1154 +         mutt_FormatString (dest, destlen, elsestring, newsgroup_format_str,
1155 +               data, flags);
1156 +      }
1157 +      else if (Context && Context->data == folder->ff->nd)
1158 +      {
1159 +       snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
1160 +       snprintf (dest, destlen, tmp, Context->unread);
1161 +      }
1162 +      else
1163 +      {
1164 +       snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
1165 +       snprintf (dest, destlen, tmp, folder->ff->nd->unread);
1166 +      }
1167 +      break;
1168 +
1169 +    case 'n':
1170 +      if (Context && Context->data == folder->ff->nd)
1171 +      {
1172 +       snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
1173 +       snprintf (dest, destlen, tmp, Context->new);
1174 +      }
1175 +      else if (option (OPTMARKOLD) &&
1176 +               folder->ff->nd->lastCached >= folder->ff->nd->firstMessage &&
1177 +               folder->ff->nd->lastCached <= folder->ff->nd->lastMessage)
1178 +      {
1179 +       snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
1180 +       snprintf (dest, destlen, tmp, folder->ff->nd->lastMessage - folder->ff->nd->lastCached);
1181 +      }
1182 +      else
1183 +      {
1184 +       snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
1185 +       snprintf (dest, destlen, tmp, folder->ff->nd->unread);
1186 +      }
1187 +      break;
1188 +
1189 +    case 'd':
1190 +      if (folder->ff->nd->desc != NULL)
1191 +      {
1192 +       snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
1193 +       snprintf (dest, destlen, tmp, folder->ff->nd->desc);
1194 +      }
1195 +      else
1196 +      {
1197 +       snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
1198 +       snprintf (dest, destlen, tmp, "");
1199 +      }
1200 +      break;
1201 +  }
1202 +  return (src);
1203 +}
1204 +#endif /* USE_NNTP */
1205 +
1206  static void add_folder (MUTTMENU *m, struct browser_state *state,
1207 -                       const char *name, const struct stat *s, int new)
1208 +                       const char *name, const struct stat *s,
1209 +                       void *data, int new)
1210  {
1211    if (state->entrylen == state->entrymax)
1212    {
1213 @@ -329,6 +451,10 @@
1214  #ifdef USE_IMAP
1215    (state->entry)[state->entrylen].imap = 0;
1216  #endif
1217 +#ifdef USE_NNTP
1218 +  if (option (OPTNEWS))
1219 +    (state->entry)[state->entrylen].nd = (NNTP_DATA *) data;
1220 +#endif
1221    (state->entrylen)++;
1222  }
1223  
1224 @@ -344,9 +470,35 @@
1225      menu->data = state->entry;
1226  }
1227  
1228 +/* get list of all files/newsgroups with mask */
1229  static int examine_directory (MUTTMENU *menu, struct browser_state *state,
1230                               char *d, const char *prefix)
1231  {
1232 +#ifdef USE_NNTP
1233 +  if (option (OPTNEWS))
1234 +  {
1235 +    LIST *tmp;
1236 +    NNTP_DATA *data;
1237 +    NNTP_SERVER *news = CurrentNewsSrv;
1238 +
1239 +/*  mutt_buffy_check (0); */
1240 +    init_state (state, menu);
1241 +
1242 +    for (tmp = news->list; tmp; tmp = tmp->next)
1243 +    {
1244 +      if (!(data = (NNTP_DATA *)tmp->data))
1245 +       continue;
1246 +      if (prefix && *prefix && strncmp (prefix, data->group,
1247 +           strlen (prefix)) != 0)
1248 +       continue;
1249 +      if (!((regexec (Mask.rx, data->group, 0, NULL, 0) == 0) ^ Mask.not))
1250 +       continue;
1251 +      add_folder (menu, state, data->group, NULL, data, data->new);
1252 +    }
1253 +  }
1254 +  else
1255 +#endif /* USE_NNTP */
1256 +  {
1257    struct stat s;
1258    DIR *dp;
1259    struct dirent *de;
1260 @@ -411,60 +563,95 @@
1261      tmp = Incoming;
1262      while (tmp && mutt_strcmp (buffer, tmp->path))
1263        tmp = tmp->next;
1264 -    add_folder (menu, state, de->d_name, &s, (tmp) ? tmp->new : 0);
1265 +    add_folder (menu, state, de->d_name, &s, NULL, (tmp) ? tmp->new : 0);
1266 +  }
1267 +  closedir (dp);
1268    }
1269 -  closedir (dp);  
1270    browser_sort (state);
1271    return 0;
1272  }
1273  
1274 +/* get list of mailboxes/subscribed newsgroups */
1275  static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state)
1276  {
1277    struct stat s;
1278    char buffer[LONG_STRING];
1279 -  BUFFY *tmp = Incoming;
1280  
1281 -  if (!Incoming)
1282 -    return (-1);
1283 -  mutt_buffy_check (0);
1284 +#ifdef USE_NNTP
1285 +  if (option (OPTNEWS))
1286 +  {
1287 +    LIST *tmp;
1288 +    NNTP_DATA *data;
1289 +    NNTP_SERVER *news = CurrentNewsSrv;
1290  
1291 -  init_state (state, menu);
1292 +/*  mutt_buffy_check (0); */
1293 +    init_state (state, menu);
1294  
1295 -  do
1296 -  {
1297 -#ifdef USE_IMAP
1298 -    if (mx_is_imap (tmp->path))
1299 +    for (tmp = news->list; tmp; tmp = tmp->next)
1300      {
1301 -      add_folder (menu, state, tmp->path, NULL, tmp->new);
1302 -      continue;
1303 +      if ((data = (NNTP_DATA *) tmp->data) != NULL && (data->new ||
1304 +         (data->subscribed && (!option (OPTSHOWONLYUNREAD) || data->unread))))
1305 +      add_folder (menu, state, data->group, NULL, data, data->new);
1306      }
1307 +  }
1308 +  else
1309  #endif
1310 -#ifdef USE_POP
1311 -    if (mx_is_pop (tmp->path))
1312 +  {
1313 +    BUFFY *tmp = Incoming;
1314 +
1315 +    if (!Incoming)
1316 +      return (-1);
1317 +    mutt_buffy_check (0);
1318 +
1319 +    init_state (state, menu);
1320 +
1321 +    do
1322      {
1323 -      add_folder (menu, state, tmp->path, NULL, tmp->new);
1324 -      continue;
1325 -    }
1326 +#ifdef USE_IMAP
1327 +      if (mx_is_imap (tmp->path))
1328 +      {
1329 +       add_folder (menu, state, tmp->path, NULL, NULL, tmp->new);
1330 +       continue;
1331 +      }
1332  #endif
1333 -    if (lstat (tmp->path, &s) == -1)
1334 -      continue;
1335 +#ifdef USE_POP
1336 +      if (mx_is_pop (tmp->path))
1337 +      {
1338 +       add_folder (menu, state, tmp->path, NULL, NULL, tmp->new);
1339 +       continue;
1340 +      }
1341 +#endif
1342 +#ifdef USE_NNTP
1343 +      if (mx_is_nntp (tmp->path))
1344 +      {
1345 +       add_folder (menu, state, tmp->path, NULL, NULL, tmp->new);
1346 +       continue;
1347 +      }
1348 +#endif
1349 +      if (lstat (tmp->path, &s) == -1)
1350 +       continue;
1351  
1352 -    if ((! S_ISREG (s.st_mode)) && (! S_ISDIR (s.st_mode)) &&
1353 -       (! S_ISLNK (s.st_mode)))
1354 -      continue;
1355 +      if ((! S_ISREG (s.st_mode)) && (! S_ISDIR (s.st_mode)) &&
1356 +         (! S_ISLNK (s.st_mode)))
1357 +       continue;
1358      
1359 -    strfcpy (buffer, NONULL(tmp->path), sizeof (buffer));
1360 -    mutt_pretty_mailbox (buffer);
1361 +      strfcpy (buffer, NONULL(tmp->path), sizeof (buffer));
1362 +      mutt_pretty_mailbox (buffer);
1363  
1364 -    add_folder (menu, state, buffer, &s, tmp->new);
1365 +      add_folder (menu, state, buffer, &s, NULL, tmp->new);
1366 +    }
1367 +    while ((tmp = tmp->next));
1368    }
1369 -  while ((tmp = tmp->next));
1370    browser_sort (state);
1371    return 0;
1372  }
1373  
1374  int select_file_search (MUTTMENU *menu, regex_t *re, int n)
1375  {
1376 +#ifdef USE_NNTP
1377 +  if (option (OPTNEWS))
1378 +    return (regexec (re, ((struct folder_file *) menu->data)[n].desc, 0, NULL, 0));
1379 +#endif
1380    return (regexec (re, ((struct folder_file *) menu->data)[n].name, 0, NULL, 0));
1381  }
1382  
1383 @@ -475,7 +662,13 @@
1384    folder.ff = &((struct folder_file *) menu->data)[num];
1385    folder.num = num;
1386    
1387 -  mutt_FormatString (s, slen, NONULL(FolderFormat), folder_format_str, 
1388 +#ifdef USE_NNTP
1389 +  if (option (OPTNEWS))
1390 +    mutt_FormatString (s, slen, NONULL(GroupFormat), newsgroup_format_str, 
1391 +      (unsigned long) &folder, M_FORMAT_ARROWCURSOR);
1392 +  else
1393 +#endif
1394 +    mutt_FormatString (s, slen, NONULL(FolderFormat), folder_format_str, 
1395        (unsigned long) &folder, M_FORMAT_ARROWCURSOR);
1396  }
1397  
1398 @@ -495,7 +688,18 @@
1399      menu->top = 0;
1400  
1401    menu->tagged = 0;
1402 -  
1403 +
1404 +#ifdef USE_NNTP
1405 +  if (option (OPTNEWS))
1406 +  {
1407 +    if (buffy)
1408 +      snprintf (title, titlelen, _("Subscribed newsgroups"));
1409 +    else
1410 +      snprintf (title, titlelen, _("Newsgroups on server [%s]"),
1411 +               CurrentNewsSrv->conn->account.host);
1412 +  }
1413 +  else
1414 +#endif
1415    if (buffy)
1416      snprintf (title, titlelen, _("Mailboxes [%d]"), mutt_buffy_check (0));
1417    else
1418 @@ -551,6 +755,31 @@
1419    if (!folder)
1420      strfcpy (LastDirBackup, LastDir, sizeof (LastDirBackup));
1421  
1422 +#ifdef USE_NNTP
1423 +  if (option (OPTNEWS))
1424 +  {
1425 +    if (*f)
1426 +      strfcpy (prefix, f, sizeof (prefix));
1427 +    else
1428 +    {
1429 +      LIST *list;
1430 +
1431 +      /* default state for news reader mode is browse subscribed newsgroups */
1432 +      buffy = 0;
1433 +      for (list = CurrentNewsSrv->list; list; list = list->next)
1434 +      {
1435 +       NNTP_DATA *data = (NNTP_DATA *) list->data;
1436 +
1437 +       if (data && data->subscribed)
1438 +       {
1439 +         buffy = 1;
1440 +         break;
1441 +       }
1442 +      }
1443 +    }
1444 +  }
1445 +  else
1446 +#endif
1447    if (*f)
1448    {
1449      mutt_expand_path (f, flen);
1450 @@ -639,6 +868,9 @@
1451      menu->tag = file_tag;
1452  
1453    menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_FOLDER,
1454 +#ifdef USE_NNTP
1455 +    (option (OPTNEWS)) ? FolderNewsHelp :
1456 +#endif
1457      FolderHelp);
1458  
1459    init_menu (&state, menu, title, sizeof (title), buffy, FolderColumns);
1460 @@ -777,7 +1009,11 @@
1461           }
1462         }
1463  
1464 +#ifdef USE_NNTP
1465 +       if (buffy || option (OPTNEWS)) /* news have not path */
1466 +#else
1467         if (buffy)
1468 +#endif
1469         {
1470           strfcpy (f, state.entry[menu->current].name, flen);
1471           mutt_expand_path (f, flen);
1472 @@ -835,14 +1071,6 @@
1473          break;
1474  
1475  #ifdef USE_IMAP
1476 -      case OP_BROWSER_SUBSCRIBE:
1477 -       imap_subscribe (state.entry[menu->current].name, 1);
1478 -       break;
1479 -
1480 -      case OP_BROWSER_UNSUBSCRIBE:
1481 -       imap_subscribe (state.entry[menu->current].name, 0);
1482 -       break;
1483 -
1484        case OP_BROWSER_TOGGLE_LSUB:
1485         if (option (OPTIMAPLSUB))
1486         {
1487 @@ -913,6 +1141,11 @@
1488        
1489        case OP_CHANGE_DIRECTORY:
1490  
1491 +#ifdef USE_NNTP
1492 +       if (option (OPTNEWS))
1493 +         break;
1494 +#endif
1495 +
1496         strfcpy (buf, LastDir, sizeof (buf));
1497  #ifdef USE_IMAP
1498         if (!state.imap_browse)
1499 @@ -1163,6 +1396,190 @@
1500           else
1501             mutt_error _("Error trying to view file");
1502         }
1503 +       break;
1504 +
1505 +#ifdef USE_NNTP
1506 +      case OP_CATCHUP:
1507 +      case OP_UNCATCHUP:
1508 +       if (option (OPTNEWS))
1509 +       {
1510 +         struct folder_file *f = &state.entry[menu->current];
1511 +         NNTP_DATA *nd;
1512 +
1513 +         if (i == OP_CATCHUP)
1514 +           nd = mutt_newsgroup_catchup (CurrentNewsSrv, f->name);
1515 +         else
1516 +           nd = mutt_newsgroup_uncatchup (CurrentNewsSrv, f->name);
1517 +
1518 +         if (nd)
1519 +         {
1520 +/*         FOLDER folder;
1521 +           struct folder_file ff;
1522 +           char buffer[_POSIX_PATH_MAX + SHORT_STRING];
1523 +
1524 +           folder.ff = &ff;
1525 +           folder.ff->name = f->name;
1526 +           folder.ff->st = NULL;
1527 +           folder.ff->is_new = nd->new;
1528 +           folder.ff->nd = nd;
1529 +           safe_free ((void **) &f->desc);
1530 +           mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
1531 +                 newsgroup_format_str, (unsigned long) &folder,
1532 +                 M_FORMAT_ARROWCURSOR);
1533 +           f->desc = safe_strdup (buffer); */
1534 +           if (menu->current + 1 < menu->max)
1535 +             menu->current++;
1536 +           menu->redraw = REDRAW_MOTION_RESYNCH;
1537 +         }
1538 +       }
1539 +       break;
1540 +
1541 +      case OP_LOAD_ACTIVE:
1542 +       if (!option (OPTNEWS))
1543 +         break;
1544 +
1545 +       {
1546 +         LIST *tmp;
1547 +         NNTP_DATA *data;
1548 +
1549 +         for (tmp = CurrentNewsSrv->list; tmp; tmp = tmp->next)
1550 +         {
1551 +           if ((data = (NNTP_DATA *)tmp->data))
1552 +             data->deleted = 1;
1553 +         }
1554 +       }
1555 +       nntp_get_active (CurrentNewsSrv);
1556 +
1557 +       destroy_state (&state);
1558 +       if (buffy)
1559 +         examine_mailboxes (menu, &state);
1560 +       else
1561 +         examine_directory (menu, &state, NULL, NULL);
1562 +       init_menu (&state, menu, title, sizeof (title), buffy, 1);
1563 +       break;
1564 +#endif /* USE_NNTP */
1565 +
1566 +#if defined USE_IMAP || defined USE_NNTP
1567 +      case OP_BROWSER_SUBSCRIBE:
1568 +      case OP_BROWSER_UNSUBSCRIBE:
1569 +#endif
1570 +#ifdef USE_NNTP
1571 +      case OP_SUBSCRIBE_PATTERN:
1572 +      case OP_UNSUBSCRIBE_PATTERN:
1573 +        if (option (OPTNEWS))
1574 +       {
1575 +         regex_t *rx = (regex_t *) safe_malloc (sizeof (regex_t));
1576 +         char *s = buf;
1577 +         int j = menu->current;
1578 +         NNTP_DATA *nd;
1579 +         NNTP_SERVER *news = CurrentNewsSrv;
1580 +
1581 +         if (i == OP_SUBSCRIBE_PATTERN || i == OP_UNSUBSCRIBE_PATTERN)
1582 +         {
1583 +           char tmp[STRING];
1584 +           int err;
1585 +
1586 +           buf[0] = 0;
1587 +           if (i == OP_SUBSCRIBE_PATTERN)
1588 +             snprintf (tmp, sizeof (tmp), _("Subscribe pattern: "));
1589 +           else
1590 +             snprintf (tmp, sizeof (tmp), _("Unsubscribe pattern: "));
1591 +           if (mutt_get_field (tmp, buf, sizeof (buf), 0) != 0 || !buf[0])
1592 +           {
1593 +             FREE (&rx);
1594 +             break;
1595 +           }
1596 +
1597 +           if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0)
1598 +           {
1599 +             regerror (err, rx, buf, sizeof (buf));
1600 +             regfree (rx);
1601 +             safe_free ((void **) &rx);
1602 +             mutt_error ("%s", buf);
1603 +             break;
1604 +           }
1605 +           menu->redraw = REDRAW_FULL;
1606 +           j = 0;
1607 +         }
1608 +         else if (!state.entrylen)
1609 +         {
1610 +           mutt_error _("No newsgroups match the mask");
1611 +           break;
1612 +         }
1613 +
1614 +         for ( ; j < state.entrylen; j++)
1615 +         {
1616 +           struct folder_file *f = &state.entry[j];
1617 +
1618 +           if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE ||
1619 +                 regexec (rx, f->name, 0, NULL, 0) == 0)
1620 +           {
1621 +             if (i == OP_BROWSER_SUBSCRIBE || i == OP_SUBSCRIBE_PATTERN)
1622 +               nd = mutt_newsgroup_subscribe (news, f->name);
1623 +             else
1624 +               nd = mutt_newsgroup_unsubscribe (news, f->name);
1625 +/*           if (nd)
1626 +             {
1627 +               FOLDER folder;
1628 +               char buffer[_POSIX_PATH_MAX + SHORT_STRING];
1629 +
1630 +               folder.name = f->name;
1631 +               folder.f = NULL;
1632 +               folder.new = nd->new;
1633 +               folder.nd = nd;
1634 +               safe_free ((void **) &f->desc);
1635 +               mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
1636 +                       newsgroup_format_str, (unsigned long) &folder,
1637 +                       M_FORMAT_ARROWCURSOR);
1638 +               f->desc = safe_strdup (buffer);
1639 +             } */
1640 +           }
1641 +           if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE)
1642 +           {
1643 +             if (menu->current + 1 < menu->max)
1644 +               menu->current++;
1645 +             menu->redraw = REDRAW_MOTION_RESYNCH;
1646 +             break;
1647 +           }
1648 +         }
1649 +         if (i == OP_SUBSCRIBE_PATTERN)
1650 +         {
1651 +           LIST *grouplist = NULL;
1652 +
1653 +           if (news)
1654 +             grouplist = news->list;
1655 +           for (; grouplist; grouplist = grouplist->next)
1656 +           {
1657 +             nd = (NNTP_DATA *) grouplist->data;
1658 +             if (nd && nd->group && !nd->subscribed)
1659 +             {
1660 +               if (regexec (rx, nd->group, 0, NULL, 0) == 0)
1661 +               {
1662 +                 mutt_newsgroup_subscribe (news, nd->group);
1663 +                 add_folder (menu, &state, nd->group, NULL, nd, nd->new);
1664 +               }
1665 +             }
1666 +           }
1667 +           init_menu (&state, menu, title, sizeof (title), buffy, 1);
1668 +         }
1669 +         mutt_newsrc_update (news);
1670 +         nntp_clear_cacheindex (news);
1671 +         if (i != OP_BROWSER_SUBSCRIBE && i != OP_BROWSER_UNSUBSCRIBE)
1672 +           regfree (rx);
1673 +         safe_free ((void **) &rx);
1674 +       }
1675 +#ifdef USE_IMAP
1676 +       else
1677 +#endif /* USE_IMAP && USE_NNTP */
1678 +#endif /* USE_NNTP */
1679 +#ifdef USE_IMAP
1680 +       {
1681 +         if (i == OP_BROWSER_SUBSCRIBE)
1682 +           imap_subscribe (state.entry[menu->current].name, 1);
1683 +         else
1684 +           imap_subscribe (state.entry[menu->current].name, 0);
1685 +       }
1686 +#endif /* USE_IMAP */
1687      }
1688    }
1689    
1690 diff -uNr mutt-1.4.orig/browser.h mutt-1.4/browser.h
1691 --- mutt-1.4.orig/browser.h     Mon Aug 21 17:42:20 2000
1692 +++ mutt-1.4/browser.h  Sun Nov  3 21:57:20 2002
1693 @@ -20,6 +20,10 @@
1694  #ifndef _BROWSER_H
1695  #define _BROWSER_H 1
1696  
1697 +#ifdef USE_NNTP
1698 +#include "nntp.h"
1699 +#endif
1700 +
1701  struct folder_file
1702  {
1703    mode_t mode;
1704 @@ -38,14 +42,17 @@
1705    unsigned selectable : 1;
1706    unsigned inferiors : 1;
1707  #endif
1708 +#ifdef USE_NNTP
1709 +  NNTP_DATA *nd;
1710 +#endif
1711    unsigned tagged : 1;
1712  };
1713  
1714  struct browser_state
1715  {
1716    struct folder_file *entry;
1717 -  short entrylen; /* number of real entries */
1718 -  short entrymax;  /* max entry */
1719 +  unsigned int entrylen; /* number of real entries */
1720 +  unsigned int entrymax; /* max entry */
1721  #ifdef USE_IMAP
1722    short imap_browse;
1723    char *folder;
1724 diff -uNr mutt-1.4.orig/buffy.c mutt-1.4/buffy.c
1725 --- mutt-1.4.orig/buffy.c       Mon Mar 25 12:30:08 2002
1726 +++ mutt-1.4/buffy.c    Sun Nov  3 21:57:20 2002
1727 @@ -257,6 +257,9 @@
1728  #ifdef USE_POP
1729    if (!Context || Context->magic != M_POP)
1730  #endif
1731 +#ifdef USE_NNTP
1732 +  if (!Context || Context->magic != M_NNTP)
1733 +#endif
1734    /* check device ID and serial number instead of comparing paths */
1735    if (!Context || !Context->path || stat (Context->path, &contex_sb) != 0)
1736    {
1737 @@ -278,6 +281,11 @@
1738        tmp->magic = M_POP;
1739      else
1740  #endif
1741 +#ifdef USE_NNTP
1742 +    if ((tmp->magic == M_NNTP) || mx_is_nntp (tmp->path))
1743 +      tmp->magic = M_NNTP;
1744 +    else
1745 +#endif
1746      if (stat (tmp->path, &sb) != 0 || sb.st_size == 0 ||
1747         (!tmp->magic && (tmp->magic = mx_get_magic (tmp->path)) <= 0))
1748      {
1749 @@ -294,25 +302,21 @@
1750      /* check to see if the folder is the currently selected folder
1751       * before polling */
1752      if (!Context || !Context->path ||
1753 -#if defined USE_IMAP || defined USE_POP
1754 -       ((
1755 +        (
1756 +          (0
1757  #ifdef USE_IMAP
1758 -       tmp->magic == M_IMAP
1759 +           || tmp->magic == M_IMAP
1760  #endif
1761  #ifdef USE_POP
1762 -#ifdef USE_IMAP
1763 -       ||
1764 -#endif
1765 -       tmp->magic == M_POP
1766 +           || tmp->magic == M_POP
1767  #endif
1768 -       ) ? mutt_strcmp (tmp->path, Context->path) :
1769 +#ifdef USE_NNTP
1770 +           || tmp->magic == M_NNTP
1771  #endif
1772 -        (sb.st_dev != contex_sb.st_dev || sb.st_ino != contex_sb.st_ino)
1773 -#if defined USE_IMAP || defined USE_POP         
1774 -           )
1775 -#endif
1776 -       )
1777 -       
1778 +          ) ? mutt_strcmp (tmp->path, Context->path) :
1779 +              (sb.st_dev != contex_sb.st_dev || sb.st_ino != contex_sb.st_ino)
1780 +        )
1781 +       )
1782      {
1783        switch (tmp->magic)
1784        {
1785 @@ -380,6 +384,11 @@
1786        case M_POP:
1787         break;
1788  #endif
1789 +
1790 +#ifdef USE_NNTP
1791 +      case M_NNTP:
1792 +       break;
1793 +#endif
1794        }
1795      }
1796  #ifdef BUFFY_SIZE
1797 diff -uNr mutt-1.4.orig/commands.c mutt-1.4/commands.c
1798 --- mutt-1.4.orig/commands.c    Sun Nov  3 21:42:52 2002
1799 +++ mutt-1.4/commands.c Sun Nov  3 21:57:20 2002
1800 @@ -26,6 +26,7 @@
1801  #include "copy.h"
1802  #include "mx.h"
1803  #include "pager.h"
1804 +#include "rfc1524.h"
1805  #include <sys/types.h>
1806  #include <sys/stat.h>
1807  #include <fcntl.h>
1808 @@ -791,6 +792,131 @@
1809    return -1;
1810  }
1811  
1812 +int mutt_update_list_file (char *filename, char *section, char *key, char *line)
1813 +{
1814 +  FILE *ifp;
1815 +  FILE *ofp;
1816 +  char buf[HUGE_STRING];
1817 +  char oldfile[_POSIX_PATH_MAX];
1818 +  char *c;
1819 +  int ext = 0, done = 0, r = 0;
1820 +
1821 +  snprintf (oldfile, sizeof(oldfile), "%s.bak", filename);
1822 +  dprint (1, (debugfile, "Renaming %s to %s\n", filename, oldfile));
1823 +
1824 +  /* if file not exist, create it */
1825 +  if ((ifp = safe_fopen (filename, "a")))
1826 +    fclose (ifp);
1827 +  if (_mutt_rename_file (filename, oldfile, 1))
1828 +  {
1829 +    mutt_perror _("Unable to create backup file");
1830 +    return (-1);
1831 +  }
1832 +  dprint (1, (debugfile, "Opening %s\n", oldfile));
1833 +  if (!(ifp = safe_fopen (oldfile, "r")))
1834 +  {
1835 +    mutt_perror _("Unable to open backup file for reading");
1836 +    return (-1);
1837 +  }
1838 +  dprint (1, (debugfile, "Opening %s\n", filename));
1839 +  if (!(ofp = fopen (filename, "w")))
1840 +  {
1841 +    fclose (ifp);
1842 +    mutt_perror _("Unable to open new file for writing");
1843 +    return (-1);
1844 +  }
1845 +  if (mx_lock_file (filename, fileno (ofp), 1, 0, 1))
1846 +  {
1847 +    fclose (ofp);
1848 +    fclose (ifp);
1849 +    mutt_error (_("Unable to lock %s, old file saved as %s"), filename, oldfile);
1850 +    return (-1);
1851 +  }
1852 +
1853 +  if (section)
1854 +  {
1855 +    while (r != EOF && !done && fgets (buf, sizeof (buf), ifp))
1856 +    {
1857 +      r = fputs (buf, ofp);
1858 +      c = buf;
1859 +      while (*c && *c != '\n') c++;
1860 +      c[0] = 0;        /* strip EOL */
1861 +      if (!strncmp (buf, "#: ", 3) && !mutt_strcasecmp (buf+3, section))
1862 +       done++;
1863 +    }
1864 +    if (r != EOF && !done)
1865 +    {
1866 +      snprintf (buf, sizeof(buf), "#: %s\n", section);
1867 +      r = fputs (buf, ofp);
1868 +    }
1869 +    done = 0;
1870 +  }
1871 +
1872 +  while (r != EOF && fgets (buf, sizeof (buf), ifp))
1873 +  {
1874 +    if (ext)
1875 +    {
1876 +      c = buf;
1877 +      while (*c && (*c != '\r') && (*c != '\n')) c++;
1878 +      c--;
1879 +      if (*c != '\\') ext = 0;
1880 +    }
1881 +    else if ((section && !strncmp (buf, "#: ", 3)))
1882 +    {
1883 +      if (!done && line)
1884 +      {
1885 +       fputs (line, ofp);
1886 +       fputc ('\n', ofp);
1887 +      }
1888 +      r = fputs (buf, ofp);
1889 +      done++;
1890 +      break;
1891 +    }
1892 +    else if (key && !strncmp (buf, key, strlen(key)) &&
1893 +           (!*key || buf[strlen(key)] == ' '))
1894 +    {
1895 +      c = buf;
1896 +      ext = 0;
1897 +      while (*c && (*c != '\r') && (*c != '\n')) c++;
1898 +      c--;
1899 +      if (*c == '\\') ext = 1;
1900 +      if (!done && line)
1901 +      {
1902 +       r = fputs (line, ofp);
1903 +       if (*key)
1904 +         r = fputc ('\n', ofp);
1905 +       done++;
1906 +      }
1907 +    }
1908 +    else
1909 +    {
1910 +      r = fputs (buf, ofp);
1911 +    }
1912 +  }
1913 +
1914 +  while (r != EOF && fgets (buf, sizeof (buf), ifp))
1915 +    r = fputs (buf, ofp);
1916 +
1917 +  /* If there wasn't a line to replace, put it on the end of the file */
1918 +  if (r != EOF && !done && line)
1919 +  {
1920 +    fputs (line, ofp);
1921 +    r = fputc ('\n', ofp);
1922 +  }
1923 +  mx_unlock_file (filename, fileno (ofp), 0);
1924 +  fclose (ofp);
1925 +  fclose (ifp);
1926 +  if (r != EOF)
1927 +  {
1928 +    unlink (oldfile);
1929 +    return 0;
1930 +  }
1931 +  unlink (filename);
1932 +  mutt_error (_("Cannot write new %s, old file saved as %s"), filename,
1933 +       oldfile);
1934 +  return (-1);
1935 +}
1936 +
1937  
1938  void mutt_version (void)
1939  {
1940 diff -uNr mutt-1.4.orig/complete.c mutt-1.4/complete.c
1941 --- mutt-1.4.orig/complete.c    Wed Nov  7 11:22:08 2001
1942 +++ mutt-1.4/complete.c Sun Nov  3 21:57:20 2002
1943 @@ -21,6 +21,9 @@
1944  #include "mailbox.h"
1945  #include "imap.h"
1946  #endif
1947 +#ifdef USE_NNTP
1948 +#include "nntp.h"
1949 +#endif
1950  
1951  #include <dirent.h>
1952  #include <string.h>
1953 @@ -44,9 +47,71 @@
1954    char filepart[_POSIX_PATH_MAX];
1955  #ifdef USE_IMAP
1956    char imap_path[LONG_STRING];
1957 +#endif
1958  
1959    dprint (2, (debugfile, "mutt_complete: completing %s\n", s));
1960  
1961 +#ifdef USE_NNTP
1962 +  if (option (OPTNEWS))
1963 +  {
1964 +    LIST *l = CurrentNewsSrv->list;
1965 +
1966 +    strfcpy (filepart, s, sizeof (filepart));
1967 +
1968 +    /*
1969 +     * special case to handle when there is no filepart yet.
1970 +     * find the first subscribed newsgroup
1971 +     */
1972 +    if ((len = mutt_strlen (filepart)) == 0)
1973 +    {
1974 +      for (; l; l = l->next)
1975 +      {
1976 +       NNTP_DATA *data = (NNTP_DATA *)l->data;
1977 +
1978 +       if (data && data->subscribed)
1979 +       {
1980 +         strfcpy (filepart, data->group, sizeof (filepart));
1981 +         init++;
1982 +         l = l->next;
1983 +         break;
1984 +       }
1985 +      }
1986 +    }
1987 +
1988 +    for (; l; l = l->next)
1989 +    {
1990 +      NNTP_DATA *data = (NNTP_DATA *)l->data;
1991 +
1992 +      if (data && data->subscribed &&
1993 +         mutt_strncmp (data->group, filepart, len) == 0)
1994 +      {
1995 +       if (init)
1996 +       {
1997 +         for (i = 0; filepart[i] && data->group[i]; i++)
1998 +         {
1999 +           if (filepart[i] != data->group[i])
2000 +           {
2001 +             filepart[i] = 0;
2002 +             break;
2003 +           }
2004 +         }
2005 +         filepart[i] = 0;
2006 +       }
2007 +       else
2008 +       {
2009 +         strfcpy (filepart, data->group, sizeof (filepart));
2010 +         init = 1;
2011 +       }
2012 +      }
2013 +    }
2014 +
2015 +    strcpy (s, filepart);
2016 +
2017 +    return (init ? 0 : -1);
2018 +  }
2019 +#endif
2020 +
2021 +#ifdef USE_IMAP
2022    /* we can use '/' as a delimiter, imap_complete rewrites it */
2023    if (*s == '=' || *s == '+' || *s == '!')
2024    {
2025 diff -uNr mutt-1.4.orig/compose.c mutt-1.4/compose.c
2026 --- mutt-1.4.orig/compose.c     Sun Nov  3 21:42:52 2002
2027 +++ mutt-1.4/compose.c  Sun Nov  3 21:57:20 2002
2028 @@ -26,10 +26,15 @@
2029  #include "mailbox.h"
2030  #include "sort.h"
2031  #include "charset.h"
2032 +#include "mx.h"
2033  
2034  #ifdef MIXMASTER
2035  #include "remailer.h"
2036  #endif
2037 +  
2038 +#ifdef USE_NNTP
2039 +#include "nntp.h"
2040 +#endif
2041  
2042  #include <errno.h>
2043  #include <string.h>
2044 @@ -63,12 +68,18 @@
2045    HDR_PGPSIGINFO,
2046  #endif
2047    
2048 +#ifdef USE_NNTP
2049 +  HDR_NEWSGROUPS,
2050 +  HDR_FOLLOWUPTO,
2051 +  HDR_XCOMMENTTO,
2052 +#endif
2053 +
2054  
2055    HDR_ATTACH  = (HDR_FCC + 5) /* where to start printing the attachments */
2056  };
2057  
2058 -#define HDR_XOFFSET 10
2059 -#define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
2060 +#define HDR_XOFFSET 14
2061 +#define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
2062  #define W (COLS - HDR_XOFFSET)
2063  
2064  static char *Prompts[] =
2065 @@ -80,6 +91,15 @@
2066    "Subject: ",
2067    "Reply-To: ",
2068    "Fcc: "
2069 +#ifdef HAVE_PGP
2070 +  ,""
2071 +  ,""
2072 +#endif
2073 +#ifdef USE_NNTP
2074 +  ,"Newsgroups: "
2075 +  ,"Followup-To: "
2076 +  ,"X-Comment-To: "
2077 +#endif
2078  };
2079  
2080  static struct mapping_t ComposeHelp[] = {
2081 @@ -94,6 +114,19 @@
2082    { NULL }
2083  };
2084  
2085 +#ifdef USE_NNTP
2086 +static struct mapping_t ComposeNewsHelp[] = {
2087 +  { N_("Send"),    OP_COMPOSE_SEND_MESSAGE },
2088 +  { N_("Abort"),   OP_EXIT },
2089 +  { "Newsgroups",  OP_COMPOSE_EDIT_NEWSGROUPS },
2090 +  { "Subj",        OP_COMPOSE_EDIT_SUBJECT },
2091 +  { N_("Attach file"),  OP_COMPOSE_ATTACH_FILE },
2092 +  { N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION },
2093 +  { N_("Help"),    OP_HELP },
2094 +  { NULL }
2095 +};
2096 +#endif
2097 +
2098  static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num)
2099  {
2100      mutt_FormatString (b, blen, NONULL (AttachFormat), mutt_attach_fmt,
2101 @@ -108,7 +141,7 @@
2102  
2103  static void redraw_pgp_lines (int pgp)
2104  {
2105 -  mvaddstr (HDR_PGP, 0,     "     PGP: ");
2106 +  mvaddstr (HDR_PGP, 0,     "         PGP: ");
2107    if ((pgp & (PGPENCRYPT | PGPSIGN)) == (PGPENCRYPT | PGPSIGN))
2108      addstr (_("Sign, Encrypt"));
2109    else if (pgp & PGPENCRYPT)
2110 @@ -122,7 +155,7 @@
2111    move (HDR_PGPSIGINFO, 0);
2112    clrtoeol ();
2113    if (pgp & PGPSIGN)
2114 -    printw ("%s%s", _(" sign as: "), PgpSignAs ? PgpSignAs : _("<default>"));
2115 +    printw ("    %s%s", _(" sign as: "), PgpSignAs ? PgpSignAs : _("<default>"));
2116  }
2117  
2118  static int pgp_send_menu (int bits, int *redraw)
2119 @@ -258,9 +291,28 @@
2120  static void draw_envelope (HEADER *msg, char *fcc)
2121  {
2122    draw_envelope_addr (HDR_FROM, msg->env->from);
2123 +#ifdef USE_NNTP
2124 +  if (!option (OPTNEWSSEND))
2125 +  {
2126 +#endif
2127    draw_envelope_addr (HDR_TO, msg->env->to);
2128    draw_envelope_addr (HDR_CC, msg->env->cc);
2129    draw_envelope_addr (HDR_BCC, msg->env->bcc);
2130 +#ifdef USE_NNTP
2131 +  }
2132 +  else
2133 +  {
2134 +    mvprintw (HDR_TO, 0, TITLE_FMT , Prompts[HDR_NEWSGROUPS - 1]);
2135 +    mutt_paddstr (W, NONULL (msg->env->newsgroups));
2136 +    mvprintw (HDR_CC, 0, TITLE_FMT , Prompts[HDR_FOLLOWUPTO - 1]);
2137 +    mutt_paddstr (W, NONULL (msg->env->followup_to));
2138 +    if (option (OPTXCOMMENTTO))
2139 +    {
2140 +      mvprintw (HDR_BCC, 0, TITLE_FMT , Prompts[HDR_XCOMMENTTO - 1]);
2141 +      mutt_paddstr (W, NONULL (msg->env->x_comment_to));
2142 +    }
2143 +  }
2144 +#endif
2145    mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
2146    mutt_paddstr (W, NONULL (msg->env->subject));
2147    draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
2148 @@ -506,6 +558,12 @@
2149    /* Sort, SortAux could be changed in mutt_index_menu() */
2150    int oldSort, oldSortAux;
2151    struct stat st;
2152 +#ifdef USE_NNTP
2153 +  int news = 0;               /* is it a news article ? */
2154 +
2155 +  if (option (OPTNEWSSEND))
2156 +    news++;
2157 +#endif
2158  
2159    mutt_attach_init (msg->content);
2160    idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
2161 @@ -517,10 +575,18 @@
2162    menu->make_entry = snd_entry;
2163    menu->tag = mutt_tag_attach;
2164    menu->data = idx;
2165 +#ifdef USE_NNTP
2166 +  if (news)
2167 +  menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeNewsHelp);
2168 +  else
2169 +#endif
2170    menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp);
2171    
2172    while (loop)
2173    {
2174 +#ifdef USE_NNTP
2175 +    unset_option (OPTNEWS);    /* for any case */
2176 +#endif
2177      switch (op = mutt_menuLoop (menu))
2178      {
2179        case OP_REDRAW:
2180 @@ -532,14 +598,81 @@
2181         menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
2182         break;
2183        case OP_COMPOSE_EDIT_TO:
2184 -       menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
2185 +#ifdef USE_NNTP
2186 +       if (!news)
2187 +#endif
2188 +         menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
2189         break;
2190        case OP_COMPOSE_EDIT_BCC:
2191 -       menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
2192 +#ifdef USE_NNTP
2193 +       if (!news)
2194 +#endif
2195 +         menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
2196         break;
2197        case OP_COMPOSE_EDIT_CC:
2198 -       menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
2199 +#ifdef USE_NNTP
2200 +       if (!news)
2201 +#endif
2202 +         menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
2203 +       break;
2204 +#ifdef USE_NNTP
2205 +      case OP_COMPOSE_EDIT_NEWSGROUPS:
2206 +       if (news)
2207 +       {
2208 +         if (msg->env->newsgroups)
2209 +           strfcpy (buf, msg->env->newsgroups, sizeof (buf));
2210 +         else
2211 +           buf[0] = 0;
2212 +         if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0 && buf[0])
2213 +         {
2214 +           safe_free ((void **) &msg->env->newsgroups);
2215 +           mutt_remove_trailing_ws (buf);
2216 +           msg->env->newsgroups = safe_strdup (mutt_skip_whitespace (buf));
2217 +           move (HDR_TO, HDR_XOFFSET);
2218 +           clrtoeol ();
2219 +           if (msg->env->newsgroups)
2220 +             printw ("%-*.*s", W, W, msg->env->newsgroups);
2221 +         }
2222 +       }
2223 +       break;
2224 +
2225 +      case OP_COMPOSE_EDIT_FOLLOWUP_TO:
2226 +       if (news)
2227 +       {
2228 +         buf[0] = 0;
2229 +         if (msg->env->followup_to)
2230 +           strfcpy (buf, msg->env->followup_to, sizeof (buf));
2231 +         if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0 && buf[0])
2232 +         {
2233 +           safe_free ((void **) &msg->env->followup_to);
2234 +           mutt_remove_trailing_ws (buf);
2235 +           msg->env->followup_to = safe_strdup (mutt_skip_whitespace (buf));
2236 +           move (HDR_CC, HDR_XOFFSET);
2237 +           clrtoeol();
2238 +           if (msg->env->followup_to)
2239 +             printw ("%-*.*s", W, W, msg->env->followup_to);
2240 +         }
2241 +       }
2242         break;
2243 +
2244 +      case OP_COMPOSE_EDIT_X_COMMENT_TO:
2245 +       if (news && option (OPTXCOMMENTTO))
2246 +       {
2247 +         buf[0] = 0;
2248 +         if (msg->env->x_comment_to)
2249 +           strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
2250 +         if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0 && buf[0])
2251 +         {
2252 +           safe_free ((void **) &msg->env->x_comment_to);
2253 +           msg->env->x_comment_to = safe_strdup (buf);
2254 +           move (HDR_BCC, HDR_XOFFSET);
2255 +           clrtoeol();
2256 +           if (msg->env->x_comment_to)
2257 +             printw ("%-*.*s", W, W, msg->env->x_comment_to);
2258 +         }
2259 +       }
2260 +       break;
2261 +#endif
2262        case OP_COMPOSE_EDIT_SUBJECT:
2263         if (msg->env->subject)
2264           strfcpy (buf, msg->env->subject, sizeof (buf));
2265 @@ -695,6 +828,9 @@
2266         break;
2267  
2268        case OP_COMPOSE_ATTACH_MESSAGE:
2269 +#ifdef USE_NNTP
2270 +      case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
2271 +#endif
2272         {
2273           char *prompt;
2274           HEADER *h;
2275 @@ -702,7 +838,22 @@
2276           fname[0] = 0;
2277           prompt = _("Open mailbox to attach message from");
2278  
2279 +#ifdef USE_NNTP
2280 +         unset_option (OPTNEWS);
2281 +         if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE)
2282 +         {
2283 +           if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
2284 +             break;
2285 +
2286 +           prompt = _("Open newsgroup to attach message from");
2287 +           set_option (OPTNEWS);
2288 +         }
2289 +#endif
2290 +
2291           if (Context)
2292 +#ifdef USE_NNTP
2293 +         if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
2294 +#endif
2295           {
2296             strfcpy (fname, NONULL (Context->path), sizeof (fname));
2297             mutt_pretty_mailbox (fname);
2298 @@ -711,6 +862,11 @@
2299           if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) == -1 || !fname[0])
2300             break;
2301  
2302 +#ifdef USE_NNTP
2303 +         if (option (OPTNEWS))
2304 +           nntp_expand_path (fname, sizeof (fname), &CurrentNewsSrv->conn->account);
2305 +         else
2306 +#endif
2307           mutt_expand_path (fname, sizeof (fname));
2308  #ifdef USE_IMAP
2309            if (!mx_is_imap (fname))
2310 @@ -718,6 +874,9 @@
2311  #ifdef USE_POP
2312            if (!mx_is_pop (fname))
2313  #endif
2314 +#ifdef USE_NNTP
2315 +          if (!mx_is_nntp (fname) && !option (OPTNEWS))
2316 +#endif
2317           /* check to make sure the file exists and is readable */
2318           if (access (fname, R_OK) == -1)
2319           {
2320 diff -uNr mutt-1.4.orig/configure.in mutt-1.4/configure.in
2321 --- mutt-1.4.orig/configure.in  Sun Nov  3 21:42:52 2002
2322 +++ mutt-1.4/configure.in       Sun Nov  3 21:57:20 2002
2323 @@ -457,6 +457,14 @@
2324  ])
2325  AM_CONDITIONAL(BUILD_IMAP, test x$need_imap = xyes)
2326  
2327 +AC_ARG_ENABLE(nntp, [  --enable-nntp              Enable NNTP support],
2328 +[      if test x$enableval = xyes ; then
2329 +               AC_DEFINE(USE_NNTP)
2330 +               MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS nntp.o newsrc.o"
2331 +               need_socket="yes"
2332 +       fi
2333 +])
2334 +
2335  dnl -- end socket dependencies --
2336  
2337  if test "$need_socket" = "yes"
2338 diff -uNr mutt-1.4.orig/curs_main.c mutt-1.4/curs_main.c
2339 --- mutt-1.4.orig/curs_main.c   Sun Nov  3 21:42:52 2002
2340 +++ mutt-1.4/curs_main.c        Sun Nov  3 21:57:20 2002
2341 @@ -18,6 +18,7 @@
2342  
2343  #include "mutt.h"
2344  #include "mutt_curses.h"
2345 +#include "mx.h"
2346  #include "mutt_menu.h"
2347  #include "mailbox.h"
2348  #include "mapping.h"
2349 @@ -33,6 +34,10 @@
2350  #include "imap.h"
2351  #endif
2352  
2353 +#ifdef USE_NNTP
2354 +#include "nntp.h"
2355 +#endif
2356 +
2357  
2358  
2359  #ifdef HAVE_PGP
2360 @@ -405,12 +410,27 @@
2361    { NULL }
2362  };
2363  
2364 +#ifdef USE_NNTP
2365 +struct mapping_t IndexNewsHelp[] = {
2366 +  { N_("Quit"),     OP_QUIT },
2367 +  { N_("Del"),      OP_DELETE },
2368 +  { N_("Undel"),    OP_UNDELETE },
2369 +  { N_("Save"),     OP_SAVE },
2370 +  { N_("Post"),     OP_POST },
2371 +  { N_("Followup"), OP_FOLLOWUP },
2372 +  { N_("Catchup"),  OP_CATCHUP },
2373 +  { N_("Help"),     OP_HELP },
2374 +  { NULL }
2375 +};
2376 +#endif
2377 +
2378  /* This function handles the message index window as well as commands returned
2379   * from the pager (MENU_PAGER).
2380   */
2381  int mutt_index_menu (void)
2382  {
2383    char buf[LONG_STRING], helpstr[SHORT_STRING];
2384 +  int flags;
2385    int op = OP_NULL;
2386    int done = 0;                /* controls when to exit the "event" loop */
2387    int i = 0, j;
2388 @@ -432,7 +452,11 @@
2389    menu->make_entry = index_make_entry;
2390    menu->color = index_color;
2391    menu->current = ci_first_message ();
2392 -  menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN, IndexHelp);
2393 +  menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
2394 +#ifdef USE_NNTP
2395 +       (Context && (Context->magic == M_NNTP)) ? IndexNewsHelp :
2396 +#endif
2397 +       IndexHelp);
2398    
2399    if (!attach_msg) 
2400      mutt_buffy_check(1); /* force the buffy check after we enter the folder */
2401 @@ -633,6 +657,9 @@
2402        mutt_curs_set (1);       /* fallback from the pager */
2403      }
2404  
2405 +#ifdef USE_NNTP
2406 +    unset_option (OPTNEWS);    /* for any case */
2407 +#endif
2408      switch (op)
2409      {
2410  
2411 @@ -683,6 +710,120 @@
2412         menu_current_bottom (menu);
2413         break;
2414  
2415 +#ifdef USE_NNTP
2416 +      case OP_GET_MESSAGE:
2417 +      case OP_GET_PARENT:
2418 +       CHECK_MSGCOUNT;
2419 +       if (Context->magic == M_NNTP)
2420 +       {
2421 +         HEADER *h;
2422 +
2423 +         if (op == OP_GET_MESSAGE)
2424 +         {
2425 +           buf[0] = 0;
2426 +           if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0) != 0
2427 +                 || !buf[0])
2428 +             break;
2429 +         }
2430 +         else
2431 +         {
2432 +           LIST *ref = CURHDR->env->references;
2433 +           if (!ref)
2434 +           {
2435 +             mutt_error _("Article has no parent reference!");
2436 +             break;
2437 +           }
2438 +           strfcpy (buf, ref->data, sizeof (buf));
2439 +         }
2440 +         if (!Context->id_hash)
2441 +           Context->id_hash = mutt_make_id_hash (Context);
2442 +         if ((h = hash_find (Context->id_hash, buf)))
2443 +         {
2444 +           if (h->virtual != -1)
2445 +           {
2446 +             menu->current = h->virtual;
2447 +             menu->redraw = REDRAW_MOTION_RESYNCH;
2448 +           }
2449 +           else if (h->collapsed)
2450 +           {
2451 +             mutt_uncollapse_thread (Context, h);
2452 +             mutt_set_virtual (Context);
2453 +             menu->current = h->virtual;
2454 +             menu->redraw = REDRAW_MOTION_RESYNCH;
2455 +           }
2456 +           else
2457 +             mutt_error _("Message not visible in limited view.");
2458 +         }
2459 +         else
2460 +         {
2461 +           if (nntp_check_msgid (Context, buf) == 0)
2462 +           {
2463 +             h = Context->hdrs[Context->msgcount-1];
2464 +             mutt_sort_headers (Context, 0);
2465 +             menu->current = h->virtual;
2466 +             menu->redraw = REDRAW_FULL;
2467 +           }
2468 +           else
2469 +             mutt_error (_("Article %s not found on server"), buf); 
2470 +         }
2471 +       }
2472 +       break;
2473 +
2474 +      case OP_GET_CHILDREN:
2475 +      case OP_RECONSTRUCT_THREAD:
2476 +       CHECK_MSGCOUNT;
2477 +       if (Context->magic == M_NNTP)
2478 +       {
2479 +         HEADER *h;
2480 +         int old = CURHDR->index, i;
2481 +
2482 +         if (!CURHDR->env->message_id)
2483 +         {
2484 +           mutt_error _("No Message-Id. Unable to perform operation");
2485 +           break;
2486 +         }
2487 +
2488 +         if (!Context->id_hash)
2489 +           Context->id_hash = mutt_make_id_hash (Context);
2490 +         strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
2491 +
2492 +         if (op == OP_RECONSTRUCT_THREAD)
2493 +         {
2494 +           LIST *ref = CURHDR->env->references;
2495 +           while (ref)
2496 +           {
2497 +             nntp_check_msgid (Context, ref->data);
2498 +             /* the last msgid in References is the root message */
2499 +             if (!ref->next)
2500 +               strfcpy (buf, ref->data, sizeof (buf));
2501 +             ref = ref->next;
2502 +           }
2503 +         }
2504 +         mutt_message _("Check for children of message...");
2505 +         if (nntp_check_children (Context, buf) == 0)
2506 +         {
2507 +           mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
2508 +           h = hash_find (Context->id_hash, buf);
2509 +           /* if the root message was retrieved, move to it */
2510 +           if (h)
2511 +             menu->current = h->virtual;
2512 +           else /* try to restore old position */
2513 +             for (i = 0; i < Context->msgcount; i++)
2514 +               if (Context->hdrs[i]->index == old)
2515 +               {
2516 +                 menu->current = Context->hdrs[i]->virtual;
2517 +                 /* As an added courtesy, recenter the menu
2518 +                  * with the current entry at the middle of the screen */
2519 +                 menu_check_recenter (menu);
2520 +                 menu_current_middle (menu);
2521 +               }
2522 +         }
2523 +         menu->redraw = REDRAW_FULL;
2524 +         mutt_clear_error ();
2525 +       }
2526 +       break;
2527 +#endif
2528 +
2529        case OP_JUMP:
2530  
2531         CHECK_MSGCOUNT;
2532 @@ -778,11 +919,33 @@
2533          break;
2534  
2535        case OP_MAIN_LIMIT:
2536 +      case OP_TOGGLE_READ:
2537  
2538         CHECK_MSGCOUNT;
2539         menu->oldcurrent = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ?
2540                 CURHDR->index : -1;
2541 -       if (mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
2542 +       if (op == OP_TOGGLE_READ)
2543 +       {
2544 +         char buf[LONG_STRING];
2545 +
2546 +         if (!Context->pattern || strncmp (Context->pattern, "!~R!~D~s", 8) != 0)
2547 +         {
2548 +           snprintf (buf, sizeof (buf), "!~R!~D~s%s",
2549 +                     Context->pattern ? Context->pattern : ".*");
2550 +           set_option (OPTHIDEREAD);
2551 +         }
2552 +         else
2553 +         {
2554 +           strfcpy (buf, Context->pattern + 8, sizeof(buf));
2555 +           if (!*buf || strncmp (buf, ".*", 2) == 0)
2556 +             snprintf (buf, sizeof(buf), "~A");
2557 +           unset_option (OPTHIDEREAD);
2558 +         }
2559 +         FREE (&Context->pattern);
2560 +         Context->pattern = safe_strdup (buf);
2561 +       }
2562 +       if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
2563 +           mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
2564         {
2565           if (menu->oldcurrent >= 0)
2566           {
2567 @@ -980,20 +1143,43 @@
2568         break;
2569  
2570        case OP_MAIN_CHANGE_FOLDER:
2571 -      
2572 -       if (attach_msg)
2573 -         op = OP_MAIN_CHANGE_FOLDER_READONLY;
2574 -
2575 -       /* fallback to the readonly case */
2576 -
2577        case OP_MAIN_CHANGE_FOLDER_READONLY:
2578 +#ifdef USE_NNTP
2579 +      case OP_MAIN_CHANGE_GROUP:
2580 +      case OP_MAIN_CHANGE_GROUP_READONLY:
2581 +#endif
2582 +
2583 +       if (attach_msg || option (OPTREADONLY) ||
2584 +#ifdef USE_NNTP
2585 +           op == OP_MAIN_CHANGE_GROUP_READONLY ||
2586 +#endif
2587 +           op == OP_MAIN_CHANGE_FOLDER_READONLY)
2588 +         flags = M_READONLY;
2589 +       else
2590 +         flags = 0;
2591  
2592 -        if ((op == OP_MAIN_CHANGE_FOLDER_READONLY) || option (OPTREADONLY))
2593 +       if (flags)
2594            cp = _("Open mailbox in read-only mode");
2595          else
2596            cp = _("Open mailbox");
2597  
2598         buf[0] = '\0';
2599 +#ifdef USE_NNTP
2600 +       unset_option (OPTNEWS);
2601 +       if (op == OP_MAIN_CHANGE_GROUP ||
2602 +           op == OP_MAIN_CHANGE_GROUP_READONLY)
2603 +       {
2604 +         set_option (OPTNEWS);
2605 +         if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
2606 +           break;
2607 +         if (flags)
2608 +           cp = _("Open newsgroup in read-only mode");
2609 +         else
2610 +           cp = _("Open newsgroup");
2611 +         nntp_buffy (buf);
2612 +       }
2613 +       else
2614 +#endif
2615         mutt_buffy (buf, sizeof (buf));
2616  
2617         if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
2618 @@ -1004,6 +1190,14 @@
2619           break;
2620         }
2621  
2622 +#ifdef USE_NNTP
2623 +        if (option (OPTNEWS))
2624 +       {
2625 +         unset_option (OPTNEWS);
2626 +          nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
2627 +       }
2628 +        else
2629 +#endif
2630         mutt_expand_path (buf, sizeof (buf));
2631         if (mx_get_magic (buf) <= 0)
2632         {
2633 @@ -1039,15 +1233,18 @@
2634        
2635         mutt_folder_hook (buf);
2636  
2637 -       if ((Context = mx_open_mailbox (buf, 
2638 -                                       (option (OPTREADONLY) || op == OP_MAIN_CHANGE_FOLDER_READONLY) ?
2639 -                                       M_READONLY : 0, NULL)) != NULL)
2640 +       if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL)
2641         {
2642           menu->current = ci_first_message ();
2643         }
2644         else
2645           menu->current = 0;
2646  
2647 +#ifdef USE_NNTP
2648 +       /* mutt_buffy_check() must be done with mail-reader mode! */
2649 +       menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
2650 +         (Context && (Context->magic == M_NNTP)) ? IndexNewsHelp : IndexHelp);
2651 +#endif
2652         mutt_clear_error ();
2653         mutt_buffy_check(1); /* force the buffy check after we have changed
2654                               the folder */
2655 @@ -1422,6 +1619,15 @@
2656         }
2657  #endif
2658  
2659 +#ifdef USE_NNTP
2660 +       if (Context->magic == M_NNTP)
2661 +       {
2662 +         mutt_flushinp ();
2663 +         mutt_error _("Can't change 'important' flag on NNTP server.");
2664 +         break;
2665 +       }
2666 +#endif
2667 +
2668          if (tag)
2669          {
2670           for (j = 0; j < Context->vcount; j++)
2671 @@ -1767,6 +1973,17 @@
2672         }
2673         break;
2674  
2675 +#ifdef USE_NNTP
2676 +      case OP_CATCHUP:
2677 +       if (Context && Context->magic == M_NNTP)
2678 +       {
2679 +         if (mutt_newsgroup_catchup (CurrentNewsSrv,
2680 +               ((NNTP_DATA *)Context->data)->group))
2681 +           menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2682 +       }
2683 +       break;
2684 +#endif
2685 +
2686        case OP_DISPLAY_ADDRESS:
2687  
2688         CHECK_MSGCOUNT;
2689 @@ -1801,6 +2018,15 @@
2690         }
2691  #endif
2692  
2693 +#ifdef USE_NNTP
2694 +       if (Context->magic == M_NNTP)
2695 +       {
2696 +         mutt_flushinp ();
2697 +         mutt_error _("Can't edit message on newsserver.");
2698 +         break;
2699 +       }
2700 +#endif
2701 +
2702          mutt_edit_message (Context, tag ? NULL : CURHDR);
2703         menu->redraw = REDRAW_FULL;
2704  
2705 @@ -1955,6 +2181,37 @@
2706        
2707          menu->redraw = REDRAW_FULL;
2708          break;
2709 +
2710 +#ifdef USE_NNTP
2711 +      case OP_POST:
2712 +      case OP_FOLLOWUP:
2713 +      case OP_FORWARD_TO_GROUP:
2714 +
2715 +       CHECK_ATTACH;
2716 +       if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2717 +           mutt_strcasecmp (CURHDR->env->followup_to, "poster") ||
2718 +           query_quadoption (OPT_FOLLOWUPTOPOSTER,_("Reply by mail as poster prefers?")) != M_YES)
2719 +       {
2720 +         if (Context && Context->magic == M_NNTP &&
2721 +             !((NNTP_DATA *)Context->data)->allowed &&
2722 +             query_quadoption (OPT_TOMODERATED, _("Posting to this group not allowed, may be moderated. Continue?")) != M_YES)
2723 +           break;
2724 +         if (op == OP_POST)
2725 +           ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2726 +         else
2727 +         {
2728 +           CHECK_MSGCOUNT;
2729 +           if (op == OP_FOLLOWUP)
2730 +             ci_send_message (SENDNEWS|SENDREPLY, NULL, NULL, Context,
2731 +                              tag ? NULL : CURHDR);
2732 +           else
2733 +             ci_send_message (SENDNEWS|SENDFORWARD, NULL, NULL, Context,
2734 +                              tag ? NULL : CURHDR);
2735 +         }
2736 +         menu->redraw = REDRAW_FULL;
2737 +         break;
2738 +       }
2739 +#endif
2740        
2741        case OP_REPLY:
2742  
2743 @@ -2081,6 +2338,12 @@
2744    if (!attach_msg)
2745      imap_logout_all ();
2746  #endif
2747 +#ifdef USE_NNTP
2748 +  /* Close all open NNTP connections */
2749 +  if (!attach_msg)
2750 +    nntp_logout_all ();
2751 +#endif
2752 +
2753  
2754    mutt_menuDestroy (&menu);
2755    return (close);
2756 diff -uNr mutt-1.4.orig/doc/manual.sgml mutt-1.4/doc/manual.sgml
2757 --- mutt-1.4.orig/doc/manual.sgml       Sun Nov  3 21:42:51 2002
2758 +++ mutt-1.4/doc/manual.sgml    Sun Nov  3 21:57:20 2002
2759 @@ -723,6 +723,17 @@
2760  
2761  See also the <ref id="postpone" name="&dollar;postpone"> quad-option.
2762  
2763 +<sect1>Reading news via NNTP<label id="reading_news">
2764 +<p>
2765 +
2766 +If compiled with ``--enable-nntp'' option, Mutt can read news from newsserver
2767 +via NNTP.  You can open a newsgroup with function ``change-newsgroup''
2768 +(default: i).  Default newsserver can be obtained from <em/NNTPSERVER/
2769 +environment variable.  Like other news readers, info about subscribed
2770 +newsgroups is saved in file by <ref id="newsrc" name="&dollar;newsrc">
2771 +variable.  Article headers are cached and can be loaded from file when
2772 +newsgroup entered instead loading from newsserver.
2773 +
2774  <sect>Configuration
2775  <p>
2776  
2777 @@ -3262,6 +3273,26 @@
2778  editing the body of an outgoing message.
2779  
2780  
2781 +<sect2>ask&lowbar;follow&lowbar;up<label id="ask_follow_up">
2782 +<p>
2783 +Type: boolean<newline>
2784 +Default: no
2785 +
2786 +<p>
2787 +If set, Mutt will prompt you for follow-up groups before editing
2788 +the body of an outgoing message.
2789 +
2790 +
2791 +<sect2>ask&lowbar;x&lowbar;comment&lowbar;to<label id="ask_x_comment_to">
2792 +<p>
2793 +Type: boolean<newline>
2794 +Default: no
2795 +
2796 +<p>
2797 +If set, Mutt will prompt you for x-comment-to field before editing
2798 +the body of an outgoing message.
2799 +
2800 +
2801  <sect2>attach&lowbar;format<label id="attach_format">
2802  <p>
2803  Type: string<newline>
2804 @@ -3379,6 +3410,16 @@
2805  bouncing messages.  Postfix users may wish to unset this variable.
2806  
2807  
2808 +<sect2>catchup&lowbar;newsgroup<label id="catchup_newsgroup">
2809 +<p>
2810 +Type: quadoption<newline>
2811 +Default: ask-yes
2812 +
2813 +<p>
2814 +If this variable is <em>set</em>, Mutt will mark all articles in newsgroup
2815 +as read when you quit the newsgroup (catchup newsgroup).
2816 +
2817 +
2818  <sect2>charset<label id="charset">
2819  <p>
2820  Type: string<newline>
2821 @@ -3781,6 +3822,18 @@
2822  resulting in two copies of the same email for you.
2823  
2824  
2825 +<sect2>followup&lowbar;to&lowbar;poster<label id="followup_to_poster">
2826 +<p>
2827 +Type: quadoption<newline>
2828 +Default: ask-yes
2829 +
2830 +<p>
2831 +If this variable is <em>set</em> and the keyword &dquot;poster&dquot; is present in
2832 +<em>Followup-To</em> header, follow-up to newsgroup function is not
2833 +permitted.  The message will be mailed to the submitter of the
2834 +message via mail.
2835 +
2836 +
2837  <sect2>force&lowbar;name<label id="force_name">
2838  <p>
2839  Type: boolean<newline>
2840 @@ -3859,6 +3912,30 @@
2841  &dquot;Franklin&dquot; to &dquot;Franklin, Steve&dquot;.
2842  
2843  
2844 +<sect2>group&lowbar;index&lowbar;format<label id="group_index_format">
2845 +<p>
2846 +Type: string<newline>
2847 +Default: &dquot;&percnt;4C &percnt;M&percnt;N &percnt;5s  &percnt;-45.45f &percnt;d&dquot;
2848 +
2849 +<p>
2850 +This variable allows you to customize the newsgroup browser display to
2851 +your personal taste.  This string is similar to ``<ref id="index_format" name="index&lowbar;format">'', but
2852 +has its own set of printf()-like sequences:
2853 +<p>
2854 +
2855 +<tscreen><verb>
2856 +%C      current newsgroup number
2857 +%d      description of newsgroup (becomes from server)
2858 +%f      newsgroup name
2859 +%M      - if newsgroup not allowed for direct post (moderated for example)
2860 +%N      N if newsgroup is new, u if unsubscribed, blank otherwise
2861 +%n      number of new articles in newsgroup
2862 +%s      number of unread articles in newsgroup
2863 +%>X     right justify the rest of the string and pad with character "X"
2864 +%|X     pad to the end of the line with character "X"
2865 +
2866 +</verb></tscreen>
2867 +
2868  <sect2>hdrs<label id="hdrs">
2869  <p>
2870  Type: boolean<newline>
2871 @@ -4203,6 +4280,7 @@
2872  <tag>&percnt;E </tag>number of messages in current thread
2873  <tag>&percnt;f </tag>entire From: line (address + real name)
2874  <tag>&percnt;F </tag>author name, or recipient name if the message is from you
2875 +<tag>&percnt;g </tag>newsgroup name (if compiled with nntp support)
2876  <tag>&percnt;i </tag>message-id of the current message
2877  <tag>&percnt;l </tag>number of lines in the message
2878  <tag>&percnt;L </tag>If an address in the To or CC header field matches an address
2879 @@ -4220,6 +4298,7 @@
2880  <tag>&percnt;T </tag>the appropriate character from the <ref id="to_chars" name="&dollar;to&lowbar;chars"> string
2881  <tag>&percnt;u </tag>user (login) name of the author
2882  <tag>&percnt;v </tag>first name of the author, or the recipient if the message is from you
2883 +<tag>&percnt;W </tag>name of organization of author (`organization:' field)
2884  <tag>&percnt;y </tag>`x-label:' field, if present
2885  <tag>&percnt;Y </tag>`x-label' field, if present, and (1) not at part of a thread tree,
2886  (2) at the top of a thread, or (3) `x-label' is different from
2887 @@ -4244,6 +4323,24 @@
2888  See also: ``<ref id="to_chars" name="&dollar;to&lowbar;chars">''.
2889  
2890  
2891 +<sect2>inews<label id="inews">
2892 +<p>
2893 +Type: path<newline>
2894 +Default: &dquot;&dquot;
2895 +
2896 +<p>
2897 +If set, specifies the program and arguments used to deliver news posted
2898 +by Mutt.  Otherwise, mutt posts article using current connection to
2899 +news server.  The following printf-style sequence is understood:
2900 +<p>
2901 +
2902 +<tscreen><verb>
2903 +%s      newsserver name
2904 +
2905 +</verb></tscreen><p>
2906 +Example: set inews=&dquot;/usr/local/bin/inews -hS&dquot;
2907 +
2908 +
2909  <sect2>ispell<label id="ispell">
2910  <p>
2911  Type: path<newline>
2912 @@ -4491,6 +4588,17 @@
2913  be attached to the newly composed message if this option is set.
2914  
2915  
2916 +<sect2>mime&lowbar;subject<label id="mime_subject">
2917 +<p>
2918 +Type: boolean<newline>
2919 +Default: yes
2920 +
2921 +<p>
2922 +If <em>unset</em>, 8-bit ``subject:'' line in article header will not be
2923 +encoded according to RFC2047 to base64.  This is useful when message
2924 +is Usenet article, because MIME for news is nonstandard feature.
2925 +
2926 +
2927  <sect2>mix&lowbar;entry&lowbar;format<label id="mix_entry_format">
2928  <p>
2929  Type: string<newline>
2930 @@ -4544,6 +4652,112 @@
2931  escape sequences see the section on ``<ref id="index_format" name="&dollar;index&lowbar;format">''.
2932  
2933  
2934 +<sect2>news&lowbar;cache&lowbar;dir<label id="news_cache_dir">
2935 +<p>
2936 +Type: path<newline>
2937 +Default: &dquot;&tilde;/.mutt&dquot;
2938 +
2939 +<p>
2940 +This variable pointing to directory where Mutt will save cached news
2941 +articles headers in. If <em>unset</em>, headers will not be saved at all
2942 +and will be reloaded each time when you enter to newsgroup.
2943 +
2944 +
2945 +<sect2>news&lowbar;server<label id="news_server">
2946 +<p>
2947 +Type: string<newline>
2948 +Default: &dquot;&dquot;
2949 +
2950 +<p>
2951 +This variable specifies domain name or address of NNTP server. It
2952 +defaults to the newsserver specified in the environment variable
2953 +&dollar;NNTPSERVER or contained in the file /etc/nntpserver.  You can also
2954 +specify username and an alternative port for each newsserver, ie:
2955 +<p>
2956 +&lsqb;nntp&lsqb;s&rsqb;://&rsqb;&lsqb;username&lsqb;:password&rsqb;@&rsqb;newsserver&lsqb;:port&rsqb;
2957 +
2958 +
2959 +<sect2>newsrc<label id="newsrc">
2960 +<p>
2961 +Type: path<newline>
2962 +Default: &dquot;&tilde;/.newsrc&dquot;
2963 +
2964 +<p>
2965 +The file, containing info about subscribed newsgroups - names and
2966 +indexes of read articles.  The following printf-style sequence
2967 +is understood:
2968 +<p>
2969 +
2970 +<tscreen><verb>
2971 +%s      newsserver name
2972 +
2973 +</verb></tscreen>
2974 +
2975 +<sect2>nntp&lowbar;context<label id="nntp_context">
2976 +<p>
2977 +Type: number<newline>
2978 +Default: 1000
2979 +
2980 +<p>
2981 +This variable defines number of articles which will be in index when
2982 +newsgroup entered.  If active newsgroup have more articles than this
2983 +number, oldest articles will be ignored.  Also controls how many
2984 +articles headers will be saved in cache when you quit newsgroup.
2985 +
2986 +
2987 +<sect2>nntp&lowbar;load&lowbar;description<label id="nntp_load_description">
2988 +<p>
2989 +Type: boolean<newline>
2990 +Default: yes
2991 +
2992 +<p>
2993 +This variable controls whether or not descriptions for each newsgroup
2994 +must be loaded when newsgroup is added to list (first time list
2995 +loading or new newsgroup adding).
2996 +
2997 +
2998 +<sect2>nntp&lowbar;user<label id="nntp_user">
2999 +<p>
3000 +Type: string<newline>
3001 +Default: &dquot;&dquot;
3002 +
3003 +<p>
3004 +Your login name on the NNTP server.  If <em>unset</em> and NNTP server requires
3005 +authentification, Mutt will prompt you for your account name when you
3006 +connect to newsserver.
3007 +
3008 +
3009 +<sect2>nntp&lowbar;pass<label id="nntp_pass">
3010 +<p>
3011 +Type: string<newline>
3012 +Default: &dquot;&dquot;
3013 +
3014 +<p>
3015 +Your password for NNTP account.
3016 +
3017 +
3018 +<sect2>nntp&lowbar;poll<label id="nntp_poll">
3019 +<p>
3020 +Type: number<newline>
3021 +Default: 60
3022 +
3023 +<p>
3024 +The time in seconds until any operations on newsgroup except post new
3025 +article will cause recheck for new news.  If set to 0, Mutt will
3026 +recheck newsgroup on each operation in index (stepping, read article,
3027 +etc.).
3028 +
3029 +
3030 +<sect2>nntp&lowbar;reconnect<label id="nntp_reconnect">
3031 +<p>
3032 +Type: quadoption<newline>
3033 +Default: ask-yes
3034 +
3035 +<p>
3036 +Controls whether or not Mutt will try to reconnect to newsserver when
3037 +connection lost.
3038 +
3039 +
3040  <sect2>pager<label id="pager">
3041  <p>
3042  Type: path<newline>
3043 @@ -5240,6 +5454,18 @@
3044  string after the inclusion of a message which is being replied to.
3045  
3046  
3047 +<sect2>post&lowbar;moderated<label id="post_moderated">
3048 +<p>
3049 +Type: quadoption<newline>
3050 +Default: ask-yes
3051 +
3052 +<p>
3053 +If set to <em>yes</em>, Mutt will post article to newsgroup that have
3054 +not permissions to posting (e.g. moderated).  <bf>Note:</bf> if newsserver
3055 +does not support posting to that newsgroup or totally read-only, that
3056 +posting will not have an effect.
3057 +
3058 +
3059  <sect2>postpone<label id="postpone">
3060  <p>
3061  Type: quadoption<newline>
3062 @@ -5723,6 +5949,38 @@
3063  shell from /etc/passwd is used.
3064  
3065  
3066 +<sect2>save&lowbar;unsubscribed<label id="save_unsubscribed">
3067 +<p>
3068 +Type: boolean<newline>
3069 +Default: no
3070 +
3071 +<p>
3072 +When <em>set</em>, info about unsubscribed newsgroups will be saved into
3073 +``newsrc'' file and into cache.
3074 +
3075 +
3076 +<sect2>show&lowbar;new&lowbar;news<label id="show_new_news">
3077 +<p>
3078 +Type: boolean<newline>
3079 +Default: yes
3080 +
3081 +<p>
3082 +If <em>set</em>, newsserver will be asked for new newsgroups on entering
3083 +the browser.  Otherwise, it will be done only once for a newsserver.
3084 +Also controls whether or not number of new articles of subscribed
3085 +newsgroups will be then checked.
3086 +
3087 +
3088 +<sect2>show&lowbar;only&lowbar;unread<label id="show_only_unread">
3089 +<p>
3090 +Type: boolean<newline>
3091 +Default: no
3092 +
3093 +<p>
3094 +If <em>set</em>, only subscribed newsgroups that contain unread articles
3095 +will be displayed in browser.
3096 +
3097 +
3098  <sect2>sig&lowbar;dashes<label id="sig_dashes">
3099  <p>
3100  Type: boolean<newline>
3101 @@ -6189,6 +6447,17 @@
3102  command.
3103  
3104  
3105 +<sect2>use&lowbar;ipv6<label id="use_ipv6">
3106 +<p>
3107 +Type: boolean<newline>
3108 +Default: yes
3109 +
3110 +<p>
3111 +When <em>set</em>, Mutt will look for IPv6 addresses of hosts it tries to
3112 +contact.  If this option is unset, Mutt will restrict itself to IPv4 addresses.
3113 +Normally, the default should work.
3114 +
3115 +
3116  <sect2>user&lowbar;agent<label id="user_agent">
3117  <p>
3118  Type: boolean<newline>
3119 @@ -6283,6 +6552,16 @@
3120  messages to be sent.  Exim users may wish to use this.
3121  
3122  
3123 +<sect2>x&lowbar;comment&lowbar;to<label id="x_comment_to">
3124 +<p>
3125 +Type: boolean<newline>
3126 +Default: no
3127 +
3128 +<p>
3129 +If <em>set</em>, Mutt will add ``X-Comment-To:'' field (that contains full
3130 +name of original article author) to article that followuped to newsgroup.
3131 +
3132 +
3133  <sect1>Functions<label id="functions">
3134  <p>
3135  The following is the list of available functions listed by the mapping
3136 diff -uNr mutt-1.4.orig/doc/manual.sgml.head mutt-1.4/doc/manual.sgml.head
3137 --- mutt-1.4.orig/doc/manual.sgml.head  Sun Nov  3 21:42:52 2002
3138 +++ mutt-1.4/doc/manual.sgml.head       Sun Nov  3 21:57:20 2002
3139 @@ -724,6 +724,17 @@
3140  
3141  See also the <ref id="postpone" name="&dollar;postpone"> quad-option.
3142  
3143 +<sect1>Reading news via NNTP<label id="reading_news">
3144 +<p>
3145 +
3146 +If compiled with ``--enable-nntp'' option, Mutt can read news from newsserver
3147 +via NNTP.  You can open a newsgroup with function ``change-newsgroup''
3148 +(default: i).  Default newsserver can be obtained from <em/NNTPSERVER/
3149 +environment variable.  Like other news readers, info about subscribed
3150 +newsgroups is saved in file by <ref id="newsrc" name="&dollar;newsrc">
3151 +variable.  Article headers are cached and can be loaded from file when
3152 +newsgroup entered instead loading from newsserver.
3153 +
3154  <sect>Configuration
3155  <p>
3156  
3157 diff -uNr mutt-1.4.orig/doc/mutt.man mutt-1.4/doc/mutt.man
3158 --- mutt-1.4.orig/doc/mutt.man  Thu Aug 30 14:55:37 2001
3159 +++ mutt-1.4/doc/mutt.man       Sun Nov  3 21:57:20 2002
3160 @@ -24,8 +24,8 @@
3161  .SH SYNOPSIS
3162  .PP
3163  .B mutt
3164 -[-nRyzZ] 
3165 -[-e \fIcmd\fP] [-F \fIfile\fP] [-m \fItype\fP] [-f \fIfile\fP]
3166 +[-GnRyzZ] 
3167 +[-e \fIcmd\fP] [-F \fIfile\fP] [-g \fIserver\fP] [-m \fItype\fP] [-f \fIfile\fP]
3168  .PP
3169  .B mutt 
3170  [-nx] 
3171 @@ -63,6 +63,10 @@
3172  Specify which mailbox to load.
3173  .IP "-F \fImuttrc\fP"
3174  Specify an initialization file to read instead of ~/.muttrc
3175 +.IP "-g \fIserver\fP"
3176 +Start Mutt with a listing of subscribed newsgroups at specified newsserver.
3177 +.IP "-G"
3178 +Start Mutt with a listing of subscribed newsgroups.
3179  .IP "-h"
3180  Display help.
3181  .IP "-H \fIdraft\fP"
3182 diff -uNr mutt-1.4.orig/doc/muttrc.man mutt-1.4/doc/muttrc.man
3183 --- mutt-1.4.orig/doc/muttrc.man        Sun Nov  3 21:42:51 2002
3184 +++ mutt-1.4/doc/muttrc.man     Sun Nov  3 21:57:47 2002
3185 @@ -257,7 +257,9 @@
3186  \fBpgp-hook\fP \fIpattern\fP \fIkey-id\fP
3187  The pgp-hook command provides a method by which you can
3188  specify the ID of the public key to be used when encrypting messages
3189 -to a certain recipient.
3190 +to a certain recipient.  You may use multiple \fBpgp-hook\fPs with the
3191 +same \fIpattern\fP; multiple matching \fBpgp-hook\fPs result in the use
3192 +of multiple \fIkey-id\fPs for recipient.
3193  .PP
3194  .nf
3195  \fBopen-hook\fP \fIregexp\fP "\fIcommand\fP"
3196 @@ -622,6 +624,28 @@
3197  
3198  
3199  .TP
3200 +.B ask_follow_up
3201 +.nf
3202 +Type: boolean
3203 +Default: no
3204 +.fi
3205 +.IP
3206 +If set, Mutt will prompt you for follow-up groups before editing
3207 +the body of an outgoing message.
3208 +
3209 +
3210 +.TP
3211 +.B ask_x_comment_to
3212 +.nf
3213 +Type: boolean
3214 +Default: no
3215 +.fi
3216 +.IP
3217 +If set, Mutt will prompt you for x-comment-to field before editing
3218 +the body of an outgoing message.
3219 +
3220 +
3221 +.TP
3222  .B attach_format
3223  .nf
3224  Type: string
3225 @@ -773,6 +797,17 @@
3226  
3227  
3228  .TP
3229 +.B catchup_newsgroup
3230 +.nf
3231 +Type: quadoption
3232 +Default: ask-yes
3233 +.fi
3234 +.IP
3235 +If this variable is \fIset\fP, Mutt will mark all articles in newsgroup
3236 +as read when you quit the newsgroup (catchup newsgroup).
3237 +
3238 +
3239 +.TP
3240  .B charset
3241  .nf
3242  Type: string
3243 @@ -990,7 +1025,7 @@
3244  .B dotlock_program
3245  .nf
3246  Type: path
3247 -Default: \(lq/usr/local/bin/mutt_dotlock\(rq
3248 +Default: \(lq/usr/bin/mutt_dotlock\(rq
3249  .fi
3250  .IP
3251  Contains the path of the mutt_dotlock (8) binary to be used by
3252 @@ -1161,6 +1196,16 @@
3253  
3254  
3255  .TP
3256 +.B folder_columns
3257 +.nf
3258 +Type: number
3259 +Default: 1
3260 +.fi
3261 +.IP
3262 +Specifies the number of folder columns in folder browser.
3263 +
3264 +
3265 +.TP
3266  .B folder_format
3267  .nf
3268  Type: string
3269 @@ -1235,6 +1280,19 @@
3270  
3271  
3272  .TP
3273 +.B followup_to_poster
3274 +.nf
3275 +Type: quadoption
3276 +Default: ask-yes
3277 +.fi
3278 +.IP
3279 +If this variable is \fIset\fP and the keyword \(rqposter\(rq is present in
3280 +\fIFollowup-To\fP header, follow-up to newsgroup function is not
3281 +permitted.  The message will be mailed to the submitter of the
3282 +message via mail.
3283 +
3284 +
3285 +.TP
3286  .B force_name
3287  .nf
3288  Type: boolean
3289 @@ -1319,6 +1377,39 @@
3290  
3291  
3292  .TP
3293 +.B group_index_format
3294 +.nf
3295 +Type: string
3296 +Default: \(lq%4C %M%N %5s  %-45.45f %d\(rq
3297 +.fi
3298 +.IP
3299 +This variable allows you to customize the newsgroup browser display to
3300 +your personal taste.  This string is similar to \(lqindex_format\(rq, but
3301 +has its own set of printf()-like sequences:
3302 +.IP
3303 +
3304 +.IP
3305 +.DS
3306 +.sp
3307 +.ft CR
3308 +.nf
3309 +%C      current newsgroup number
3310 +%d      description of newsgroup (becomes from server)
3311 +%f      newsgroup name
3312 +%M      - if newsgroup not allowed for direct post (moderated for example)
3313 +%N      N if newsgroup is new, u if unsubscribed, blank otherwise
3314 +%n      number of new articles in newsgroup
3315 +%s      number of unread articles in newsgroup
3316 +%>X     right justify the rest of the string and pad with character \(rqX\(rq
3317 +%|X     pad to the end of the line with character \(rqX\(rq
3318 +
3319 +.fi
3320 +.ec
3321 +.ft P
3322 +.sp
3323 +
3324 +
3325 +.TP
3326  .B hdrs
3327  .nf
3328  Type: boolean
3329 @@ -1711,6 +1802,9 @@
3330  .IP %F 
3331  author name, or recipient name if the message is from you
3332  
3333 +.IP %g 
3334 +newsgroup name (if compiled with nntp support)
3335 +
3336  .IP %i 
3337  message-id of the current message
3338  
3339 @@ -1756,6 +1850,9 @@
3340  .IP %v 
3341  first name of the author, or the recipient if the message is from you
3342  
3343 +.IP %W 
3344 +name of organization of author (`organization:' field)
3345 +
3346  .IP %y 
3347  `x-label:' field, if present
3348  
3349 @@ -1798,10 +1895,37 @@
3350  
3351  
3352  .TP
3353 +.B inews
3354 +.nf
3355 +Type: path
3356 +Default: \(lq\(rq
3357 +.fi
3358 +.IP
3359 +If set, specifies the program and arguments used to deliver news posted
3360 +by Mutt.  Otherwise, mutt posts article using current connection to
3361 +news server.  The following printf-style sequence is understood:
3362 +.IP
3363 +
3364 +.IP
3365 +.DS
3366 +.sp
3367 +.ft CR
3368 +.nf
3369 +%s      newsserver name
3370 +
3371 +.fi
3372 +.ec
3373 +.ft P
3374 +.sp
3375 +.IP
3376 +Example: set inews=\(rq/usr/local/bin/inews -hS\(rq
3377 +
3378 +
3379 +.TP
3380  .B ispell
3381  .nf
3382  Type: path
3383 -Default: \(lq/usr/bin/ispell\(rq
3384 +Default: \(lqispell\(rq
3385  .fi
3386  .IP
3387  How to invoke ispell (GNU's spell-checking software).
3388 @@ -2067,6 +2191,18 @@
3389  
3390  
3391  .TP
3392 +.B mime_subject
3393 +.nf
3394 +Type: boolean
3395 +Default: yes
3396 +.fi
3397 +.IP
3398 +If \fIunset\fP, 8-bit \(lqsubject:\(rq line in article header will not be
3399 +encoded according to RFC2047 to base64.  This is useful when message
3400 +is Usenet article, because MIME for news is nonstandard feature.
3401 +
3402 +
3403 +.TP
3404  .B mix_entry_format
3405  .nf
3406  Type: string
3407 @@ -2131,6 +2267,142 @@
3408  
3409  
3410  .TP
3411 +.B narrow_tree
3412 +.nf
3413 +Type: boolean
3414 +Default: no
3415 +.fi
3416 +.IP
3417 +This variable controls the width of the thread tree when sorting by
3418 +threads.  When set, it makes the tree approximately twice as narrow,
3419 +to allow more room the tree and message subjects.  This is useful on
3420 +narrow screens.
3421 +
3422 +
3423 +.TP
3424 +.B news_cache_dir
3425 +.nf
3426 +Type: path
3427 +Default: \(lq~/.mutt\(rq
3428 +.fi
3429 +.IP
3430 +This variable pointing to directory where Mutt will save cached news
3431 +articles headers in. If \fIunset\fP, headers will not be saved at all
3432 +and will be reloaded each time when you enter to newsgroup.
3433 +
3434 +
3435 +.TP
3436 +.B news_server
3437 +.nf
3438 +Type: string
3439 +Default: \(lq\(rq
3440 +.fi
3441 +.IP
3442 +This variable specifies domain name or address of NNTP server. It
3443 +defaults to the newsserver specified in the environment variable
3444 +$NNTPSERVER or contained in the file /etc/nntpserver.  You can also
3445 +specify username and an alternative port for each newsserver, ie:
3446 +.IP
3447 +[nntp[s]://][username[:password]@]newsserver[:port]
3448 +
3449 +
3450 +.TP
3451 +.B newsrc
3452 +.nf
3453 +Type: path
3454 +Default: \(lq~/.newsrc\(rq
3455 +.fi
3456 +.IP
3457 +The file, containing info about subscribed newsgroups - names and
3458 +indexes of read articles.  The following printf-style sequence
3459 +is understood:
3460 +.IP
3461 +
3462 +.IP
3463 +.DS
3464 +.sp
3465 +.ft CR
3466 +.nf
3467 +%s      newsserver name
3468 +
3469 +.fi
3470 +.ec
3471 +.ft P
3472 +.sp
3473 +
3474 +
3475 +.TP
3476 +.B nntp_context
3477 +.nf
3478 +Type: number
3479 +Default: 1000
3480 +.fi
3481 +.IP
3482 +This variable defines number of articles which will be in index when
3483 +newsgroup entered.  If active newsgroup have more articles than this
3484 +number, oldest articles will be ignored.  Also controls how many
3485 +articles headers will be saved in cache when you quit newsgroup.
3486 +
3487 +
3488 +.TP
3489 +.B nntp_load_description
3490 +.nf
3491 +Type: boolean
3492 +Default: yes
3493 +.fi
3494 +.IP
3495 +This variable controls whether or not descriptions for each newsgroup
3496 +must be loaded when newsgroup is added to list (first time list
3497 +loading or new newsgroup adding).
3498 +
3499 +
3500 +.TP
3501 +.B nntp_user
3502 +.nf
3503 +Type: string
3504 +Default: \(lq\(rq
3505 +.fi
3506 +.IP
3507 +Your login name on the NNTP server.  If \fIunset\fP and NNTP server requires
3508 +authentification, Mutt will prompt you for your account name when you
3509 +connect to newsserver.
3510 +
3511 +
3512 +.TP
3513 +.B nntp_pass
3514 +.nf
3515 +Type: string
3516 +Default: \(lq\(rq
3517 +.fi
3518 +.IP
3519 +Your password for NNTP account.
3520 +
3521 +
3522 +.TP
3523 +.B nntp_poll
3524 +.nf
3525 +Type: number
3526 +Default: 60
3527 +.fi
3528 +.IP
3529 +The time in seconds until any operations on newsgroup except post new
3530 +article will cause recheck for new news.  If set to 0, Mutt will
3531 +recheck newsgroup on each operation in index (stepping, read article,
3532 +etc.).
3533 +
3534 +
3535 +.TP
3536 +.B nntp_reconnect
3537 +.nf
3538 +Type: quadoption
3539 +Default: ask-yes
3540 +.fi
3541 +.IP
3542 +Controls whether or not Mutt will try to reconnect to newsserver when
3543 +connection lost.
3544 +
3545 +
3546 +.TP
3547  .B pager
3548  .nf
3549  Type: path
3550 @@ -2207,6 +2479,19 @@
3551  
3552  
3553  .TP
3554 +.B pgp_autoselectkey
3555 +.nf
3556 +Type: boolean
3557 +Default: no
3558 +.fi
3559 +.IP
3560 +If set, then a list of keys is not presented for selection when only
3561 +one matching key is available.  This may be useful in conjunction with
3562 +the \fIpgp-hook\fP command (with \(lq$pgp_confirmhook\(rq set) and the
3563 +\(lq$pgp_ignore_subkeys\(rq variable.
3564 +
3565 +
3566 +.TP
3567  .B pgp_autosign
3568  .nf
3569  Type: boolean
3570 @@ -2234,6 +2519,19 @@
3571  
3572  
3573  .TP
3574 +.B pgp_confirmhook
3575 +.nf
3576 +Type: boolean
3577 +Default: yes
3578 +.fi
3579 +.IP
3580 +If set, then you will be prompted for confirmation of keys when using
3581 +the \fIpgp-hook\fP command.  If unset, no such confirmation prompt will
3582 +be presented.  This is generally considered unsafe, especially where
3583 +typos are concerned.
3584 +
3585 +
3586 +.TP
3587  .B pgp_ignore_subkeys
3588  .nf
3589  Type: boolean
3590 @@ -2916,6 +3214,19 @@
3591  
3592  
3593  .TP
3594 +.B post_moderated
3595 +.nf
3596 +Type: quadoption
3597 +Default: ask-yes
3598 +.fi
3599 +.IP
3600 +If set to \fIyes\fP, Mutt will post article to newsgroup that have
3601 +not permissions to posting (e.g. moderated).  \fBNote:\fP if newsserver
3602 +does not support posting to that newsgroup or totally read-only, that
3603 +posting will not have an effect.
3604 +
3605 +
3606 +.TP
3607  .B postpone
3608  .nf
3609  Type: quadoption
3610 @@ -3056,6 +3367,29 @@
3611  
3612  
3613  .TP
3614 +.B quote_empty
3615 +.nf
3616 +Type: boolean
3617 +Default: yes
3618 +.fi
3619 +.IP
3620 +Controls whether or not empty lines will be quoted using
3621 +\(lqindent_string\(rq.
3622 +
3623 +
3624 +.TP
3625 +.B quote_quoted
3626 +.nf
3627 +Type: boolean
3628 +Default: no
3629 +.fi
3630 +.IP
3631 +Controls how quoted lines will be quoted. If set, one quote
3632 +character will be added to the end of existing prefix.  Otherwise,
3633 +quoted lines will be prepended by \(lqindent_string\(rq.
3634 +
3635 +
3636 +.TP
3637  .B quote_regexp
3638  .nf
3639  Type: regular expression
3640 @@ -3455,6 +3789,41 @@
3641  
3642  
3643  .TP
3644 +.B save_unsubscribed
3645 +.nf
3646 +Type: boolean
3647 +Default: no
3648 +.fi
3649 +.IP
3650 +When \fIset\fP, info about unsubscribed newsgroups will be saved into
3651 +\(lqnewsrc\(rq file and into cache.
3652 +
3653 +
3654 +.TP
3655 +.B show_new_news
3656 +.nf
3657 +Type: boolean
3658 +Default: yes
3659 +.fi
3660 +.IP
3661 +If \fIset\fP, newsserver will be asked for new newsgroups on entering
3662 +the browser.  Otherwise, it will be done only once for a newsserver.
3663 +Also controls whether or not number of new articles of subscribed
3664 +newsgroups will be then checked.
3665 +
3666 +
3667 +.TP
3668 +.B show_only_unread
3669 +.nf
3670 +Type: boolean
3671 +Default: no
3672 +.fi
3673 +.IP
3674 +If \fIset\fP, only subscribed newsgroups that contain unread articles
3675 +will be displayed in browser.
3676 +
3677 +
3678 +.TP
3679  .B sig_dashes
3680  .nf
3681  Type: boolean
3682 @@ -3496,6 +3865,19 @@
3683  
3684  
3685  .TP
3686 +.B signatures_directory
3687 +.nf
3688 +Type: path
3689 +Default: \(lq\(rq
3690 +.fi
3691 +.IP
3692 +Specifies the path where your signatures are located. In the files of
3693 +this directory, the signatures are separated by blank lines and/or
3694 +sig_dashes (\(lq-- \(rq).
3695 +You can choose between these signatures from the compose menu.
3696 +
3697 +
3698 +.TP
3699  .B simple_search
3700  .nf
3701  Type: string
3702 @@ -3788,6 +4170,11 @@
3703  .IP %V  
3704  currently active limit pattern, if any *
3705  
3706 +.IP %[fmt] 
3707 +the current date and time. \(lqfmt\(rq is
3708 +expanded by the system call \(lqstrftime\(rq;
3709 +a leading bang disables locales 
3710 +
3711  .IP %>X 
3712  right justify the rest of the string and pad with \(rqX\(rq
3713  
3714 @@ -3840,6 +4227,21 @@
3715  
3716  
3717  .TP
3718 +.B status_update
3719 +.nf
3720 +Type: number
3721 +Default: -1
3722 +.fi
3723 +.IP
3724 +This variable controls, if positive, the maximum interval in seconds
3725 +before the time in the status line is updated. It is checked at
3726 +every key press and after a keyboard $timeout.
3727 +If the value is zero, the status line will be updated at every check.
3728 +If it is negative, the status time will only be updated
3729 +if it necessary to update to the status line for some other reason.
3730 +
3731 +
3732 +.TP
3733  .B strict_threads
3734  .nf
3735  Type: boolean
3736 @@ -3960,6 +4362,18 @@
3737  
3738  
3739  .TP
3740 +.B trash
3741 +.nf
3742 +Type: path
3743 +Default: \(lq\(rq
3744 +.fi
3745 +.IP
3746 +If set, this variable specifies the path of the trash folder where the
3747 +mails marked for deletion will be moved, instead of being irremediably
3748 +purged.
3749 +
3750 +
3751 +.TP
3752  .B tunnel
3753  .nf
3754  Type: string
3755 @@ -4017,6 +4431,18 @@
3756  
3757  
3758  .TP
3759 +.B use_ipv6
3760 +.nf
3761 +Type: boolean
3762 +Default: yes
3763 +.fi
3764 +.IP
3765 +When \fIset\fP, Mutt will look for IPv6 addresses of hosts it tries to
3766 +contact.  If this option is unset, Mutt will restrict itself to IPv4 addresses.
3767 +Normally, the default should work.
3768 +
3769 +
3770 +.TP
3771  .B user_agent
3772  .nf
3773  Type: boolean
3774 @@ -4118,6 +4544,17 @@
3775  messages to be sent.  Exim users may wish to use this.
3776  
3777  
3778 +.TP
3779 +.B x_comment_to
3780 +.nf
3781 +Type: boolean
3782 +Default: no
3783 +.fi
3784 +.IP
3785 +If \fIset\fP, Mutt will add \(lqX-Comment-To:\(rq field (that contains full
3786 +name of original article author) to article that followuped to newsgroup.
3787 +
3788 +
3789  .\" -*-nroff-*-
3790  .SH SEE ALSO
3791  .PP
3792 diff -uNr mutt-1.4.orig/functions.h mutt-1.4/functions.h
3793 --- mutt-1.4.orig/functions.h   Sun Nov  3 21:42:52 2002
3794 +++ mutt-1.4/functions.h        Sun Nov  3 21:57:20 2002
3795 @@ -69,6 +69,10 @@
3796    { "break-thread",            OP_MAIN_BREAK_THREAD,           "#" },
3797    { "change-folder",           OP_MAIN_CHANGE_FOLDER,          "c" },
3798    { "change-folder-readonly",  OP_MAIN_CHANGE_FOLDER_READONLY, "\033c" },
3799 +#ifdef USE_NNTP
3800 +  { "change-newsgroup",                OP_MAIN_CHANGE_GROUP,           NULL },
3801 +  { "change-newsgroup-readonly",OP_MAIN_CHANGE_GROUP_READONLY, NULL },
3802 +#endif
3803    { "collapse-thread",         OP_MAIN_COLLAPSE_THREAD,        "\033v" },
3804    { "collapse-all",            OP_MAIN_COLLAPSE_ALL,           "\033V" },
3805    { "copy-message",            OP_COPY_MESSAGE,                "C" },
3806 @@ -81,7 +85,15 @@
3807    { "edit",                    OP_EDIT_MESSAGE,                "e" },
3808    { "edit-type",               OP_EDIT_TYPE,                   "\005" },
3809    { "forward-message",         OP_FORWARD_MESSAGE,             "f" },
3810 -  { "flag-message",            OP_FLAG_MESSAGE,                "F" },
3811 +#ifdef USE_NNTP
3812 +  { "forward-to-group",                OP_FORWARD_TO_GROUP,            NULL },
3813 +  { "followup-message",                OP_FOLLOWUP,                    NULL },
3814 +  { "get-children",            OP_GET_CHILDREN,                NULL },
3815 +  { "get-message",             OP_GET_MESSAGE,                 NULL },
3816 +  { "get-parent",              OP_GET_PARENT,                  NULL },
3817 +  { "reconstruct-thread",      OP_RECONSTRUCT_THREAD,          NULL },
3818 +#endif
3819 +  { "flag-message",            OP_FLAG_MESSAGE,                "F" },
3820    { "group-reply",             OP_GROUP_REPLY,                 "g" },
3821  #ifdef USE_POP
3822    { "fetch-mail",              OP_MAIN_FETCH_MAIL,             "G" },
3823 @@ -108,6 +120,9 @@
3824    { "sort-mailbox",            OP_SORT,                        "o" },
3825    { "sort-reverse",            OP_SORT_REVERSE,                "O" },
3826    { "print-message",           OP_PRINT,                       "p" },
3827 +#ifdef USE_NNTP
3828 +  { "post-message",            OP_POST,                        NULL },
3829 +#endif
3830    { "previous-thread",         OP_MAIN_PREV_THREAD,            "\020" },
3831    { "previous-subthread",      OP_MAIN_PREV_SUBTHREAD,         "\033p" },
3832    { "recall-message",          OP_RECALL_MESSAGE,              "R" },
3833 @@ -127,6 +142,10 @@
3834    { "show-version",            OP_VERSION,                     "V" },
3835    { "set-flag",                        OP_MAIN_SET_FLAG,               "w" },
3836    { "clear-flag",              OP_MAIN_CLEAR_FLAG,             "W" },
3837 +  { "toggle-read",             OP_TOGGLE_READ,                 NULL },
3838 +#ifdef USE_NNTP
3839 +  { "catchup",                 OP_CATCHUP,                     NULL },
3840 +#endif
3841    { "display-message",         OP_DISPLAY_MESSAGE,             M_ENTER_S },
3842    { "sync-mailbox",            OP_MAIN_SYNC_FOLDER,            "$" },
3843    { "display-address",         OP_DISPLAY_ADDRESS,             "@" },
3844 @@ -158,6 +177,10 @@
3845    { "bounce-message",  OP_BOUNCE_MESSAGE,              "b" },
3846    { "change-folder",   OP_MAIN_CHANGE_FOLDER,          "c" },
3847    { "change-folder-readonly",  OP_MAIN_CHANGE_FOLDER_READONLY, "\033c" },
3848 +#ifdef USE_NNTP
3849 +  { "change-newsgroup",                OP_MAIN_CHANGE_GROUP,           NULL },
3850 +  { "change-newsgroup-readonly",OP_MAIN_CHANGE_GROUP_READONLY, NULL },
3851 +#endif
3852    { "copy-message",    OP_COPY_MESSAGE,                "C" },
3853    { "decode-copy",     OP_DECODE_COPY,                 "\033C" },
3854    { "delete-message",  OP_DELETE,                      "d" },
3855 @@ -165,8 +188,12 @@
3856    { "delete-subthread",        OP_DELETE_SUBTHREAD,            "\033d" },
3857    { "edit",            OP_EDIT_MESSAGE,                "e" },
3858    { "edit-type",       OP_EDIT_TYPE,                   "\005" },
3859 +#ifdef USE_NNTP
3860 +  { "followup-message",        OP_FOLLOWUP,                    NULL },
3861 +  { "forward-to-group",        OP_FORWARD_TO_GROUP,            NULL },
3862 +#endif
3863    { "forward-message", OP_FORWARD_MESSAGE,             "f" },
3864 -  { "flag-message",    OP_FLAG_MESSAGE,                "F" },
3865 +  { "flag-message",    OP_FLAG_MESSAGE,                "F" },
3866    { "group-reply",     OP_GROUP_REPLY,                 "g" },
3867  #ifdef USE_IMAP
3868    { "imap-fetch-mail",  OP_MAIN_IMAP_FETCH,            NULL },
3869 @@ -185,6 +212,9 @@
3870    { "next-thread",     OP_MAIN_NEXT_THREAD,            "\016" },
3871    { "next-subthread",  OP_MAIN_NEXT_SUBTHREAD,         "\033n" },
3872    { "print-message",   OP_PRINT,                       "p" },
3873 +#ifdef USE_NNTP
3874 +  { "post-message",    OP_POST,                        NULL },
3875 +#endif
3876    { "previous-thread", OP_MAIN_PREV_THREAD,            "\020" },
3877    { "previous-subthread",OP_MAIN_PREV_SUBTHREAD,       "\033p" },
3878    { "purge-message",   OP_PURGE_MESSAGE,               NULL },
3879 @@ -252,6 +282,10 @@
3880    { "bounce-message",  OP_BOUNCE_MESSAGE,              "b" },
3881    { "display-toggle-weed",     OP_DISPLAY_HEADERS,     "h" },
3882    { "edit-type",       OP_EDIT_TYPE,                   "\005" },
3883 +#ifdef USE_NNTP
3884 +  { "followup-message",        OP_FOLLOWUP,                    NULL },
3885 +  { "forward-to-group",        OP_FORWARD_TO_GROUP,            NULL },
3886 +#endif
3887    { "print-entry",     OP_PRINT,                       "p" },
3888    { "save-entry",      OP_SAVE,                        "s" },
3889    { "pipe-entry",      OP_PIPE,                        "|" },
3890 @@ -282,6 +316,7 @@
3891  struct binding_t OpCompose[] = {
3892    { "attach-file",     OP_COMPOSE_ATTACH_FILE,         "a" },
3893    { "attach-message",  OP_COMPOSE_ATTACH_MESSAGE,      "A" },
3894 +  { "attach-news-message",OP_COMPOSE_ATTACH_NEWS_MESSAGE,NULL },
3895    { "edit-bcc",                OP_COMPOSE_EDIT_BCC,            "b" },
3896    { "edit-cc",         OP_COMPOSE_EDIT_CC,             "c" },
3897    { "copy-file",       OP_SAVE,                        "C" },
3898 @@ -301,6 +336,11 @@
3899    { "print-entry",     OP_PRINT,                       "l" },
3900    { "edit-mime",       OP_COMPOSE_EDIT_MIME,           "m" },
3901    { "new-mime",                OP_COMPOSE_NEW_MIME,            "n" },
3902 +#ifdef USE_NNTP
3903 +  { "edit-newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS,     NULL },
3904 +  { "edit-followup-to",        OP_COMPOSE_EDIT_FOLLOWUP_TO,    NULL },
3905 +  { "edit-x-comment-to",OP_COMPOSE_EDIT_X_COMMENT_TO,  NULL },
3906 +#endif
3907    { "postpone-message",        OP_COMPOSE_POSTPONE_MESSAGE,    "P" },
3908    { "edit-reply-to",   OP_COMPOSE_EDIT_REPLY_TO,       "r" },
3909    { "rename-file",     OP_COMPOSE_RENAME_FILE,         "R" },
3910 @@ -352,12 +392,23 @@
3911    { "select-new",      OP_BROWSER_NEW_FILE,    "N" },
3912    { "check-new",       OP_CHECK_NEW,           NULL },
3913    { "toggle-mailboxes", OP_TOGGLE_MAILBOXES,   "\t" },
3914 +#ifdef USE_NNTP
3915 +  { "reload-active",   OP_LOAD_ACTIVE,         NULL},
3916 +  { "subscribe-pattern", OP_SUBSCRIBE_PATTERN, NULL },
3917 +  { "unsubscribe-pattern", OP_UNSUBSCRIBE_PATTERN, NULL },
3918 +  { "catchup",         OP_CATCHUP,             NULL },
3919 +  { "uncatchup",       OP_UNCATCHUP,           NULL },
3920 +#endif
3921    { "view-file",       OP_BROWSER_VIEW_FILE,   " " },
3922  #ifdef USE_IMAP
3923    { "create-mailbox",   OP_CREATE_MAILBOX,      "C" },
3924    { "delete-mailbox",   OP_DELETE_MAILBOX,      "d" },
3925 +#endif
3926 +#if defined USE_IMAP || defined USE_NNTP
3927    { "subscribe",       OP_BROWSER_SUBSCRIBE,   "s" },
3928    { "unsubscribe",     OP_BROWSER_UNSUBSCRIBE, "u" },
3929 +#endif
3930 +#ifdef USE_IMAP
3931    { "toggle-subscribed", OP_BROWSER_TOGGLE_LSUB, "T" },
3932  #endif
3933    { NULL,              0,                      NULL }
3934 diff -uNr mutt-1.4.orig/globals.h mutt-1.4/globals.h
3935 --- mutt-1.4.orig/globals.h     Sun Nov  3 21:42:52 2002
3936 +++ mutt-1.4/globals.h  Sun Nov  3 21:57:20 2002
3937 @@ -80,6 +80,15 @@
3938  #endif
3939  
3940  WHERE char *Muttrc INITVAL (NULL);
3941 +#ifdef USE_NNTP
3942 +WHERE char *NewsCacheDir;
3943 +WHERE char *GroupFormat;
3944 +WHERE char *Inews;
3945 +WHERE char *NewsServer;
3946 +WHERE char *NntpUser;
3947 +WHERE char *NntpPass;
3948 +WHERE char *NewsRc;
3949 +#endif
3950  WHERE char *Outbox;
3951  WHERE char *Pager;
3952  WHERE char *PagerFmt;
3953 @@ -146,6 +155,11 @@
3954  
3955  WHERE unsigned short Counter INITVAL (0);
3956  
3957 +#ifdef USE_NNTP
3958 +WHERE short NewsPollTimeout;
3959 +WHERE short NntpContext;
3960 +#endif
3961 +
3962  WHERE short ConnectTimeout;
3963  WHERE short FolderColumns;
3964  WHERE short HistSize;
3965 diff -uNr mutt-1.4.orig/hash.c mutt-1.4/hash.c
3966 --- mutt-1.4.orig/hash.c        Mon Nov 19 11:41:32 2001
3967 +++ mutt-1.4/hash.c     Sun Nov  3 21:57:20 2002
3968 @@ -47,10 +47,35 @@
3969    if (nelem == 0)
3970      nelem = 2;
3971    table->nelem = nelem;
3972 +  table->curnelem = 0;
3973    table->table = safe_calloc (nelem, sizeof (struct hash_elem *));
3974    return table;
3975  }
3976  
3977 +HASH *hash_resize (HASH *ptr, int nelem)
3978 +{
3979 +  HASH *table;
3980 +  struct hash_elem *elem, *tmp;
3981 +  int i;
3982 +
3983 +  table = hash_create (nelem);
3984 +
3985 +  for (i = 0; i < ptr->nelem; i++)
3986 +  {
3987 +    for (elem = ptr->table[i]; elem; )
3988 +    {
3989 +      tmp = elem;
3990 +      elem = elem->next;
3991 +      hash_insert (table, tmp->key, tmp->data, 1);
3992 +      safe_free ((void **) &tmp);
3993 +    }
3994 +  }
3995 +  safe_free ((void **) &ptr->table);
3996 +  safe_free ((void **) &ptr);
3997 +
3998 +  return table;
3999 +}
4000 +
4001  /* table        hash table to update
4002   * key          key to hash on
4003   * data         data to associate with `key'
4004 @@ -70,6 +95,7 @@
4005    {
4006      ptr->next = table->table[h];
4007      table->table[h] = ptr;
4008 +    table->curnelem++;
4009    }
4010    else
4011    {
4012 @@ -92,6 +118,7 @@
4013      else
4014        table->table[h] = ptr;
4015      ptr->next = tmp;
4016 +    table->curnelem++;
4017    }
4018    return h;
4019  }
4020 @@ -124,6 +151,7 @@
4021        *last = ptr->next;
4022        if (destroy) destroy (ptr->data);
4023        FREE (&ptr);
4024 +      table->curnelem--;
4025        return;
4026      }
4027    }
4028 diff -uNr mutt-1.4.orig/hash.h mutt-1.4/hash.h
4029 --- mutt-1.4.orig/hash.h        Fri Mar  3 11:10:08 2000
4030 +++ mutt-1.4/hash.h     Sun Nov  3 21:57:20 2002
4031 @@ -28,7 +28,7 @@
4032  
4033  typedef struct
4034  {
4035 -  int nelem;
4036 +  int nelem, curnelem;
4037    struct hash_elem **table;
4038  }
4039  HASH;
4040 @@ -40,6 +40,7 @@
4041  HASH *hash_create (int nelem);
4042  int hash_string (const unsigned char *s, int n);
4043  int hash_insert (HASH * table, const char *key, void *data, int allow_dup);
4044 +HASH *hash_resize (HASH * table, int nelem);
4045  void *hash_find_hash (const HASH * table, int hash, const char *key);
4046  void hash_delete_hash (HASH * table, int hash, const char *key, const void *data,
4047                        void (*destroy) (void *));
4048 diff -uNr mutt-1.4.orig/hdrline.c mutt-1.4/hdrline.c
4049 --- mutt-1.4.orig/hdrline.c     Sun Nov  3 21:42:52 2002
4050 +++ mutt-1.4/hdrline.c  Sun Nov  3 21:57:20 2002
4051 @@ -255,6 +255,7 @@
4052   * %E = number of messages in current thread
4053   * %f = entire from line
4054   * %F = like %n, unless from self
4055 + * %g = newsgroup name (if compiled with nntp support)
4056   * %i = message-id
4057   * %l = number of lines in the message
4058   * %L = like %F, except `lists' are displayed first
4059 @@ -268,6 +269,7 @@
4060   * %T = $to_chars
4061   * %u = user (login) name of author
4062   * %v = first name of author, unless from self
4063 + * %W = where user is (organization)
4064   * %y = `x-label:' field (if present)
4065   * %Y = `x-label:' field (if present, tree unfolded, and != parent's x-label)
4066   * %Z = status flags   */
4067 @@ -484,6 +486,12 @@
4068          optional = 0;
4069        break;
4070  
4071 +#ifdef USE_NNTP
4072 +    case 'g':
4073 +      mutt_format_s (dest, destlen, prefix, hdr->env->newsgroups ? hdr->env->newsgroups : "");
4074 +      break;
4075 +#endif
4076 +
4077      case 'i':
4078        mutt_format_s (dest, destlen, prefix, hdr->env->message_id ? hdr->env->message_id : "<no.id>");
4079        break;
4080 @@ -655,6 +663,13 @@
4081        mutt_format_s (dest, destlen, prefix, buf2);
4082        break;
4083  
4084 +    case 'W':
4085 +      if (!optional)
4086 +       mutt_format_s (dest, destlen, prefix, hdr->env->organization ? hdr->env->organization : "");
4087 +      else if (!hdr->env->organization)
4088 +       optional = 0;
4089 +      break;
4090 +
4091      case 'Z':
4092      
4093        ch = ' ';
4094 diff -uNr mutt-1.4.orig/headers.c mutt-1.4/headers.c
4095 --- mutt-1.4.orig/headers.c     Mon Nov  5 22:19:33 2001
4096 +++ mutt-1.4/headers.c  Sun Nov  3 21:57:20 2002
4097 @@ -115,6 +115,9 @@
4098    msg->env = n; n = NULL;
4099  
4100    if (!msg->env->in_reply_to)
4101 +#ifdef USE_NNTP
4102 +  if (!option (OPTNEWSSEND))
4103 +#endif
4104      mutt_free_list (&msg->env->references);
4105  
4106    mutt_expand_aliases_env (msg->env);
4107 diff -uNr mutt-1.4.orig/init.c mutt-1.4/init.c
4108 --- mutt-1.4.orig/init.c        Sun Nov  3 21:42:51 2002
4109 +++ mutt-1.4/init.c     Sun Nov  3 21:57:20 2002
4110 @@ -1789,6 +1789,28 @@
4111    else
4112      Fqdn = safe_strdup(NONULL(Hostname));
4113  
4114 +#ifdef USE_NNTP
4115 +  {
4116 +    FILE *f;
4117 +    char *i;
4118 +
4119 +    if ((f = safe_fopen (SYSCONFDIR "/nntpserver", "r")))
4120 +    {
4121 +      buffer[0] = '\0';
4122 +      fgets (buffer, sizeof (buffer), f);
4123 +      p = &buffer;
4124 +      SKIPWS (p);
4125 +      i = p;
4126 +      while (*i && (*i != ' ') && (*i != '\t') && (*i != '\r') && (*i != '\n')) i++;
4127 +      *i = '\0';
4128 +      NewsServer = safe_strdup (p);
4129 +      fclose (f);
4130 +    }
4131 +  }
4132 +  if ((p = getenv ("NNTPSERVER")))
4133 +    NewsServer = safe_strdup (p);
4134 +#endif
4135 +
4136    if ((p = getenv ("MAIL")))
4137      Spoolfile = safe_strdup (p);
4138    else if ((p = getenv ("MAILDIR")))
4139 diff -uNr mutt-1.4.orig/init.h mutt-1.4/init.h
4140 --- mutt-1.4.orig/init.h        Sun Nov  3 21:42:52 2002
4141 +++ mutt-1.4/init.h     Sun Nov  3 21:57:20 2002
4142 @@ -193,6 +193,20 @@
4143    ** If set, Mutt will prompt you for carbon-copy (Cc) recipients before
4144    ** editing the body of an outgoing message.
4145    */  
4146 +#ifdef USE_NNTP
4147 +  { "ask_follow_up",   DT_BOOL, R_NONE, OPTASKFOLLOWUP, 0 },
4148 +  /*
4149 +  ** .pp
4150 +  ** If set, Mutt will prompt you for follow-up groups before editing
4151 +  ** the body of an outgoing message.
4152 +  */  
4153 +  { "ask_x_comment_to",        DT_BOOL, R_NONE, OPTASKXCOMMENTTO, 0 },
4154 +  /*
4155 +  ** .pp
4156 +  ** If set, Mutt will prompt you for x-comment-to field before editing
4157 +  ** the body of an outgoing message.
4158 +  */  
4159 +#endif
4160    { "attach_format",   DT_STR,  R_NONE, UL &AttachFormat, UL "%u%D%I %t%4n %T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] " },
4161    /*
4162    ** .pp
4163 @@ -273,6 +287,14 @@
4164    ** When this variable is set, mutt will include Delivered-To headers when
4165    ** bouncing messages.  Postfix users may wish to unset this variable.
4166    */
4167 +#ifdef USE_NNTP
4168 +  { "catchup_newsgroup", DT_QUAD, R_NONE, OPT_CATCHUP, M_ASKYES },
4169 +  /*
4170 +  ** .pp
4171 +  ** If this variable is \fIset\fP, Mutt will mark all articles in newsgroup
4172 +  ** as read when you quit the newsgroup (catchup newsgroup).
4173 +  */
4174 +#endif
4175    { "charset",         DT_STR,  R_NONE, UL &Charset, UL 0 },
4176    /*
4177    ** .pp
4178 @@ -565,6 +587,16 @@
4179    ** subscribed list will be sent to both the list and your address,
4180    ** resulting in two copies of the same email for you.
4181    */
4182 +#ifdef USE_NNTP
4183 +  { "followup_to_poster", DT_QUAD, R_NONE, OPT_FOLLOWUPTOPOSTER, M_ASKYES },
4184 +  /*
4185 +  ** .pp
4186 +  ** If this variable is \fIset\fP and the keyword "poster" is present in
4187 +  ** \fIFollowup-To\fP header, follow-up to newsgroup function is not
4188 +  ** permitted.  The message will be mailed to the submitter of the
4189 +  ** message via mail.
4190 +  */
4191 +#endif
4192    { "force_name",      DT_BOOL, R_NONE, OPTFORCENAME, 0 },
4193    /*
4194    ** .pp
4195 @@ -628,6 +660,27 @@
4196    ** a regular expression that will match the whole name so mutt will expand
4197    ** "Franklin" to "Franklin, Steve".
4198    */
4199 +#ifdef USE_NNTP
4200 +  { "group_index_format", DT_STR, R_BOTH, UL &GroupFormat, UL "%4C %M%N %5s  %-45.45f %d" },
4201 +  /*
4202 +  ** .pp
4203 +  ** This variable allows you to customize the newsgroup browser display to
4204 +  ** your personal taste.  This string is similar to ``$index_format'', but
4205 +  ** has its own set of printf()-like sequences:
4206 +  ** .pp
4207 +  ** .ts
4208 +  ** %C      current newsgroup number
4209 +  ** %d      description of newsgroup (becomes from server)
4210 +  ** %f      newsgroup name
4211 +  ** %M      - if newsgroup not allowed for direct post (moderated for example)
4212 +  ** %N      N if newsgroup is new, u if unsubscribed, blank otherwise
4213 +  ** %n      number of new articles in newsgroup
4214 +  ** %s      number of unread articles in newsgroup
4215 +  ** %>X     right justify the rest of the string and pad with character "X"
4216 +  ** %|X     pad to the end of the line with character "X"
4217 +  ** .te
4218 +  */
4219 +#endif
4220    { "hdr_format",      DT_SYN,  R_NONE, UL "index_format", 0 },
4221    /*
4222    */
4223 @@ -874,6 +927,7 @@
4224    ** .dt %E .dd number of messages in current thread
4225    ** .dt %f .dd entire From: line (address + real name)
4226    ** .dt %F .dd author name, or recipient name if the message is from you
4227 +  ** .dt %g .dd newsgroup name (if compiled with nntp support)
4228    ** .dt %i .dd message-id of the current message
4229    ** .dt %l .dd number of lines in the message
4230    ** .dt %L .dd If an address in the To or CC header field matches an address
4231 @@ -891,6 +945,7 @@
4232    ** .dt %T .dd the appropriate character from the $$to_chars string
4233    ** .dt %u .dd user (login) name of the author
4234    ** .dt %v .dd first name of the author, or the recipient if the message is from you
4235 +  ** .dt %W .dd name of organization of author (`organization:' field)
4236    ** .dt %y .dd `x-label:' field, if present
4237    ** .dt %Y .dd `x-label' field, if present, and (1) not at part of a thread tree,
4238    **            (2) at the top of a thread, or (3) `x-label' is different from
4239 @@ -913,6 +968,21 @@
4240    ** .pp
4241    ** See also: ``$$to_chars''.
4242    */
4243 +#ifdef USE_NNTP
4244 +  { "inews",          DT_PATH, R_NONE, UL &Inews, UL "" },
4245 +  /*
4246 +  ** .pp
4247 +  ** If set, specifies the program and arguments used to deliver news posted
4248 +  ** by Mutt.  Otherwise, mutt posts article using current connection to
4249 +  ** news server.  The following printf-style sequence is understood:
4250 +  ** .pp
4251 +  ** .ts
4252 +  ** %s      newsserver name
4253 +  ** .te
4254 +  ** .pp
4255 +  ** Example: set inews="/usr/local/bin/inews -hS"
4256 +  */
4257 +#endif
4258    { "ispell",          DT_PATH, R_NONE, UL &Ispell, UL ISPELL },
4259    /*
4260    ** .pp
4261 @@ -1077,6 +1147,16 @@
4262    ** be attached to the newly composed message if this option is set.
4263    */
4264  
4265 +#ifdef USE_NNTP
4266 +  { "mime_subject",   DT_BOOL, R_NONE, OPTMIMESUBJECT, 1 },
4267 +  /*
4268 +  ** .pp
4269 +  ** If \fIunset\fP, 8-bit ``subject:'' line in article header will not be
4270 +  ** encoded according to RFC2047 to base64.  This is useful when message
4271 +  ** is Usenet article, because MIME for news is nonstandard feature.
4272 +  */
4273 +#endif
4274 +
4275  #ifdef MIXMASTER
4276    { "mix_entry_format", DT_STR,  R_NONE, UL &MixEntryFormat, UL "%4n %c %-16s %a" },
4277    /*
4278 @@ -1128,6 +1208,77 @@
4279    ** to allow more room the tree and message subjects.  This is useful on
4280    ** narrow screens.
4281    */
4282 +#ifdef USE_NNTP
4283 +  { "news_cache_dir", DT_PATH, R_NONE, UL &NewsCacheDir, UL "~/.mutt" },
4284 +  /*
4285 +  ** .pp
4286 +  ** This variable pointing to directory where Mutt will save cached news
4287 +  ** articles headers in. If \fIunset\fP, headers will not be saved at all
4288 +  ** and will be reloaded each time when you enter to newsgroup.
4289 +  */
4290 +  { "news_server",    DT_STR,  R_NONE, UL &NewsServer, 0 },
4291 +  /*
4292 +  ** .pp
4293 +  ** This variable specifies domain name or address of NNTP server. It
4294 +  ** defaults to the newsserver specified in the environment variable
4295 +  ** $$$NNTPSERVER or contained in the file /etc/nntpserver.  You can also
4296 +  ** specify username and an alternative port for each newsserver, ie:
4297 +  ** .pp
4298 +  ** [nntp[s]://][username[:password]@]newsserver[:port]
4299 +  */
4300 +  { "newsrc",         DT_PATH, R_NONE, UL &NewsRc, UL "~/.newsrc" },
4301 +  /*
4302 +  ** .pp
4303 +  ** The file, containing info about subscribed newsgroups - names and
4304 +  ** indexes of read articles.  The following printf-style sequence
4305 +  ** is understood:
4306 +  ** .pp
4307 +  ** .ts
4308 +  ** %s      newsserver name
4309 +  ** .te
4310 +  */
4311 +  { "nntp_context",   DT_NUM,  R_NONE, UL &NntpContext, 1000 },
4312 +  /*
4313 +  ** .pp
4314 +  ** This variable defines number of articles which will be in index when
4315 +  ** newsgroup entered.  If active newsgroup have more articles than this
4316 +  ** number, oldest articles will be ignored.  Also controls how many
4317 +  ** articles headers will be saved in cache when you quit newsgroup.
4318 +  */
4319 +  { "nntp_load_description", DT_BOOL, R_NONE, OPTLOADDESC, 1 },
4320 +  /*
4321 +  ** .pp
4322 +  ** This variable controls whether or not descriptions for each newsgroup
4323 +  ** must be loaded when newsgroup is added to list (first time list
4324 +  ** loading or new newsgroup adding).
4325 +  */
4326 +  { "nntp_user",      DT_STR,  R_NONE, UL &NntpUser, UL "" },
4327 +  /*
4328 +  ** .pp
4329 +  ** Your login name on the NNTP server.  If \fIunset\fP and NNTP server requires
4330 +  ** authentification, Mutt will prompt you for your account name when you
4331 +  ** connect to newsserver.
4332 +  */
4333 +  { "nntp_pass",      DT_STR,  R_NONE, UL &NntpPass, UL "" },
4334 +  /*
4335 +  ** .pp
4336 +  ** Your password for NNTP account.
4337 +  */
4338 +  { "nntp_poll",      DT_NUM,  R_NONE, UL &NewsPollTimeout, 60 },
4339 +  /*
4340 +  ** .pp
4341 +  ** The time in seconds until any operations on newsgroup except post new
4342 +  ** article will cause recheck for new news.  If set to 0, Mutt will
4343 +  ** recheck newsgroup on each operation in index (stepping, read article,
4344 +  ** etc.).
4345 +  */
4346 +  { "nntp_reconnect", DT_QUAD, R_NONE, OPT_NNTPRECONNECT, M_ASKYES },
4347 +  /*
4348 +  ** .pp
4349 +  ** Controls whether or not Mutt will try to reconnect to newsserver when
4350 +  ** connection lost.
4351 +  */
4352 +#endif
4353    { "pager",           DT_PATH, R_NONE, UL &Pager, UL "builtin" },
4354    /*
4355    ** .pp
4356 @@ -1633,6 +1784,16 @@
4357    { "post_indent_str",  DT_SYN,  R_NONE, UL "post_indent_string", 0 },
4358    /*
4359    */
4360 +#ifdef USE_NNTP
4361 +  { "post_moderated", DT_QUAD, R_NONE, OPT_TOMODERATED, M_ASKYES },
4362 +  /*
4363 +  ** .pp
4364 +  ** If set to \fIyes\fP, Mutt will post article to newsgroup that have
4365 +  ** not permissions to posting (e.g. moderated).  \fBNote:\fP if newsserver
4366 +  ** does not support posting to that newsgroup or totally read-only, that
4367 +  ** posting will not have an effect.
4368 +  */
4369 +#endif
4370    { "postpone",                DT_QUAD, R_NONE, OPT_POSTPONE, M_ASKYES },
4371    /*
4372    ** .pp
4373 @@ -1991,6 +2152,28 @@
4374    ** Command to use when spawning a subshell.  By default, the user's login
4375    ** shell from /etc/passwd is used.
4376    */
4377 +#ifdef USE_NNTP
4378 +  { "save_unsubscribed",DT_BOOL, R_NONE, OPTSAVEUNSUB, 0 },
4379 +  /*
4380 +  ** .pp
4381 +  ** When \fIset\fP, info about unsubscribed newsgroups will be saved into
4382 +  ** ``newsrc'' file and into cache.
4383 +  */
4384 +  { "show_new_news",  DT_BOOL, R_NONE, OPTSHOWNEWNEWS, 1 },
4385 +  /*
4386 +  ** .pp
4387 +  ** If \fIset\fP, newsserver will be asked for new newsgroups on entering
4388 +  ** the browser.  Otherwise, it will be done only once for a newsserver.
4389 +  ** Also controls whether or not number of new articles of subscribed
4390 +  ** newsgroups will be then checked.
4391 +  */
4392 +  { "show_only_unread",  DT_BOOL, R_NONE, OPTSHOWONLYUNREAD, 0 },
4393 +  /*
4394 +  ** .pp
4395 +  ** If \fIset\fP, only subscribed newsgroups that contain unread articles
4396 +  ** will be displayed in browser.
4397 +  */
4398 +#endif
4399    { "sig_dashes",      DT_BOOL, R_NONE, OPTSIGDASHES, 1 },
4400    /*
4401    ** .pp
4402 @@ -2437,6 +2620,14 @@
4403    ** Controls whether mutt writes out the Bcc header when preparing
4404    ** messages to be sent.  Exim users may wish to use this.
4405    */
4406 +#ifdef USE_NNTP
4407 +  { "x_comment_to",   DT_BOOL, R_NONE, OPTXCOMMENTTO, 0 },
4408 +  /*
4409 +  ** .pp
4410 +  ** If \fIset\fP, Mutt will add ``X-Comment-To:'' field (that contains full
4411 +  ** name of original article author) to article that followuped to newsgroup.
4412 +  */
4413 +#endif
4414    /*--*/
4415    { NULL }
4416  };
4417 diff -uNr mutt-1.4.orig/keymap.c mutt-1.4/keymap.c
4418 --- mutt-1.4.orig/keymap.c      Sun Nov  3 21:42:52 2002
4419 +++ mutt-1.4/keymap.c   Sun Nov  3 21:57:20 2002
4420 @@ -593,7 +593,6 @@
4421    km_bindkey ("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
4422  
4423    km_bindkey ("x", MENU_PAGER, OP_EXIT);
4424 -  km_bindkey ("i", MENU_PAGER, OP_EXIT);
4425    km_bindkey ("<backspace>", MENU_PAGER, OP_PREV_LINE);
4426    km_bindkey ("<pagedown>", MENU_PAGER, OP_NEXT_PAGE);
4427    km_bindkey ("<pageup>", MENU_PAGER, OP_PREV_PAGE);
4428 diff -uNr mutt-1.4.orig/mailbox.h mutt-1.4/mailbox.h
4429 --- mutt-1.4.orig/mailbox.h     Wed Mar 20 10:53:34 2002
4430 +++ mutt-1.4/mailbox.h  Sun Nov  3 21:57:20 2002
4431 @@ -73,6 +73,9 @@
4432  #ifdef USE_POP
4433  int mx_is_pop (const char *);
4434  #endif
4435 +#ifdef USE_NNTP
4436 +int mx_is_nntp (const char *);
4437 +#endif
4438  
4439  int mx_access (const char*, int);
4440  
4441 diff -uNr mutt-1.4.orig/main.c mutt-1.4/main.c
4442 --- mutt-1.4.orig/main.c        Sun Nov  3 21:42:51 2002
4443 +++ mutt-1.4/main.c     Sun Nov  3 21:57:20 2002
4444 @@ -37,6 +37,10 @@
4445  #include <getopt.h>
4446  #endif
4447  
4448 +#ifdef USE_NNTP
4449 +#include <nntp.h>
4450 +#endif
4451 +
4452  static const char *ReachingUs = N_("\
4453  To contact the developers, please mail to <mutt-dev@mutt.org>.\n\
4454  To report a bug, please use the flea(1) utility.\n");
4455 @@ -97,6 +101,8 @@
4456    -e <command>\tspecify a command to be executed after initialization\n\
4457    -f <file>\tspecify which mailbox to read\n\
4458    -F <file>\tspecify an alternate muttrc file\n\
4459 +  -g <server>\tspecify a newsserver (if compiled with NNTP)\n\
4460 +  -G\t\tselect a newsgroup (if compiled with NNTP)\n\
4461    -H <file>\tspecify a draft file to read header from\n\
4462    -i <file>\tspecify a file which Mutt should include in the reply\n\
4463    -m <type>\tspecify a default mailbox type\n\
4464 @@ -202,6 +208,12 @@
4465         "-USE_POP  "
4466  #endif
4467  
4468 +#ifdef USE_NNTP
4469 +       "+USE_NNTP  "
4470 +#else
4471 +       "-USE_NNTP  "
4472 +#endif
4473 +
4474  #ifdef USE_IMAP
4475          "+USE_IMAP  "
4476  #else
4477 @@ -444,6 +456,9 @@
4478  #define M_NOSYSRC (1<<2)       /* -n */
4479  #define M_RO      (1<<3)       /* -R */
4480  #define M_SELECT  (1<<4)       /* -y */
4481 +#ifdef USE_NNTP
4482 +#define M_NEWS    (1<<5)       /* -g and -G */
4483 +#endif
4484  
4485  int main (int argc, char **argv)
4486  {
4487 @@ -489,7 +504,11 @@
4488    memset (Options, 0, sizeof (Options));
4489    memset (QuadOptions, 0, sizeof (QuadOptions));
4490    
4491 +#ifdef USE_NNTP
4492 +  while ((i = getopt (argc, argv, "a:b:F:f:c:d:e:H:s:i:hm:npRvxyg:GzZ")) != EOF)
4493 +#else
4494    while ((i = getopt (argc, argv, "a:b:F:f:c:d:e:H:s:i:hm:npRvxyzZ")) != EOF)
4495 +#endif
4496      switch (i)
4497      {
4498        case 'a':
4499 @@ -571,6 +590,20 @@
4500         flags |= M_SELECT;
4501         break;
4502  
4503 +#ifdef USE_NNTP
4504 +      case 'g': /* Specify a newsserver */
4505 +       {
4506 +         char buf[LONG_STRING];
4507 +
4508 +         snprintf (buf, sizeof (buf), "set news_server=%s", optarg);
4509 +         commands = mutt_add_list (commands, buf);
4510 +       }
4511 +
4512 +      case 'G': /* List of newsgroups */
4513 +       flags |= M_SELECT | M_NEWS;
4514 +       break;
4515 +#endif
4516 +
4517        case 'z':
4518         flags |= M_IGNORE;
4519         break;
4520 @@ -802,6 +835,18 @@
4521      }
4522      else if (flags & M_SELECT)
4523      {
4524 +#ifdef USE_NNTP
4525 +      if (flags & M_NEWS)
4526 +      {
4527 +       set_option (OPTNEWS);
4528 +       if(!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
4529 +       {
4530 +         mutt_endwin (Errorbuf);
4531 +         exit (1);
4532 +       }
4533 +      }
4534 +      else
4535 +#endif
4536        if (!Incoming) {
4537         mutt_endwin _("No incoming mailboxes defined.");
4538         exit (1);
4539 @@ -817,6 +862,15 @@
4540  
4541      if (!folder[0])
4542        strfcpy (folder, NONULL(Spoolfile), sizeof (folder));
4543 +
4544 +#ifdef USE_NNTP
4545 +    if (option (OPTNEWS))
4546 +    {
4547 +      unset_option (OPTNEWS);
4548 +      nntp_expand_path (folder, sizeof (folder), &CurrentNewsSrv->conn->account);
4549 +    }
4550 +    else
4551 +#endif
4552      mutt_expand_path (folder, sizeof (folder));
4553  
4554      mutt_str_replace (&LastFolder, folder);
4555 diff -uNr mutt-1.4.orig/mutt.h mutt-1.4/mutt.h
4556 --- mutt-1.4.orig/mutt.h        Sun Nov  3 21:42:52 2002
4557 +++ mutt-1.4/mutt.h     Sun Nov  3 21:57:20 2002
4558 @@ -231,6 +231,9 @@
4559    M_PGP_KEY,
4560  #endif
4561    M_XLABEL,
4562 +#ifdef USE_NNTP
4563 +  M_NEWSGROUPS,
4564 +#endif
4565    
4566    /* Options for Mailcap lookup */
4567    M_EDIT,
4568 @@ -266,6 +269,12 @@
4569    OPT_VERIFYSIG,      /* verify PGP signatures */
4570    OPT_PGPTRADITIONAL, /* create old-style PGP messages */
4571  #endif
4572 +#ifdef USE_NNTP
4573 +  OPT_TOMODERATED,
4574 +  OPT_NNTPRECONNECT,
4575 +  OPT_CATCHUP,
4576 +  OPT_FOLLOWUPTOPOSTER,
4577 +#endif /* USE_NNTP */
4578  
4579  #ifdef USE_SSL
4580    OPT_SSLSTARTTLS,
4581 @@ -302,6 +311,7 @@
4582  #define SENDMAILX      (1<<6)
4583  #define SENDKEY                (1<<7)
4584  #define SENDRESEND     (1<<8)
4585 +#define SENDNEWS       (1<<9)
4586  
4587  /* flags to _mutt_select_file() */
4588  #define M_SEL_BUFFY    (1<<0)
4589 @@ -318,6 +328,8 @@
4590    OPTASCIICHARS,
4591    OPTASKBCC,
4592    OPTASKCC,
4593 +  OPTASKFOLLOWUP,
4594 +  OPTASKXCOMMENTTO,
4595    OPTATTACHSPLIT,
4596    OPTAUTOEDIT,
4597    OPTAUTOTAG,
4598 @@ -376,6 +388,9 @@
4599    OPTMETOO,
4600    OPTMHPURGE,
4601    OPTMIMEFORWDECODE,
4602 +#ifdef USE_NNTP
4603 +  OPTMIMESUBJECT,      /* encode subject line with RFC2047 */
4604 +#endif
4605    OPTNARROWTREE,
4606    OPTPAGERSTOP,
4607    OPTPIPEDECODE,
4608 @@ -445,6 +460,16 @@
4609    OPTPGPSHOWUNUSABLE,
4610  #endif
4611  
4612 +  /* news options */
4613 +
4614 +#ifdef USE_NNTP
4615 +  OPTSHOWNEWNEWS,
4616 +  OPTSHOWONLYUNREAD,
4617 +  OPTSAVEUNSUB,
4618 +  OPTLOADDESC,
4619 +  OPTXCOMMENTTO,
4620 +#endif /* USE_NNTP */
4621 +
4622    /* pseudo options */
4623  
4624    OPTAUXSORT,          /* (pseudo) using auxillary sort function */
4625 @@ -465,6 +490,7 @@
4626    OPTSORTSUBTHREADS,   /* (pseudo) used when $sort_aux changes */
4627    OPTNEEDRESCORE,      /* (pseudo) set when the `score' command is used */
4628    OPTATTACHMSG,                /* (pseudo) used by attach-message */
4629 +  OPTHIDEREAD,         /* (pseudo) whether or not hide read messages */
4630    OPTKEEPQUIET,                /* (pseudo) shut up the message and refresh
4631                          *          functions while we are executing an
4632                          *          external program.
4633 @@ -475,6 +501,12 @@
4634    OPTDONTHANDLEPGPKEYS,        /* (pseudo) used to extract PGP keys */
4635  #endif
4636  
4637 +#ifdef USE_NNTP
4638 +  OPTNEWS,             /* (pseudo) used to change reader mode */
4639 +  OPTNEWSSEND,         /* (pseudo) used to change behavior when posting */
4640 +  OPTNEWSCACHE,                /* (pseudo) used to indicate if news cache exist */
4641 +#endif
4642 +
4643  
4644  
4645  
4646 @@ -538,6 +570,13 @@
4647    char *supersedes;
4648    char *date;
4649    char *x_label;
4650 +  char *organization;
4651 +#ifdef USE_NNTP
4652 +  char *newsgroups;
4653 +  char *xref;
4654 +  char *followup_to;
4655 +  char *x_comment_to;
4656 +#endif
4657    LIST *references;            /* message references (in reverse order) */
4658    LIST *in_reply_to;           /* in-reply-to header content */
4659    LIST *userhdrs;              /* user defined headers */
4660 @@ -685,6 +724,9 @@
4661    ENVELOPE *env;               /* envelope information */
4662    BODY *content;               /* list of MIME parts */
4663    char *path;
4664 +#ifdef USE_NNTP
4665 +  int article_num;
4666 +#endif
4667    
4668    char *tree;                  /* character string to print thread tree */
4669    struct thread *thread;
4670 @@ -697,7 +739,7 @@
4671    int refno;                   /* message number on server */
4672  #endif
4673  
4674 -#if defined USE_POP || defined USE_IMAP
4675 +#if defined USE_POP || defined USE_IMAP || defined USE_NNTP
4676    void *data;                  /* driver-specific data */
4677  #endif
4678  } HEADER;
4679 @@ -768,7 +810,7 @@
4680    int appended;                 /* how many saved messages? */
4681    int flagged;                 /* how many flagged messages */
4682    int msgnotreadyet;           /* which msg "new" in pager, -1 if none */
4683 -#if defined USE_POP || defined USE_IMAP
4684 +#if defined USE_POP || defined USE_IMAP || defined USE_NNTP
4685    void *data;                  /* driver specific data */
4686  #endif /* USE_IMAP */
4687  
4688 diff -uNr mutt-1.4.orig/muttlib.c mutt-1.4/muttlib.c
4689 --- mutt-1.4.orig/muttlib.c     Sun Nov  3 21:42:52 2002
4690 +++ mutt-1.4/muttlib.c  Sun Nov  3 21:57:20 2002
4691 @@ -270,7 +270,7 @@
4692  #ifdef MIXMASTER
4693    mutt_free_list (&(*h)->chain);
4694  #endif
4695 -#if defined USE_POP || defined USE_IMAP
4696 +#if defined USE_POP || defined USE_IMAP || defined USE_NNTP
4697    safe_free ((void**) &(*h)->data);
4698  #endif
4699    safe_free ((void **) h);
4700 @@ -648,6 +648,13 @@
4701    safe_free ((void **) &(*p)->message_id);
4702    safe_free ((void **) &(*p)->supersedes);
4703    safe_free ((void **) &(*p)->date);
4704 +  safe_free ((void **) &(*p)->organization);
4705 +#ifdef USE_NNTP
4706 +  safe_free ((void **) &(*p)->newsgroups);
4707 +  safe_free ((void **) &(*p)->xref);
4708 +  safe_free ((void **) &(*p)->followup_to);
4709 +  safe_free ((void **) &(*p)->x_comment_to);
4710 +#endif
4711    mutt_free_list (&(*p)->references);
4712    mutt_free_list (&(*p)->in_reply_to);
4713    mutt_free_list (&(*p)->userhdrs);
4714 @@ -1143,6 +1150,14 @@
4715      return 0;
4716    }
4717  #endif
4718 +
4719 +#ifdef USE_NNTP
4720 +  if (magic == M_NNTP)
4721 +  {
4722 +    mutt_error _("Can't save message to newsserver.");
4723 +    return 0;
4724 +  }
4725 +#endif
4726  
4727    if (stat (s, st) != -1)
4728    {
4729 diff -uNr mutt-1.4.orig/mx.c mutt-1.4/mx.c
4730 --- mutt-1.4.orig/mx.c  Sun Nov  3 21:42:52 2002
4731 +++ mutt-1.4/mx.c       Sun Nov  3 21:57:20 2002
4732 @@ -42,6 +42,10 @@
4733  #include "pop.h"
4734  #endif
4735  
4736 +#ifdef USE_NNTP
4737 +#include "nntp.h"
4738 +#endif
4739 +
4740  #ifdef BUFFY_SIZE
4741  #include "buffy.h"
4742  #endif
4743 @@ -354,6 +358,22 @@
4744  }
4745  #endif
4746  
4747 +#ifdef USE_NNTP
4748 +int mx_is_nntp (const char *p)
4749 +{
4750 +  url_scheme_t scheme;
4751 +
4752 +  if (!p)
4753 +    return 0;
4754 +
4755 +  scheme = url_check_scheme (p);
4756 +  if (scheme == U_NNTP || scheme == U_NNTPS)
4757 +    return 1;
4758 +
4759 +  return 0;
4760 +}
4761 +#endif
4762 +
4763  int mx_get_magic (const char *path)
4764  {
4765    struct stat st;
4766 @@ -371,6 +391,11 @@
4767      return M_POP;
4768  #endif /* USE_POP */
4769  
4770 +#ifdef USE_NNTP
4771 +  if (mx_is_nntp (path))
4772 +    return M_NNTP;
4773 +#endif /* USE_NNTP */
4774 +
4775    if (stat (path, &st) == -1)
4776    {
4777      dprint (1, (debugfile, "mx_get_magic(): unable to stat %s: %s (errno %d).\n",
4778 @@ -721,6 +746,12 @@
4779        break;
4780  #endif /* USE_POP */
4781  
4782 +#ifdef USE_NNTP
4783 +    case M_NNTP:
4784 +      rc = nntp_open_mailbox (ctx);
4785 +      break;
4786 +#endif /* USE_NNTP */
4787 +
4788      default:
4789        rc = -1;
4790        break;
4791 @@ -766,6 +797,10 @@
4792    if (ctx->magic == M_POP)
4793      pop_close_mailbox (ctx);
4794  #endif /* USE_POP */
4795 +#ifdef USE_NNTP
4796 +  if (ctx->magic == M_NNTP)
4797 +    nntp_fastclose_mailbox (ctx);
4798 +#endif /* USE_NNTP */
4799    if (ctx->id_hash)
4800      hash_destroy (&ctx->id_hash, NULL);
4801    mutt_clear_threads (ctx);
4802 @@ -823,6 +858,12 @@
4803        rc = pop_sync_mailbox (ctx, index_hint);
4804        break;
4805  #endif /* USE_POP */
4806 +
4807 +#ifdef USE_NNTP
4808 +    case M_NNTP:
4809 +      rc = nntp_sync_mailbox (ctx);
4810 +      break;
4811 +#endif /* USE_NNTP */
4812    }
4813  
4814  #if 0
4815 @@ -899,6 +940,16 @@
4816  
4817    ctx->closing = 1;
4818  
4819 +#ifdef USE_NNTP
4820 +  if (ctx->magic == M_NNTP)
4821 +  {
4822 +    int ret;
4823 +
4824 +    ret = nntp_close_mailbox (ctx);
4825 +    mx_fastclose_mailbox (ctx);
4826 +    return ret;
4827 +  }
4828 +#endif
4829    if (ctx->readonly || ctx->dontwrite)
4830    {
4831      /* mailbox is readonly or we don't want to write */
4832 @@ -1460,6 +1511,11 @@
4833        case M_POP:
4834         return (pop_check_mailbox (ctx, index_hint));
4835  #endif /* USE_POP */
4836 +
4837 +#ifdef USE_NNTP
4838 +      case M_NNTP:
4839 +       return (nntp_check_mailbox (ctx));
4840 +#endif /* USE_NNTP */
4841      }
4842    }
4843  
4844 @@ -1520,6 +1576,15 @@
4845      }
4846  #endif /* USE_POP */
4847  
4848 +#ifdef USE_NNTP
4849 +    case M_NNTP:
4850 +    {
4851 +      if (nntp_fetch_message (msg, ctx, msgno) != 0)
4852 +       FREE (&msg);
4853 +      break;
4854 +    }
4855 +#endif /* USE_NNTP */
4856 +
4857      default:
4858        dprint (1, (debugfile, "mx_open_message(): function not implemented for mailbox type %d.\n", ctx->magic));
4859        FREE (&msg);
4860 @@ -1608,6 +1673,9 @@
4861  #ifdef USE_POP
4862        || (*msg)->magic == M_POP
4863  #endif
4864 +#ifdef USE_NNTP
4865 +      || (*msg)->magic == M_NNTP
4866 +#endif
4867        )
4868    {
4869      r = safe_fclose (&(*msg)->fp);
4870 diff -uNr mutt-1.4.orig/mx.h mutt-1.4/mx.h
4871 --- mutt-1.4.orig/mx.h  Sun Nov  3 21:42:51 2002
4872 +++ mutt-1.4/mx.h       Sun Nov  3 21:57:20 2002
4873 @@ -44,6 +44,9 @@
4874  #ifdef USE_COMPRESSED
4875    , M_COMPRESSED
4876  #endif
4877 +#ifdef USE_NNTP
4878 +  , M_NNTP
4879 +#endif
4880  };
4881  
4882  WHERE short DefaultMagic INITVAL (M_MBOX);
4883 diff -uNr mutt-1.4.orig/newsrc.c mutt-1.4/newsrc.c
4884 --- mutt-1.4.orig/newsrc.c      Thu Jan  1 01:00:00 1970
4885 +++ mutt-1.4/newsrc.c   Sun Nov  3 21:57:20 2002
4886 @@ -0,0 +1,1042 @@
4887 +/*
4888 + * Copyright (C) 1998 Brandon Long <blong@fiction.net>
4889 + * Copyright (C) 1999 Andrej Gritsenko <andrej@lucky.net>
4890 + * Copyright (C) 2000-2001 Vsevolod Volkov <vvv@mutt.org.ua>
4891 + * 
4892 + *     This program is free software; you can redistribute it and/or modify
4893 + *     it under the terms of the GNU General Public License as published by
4894 + *     the Free Software Foundation; either version 2 of the License, or
4895 + *     (at your option) any later version.
4896 + * 
4897 + *     This program is distributed in the hope that it will be useful,
4898 + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
4899 + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4900 + *     GNU General Public License for more details.
4901 + * 
4902 + *     You should have received a copy of the GNU General Public License
4903 + *     along with this program; if not, write to the Free Software
4904 + *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4905 + */ 
4906 +
4907 +#include "mutt.h"
4908 +#include "mutt_curses.h"
4909 +#include "sort.h"
4910 +#include "mx.h"
4911 +#include "mime.h"
4912 +#include "mailbox.h"
4913 +#include "nntp.h"
4914 +#include "rfc822.h"
4915 +#include "rfc1524.h"
4916 +#include "rfc2047.h"
4917 +
4918 +#include <unistd.h>
4919 +#include <string.h>
4920 +#include <ctype.h>
4921 +#include <stdlib.h>
4922 +#include <sys/stat.h>
4923 +
4924 +void nntp_add_to_list (NNTP_SERVER *s, NNTP_DATA *d)
4925 +{
4926 +  LIST *l;
4927 +
4928 +  if (!s || !d)
4929 +    return;
4930 +
4931 +  l = safe_calloc (1, sizeof (LIST));
4932 +  if (s->list)
4933 +    s->tail->next = l;
4934 +  else
4935 +    s->list = l;
4936 +  s->tail = l;
4937 +  l->data = (void *) d;
4938 +}
4939 +
4940 +static int nntp_parse_newsrc_line (NNTP_SERVER *news, char *line)
4941 +{
4942 +  NNTP_DATA *data;
4943 +  char group[LONG_STRING];
4944 +  int x = 1;
4945 +  char *p = line, *b, *h;
4946 +  size_t len;
4947 +
4948 +  while (*p)
4949 +  {
4950 +    if (*p++ == ',')
4951 +      x++;
4952 +  }
4953 +
4954 +  p = line;
4955 +  while (*p && (*p != ':' && *p != '!')) p++;
4956 +  if (!*p)
4957 +    return -1;
4958 +  len = p + 1 - line;
4959 +  if (len > sizeof (group))
4960 +    len = sizeof (group);
4961 +  strfcpy (group, line, len);
4962 +  if ((data = (NNTP_DATA *)hash_find (news->newsgroups, group)) == NULL)
4963 +  {
4964 +    data = (NNTP_DATA *) safe_calloc (1, sizeof (NNTP_DATA) + strlen (group) + 1);
4965 +    data->group = (char *) data + sizeof (NNTP_DATA);
4966 +    strcpy (data->group, group);
4967 +    data->nserv = news;
4968 +    data->deleted = 1;
4969 +    if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
4970 +      news->newsgroups = hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
4971 +    hash_insert (news->newsgroups, data->group, data, 0);
4972 +    nntp_add_to_list (news, data);
4973 +  }
4974 +  else
4975 +    FREE ((void **) &data->entries);
4976 +
4977 +  data->rc = 1;
4978 +  data->entries = safe_calloc (x*2, sizeof (NEWSRC_ENTRY));
4979 +  data->max = x*2;
4980 +
4981 +  if (*p == ':')
4982 +    data->subscribed = 1;
4983 +  else
4984 +    data->subscribed = 0;
4985 +
4986 +  p++;
4987 +  b = p;
4988 +  x = 0;
4989 +  while (*b)
4990 +  {
4991 +    while (*p && *p != ',' && *p != '\n') p++;
4992 +    if (*p)
4993 +    {
4994 +      *p = '\0';
4995 +      p++;
4996 +    }
4997 +    if ((h = strchr(b, '-')))
4998 +    {
4999 +      *h = '\0';
5000 +      h++;
5001 +      data->entries[x].first = atoi(b);
5002 +      data->entries[x].last = atoi(h);
5003 +    }
5004 +    else
5005 +    {
5006 +      data->entries[x].first = atoi(b);
5007 +      data->entries[x].last = data->entries[x].first;
5008 +    }
5009 +    b = p;
5010 +    if (data->entries[x].last != 0)
5011 +      x++;
5012 +  }
5013 +  if (x && !data->lastMessage)
5014 +    data->lastMessage = data->entries[x-1].last;
5015 +  data->num = x;
5016 +  mutt_newsgroup_stat (data);
5017 +  dprint (2, (debugfile, "parse_line: Newsgroup %s\n", data->group));
5018 +  
5019 +  return 0;
5020 +}
5021 +
5022 +static int slurp_newsrc (NNTP_SERVER *news)
5023 +{
5024 +  FILE *fp;
5025 +  char *buf;
5026 +  struct stat sb;
5027 +
5028 +  news->stat = stat (news->newsrc, &sb);
5029 +  news->size = sb.st_size;
5030 +  news->mtime = sb.st_mtime;
5031 +
5032 +  if ((fp = safe_fopen (news->newsrc, "r")) == NULL)
5033 +    return -1;
5034 +  /* hmm, should we use dotlock? */
5035 +  if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1))
5036 +  {
5037 +    fclose (fp);
5038 +    return -1;
5039 +  }
5040 +
5041 +  buf = safe_malloc (sb.st_size + 1);
5042 +  while (fgets (buf, sb.st_size + 1, fp))
5043 +    nntp_parse_newsrc_line (news, buf);
5044 +  FREE (&buf);
5045 +
5046 +  mx_unlock_file (news->newsrc, fileno (fp), 0);
5047 +  fclose (fp);
5048 +  return 0;
5049 +}
5050 +
5051 +void nntp_cache_expand (char *dst, const char *src)
5052 +{
5053 +  snprintf (dst, _POSIX_PATH_MAX, "%s/%s", NewsCacheDir, src);
5054 +  mutt_expand_path (dst, _POSIX_PATH_MAX);
5055 +}
5056 +
5057 +/* Loads $news_cache_dir/.index into memory, loads newsserver data
5058 + * and newsgroup cache names */
5059 +static int nntp_parse_cacheindex (NNTP_SERVER *news)
5060 +{
5061 +  struct stat st;
5062 +  char buf[HUGE_STRING], *cp;
5063 +  char dir[_POSIX_PATH_MAX], file[_POSIX_PATH_MAX];
5064 +  FILE *index;
5065 +  NNTP_DATA *data;
5066 +  int l, m, t;
5067 +
5068 +  /* check is server name defined or not */
5069 +  if (!news || !news->conn || !news->conn->account.host)
5070 +    return -1;
5071 +  unset_option (OPTNEWSCACHE);
5072 +  if (!NewsCacheDir || !*NewsCacheDir)
5073 +    return 0;
5074 +
5075 +  strfcpy (dir, NewsCacheDir, sizeof (dir));
5076 +  mutt_expand_path (dir, sizeof(dir));
5077 +
5078 +  if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0)
5079 +  {
5080 +    snprintf (buf, sizeof(buf), _("Directory %s not exist. Create it?"), dir);
5081 +    if (mutt_yesorno (buf, M_YES) != M_YES || mkdir (dir, (S_IRWXU+S_IRWXG+
5082 +         S_IRWXO)))
5083 +    {
5084 +      mutt_error _("Cache directory not created!");
5085 +      return -1;
5086 +    }
5087 +    mutt_clear_error();
5088 +  }
5089 +
5090 +  set_option (OPTNEWSCACHE);
5091 +
5092 +  FREE (&news->cache);
5093 +  snprintf (buf, sizeof(buf), "%s/.index", dir);
5094 +  if (!(index = safe_fopen (buf, "a+")))
5095 +    return 0;
5096 +  rewind (index);
5097 +  while (fgets (buf, sizeof(buf), index))
5098 +  {
5099 +    buf[strlen(buf) - 1] = 0;  /* strip ending '\n' */
5100 +    if (!mutt_strncmp (buf, "#: ", 3) &&
5101 +       !mutt_strcasecmp (buf+3, news->conn->account.host))
5102 +      break;
5103 +  }
5104 +  while (fgets (buf, sizeof(buf), index))
5105 +  {
5106 +    cp = buf;
5107 +    while (*cp && *cp != ' ') cp++;
5108 +    if (!*cp) continue;
5109 +    cp[0] = 0;
5110 +    if (!mutt_strcmp (buf, "#:"))
5111 +      break;
5112 +    sscanf (cp + 1, "%s %d %d", file, &l, &m);
5113 +    if (!mutt_strcmp (buf, "ALL"))
5114 +    {
5115 +      news->cache = safe_strdup (file);
5116 +      news->newgroups_time = m;
5117 +    }
5118 +    else if (news->newsgroups)
5119 +    {
5120 +      if ((data = (NNTP_DATA *)hash_find (news->newsgroups, buf)) == NULL)
5121 +      {
5122 +       data = (NNTP_DATA *) safe_calloc (1, sizeof (NNTP_DATA) + strlen (buf) + 1);
5123 +       data->group = (char *) data + sizeof (NNTP_DATA);
5124 +       strcpy(data->group, buf);
5125 +       data->nserv = news;
5126 +       data->deleted = 1;
5127 +       if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
5128 +         news->newsgroups = hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
5129 +       hash_insert (news->newsgroups, data->group, data, 0);
5130 +       nntp_add_to_list (news, data);
5131 +      }
5132 +      data->cache = safe_strdup (file);
5133 +      t = 0;
5134 +      if (!data->firstMessage || data->lastMessage < m)
5135 +       t = 1;
5136 +      if (!data->firstMessage)
5137 +       data->firstMessage = l;
5138 +      if (data->lastMessage < m)
5139 +       data->lastMessage = m;
5140 +      data->lastCached = m;
5141 +      if (t || !data->unread)
5142 +       mutt_newsgroup_stat (data);
5143 +    }
5144 +  }
5145 +  fclose (index);
5146 +  return 0;
5147 +}
5148 +
5149 +const char *
5150 +nntp_format_str (char *dest, size_t destlen, char op, const char *src,
5151 +               const char *fmt, const char *ifstring, const char *elsestring,
5152 +               unsigned long data, format_flag flags)
5153 +{
5154 +  char fn[SHORT_STRING], tmp[SHORT_STRING];
5155 +
5156 +  switch (op)
5157 +  {
5158 +    case 's':
5159 +      strncpy (fn, NewsServer, sizeof(fn) - 1);
5160 +      mutt_strlower (fn);
5161 +      snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
5162 +      snprintf (dest, destlen, tmp, fn);
5163 +      break;
5164 +  }
5165 +  return (src);
5166 +}
5167 +
5168 +/* nntp_parse_url: given an NNPT URL, return host, port,
5169 + * username, password and newsgroup will recognise. */
5170 +int nntp_parse_url (const char *server, ACCOUNT *acct,
5171 +                   char *group, size_t group_len)
5172 +{
5173 +  ciss_url_t url;
5174 +  char *c;
5175 +  int ret = -1;
5176 +
5177 +  /* Defaults */
5178 +  acct->flags = 0;
5179 +  acct->port = NNTP_PORT;
5180 +  acct->type = M_ACCT_TYPE_NNTP;
5181 +
5182 +  c = safe_strdup (server);
5183 +  url_parse_ciss (&url, c);
5184 +
5185 +  if (url.scheme == U_NNTP || url.scheme == U_NNTPS)
5186 +  {
5187 +    if (url.scheme == U_NNTPS)
5188 +    {
5189 +      acct->flags |= M_ACCT_SSL;
5190 +      acct->port = NNTP_SSL_PORT;
5191 +    }
5192 +
5193 +    *group = '\0';
5194 +    if (url.path)
5195 +      strfcpy (group, url.path, group_len);
5196 +
5197 +    ret = mutt_account_fromurl (acct, &url);
5198 +  }
5199 +
5200 +  FREE (&c);
5201 +  return ret;
5202 +}
5203 +
5204 +void nntp_expand_path (char *line, size_t len, ACCOUNT *acct)
5205 +{
5206 +  ciss_url_t url;
5207 +
5208 +  url.path = safe_strdup (line);
5209 +  mutt_account_tourl (acct, &url);
5210 +  url_ciss_tostring (&url, line, len, 0);
5211 +  FREE (&url.path);
5212 +}
5213 +
5214 +/*
5215 + * Automatically loads a newsrc into memory, if necessary.
5216 + * Checks the size/mtime of a newsrc file, if it doesn't match, load
5217 + * again.  Hmm, if a system has broken mtimes, this might mean the file
5218 + * is reloaded every time, which we'd have to fix.
5219 + *
5220 + * a newsrc file is a line per newsgroup, with the newsgroup, then a 
5221 + * ':' denoting subscribed or '!' denoting unsubscribed, then a 
5222 + * comma separated list of article numbers and ranges.
5223 + */
5224 +NNTP_SERVER *mutt_select_newsserver (char *server)
5225 +{
5226 +  char file[_POSIX_PATH_MAX];
5227 +  char *buf, *p;
5228 +  LIST *list;
5229 +  ACCOUNT acct;
5230 +  NNTP_SERVER *serv;
5231 +  CONNECTION *conn;
5232 +
5233 +  if (!server || !*server)
5234 +  {
5235 +    mutt_error _("No newsserver defined!");
5236 +    return NULL;
5237 +  }
5238 +
5239 +  buf = p = safe_calloc (strlen (server) + 10, sizeof (char));
5240 +  if (url_check_scheme (server) == U_UNKNOWN)
5241 +  {
5242 +    strcpy (buf, "nntp://");
5243 +    p = strchr (buf, '\0');
5244 +  }
5245 +  strcpy (p, server);
5246 +
5247 +  if ((nntp_parse_url (buf, &acct, file, sizeof (file))) < 0 || *file)
5248 +  {
5249 +    FREE (&buf);
5250 +    mutt_error (_("%s is an invalid newsserver specification!"), server);
5251 +    return NULL;
5252 +  }
5253 +  FREE (&buf);
5254 +
5255 +  conn = mutt_conn_find (NULL, &acct);
5256 +  if (!conn)
5257 +    return NULL;
5258 +
5259 +  mutt_FormatString (file, sizeof (file), NONULL (NewsRc), nntp_format_str, 0, 0);
5260 +  mutt_expand_path (file, sizeof (file));
5261 +
5262 +  serv = (NNTP_SERVER *)conn->data;
5263 +  if (serv)
5264 +  {
5265 +    struct stat sb;
5266 +
5267 +    /* externally modified? */
5268 +    if (serv->stat != stat (file, &sb) || (!serv->stat &&
5269 +       (serv->size != sb.st_size || serv->mtime != sb.st_mtime)))
5270 +    {
5271 +      for (list = serv->list; list; list = list->next)
5272 +      {
5273 +       NNTP_DATA *data = (NNTP_DATA *) list->data;
5274 +
5275 +       if (data)
5276 +       {
5277 +         data->subscribed = 0;
5278 +         data->rc = 0;
5279 +         data->num = 0;
5280 +       }
5281 +      }
5282 +      slurp_newsrc (serv);
5283 +      nntp_clear_cacheindex (serv);
5284 +    }
5285 +
5286 +    if (serv->status == NNTP_BYE)
5287 +      serv->status = NNTP_NONE;
5288 +    nntp_check_newgroups (serv, 0);
5289 +    return serv;
5290 +  }
5291 +
5292 +  /* New newsserver */
5293 +  serv = safe_calloc (1, sizeof (NNTP_SERVER));
5294 +  serv->conn = conn;
5295 +  serv->newsrc = safe_strdup (file);
5296 +  serv->newsgroups = hash_create (1009);
5297 +  slurp_newsrc (serv);                 /* load .newsrc */
5298 +  nntp_parse_cacheindex (serv);                /* load .index */
5299 +  if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
5300 +    nntp_check_newgroups (serv, 1);
5301 +  else if (nntp_get_active (serv) < 0)
5302 +  {
5303 +    hash_destroy (&serv->newsgroups, nntp_delete_data);
5304 +    for (list = serv->list; list; list = list->next)
5305 +      list->data = NULL;
5306 +    mutt_free_list (&serv->list);
5307 +    FREE (&serv->newsrc);
5308 +    FREE (&serv->cache);
5309 +    FREE (&serv);
5310 +    return NULL;
5311 +  }
5312 +  nntp_clear_cacheindex (serv);
5313 +  conn->data = (void *)serv;
5314 +
5315 +  return serv;
5316 +}
5317 +
5318 +/* 
5319 + * full status flags are not supported by nntp, but we can fake some
5320 + * of them.  This is how:
5321 + * Read = a read message number is in the .newsrc
5322 + * New = a message is new since we last read this newsgroup
5323 + * Old = anything else
5324 + * So, Read is marked as such in the newsrc, old is anything that is 
5325 + * "skipped" in the newsrc, and new is anything not in the newsrc nor
5326 + * in the cache. By skipped, I mean before the last unread message
5327 + */
5328 +void nntp_get_status (CONTEXT *ctx, HEADER *h, char *group, int article)
5329 +{
5330 +  NNTP_DATA *data = (NNTP_DATA *) ctx->data;
5331 +  int x;
5332 +
5333 +  if (group)
5334 +    data = (NNTP_DATA *) hash_find (data->nserv->newsgroups, group);
5335 +
5336 +  if (!data)
5337 +  {
5338 +#ifdef DEBUG
5339 +    if (group)
5340 +      dprint (3, (debugfile, "newsgroup %s not found\n", group));
5341 +#endif
5342 +    return;
5343 +  }
5344 +
5345 +  for (x = 0; x < data->num; x++)
5346 +  {
5347 +    if ((article >= data->entries[x].first) &&
5348 +       (article <= data->entries[x].last))
5349 +    {
5350 +      /* we cannot use mutt_set_flag() because mx_update_context()
5351 +        didn't called yet */
5352 +      h->read = 1;
5353 +      return;
5354 +    }
5355 +  }
5356 +  /* If article was not cached yet, it is new! :) */
5357 +  if (!data->cache || article > data->lastCached)
5358 +    return;
5359 +  /* Old articles are articles which aren't read but an article after them
5360 +   * has been cached */
5361 +  if (option (OPTMARKOLD))
5362 +    h->old = 1;
5363 +}
5364 +
5365 +void mutt_newsgroup_stat (NNTP_DATA *data)
5366 +{
5367 +  int i;
5368 +  unsigned int first, last;
5369 +
5370 +  data->unread = 0;
5371 +  if (data->lastMessage == 0 || data->firstMessage > data->lastMessage)
5372 +    return;
5373 +
5374 +  data->unread = data->lastMessage - data->firstMessage + 1;
5375 +  for (i = 0; i < data->num; i++)
5376 +  {
5377 +    first = data->entries[i].first;
5378 +    if (first < data->firstMessage)
5379 +      first = data->firstMessage;
5380 +    last = data->entries[i].last;
5381 +    if (last > data->lastMessage)
5382 +      last = data->lastMessage;
5383 +    if (first <= last)
5384 +      data->unread -= last - first + 1;
5385 +  }
5386 +}
5387 +
5388 +static int puti (char *line, int num)
5389 +{
5390 +  char *p, s[32];
5391 +
5392 +  for (p = s; num; )
5393 +  {
5394 +    *p++ = '0' + num % 10;
5395 +    num /= 10;
5396 +  }
5397 +  while (p > s)
5398 +    *line++ = *--p, num++;
5399 +  *line = '\0';
5400 +  return num;
5401 +}
5402 +
5403 +static void nntp_create_newsrc_line (NNTP_DATA *data, char **buf, char **pline, size_t *buflen)
5404 +{
5405 +  char *line = *pline;
5406 +  size_t len = *buflen - (*pline - *buf);
5407 +  int x, i;
5408 +
5409 +  if (len < LONG_STRING * 10)
5410 +  {
5411 +    len += *buflen;
5412 +    *buflen *= 2;
5413 +    line = *buf;
5414 +    safe_realloc ((void **) buf, *buflen);
5415 +    line = *buf + (*pline - line);
5416 +  }
5417 +  strcpy (line, data->group);
5418 +  len -= strlen (line) + 1;
5419 +  line += strlen (line);
5420 +  *line++ = data->subscribed ? ':' : '!';
5421 +  *line = '\0';
5422 +
5423 +  for (x = 0; x < data->num; x++)
5424 +  {
5425 +    if (len < LONG_STRING)
5426 +    {
5427 +      len += *buflen;
5428 +      *buflen *= 2;
5429 +      *pline = line;
5430 +      line = *buf;
5431 +      safe_realloc ((void **) buf, *buflen);
5432 +      line = *buf + (*pline - line);
5433 +    }
5434 +    if (x)
5435 +    {
5436 +      *line++ = ',';
5437 +      len--;
5438 +    }
5439 +
5440 +#if 0
5441 +    if (data->entries[x].first == data->entries[x].last)
5442 +      snprintf (line, len, "%d%n", data->entries[x].first, &i);
5443 +    else
5444 +      snprintf (line, len, "%d-%d%n", 
5445 +           data->entries[x].first, data->entries[x].last, &i);
5446 +    len -= i;
5447 +    line += i;
5448 +#else
5449 +    i = puti (line, data->entries[x].first);
5450 +    line +=i; len -= i;
5451 +    if (data->entries[x].first != data->entries[x].last)
5452 +    {
5453 +      *line++ = '-';
5454 +      len--;
5455 +      i = puti (line, data->entries[x].last);
5456 +      line +=i; len -= i;
5457 +    }
5458 +#endif
5459 +  }
5460 +  *line++ = '\n';
5461 +  *line = '\0';
5462 +  *pline = line;
5463 +}
5464 +
5465 +void newsrc_gen_entries (CONTEXT *ctx)
5466 +{
5467 +  NNTP_DATA *data = (NNTP_DATA *)ctx->data;
5468 +  int series, x;
5469 +  unsigned int last = 0, first = 1;
5470 +  int save_sort = SORT_ORDER;
5471 +
5472 +  if (Sort != SORT_ORDER)
5473 +  {
5474 +    save_sort = Sort;
5475 +    Sort = SORT_ORDER;
5476 +    mutt_sort_headers (ctx, 0);
5477 +  }
5478 +
5479 +  if (!data->max)
5480 +  {
5481 +    data->entries = safe_calloc (5, sizeof (NEWSRC_ENTRY));
5482 +    data->max = 5;
5483 +  }
5484 +
5485 +  /*
5486 +   * Set up to fake initial sequence from 1 to the article before the 
5487 +   * first article in our list
5488 +   */
5489 +  data->num = 0;
5490 +  series = 1;
5491 +
5492 +  for (x = 0; x < ctx->msgcount; x++)
5493 +  {
5494 +    if (series) /* search for first unread */
5495 +    {
5496 +      /*
5497 +       * We don't actually check sequential order, since we mark 
5498 +       * "missing" entries as read/deleted
5499 +       */
5500 +      last = ctx->hdrs[x]->article_num;
5501 +      if (last >= data->firstMessage && !ctx->hdrs[x]->deleted &&
5502 +           !ctx->hdrs[x]->read)
5503 +      {
5504 +       if (data->num >= data->max)
5505 +       {
5506 +         data->max = data->max * 2;
5507 +         safe_realloc ((void **)&data->entries, 
5508 +             data->max * sizeof (NEWSRC_ENTRY));
5509 +       }
5510 +       data->entries[data->num].first = first;
5511 +       data->entries[data->num].last = last - 1;
5512 +       data->num++;
5513 +       series = 0;
5514 +      }
5515 +    }
5516 +    else /* search for first read */
5517 +    {
5518 +      if (ctx->hdrs[x]->deleted || ctx->hdrs[x]->read)
5519 +      {
5520 +       first = last + 1;
5521 +       series = 1;
5522 +      }
5523 +      last = ctx->hdrs[x]->article_num;
5524 +    }
5525 +  }
5526 +  if (series && first <= data->lastLoaded)
5527 +  {
5528 +    if (data->num >= data->max)
5529 +    {
5530 +      data->max = data->max * 2;
5531 +      safe_realloc ((void **)&data->entries, 
5532 +                   data->max * sizeof (NEWSRC_ENTRY));
5533 +    }
5534 +    data->entries[data->num].first = first;
5535 +    data->entries[data->num].last = data->lastLoaded;
5536 +    data->num++;
5537 +  }
5538 +
5539 +  if (save_sort != Sort)
5540 +  {
5541 +    Sort = save_sort;
5542 +    mutt_sort_headers (ctx, 0);
5543 +  }
5544 +}
5545 +
5546 +int mutt_newsrc_update (NNTP_SERVER *news)
5547 +{
5548 +  char *buf, *line;
5549 +  NNTP_DATA *data;
5550 +  LIST *tmp;
5551 +  int r = -1;
5552 +  size_t len, llen;
5553 +
5554 +  if (!news)
5555 +    return -1;
5556 +  llen = len = 10 * LONG_STRING;
5557 +  line = buf = safe_calloc (1, len);
5558 +  /* we will generate full newsrc here */
5559 +  for (tmp = news->list; tmp; tmp = tmp->next)
5560 +  {
5561 +    data = (NNTP_DATA *) tmp->data;
5562 +    if (!data || !data->rc)
5563 +      continue;
5564 +    nntp_create_newsrc_line (data, &buf, &line, &llen);
5565 +    dprint (2, (debugfile, "Added to newsrc: %s", line));
5566 +    line += strlen (line);
5567 +  }
5568 +  /* newrc being fully rewritten */
5569 +  if (news->newsrc &&
5570 +     (r = mutt_update_list_file (news->newsrc, NULL, "", buf)) == 0)
5571 +  {
5572 +    struct stat st;
5573 +
5574 +    stat (news->newsrc, &st);
5575 +    news->size = st.st_size;
5576 +    news->mtime = st.st_mtime;
5577 +  }
5578 +  FREE (&buf);
5579 +  return r;
5580 +}
5581 +
5582 +static FILE *mutt_mkname (char *s)
5583 +{
5584 +  char buf[_POSIX_PATH_MAX], *pc;
5585 +  int fd;
5586 +  FILE *fp;
5587 +
5588 +  nntp_cache_expand (buf, s);
5589 +  if ((fp = safe_fopen (buf, "w")))
5590 +    return fp;
5591 +
5592 +  nntp_cache_expand (buf, "cache-XXXXXX");
5593 +  pc = buf + strlen (buf) - 12;        /* positioning to "cache-XXXXXX" */
5594 +  if ((fd = mkstemp (buf)) == -1)
5595 +    return NULL;
5596 +  strcpy (s, pc);      /* generated name */
5597 +  return fdopen (fd, "w");
5598 +}
5599 +
5600 +/* Updates info into .index file: ALL or about selected newsgroup */
5601 +static int nntp_update_cacheindex (NNTP_SERVER *serv, NNTP_DATA *data)
5602 +{
5603 +  char buf[LONG_STRING], *key = "ALL";
5604 +  char file[_POSIX_PATH_MAX];
5605 +
5606 +  if (!serv || !serv->conn || !serv->conn->account.host)
5607 +    return -1;
5608 +
5609 +  if (data && data->group)
5610 +  {
5611 +    key = data->group;
5612 +    snprintf (buf, sizeof (buf), "%s %s %d %d", key, data->cache,
5613 +         data->firstMessage, data->lastLoaded);
5614 +  }
5615 +  else
5616 +  {
5617 +    strfcpy (file, serv->cache, sizeof (file));
5618 +    snprintf (buf, sizeof (buf), "ALL %s 0 %d", file, (int)serv->newgroups_time);
5619 +  }
5620 +  nntp_cache_expand (file, ".index");
5621 +  return mutt_update_list_file (file, serv->conn->account.host, key, buf);
5622 +}
5623 +
5624 +/* Remove cache files of unsubscribed newsgroups */
5625 +void nntp_clear_cacheindex (NNTP_SERVER *news)
5626 +{
5627 +  NNTP_DATA *data;
5628 +  LIST *tmp;
5629 +
5630 +  if (option (OPTSAVEUNSUB) || !news)
5631 +    return;
5632 +
5633 +  for (tmp = news->list; tmp; tmp = tmp->next)
5634 +  {
5635 +    data = (NNTP_DATA *) tmp->data;
5636 +    if (!data || data->subscribed || !data->cache)
5637 +      continue;
5638 +    nntp_delete_cache (data);
5639 +    dprint (2, (debugfile, "Removed from .index: %s\n", data->group));
5640 +  }
5641 +  return;
5642 +}
5643 +
5644 +int nntp_save_cache_index (NNTP_SERVER *news)
5645 +{
5646 +  char buf[HUGE_STRING];
5647 +  char file[_POSIX_PATH_MAX];
5648 +  NNTP_DATA *d;
5649 +  FILE *f;
5650 +  LIST *l;
5651 +
5652 +  if (!news || !news->newsgroups)
5653 +    return -1;
5654 +  if (!option (OPTNEWSCACHE))
5655 +    return 0;
5656 +
5657 +  if (news->cache)
5658 +  {
5659 +    nntp_cache_expand (file, news->cache);
5660 +    unlink (file);
5661 +    f = safe_fopen (file, "w");
5662 +  }
5663 +  else
5664 +  {
5665 +    strfcpy (buf, news->conn->account.host, sizeof(buf));
5666 +    f = mutt_mkname (buf);
5667 +    news->cache = safe_strdup (buf);
5668 +    nntp_cache_expand (file, buf);
5669 +  }
5670 +  if (!f)
5671 +    return -1;
5672 +
5673 +  for (l = news->list; l; l = l->next)
5674 +  {
5675 +    if ((d = (NNTP_DATA *)l->data) && !d->deleted)
5676 +    {
5677 +      if (d->desc)
5678 +       snprintf (buf, sizeof(buf), "%s %d %d %c %s\n", d->group,
5679 +             d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n',
5680 +             d->desc);
5681 +      else
5682 +       snprintf (buf, sizeof(buf), "%s %d %d %c\n", d->group,
5683 +             d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
5684 +      if (fputs (buf, f) == EOF)
5685 +      {
5686 +       fclose (f);
5687 +       unlink (file);
5688 +       return -1;
5689 +      }
5690 +    }
5691 +  }
5692 +  fclose (f);
5693 +
5694 +  if (nntp_update_cacheindex (news, NULL))
5695 +  {
5696 +    unlink (file);
5697 +    return -1;
5698 +  }
5699 +  return 0;
5700 +}
5701 +
5702 +int nntp_save_cache_group (CONTEXT *ctx)
5703 +{
5704 +  char buf[HUGE_STRING], addr[STRING];
5705 +  char file[_POSIX_PATH_MAX];
5706 +  FILE *f;
5707 +  HEADER *h;
5708 +  struct tm *tm;
5709 +  int i = 0, save = SORT_ORDER;
5710 +  int prev = 0;
5711 +
5712 +  if (!option (OPTNEWSCACHE))
5713 +    return 0;
5714 +  if (!ctx || !ctx->data || ctx->magic != M_NNTP)
5715 +    return -1;
5716 +
5717 +  if (((NNTP_DATA *)ctx->data)->cache)
5718 +  {
5719 +    nntp_cache_expand (file, ((NNTP_DATA *)ctx->data)->cache);
5720 +    unlink (file);
5721 +    f = safe_fopen (file, "w");
5722 +  }
5723 +  else
5724 +  {
5725 +    snprintf (buf, sizeof(buf), "%s-%s",
5726 +       ((NNTP_DATA *)ctx->data)->nserv->conn->account.host,
5727 +       ((NNTP_DATA *)ctx->data)->group);
5728 +    f = mutt_mkname (buf);
5729 +    ((NNTP_DATA *)ctx->data)->cache = safe_strdup (buf);
5730 +    nntp_cache_expand (file, buf);
5731 +  }
5732 +  if (!f)
5733 +    return -1;
5734 +
5735 +  if (Sort != SORT_ORDER)
5736 +  {
5737 +    save = Sort;
5738 +    Sort = SORT_ORDER;
5739 +    mutt_sort_headers (ctx, 0);
5740 +  }
5741 +
5742 +  /* Save only $nntp_context messages... */
5743 +  ((NNTP_DATA *)ctx->data)->lastCached = 0;
5744 +  if (NntpContext && ctx->msgcount > NntpContext)
5745 +    i = ctx->msgcount - NntpContext;
5746 +  for (; i < ctx->msgcount; i++)
5747 +  {
5748 +    if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev)
5749 +    {
5750 +      h = ctx->hdrs[i];
5751 +      addr[0] = 0;
5752 +      rfc822_write_address (addr, sizeof(addr), h->env->from);
5753 +      tm = gmtime (&h->date_sent);
5754 +      snprintf (buf, sizeof(buf),
5755 +           "%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
5756 +           h->article_num, h->env->subject, addr, tm->tm_mday,
5757 +           Months[tm->tm_mon], tm->tm_year+1900, tm->tm_hour, tm->tm_min,
5758 +           tm->tm_sec, h->env->message_id);
5759 +      fputs (buf, f);
5760 +      if (h->env->references)
5761 +       mutt_write_references (h->env->references, f);
5762 +      snprintf (buf, sizeof(buf), "\t%ld\t%d\tXref: %s\n", h->content->length,
5763 +           h->lines, NONULL(h->env->xref));
5764 +      if (fputs (buf, f) == EOF)
5765 +      {
5766 +       fclose (f);
5767 +       unlink (file);
5768 +       return -1;
5769 +      }
5770 +    }
5771 +    prev = ctx->hdrs[i]->article_num;
5772 +  }
5773 +
5774 +  if (save != Sort)
5775 +  {
5776 +    Sort = save;
5777 +    mutt_sort_headers (ctx, 0);
5778 +  }
5779 +  fclose (f);
5780 +
5781 +  if (nntp_update_cacheindex (((NNTP_DATA *)ctx->data)->nserv,
5782 +       (NNTP_DATA *)ctx->data))
5783 +  {
5784 +    unlink (file);
5785 +    return -1;
5786 +  }
5787 +  ((NNTP_DATA *)ctx->data)->lastCached = ((NNTP_DATA *)ctx->data)->lastLoaded;
5788 +  return 0;
5789 +}
5790 +
5791 +void nntp_delete_cache (NNTP_DATA *data)
5792 +{
5793 +  char buf[_POSIX_PATH_MAX];
5794 +
5795 +  if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
5796 +    return;
5797 +
5798 +  nntp_cache_expand (buf, data->cache);
5799 +  unlink (buf);
5800 +  FREE (&data->cache);
5801 +  data->lastCached = 0;
5802 +  nntp_cache_expand (buf, ".index");
5803 +  mutt_update_list_file (buf, data->nserv->conn->account.host, data->group, NULL);
5804 +}
5805 +
5806 +NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER *news, char *group)
5807 +{
5808 +  NNTP_DATA *data;
5809 +
5810 +  if (!news || !news->newsgroups || !group || !*group)
5811 +    return NULL;
5812 +  if (!(data = (NNTP_DATA *)hash_find (news->newsgroups, group)))
5813 +  {
5814 +    data = (NNTP_DATA *) safe_calloc (1, sizeof (NNTP_DATA) + strlen (group) + 1);
5815 +    data->group = (char *) data + sizeof (NNTP_DATA);
5816 +    strcpy (data->group, group);
5817 +    data->nserv = news;
5818 +    data->deleted = 1;
5819 +    if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
5820 +      news->newsgroups = hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
5821 +    hash_insert (news->newsgroups, data->group, data, 0);
5822 +    nntp_add_to_list (news, data);
5823 +  }
5824 +  if (!data->subscribed)
5825 +  {
5826 +    data->subscribed = 1;
5827 +    data->rc = 1;
5828 +  }
5829 +  return data;
5830 +}
5831 +
5832 +NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER *news, char *group)
5833 +{
5834 +  NNTP_DATA *data;
5835 +
5836 +  if (!news || !news->newsgroups || !group || !*group ||
5837 +       !(data = (NNTP_DATA *)hash_find (news->newsgroups, group)))
5838 +    return NULL;
5839 +  if (data->subscribed)
5840 +  {
5841 +    data->subscribed = 0;
5842 +    if (!option (OPTSAVEUNSUB))
5843 +      data->rc = 0;
5844 +  }
5845 +  return data;
5846 +}
5847 +
5848 +NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER *news, char *group)
5849 +{
5850 +  NNTP_DATA *data;
5851 +
5852 +  if (!news || !news->newsgroups || !group || !*group ||
5853 +      !(data = (NNTP_DATA *)hash_find (news->newsgroups, group)))
5854 +    return NULL;
5855 +  if (!data->max)
5856 +  {
5857 +    data->entries = safe_calloc (5, sizeof (NEWSRC_ENTRY));
5858 +    data->max = 5;
5859 +  }
5860 +  data->num = 1;
5861 +  data->entries[0].first = 1;
5862 +  data->unread = 0;
5863 +  data->entries[0].last = data->lastMessage;
5864 +  if (Context && Context->data == data)
5865 +  {
5866 +    int x;
5867 +
5868 +    for (x = 0; x < Context->msgcount; x++)
5869 +      mutt_set_flag (Context, Context->hdrs[x], M_READ, 1);
5870 +  }
5871 +  return data;
5872 +}
5873 +
5874 +NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER *news, char *group)
5875 +{
5876 +  NNTP_DATA *data;
5877 +
5878 +  if (!news || !news->newsgroups || !group || !*group ||
5879 +      !(data = (NNTP_DATA *)hash_find (news->newsgroups, group)))
5880 +    return NULL;
5881 +  if (!data->max)
5882 +  {
5883 +    data->entries = safe_calloc (5, sizeof (NEWSRC_ENTRY));
5884 +    data->max = 5;
5885 +  }
5886 +  data->num = 1;
5887 +  data->entries[0].first = 1;
5888 +  data->entries[0].last = data->firstMessage - 1;
5889 +  if (Context && Context->data == data)
5890 +  {
5891 +    int x;
5892 +
5893 +    data->unread = Context->msgcount;
5894 +    for (x = 0; x < Context->msgcount; x++)
5895 +      mutt_set_flag (Context, Context->hdrs[x], M_READ, 0);
5896 +  }
5897 +  else
5898 +    data->unread = data->lastMessage - data->entries[0].last;
5899 +  return data;
5900 +}
5901 +
5902 +/* this routine gives the first newsgroup with new messages */
5903 +void nntp_buffy (char *s)
5904 +{
5905 +  LIST *list;
5906 +
5907 +  for (list = CurrentNewsSrv->list; list; list = list->next)
5908 +  {
5909 +    NNTP_DATA *data = (NNTP_DATA *) list->data;
5910 +
5911 +    if (data && data->subscribed && data->unread)
5912 +    {
5913 +      if (Context && Context->magic == M_NNTP &&
5914 +         !mutt_strcmp (data->group, ((NNTP_DATA *) Context->data)->group))
5915 +      {
5916 +       unsigned int i, unread = 0;
5917 +
5918 +       for (i = 0; i < Context->msgcount; i++)
5919 +         if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)
5920 +           unread++;
5921 +       if (!unread)
5922 +         continue;
5923 +      }
5924 +      strcpy (s, data->group);
5925 +      break;
5926 +    }
5927 +  }
5928 +}
5929 diff -uNr mutt-1.4.orig/nntp.c mutt-1.4/nntp.c
5930 --- mutt-1.4.orig/nntp.c        Thu Jan  1 01:00:00 1970
5931 +++ mutt-1.4/nntp.c     Sun Nov  3 21:57:20 2002
5932 @@ -0,0 +1,1526 @@
5933 +/*
5934 + * Copyright (C) 1998 Brandon Long <blong@fiction.net>
5935 + * Copyright (C) 1999 Andrej Gritsenko <andrej@lucky.net>
5936 + * Copyright (C) 2000-2002 Vsevolod Volkov <vvv@mutt.org.ua>
5937 + * 
5938 + *     This program is free software; you can redistribute it and/or modify
5939 + *     it under the terms of the GNU General Public License as published by
5940 + *     the Free Software Foundation; either version 2 of the License, or
5941 + *     (at your option) any later version.
5942 + * 
5943 + *     This program is distributed in the hope that it will be useful,
5944 + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
5945 + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5946 + *     GNU General Public License for more details.
5947 + * 
5948 + *     You should have received a copy of the GNU General Public License
5949 + *     along with this program; if not, write to the Free Software
5950 + *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5951 + */ 
5952 +
5953 +#include "mutt.h"
5954 +#include "mutt_curses.h"
5955 +#include "sort.h"
5956 +#include "mx.h"
5957 +#include "mime.h"
5958 +#include "rfc1524.h"
5959 +#include "rfc2047.h"
5960 +#include "mailbox.h"
5961 +#include "nntp.h"
5962 +
5963 +#ifdef HAVE_PGP
5964 +#include "pgp.h"
5965 +#endif
5966 +
5967 +#include <unistd.h>
5968 +#include <string.h>
5969 +#include <ctype.h>
5970 +#include <stdlib.h>
5971 +
5972 +static unsigned int _checked = 0;
5973 +
5974 +#ifdef DEBUG
5975 +static void nntp_error (const char *where, const char *msg)
5976 +{
5977 +  dprint (1, (debugfile, "nntp_error(): unexpected response in %s: %s\n", where, msg));
5978 +}
5979 +#endif /* DEBUG */
5980 +
5981 +static int nntp_connect_error (NNTP_SERVER *serv)
5982 +{
5983 +  serv->status = NNTP_NONE;
5984 +  mutt_socket_close (serv->conn);
5985 +  mutt_error _("Server closed connection!");
5986 +  sleep (2);
5987 +  return -1;
5988 +}
5989 +
5990 +static int nntp_connect_and_auth (NNTP_SERVER *serv)
5991 +{
5992 +  CONNECTION *conn = serv->conn;
5993 +  char buf[STRING];
5994 +  unsigned char flags = conn->account.flags;
5995 +
5996 +  serv->status = NNTP_NONE;
5997 +
5998 +  if (mutt_socket_open (conn) < 0)
5999 +    return -1;
6000 +
6001 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
6002 +    return nntp_connect_error (serv);
6003 +
6004 +  if (!mutt_strncmp ("200", buf, 3))
6005 +    mutt_message (_("Connected to %s. Posting ok."), conn->account.host);
6006 +  else if (!mutt_strncmp ("201", buf, 3))
6007 +    mutt_message (_("Connected to %s. Posting NOT ok."), conn->account.host);
6008 +  else
6009 +  {
6010 +    mutt_socket_close (conn);
6011 +    mutt_remove_trailing_ws (buf);
6012 +    mutt_error ("%s", buf);
6013 +    sleep (2);
6014 +    return -1;
6015 +  }
6016 +
6017 +  sleep (1);
6018 +
6019 +  /* Tell INN to switch to mode reader if it isn't so. Ignore all
6020 +   returned codes and messages. */
6021 +  mutt_socket_write (conn, "MODE READER\r\n");
6022 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
6023 +    return nntp_connect_error (serv);
6024 +
6025 +  mutt_socket_write (conn, "STAT\r\n");
6026 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
6027 +    return nntp_connect_error (serv);
6028 +
6029 +  if (!(conn->account.flags & M_ACCT_USER) && mutt_strncmp ("480", buf, 3))
6030 +  {
6031 +    serv->status = NNTP_OK;
6032 +    return 0;
6033 +  }
6034 +
6035 +  if (mutt_account_getuser (&conn->account) || !conn->account.user[0] ||
6036 +      mutt_account_getpass (&conn->account) || !conn->account.pass[0])
6037 +  {
6038 +    mutt_socket_close (conn);
6039 +    serv->status = NNTP_BYE;
6040 +    conn->account.flags = flags;
6041 +    return -1;
6042 +  }
6043 +
6044 +  mutt_message _("Logging in...");
6045 +
6046 +  snprintf (buf, sizeof (buf), "AUTHINFO USER %s\r\n", conn->account.user);
6047 +  mutt_socket_write (conn, buf);
6048 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
6049 +  {
6050 +    conn->account.flags = flags;
6051 +    return nntp_connect_error (serv);
6052 +  }
6053 +
6054 +#ifdef DEBUG
6055 +  /* don't print the password unless we're at the ungodly debugging level */
6056 +  if (debuglevel < M_SOCK_LOG_FULL)
6057 +    dprint (M_SOCK_LOG_CMD, (debugfile, "> AUTHINFO PASS *\n"));
6058 +#endif
6059 +  snprintf (buf, sizeof (buf), "AUTHINFO PASS %s\r\n", conn->account.pass);
6060 +  mutt_socket_write_d (conn, buf, M_SOCK_LOG_FULL);
6061 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
6062 +  {
6063 +    conn->account.flags = flags;
6064 +    return nntp_connect_error (serv);
6065 +  }
6066 +
6067 +  if (!mutt_strncmp ("281", buf, 3))
6068 +  {
6069 +    serv->status = NNTP_OK;
6070 +    return 0;
6071 +  }
6072 +
6073 +  mutt_socket_close (conn);
6074 +  conn->account.flags = flags;
6075 +  mutt_error _("Login failed.");
6076 +  sleep (2);
6077 +  return -1;
6078 +}
6079 +
6080 +static int nntp_attempt_features (NNTP_SERVER *serv)
6081 +{
6082 +  char buf[LONG_STRING];
6083 +  CONNECTION *conn = serv->conn;
6084 +
6085 +  mutt_socket_write (conn, "XOVER\r\n");
6086 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
6087 +    return nntp_connect_error (serv);
6088 +  if (mutt_strncmp ("500", buf, 3))
6089 +    serv->hasXOVER = 1;
6090 +
6091 +  mutt_socket_write (conn, "XPAT\r\n");
6092 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
6093 +    return nntp_connect_error (serv);
6094 +  if (mutt_strncmp ("500", buf, 3))
6095 +    serv->hasXPAT = 1;
6096 +
6097 +  mutt_socket_write (conn, "XGTITLE +\r\n");
6098 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
6099 +    return nntp_connect_error (serv);
6100 +  if (mutt_strncmp ("500", buf, 3))
6101 +    serv->hasXGTITLE = 1;
6102 +
6103 +  if (!mutt_strncmp ("282", buf, 3))
6104 +  {
6105 +    do
6106 +    {
6107 +      if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
6108 +       return nntp_connect_error (serv);
6109 +    } while (!(buf[0] == '.' && buf[1] == '\0'));
6110 +  }
6111 +
6112 +  return 0;
6113 +}
6114 +
6115 +static int nntp_open_connection (NNTP_SERVER *serv)
6116 +{
6117 +  if (serv->status == NNTP_OK)
6118 +    return 0;
6119 +  if (serv->status == NNTP_BYE)
6120 +    return -1;
6121 +  if (nntp_connect_and_auth (serv) < 0)
6122 +    return -1;
6123 +  if (nntp_attempt_features (serv) < 0)
6124 +    return -1;
6125 +  return 0;
6126 +}
6127 +
6128 +static int nntp_reconnect (NNTP_SERVER *serv)
6129 +{
6130 +  char buf[SHORT_STRING];
6131 +
6132 +  mutt_socket_close (serv->conn);
6133 +
6134 +  FOREVER
6135 +  {
6136 +    if (nntp_connect_and_auth (serv) == 0)
6137 +      return 0;
6138 +
6139 +    snprintf (buf, sizeof (buf), _("Connection to %s lost. Reconnect?"),
6140 +                               serv->conn->account.host);
6141 +    if (query_quadoption (OPT_NNTPRECONNECT, buf) != M_YES)
6142 +    {
6143 +      serv->status = NNTP_BYE;
6144 +      return -1;
6145 +    }
6146 +  }
6147 +}
6148 +
6149 +/* Send data from line[LONG_STRING] and receive answer to same line */
6150 +static int mutt_nntp_query (NNTP_DATA *data, char *line, size_t linelen)
6151 +{
6152 +  char buf[LONG_STRING];
6153 +  int done = TRUE;
6154 +
6155 +  if (data->nserv->status == NNTP_BYE)
6156 +    return -1;
6157 +
6158 +  do
6159 +  {
6160 +    if (!*line && data->group)
6161 +    {
6162 +      snprintf (buf, sizeof (buf), "GROUP %s\r\n", data->group);
6163 +      mutt_socket_write (data->nserv->conn, buf);
6164 +    }
6165 +    else
6166 +      mutt_socket_write (data->nserv->conn, line);
6167 +
6168 +    done = TRUE;
6169 +    if (mutt_socket_readln (buf, sizeof (buf), data->nserv->conn) < 0)
6170 +    {
6171 +      if (nntp_reconnect (data->nserv) < 0)
6172 +       return -1;
6173 +
6174 +      if (data->group)
6175 +      {
6176 +       snprintf (buf, sizeof (buf), "GROUP %s\r\n", data->group);
6177 +       mutt_socket_write (data->nserv->conn, buf);
6178 +       if (mutt_socket_readln (buf, sizeof (buf), data->nserv->conn) < 0)
6179 +         return -1;
6180 +      }
6181 +      if (*line) done = FALSE;
6182 +    }
6183 +  } while (!done);
6184 +
6185 +  strfcpy (line, buf, linelen);
6186 +  return 0;
6187 +}
6188 +
6189 +/*
6190 + * This function calls  funct(*line, *data)  for each received line,
6191 + * funct(NULL, *data)  if  rewind(*data)  needs, exits when fail or done.
6192 + * Returned codes:
6193 + *  0 - successful,
6194 + *  1 - correct but not performed (may be, have to be continued),
6195 + * -1 - conection lost,
6196 + * -2 - invalid command or execution error,
6197 + * -3 - error in funct(*line, *data).
6198 + */
6199 +static int mutt_nntp_fetch (NNTP_DATA *nntp_data, char *query, char *msg,
6200 +               int (*funct) (char *, void *), void *data, int tagged)
6201 +{
6202 +  char buf[LONG_STRING];
6203 +  char *inbuf, *p;
6204 +  int done = FALSE;
6205 +  int chunk, line;
6206 +  size_t lenbuf = 0;
6207 +  int ret;
6208 +
6209 +  do
6210 +  {
6211 +    strfcpy (buf, query, sizeof (buf));
6212 +    if (mutt_nntp_query (nntp_data, buf, sizeof (buf)) < 0)
6213 +      return -1;
6214 +    if (buf[0] == '5')
6215 +      return -2;
6216 +    if (buf[0] != '2')
6217 +      return 1;
6218 +
6219 +    ret = 0;
6220 +    line = 0;
6221 +    inbuf = safe_malloc (sizeof (buf));
6222 +
6223 +    FOREVER
6224 +    {
6225 +      chunk = mutt_socket_readln_d (buf, sizeof (buf), nntp_data->nserv->conn,
6226 +                                   M_SOCK_LOG_HDR);
6227 +      if (chunk < 0)
6228 +       break;
6229 +
6230 +      p = buf;
6231 +      if (!lenbuf && buf[0] == '.')
6232 +      {
6233 +       if (buf[1] == '\0')
6234 +       {
6235 +         done = TRUE;
6236 +         break;
6237 +       }
6238 +       if (buf[1] == '.')
6239 +         p++;
6240 +      }
6241 +
6242 +      strfcpy (inbuf + lenbuf, p, sizeof (buf));
6243 +
6244 +      if (chunk >= sizeof (buf))
6245 +      {
6246 +       lenbuf += strlen (p);
6247 +      }
6248 +      else
6249 +      {
6250 +       line++;
6251 +       if (msg && ReadInc && (line % ReadInc == 0)) {
6252 +         if (tagged)
6253 +           mutt_message (_("%s (tagged: %d) %d"), msg, tagged, line);
6254 +         else
6255 +           mutt_message ("%s %d", msg, line);
6256 +       }
6257 +
6258 +       if (ret == 0 && funct (inbuf, data) < 0)
6259 +         ret = -3;
6260 +       lenbuf = 0;
6261 +      }
6262 +
6263 +      safe_realloc ((void **) &inbuf, lenbuf + sizeof (buf));
6264 +    }
6265 +    FREE (&inbuf);
6266 +    funct (NULL, data);
6267 +  }
6268 +  while (!done);
6269 +  return ret;
6270 +}
6271 +
6272 +static int nntp_read_tempfile (char *line, void *file)
6273 +{
6274 +  FILE *f = (FILE *)file;
6275 +
6276 +  if (!line)
6277 +    rewind (f);
6278 +  else
6279 +  {
6280 +    fputs (line, f);
6281 +    if (fputc ('\n', f) == EOF)
6282 +      return -1;
6283 +  }
6284 +  return 0;
6285 +}
6286 +
6287 +static void nntp_parse_xref (CONTEXT *ctx, char *group, char *xref, HEADER *h)
6288 +{
6289 +  register char *p, *b;
6290 +  register char *colon = NULL;
6291 +
6292 +  b = p = xref;
6293 +  while (*p)
6294 +  {
6295 +    /* skip to next word */
6296 +    b = p;
6297 +    while (*b && ((*b == ' ') || (*b == '\t'))) b++;
6298 +    p = b;
6299 +    colon = NULL;
6300 +    /* skip to end of word */
6301 +    while (*p && (*p != ' ') && (*p != '\t')) 
6302 +    {
6303 +      if (*p == ':')
6304 +       colon = p;
6305 +      p++;
6306 +    }
6307 +    if (*p)
6308 +    {
6309 +      *p = '\0';
6310 +      p++;
6311 +    }
6312 +    if (colon)
6313 +    {
6314 +      *colon = '\0';
6315 +      colon++;
6316 +      nntp_get_status (ctx, h, p, atoi(colon));
6317 +      if (h && h->article_num == 0 && mutt_strcmp (group, b) == 0)
6318 +       h->article_num = atoi(colon);
6319 +    }
6320 +  }
6321 +}
6322 +
6323 +/*
6324 + * returns:
6325 + *  0 on success
6326 + *  1 if article not found
6327 + * -1 if read or write error on tempfile or socket
6328 + */
6329 +static int nntp_read_header (CONTEXT *ctx, const char *msgid, int article_num)
6330 +{
6331 +  NNTP_DATA *nntp_data = ((NNTP_DATA *)ctx->data);
6332 +  FILE *f;
6333 +  char buf[LONG_STRING];
6334 +  char tempfile[_POSIX_PATH_MAX];
6335 +  int ret;
6336 +  HEADER *h = ctx->hdrs[ctx->msgcount];
6337 +
6338 +  mutt_mktemp (tempfile);
6339 +  if (!(f = safe_fopen (tempfile, "w+")))
6340 +    return -1;
6341 +
6342 +  if (!msgid)
6343 +    snprintf (buf, sizeof (buf), "HEAD %d\r\n", article_num);
6344 +  else
6345 +    snprintf (buf, sizeof (buf), "HEAD %s\r\n", msgid);
6346 +
6347 +  ret = mutt_nntp_fetch (nntp_data, buf, NULL, nntp_read_tempfile, f, 0);
6348 +  if (ret)
6349 +  {
6350 +#ifdef DEBUG
6351 +    if (ret != -1)
6352 +      dprint(1, (debugfile, "nntp_read_header: %s\n", buf));
6353 +#endif
6354 +    fclose (f);
6355 +    unlink (tempfile);
6356 +    return (ret == -1 ? -1 : 1);
6357 +  }
6358 +
6359 +  h->article_num = article_num;
6360 +  h->env = mutt_read_rfc822_header (f, h, 0, 0);
6361 +  fclose (f);
6362 +  unlink (tempfile);
6363 +
6364 +  if (h->env->xref != NULL)
6365 +    nntp_parse_xref (ctx, nntp_data->group, h->env->xref, h);
6366 +  else if (h->article_num == 0 && msgid)
6367 +  {
6368 +    snprintf (buf, sizeof (buf), "STAT %s\r\n", msgid);
6369 +    if (mutt_nntp_query (nntp_data, buf, sizeof (buf)) == 0)
6370 +      h->article_num = atoi (buf + 4);
6371 +  }
6372 +
6373 +  return 0;
6374 +}
6375 +
6376 +static int parse_description (char *line, void *n)
6377 +{
6378 +#define news ((NNTP_SERVER *) n)
6379 +  register char *d = line;
6380 +  NNTP_DATA *data;
6381 +
6382 +  if (!line)
6383 +    return 0;
6384 +  while (*d && *d != '\t' && *d != ' ') d++;
6385 +    *d = 0;
6386 +  d++;
6387 +  while (*d && (*d == '\t' || *d == ' ')) d++;
6388 +  dprint (2, (debugfile, "group: %s, desc: %s\n", line, d));
6389 +  if ((data = (NNTP_DATA *) hash_find (news->newsgroups, line)) != NULL &&
6390 +       mutt_strcmp (d, data->desc))
6391 +  {
6392 +    FREE (&data->desc);
6393 +    data->desc = safe_strdup (d);
6394 +  }
6395 +  return 0;
6396 +#undef news
6397 +}
6398 +
6399 +static void nntp_get_desc (NNTP_DATA *data, char *mask, char *msg)
6400 +{
6401 +  char buf[STRING];
6402 +
6403 +  if (!option (OPTLOADDESC) || !data || !data->nserv)
6404 +    return;
6405 +
6406 +  /* Get newsgroup description, if we can */
6407 +  if (data->nserv->hasXGTITLE)
6408 +    snprintf (buf, sizeof (buf), "XGTITLE %s\r\n", mask);
6409 +  else
6410 +    snprintf (buf, sizeof (buf), "LIST NEWSGROUPS %s\r\n", mask);
6411 +  if (mutt_nntp_fetch (data, buf, msg, parse_description, data->nserv, 0) != 0)
6412 +  {
6413 +#ifdef DEBUG
6414 +    nntp_error ("nntp_get_desc()", buf);
6415 +#endif
6416 +  }
6417 +}
6418 +
6419 +/*
6420 + * XOVER returns a tab separated list of:
6421 + * id|subject|from|date|Msgid|references|bytes|lines|xref
6422 + *
6423 + * This has to duplicate some of the functionality of 
6424 + * mutt_read_rfc822_header(), since it replaces the call to that (albeit with
6425 + * a limited number of headers which are "parsed" by placement in the list)
6426 + */
6427 +static int nntp_parse_xover (CONTEXT *ctx, char *buf, HEADER *hdr)
6428 +{
6429 +  NNTP_DATA *nntp_data = (NNTP_DATA *) ctx->data;
6430 +  char *p, *b;
6431 +  int x, done = 0;
6432 +
6433 +  hdr->env = mutt_new_envelope();
6434 +  hdr->env->newsgroups = safe_strdup (nntp_data->group);
6435 +  hdr->content = mutt_new_body();
6436 +  hdr->content->type = TYPETEXT;
6437 +  hdr->content->subtype = safe_strdup ("plain");
6438 +  hdr->content->encoding = ENC7BIT;
6439 +  hdr->content->disposition = DISPINLINE;
6440 +  hdr->content->length = -1;
6441 +  b = p = buf;
6442 +
6443 +  for (x = 0; !done && x < 9; x++)
6444 +  {
6445 +    /* if from file, need to skip newline character */
6446 +    while (*p && *p != '\n' && *p != '\t') p++;
6447 +    if (!*p) done++;
6448 +    *p = '\0';
6449 +    p++;
6450 +    switch (x)
6451 +    {
6452 +      case 0:
6453 +
6454 +       hdr->article_num = atoi (b);
6455 +       nntp_get_status (ctx, hdr, NULL, hdr->article_num);
6456 +       break;
6457 +      case 1:
6458 +       hdr->env->subject = safe_strdup (b);
6459 +       /* Now we need to do the things which would normally be done in 
6460 +        * mutt_read_rfc822_header() */
6461 +       if (hdr->env->subject)
6462 +       {
6463 +         regmatch_t pmatch[1];
6464 +
6465 +         rfc2047_decode (&hdr->env->subject);
6466 +
6467 +         if (regexec (ReplyRegexp.rx, hdr->env->subject, 1, pmatch, 0) == 0)
6468 +           hdr->env->real_subj = hdr->env->subject + pmatch[0].rm_eo;
6469 +         else
6470 +           hdr->env->real_subj = hdr->env->subject;
6471 +       }
6472 +       break;
6473 +      case 2:
6474 +       rfc822_free_address (&hdr->env->from);
6475 +       hdr->env->from = rfc822_parse_adrlist (hdr->env->from, b);
6476 +       rfc2047_decode_adrlist (hdr->env->from);
6477 +       break;
6478 +      case 3:
6479 +       hdr->date_sent = mutt_parse_date (b, hdr);
6480 +       hdr->received = hdr->date_sent;
6481 +       break;
6482 +      case 4:
6483 +       FREE (&hdr->env->message_id);
6484 +       hdr->env->message_id = safe_strdup (b);
6485 +       break;
6486 +      case 5:
6487 +       mutt_free_list (&hdr->env->references);
6488 +       hdr->env->references = mutt_parse_references (b, 0);
6489 +       break;
6490 +      case 6:
6491 +       hdr->content->length = atoi (b);
6492 +       break;
6493 +      case 7:
6494 +       hdr->lines = atoi (b);
6495 +       break;
6496 +      case 8:
6497 +       if (!hdr->read)
6498 +         FREE (&hdr->env->xref);
6499 +         b = b + 6;    /* skips the "Xref: " */
6500 +         hdr->env->xref = safe_strdup (b);
6501 +         nntp_parse_xref (ctx, nntp_data->group, b, hdr);
6502 +    }
6503 +    if (!*p)
6504 +      return -1;
6505 +    b = p;
6506 +  }
6507 +  return 0;
6508 +}
6509 +
6510 +typedef struct
6511 +{
6512 +  CONTEXT *ctx;
6513 +  unsigned int base;
6514 +  unsigned int first;
6515 +  unsigned int last;
6516 +  unsigned short *messages;
6517 +  char* msg;
6518 +} FETCH_CONTEXT;
6519 +
6520 +#define fc ((FETCH_CONTEXT *) c)
6521 +static int nntp_fetch_numbers (char *line, void *c)
6522 +{
6523 +  unsigned int num;
6524 +
6525 +  if (!line)
6526 +    return 0;
6527 +  num = atoi (line);
6528 +  if (num < fc->base || num > fc->last)
6529 +    return 0;
6530 +  fc->messages[num - fc->base] = 1;
6531 +  return 0;
6532 +}
6533 +
6534 +static int add_xover_line (char *line, void *c)
6535 +{
6536 +  unsigned int num, total;
6537 +  CONTEXT *ctx = fc->ctx;
6538 +  NNTP_DATA *data = (NNTP_DATA *)ctx->data;
6539 +
6540 +  if (!line)
6541 +    return 0;
6542 +
6543 +  if (ctx->msgcount >= ctx->hdrmax)
6544 +    mx_alloc_memory (ctx);
6545 +  ctx->hdrs[ctx->msgcount] = mutt_new_header ();
6546 +  ctx->hdrs[ctx->msgcount]->index = ctx->msgcount;
6547 +
6548 +  nntp_parse_xover (ctx, line, ctx->hdrs[ctx->msgcount]);
6549 +  num = ctx->hdrs[ctx->msgcount]->article_num;
6550 +
6551 +  if (num >= fc->first && num <= fc->last && fc->messages[num - fc->base])
6552 +  {
6553 +    ctx->msgcount++;
6554 +    if (num > data->lastLoaded)
6555 +      data->lastLoaded = num;
6556 +    num = num - fc->first + 1;
6557 +    total = fc->last - fc->first + 1;
6558 +    if (!ctx->quiet && fc->msg && ReadInc && (num % ReadInc == 0))
6559 +      mutt_message ("%s %d/%d", fc->msg, num, total);
6560 +  }
6561 +  else
6562 +    mutt_free_header (&ctx->hdrs[ctx->msgcount]); /* skip it */
6563 +
6564 +  return 0;
6565 +}
6566 +#undef fc
6567 +
6568 +static int nntp_fetch_headers (CONTEXT *ctx, unsigned int first,
6569 +       unsigned int last)
6570 +{
6571 +  char buf[HUGE_STRING];
6572 +  char *msg = _("Fetching message headers...");
6573 +  NNTP_DATA *nntp_data = ((NNTP_DATA *)ctx->data);
6574 +  int ret;
6575 +  int num;
6576 +  int oldmsgcount;
6577 +  unsigned int current;
6578 +  FILE *f;
6579 +  FETCH_CONTEXT fc;
6580 +
6581 +  /* if empty group or nothing to do */
6582 +  if (!last || first > last)
6583 +    return 0;
6584 +
6585 +  /* fetch list of articles */
6586 +  mutt_message _("Fetching list of articles...");
6587 +  fc.ctx = ctx;
6588 +  fc.base = first;
6589 +  fc.last = last;
6590 +  fc.messages = safe_calloc (last - first + 1, sizeof (unsigned short));
6591 +  snprintf (buf, sizeof (buf), "LISTGROUP %s\r\n", nntp_data->group);
6592 +  if (mutt_nntp_fetch (nntp_data, buf, NULL, nntp_fetch_numbers, &fc, 0) != 0)
6593 +  {
6594 +    mutt_error (_("LISTGROUP command failed: %s"), buf);
6595 +#ifdef DEBUG
6596 +    nntp_error ("nntp_fetch_headers()", buf);
6597 +#endif
6598 +    FREE (&fc.messages);
6599 +    return -1;
6600 +  }
6601 +
6602 +  /* CACHE: must be loaded xover cache here */
6603 +  num = nntp_data->lastCached - first + 1;
6604 +  if (option (OPTNEWSCACHE) && nntp_data->cache && num > 0)
6605 +  {
6606 +    nntp_cache_expand (buf, nntp_data->cache);
6607 +    mutt_message _("Fetching headers from cache...");
6608 +    if ((f = safe_fopen (buf, "r")))
6609 +    {
6610 +      int r = 0;
6611 +
6612 +      /* counting number of lines */
6613 +      while (fgets (buf, sizeof (buf), f) != NULL)
6614 +       r++;
6615 +      rewind (f);
6616 +      while (r > num && fgets (buf, sizeof (buf), f) != NULL)
6617 +       r--;
6618 +      oldmsgcount = ctx->msgcount;
6619 +      fc.first = first;
6620 +      fc.last = first + num - 1;
6621 +      fc.msg = NULL;
6622 +      while (fgets (buf, sizeof (buf), f) != NULL)
6623 +       add_xover_line (buf, &fc);
6624 +      fclose (f);
6625 +      nntp_data->lastLoaded = fc.last;
6626 +      first = fc.last + 1;
6627 +      if (ctx->msgcount > oldmsgcount)
6628 +       mx_update_context (ctx, ctx->msgcount - oldmsgcount);
6629 +    }
6630 +    else
6631 +      nntp_delete_cache (nntp_data);
6632 +  }
6633 +  num = last - first + 1;
6634 +  if (num <= 0)
6635 +  {
6636 +    FREE (&fc.messages);
6637 +    return 0;
6638 +  }
6639 +
6640 +  /*
6641 +   * Without XOVER, we have to fetch each article header and parse
6642 +   * it.  With XOVER, we ask for all of them
6643 +   */
6644 +  mutt_message (msg);
6645 +  if (nntp_data->nserv->hasXOVER)
6646 +  {
6647 +    oldmsgcount = ctx->msgcount;
6648 +    fc.first = first;
6649 +    fc.last = last;
6650 +    fc.msg = msg;
6651 +    snprintf (buf, sizeof (buf), "XOVER %d-%d\r\n", first, last);
6652 +    ret = mutt_nntp_fetch (nntp_data, buf, NULL, add_xover_line, &fc, 0);
6653 +    if (ctx->msgcount > oldmsgcount)
6654 +      mx_update_context (ctx, ctx->msgcount - oldmsgcount);
6655 +    if (ret != 0)
6656 +    {
6657 +      mutt_error (_("XOVER command failed: %s"), buf);
6658 +#ifdef DEBUG
6659 +      nntp_error ("nntp_fetch_headers()", buf);
6660 +#endif
6661 +      FREE (&fc.messages);
6662 +      return -1;
6663 +    }
6664 +    /* fetched OK */
6665 +  }
6666 +  else
6667 +  for (current = first; current <= last; current++)
6668 +  {
6669 +    HEADER *h;
6670 +
6671 +    ret = current - first + 1;
6672 +    mutt_message ("%s %d/%d", msg, ret, num);
6673 +
6674 +    if (!fc.messages[current - fc.base])
6675 +      continue;
6676 +
6677 +    if (ctx->msgcount >= ctx->hdrmax)
6678 +      mx_alloc_memory (ctx);
6679 +    h = ctx->hdrs[ctx->msgcount] = mutt_new_header ();
6680 +    h->index = ctx->msgcount;
6681 +
6682 +    ret = nntp_read_header (ctx, NULL, current);
6683 +    if (ret == 0) /* Got article. Fetch next header */
6684 +    {
6685 +      nntp_get_status (ctx, h, NULL, h->article_num);
6686 +      ctx->msgcount++;
6687 +      mx_update_context (ctx, 1);
6688 +    }
6689 +    else
6690 +      mutt_free_header (&h); /* skip it */
6691 +    if (ret == -1)
6692 +    {
6693 +      FREE (&fc.messages);
6694 +      return -1;
6695 +    }
6696 +
6697 +    if (current > nntp_data->lastLoaded)
6698 +      nntp_data->lastLoaded = current;
6699 +  }
6700 +  FREE (&fc.messages);
6701 +  nntp_data->lastLoaded = last;
6702 +  mutt_clear_error ();
6703 +  return 0;
6704 +}
6705 +
6706 +/* 
6707 + * currently, nntp "mailbox" is "newsgroup"
6708 + */
6709 +int nntp_open_mailbox (CONTEXT *ctx)
6710 +{
6711 +  NNTP_DATA *nntp_data;
6712 +  NNTP_SERVER *serv;
6713 +  char buf[HUGE_STRING];
6714 +  char server[LONG_STRING];
6715 +  int count = 0;
6716 +  unsigned int first;
6717 +  ACCOUNT acct;
6718 +
6719 +  if (nntp_parse_url (ctx->path, &acct, buf, sizeof (buf)) < 0 || !*buf)
6720 +  {
6721 +    mutt_error (_("%s is an invalid newsgroup specification!"), ctx->path);
6722 +    mutt_sleep (2);
6723 +    return -1;
6724 +  }
6725 +
6726 +  server[0] = '\0';
6727 +  nntp_expand_path (server, sizeof (server), &acct);
6728 +  if (!(serv = mutt_select_newsserver (server)) || serv->status != NNTP_OK)
6729 +    return -1;
6730 +
6731 +  CurrentNewsSrv = serv;
6732 +
6733 +  /* create NNTP-specific state struct if nof found in list */
6734 +  if ((nntp_data = (NNTP_DATA *) hash_find (serv->newsgroups, buf)) == NULL)
6735 +  {
6736 +    nntp_data = safe_calloc (1, sizeof (NNTP_DATA) + strlen (buf) + 1);
6737 +    nntp_data->group = (char *) nntp_data + sizeof (NNTP_DATA);
6738 +    strcpy (nntp_data->group, buf);
6739 +    hash_insert (serv->newsgroups, nntp_data->group, nntp_data, 0);
6740 +    nntp_add_to_list (serv, nntp_data);
6741 +  }
6742 +  ctx->data = nntp_data;
6743 +  nntp_data->nserv = serv;
6744 +
6745 +  mutt_message (_("Selecting %s..."), nntp_data->group);
6746 +
6747 +  if (!nntp_data->desc)
6748 +  {
6749 +    nntp_get_desc (nntp_data, nntp_data->group, NULL);
6750 +    if (nntp_data->desc)
6751 +      nntp_save_cache_index (serv);
6752 +  }
6753 +
6754 +  buf[0] = 0;
6755 +  if (mutt_nntp_query (nntp_data, buf, sizeof(buf)) < 0)
6756 +  {
6757 +#ifdef DEBUG
6758 +    nntp_error ("nntp_open_mailbox()", buf);
6759 +#endif
6760 +    return -1;
6761 +  }
6762 +
6763 +  if (mutt_strncmp ("211", buf, 3))
6764 +  {
6765 +    LIST *l = serv->list;
6766 +
6767 +    /* GROUP command failed */
6768 +    if (!mutt_strncmp ("411", buf, 3))
6769 +    {
6770 +      mutt_error (_("Newsgroup %s not found on server %s"),
6771 +                   nntp_data->group, serv->conn->account.host);
6772 +
6773 +      /* CACHE: delete cache and line from .index */
6774 +      nntp_delete_cache (nntp_data);
6775 +      hash_delete (serv->newsgroups, nntp_data->group, NULL, nntp_delete_data);
6776 +      while (l && l->data != (void *) nntp_data) l = l->next;
6777 +      if (l)
6778 +       l->data = NULL;
6779 +
6780 +      sleep (2);
6781 +    }
6782 +
6783 +    return -1;
6784 +  }
6785 +
6786 +  sscanf (buf + 4, "%d %u %u %s", &count, &nntp_data->firstMessage, 
6787 +         &nntp_data->lastMessage, buf);
6788 +
6789 +  nntp_data->deleted = 0;
6790 +
6791 +  time (&serv->check_time);
6792 +
6793 +  /*
6794 +   * Check for max adding context. If it is greater than $nntp_context,
6795 +   * strip off extra articles
6796 +   */
6797 +  first = nntp_data->firstMessage;
6798 +  if (NntpContext && nntp_data->lastMessage - first + 1 > NntpContext)
6799 +    first = nntp_data->lastMessage - NntpContext + 1;
6800 +  if (first)
6801 +    nntp_data->lastLoaded = first - 1;
6802 +  return nntp_fetch_headers (ctx, first, nntp_data->lastMessage);
6803 +}
6804 +
6805 +int nntp_fetch_message (MESSAGE *msg, CONTEXT *ctx, int msgno)
6806 +{
6807 +  char buf[LONG_STRING];
6808 +  char path[_POSIX_PATH_MAX];
6809 +  NNTP_CACHE *cache;
6810 +  char *m = _("Fetching message...");
6811 +  int ret;
6812 +
6813 +  /* see if we already have the message in our cache */
6814 +  cache = &((NNTP_DATA *) ctx->data)->acache[ctx->hdrs[msgno]->index % NNTP_CACHE_LEN];
6815 +
6816 +  /* if everything is fine, assign msg->fp and return */
6817 +  if (cache->path && cache->index == ctx->hdrs[msgno]->index &&
6818 +      (msg->fp = fopen (cache->path, "r")))
6819 +    return 0;
6820 +
6821 +  /* clear the previous entry */
6822 +  unlink (cache->path);
6823 +  free (cache->path);
6824 +
6825 +  mutt_message (m);
6826 +
6827 +  cache->index = ctx->hdrs[msgno]->index;
6828 +  mutt_mktemp (path);
6829 +  cache->path = safe_strdup (path);
6830 +  if (!(msg->fp = safe_fopen (path, "w+")))
6831 +  {
6832 +    FREE (&cache->path);
6833 +    return -1;
6834 +  }
6835 +
6836 +  if (ctx->hdrs[msgno]->article_num == 0)
6837 +    snprintf (buf, sizeof (buf), "ARTICLE %s\r\n",
6838 +         ctx->hdrs[msgno]->env->message_id);
6839 +  else
6840 +    snprintf (buf, sizeof (buf), "ARTICLE %d\r\n",
6841 +         ctx->hdrs[msgno]->article_num);
6842 +
6843 +  ret = mutt_nntp_fetch ((NNTP_DATA *)ctx->data, buf, m, nntp_read_tempfile,
6844 +       msg->fp, ctx->tagged);
6845 +  if (ret == 1)
6846 +  {
6847 +    mutt_error (_("Article %d not found on server"), 
6848 +         ctx->hdrs[msgno]->article_num);
6849 +    dprint (1, (debugfile, "nntp_fetch_message: %s\n", buf));
6850 +  }
6851 +
6852 +  if (ret)
6853 +  {
6854 +    fclose (msg->fp);
6855 +    unlink (path);
6856 +    FREE (&cache->path);
6857 +    return -1;
6858 +  }
6859 +
6860 +  mutt_free_envelope (&ctx->hdrs[msgno]->env);
6861 +  ctx->hdrs[msgno]->env = mutt_read_rfc822_header (msg->fp, ctx->hdrs[msgno], 0, 0);
6862 +  /* fix content length */
6863 +  fseek(msg->fp, 0, SEEK_END);
6864 +  ctx->hdrs[msgno]->content->length = ftell (msg->fp) - 
6865 +                                        ctx->hdrs[msgno]->content->offset;
6866 +
6867 +  /* this is called in mutt before the open which fetches the message, 
6868 +   * which is probably wrong, but we just call it again here to handle
6869 +   * the problem instead of fixing it.
6870 +   */
6871 +  mutt_parse_mime_message (ctx, ctx->hdrs[msgno]);
6872 +
6873 +  /* These would normally be updated in mx_update_context(), but the 
6874 +   * full headers aren't parsed with XOVER, so the information wasn't
6875 +   * available then.
6876 +   */
6877 +#ifdef HAVE_PGP
6878 +  ctx->hdrs[msgno]->pgp = pgp_query (ctx->hdrs[msgno]->content);
6879 +#endif /* HAVE_PGP */
6880 +
6881 +  mutt_clear_error();
6882 +  rewind (msg->fp);
6883 +
6884 +  return 0;
6885 +}
6886 +
6887 +/* Post article */
6888 +int nntp_post (const char *msg) {
6889 +  char buf[LONG_STRING];
6890 +  size_t len;
6891 +  FILE *f;
6892 +  NNTP_DATA *nntp_data;
6893 +
6894 +  if (Context && Context->magic == M_NNTP)
6895 +    nntp_data = (NNTP_DATA *)Context->data;
6896 +  else
6897 +  {
6898 +    if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)) ||
6899 +       !CurrentNewsSrv->list || !CurrentNewsSrv->list->data)
6900 +    {
6901 +      mutt_error (_("Can't post article. No connection to news server."));
6902 +      return -1;
6903 +    }
6904 +    nntp_data = (NNTP_DATA *)CurrentNewsSrv->list->data;
6905 +  }
6906 +
6907 +  if (!(f = safe_fopen (msg, "r")))
6908 +  {
6909 +    mutt_error (_("Can't post article. Unable to open %s"), msg);
6910 +    return -1;
6911 +  }
6912 +
6913 +  strfcpy (buf, "POST\r\n", sizeof (buf));
6914 +  if (mutt_nntp_query (nntp_data, buf, sizeof (buf)) < 0)
6915 +  {
6916 +    mutt_error (_("Can't post article. Connection to %s lost."),
6917 +               nntp_data->nserv->conn->account.host);
6918 +    return -1;
6919 +  }
6920 +  if (buf[0] != '3')
6921 +  {
6922 +    mutt_error (_("Can't post article: %s"), buf);
6923 +    return -1;
6924 +  }
6925 +
6926 +  buf[0] = '.';
6927 +  buf[1] = '\0';
6928 +  while (fgets (buf + 1, sizeof (buf) - 2, f) != NULL)
6929 +  {
6930 +    len = strlen (buf);
6931 +    if (buf[len - 1] == '\n')
6932 +    {
6933 +      buf[len - 1] = '\r';
6934 +      buf[len] = '\n';
6935 +      len++;
6936 +      buf[len] = '\0';
6937 +    }
6938 +    if (buf[1] == '.')
6939 +      mutt_socket_write_d (nntp_data->nserv->conn, buf, M_SOCK_LOG_HDR);
6940 +    else
6941 +      mutt_socket_write_d (nntp_data->nserv->conn, buf + 1, M_SOCK_LOG_HDR);
6942 +  }
6943 +  fclose (f);
6944 +
6945 +  if (buf[strlen (buf) - 1] != '\n')
6946 +    mutt_socket_write_d (nntp_data->nserv->conn, "\r\n", M_SOCK_LOG_HDR);
6947 +  mutt_socket_write_d (nntp_data->nserv->conn, ".\r\n", M_SOCK_LOG_HDR);
6948 +  if (mutt_socket_readln (buf, sizeof (buf), nntp_data->nserv->conn) < 0)
6949 +  {
6950 +    mutt_error (_("Can't post article. Connection to %s lost."),
6951 +               nntp_data->nserv->conn->account.host);
6952 +    return -1;
6953 +  }
6954 +  if (buf[0] != '2')
6955 +  {
6956 +    mutt_error (_("Can't post article: %s"), buf);
6957 +    return -1;
6958 +  }
6959 +
6960 +  return 0;
6961 +}
6962 +
6963 +/* nntp_logout_all: close all open connections. */
6964 +void nntp_logout_all (void)
6965 +{
6966 +  char buf[LONG_STRING];
6967 +  CONNECTION* conn;
6968 +  CONNECTION* tmp;
6969 +
6970 +  conn = mutt_socket_head ();
6971 +
6972 +  while (conn)
6973 +  {
6974 +    tmp = conn;
6975 +
6976 +    if (conn->account.type == M_ACCT_TYPE_NNTP)
6977 +    {
6978 +      mutt_message (_("Closing connection to %s..."), conn->account.host);
6979 +      mutt_socket_write (conn, "QUIT\r\n");
6980 +      mutt_socket_readln (buf, sizeof (buf), conn);
6981 +      mutt_clear_error ();
6982 +      mutt_socket_close (conn);
6983 +
6984 +      mutt_socket_free (tmp);
6985 +    }
6986 +
6987 +    conn = conn->next;
6988 +  }
6989 +}
6990 +
6991 +static void nntp_free_acache (NNTP_DATA *data)
6992 +{
6993 +  int i;
6994 +
6995 +  for (i = 0; i < NNTP_CACHE_LEN; i++)
6996 +  {
6997 +    if (data->acache[i].path)
6998 +    {
6999 +      unlink (data->acache[i].path);
7000 +      FREE (&data->acache[i].path);
7001 +    }
7002 +  }
7003 +}
7004 +
7005 +void nntp_delete_data (void *p)
7006 +{
7007 +  NNTP_DATA *data = (NNTP_DATA *)p;
7008 +
7009 +  if (!p)
7010 +    return;
7011 +  FREE (&data->entries);
7012 +  FREE (&data->desc);
7013 +  FREE (&data->cache);
7014 +  nntp_free_acache (data);
7015 +  FREE (p);
7016 +}
7017 +
7018 +int nntp_sync_mailbox (CONTEXT *ctx)
7019 +{
7020 +  NNTP_DATA *data = ctx->data;
7021 +
7022 +  /* CACHE: update cache and .index files */
7023 +  if ((option (OPTSAVEUNSUB) || data->subscribed))
7024 +    nntp_save_cache_group (ctx);
7025 +  nntp_free_acache (data);
7026 +
7027 +  data->nserv->check_time = 0; /* next nntp_check_mailbox() will really check */
7028 +  return 0;
7029 +}
7030 +
7031 +void nntp_fastclose_mailbox (CONTEXT *ctx)
7032 +{
7033 +  NNTP_DATA *data = (NNTP_DATA *) ctx->data, *tmp;
7034 +
7035 +  if (!data)
7036 +    return;
7037 +  nntp_free_acache (data);
7038 +  if (!data->nserv || !data->nserv->newsgroups || !data->group)
7039 +    return;
7040 +  nntp_save_cache_index (data->nserv);
7041 +  if ((tmp = hash_find (data->nserv->newsgroups, data->group)) == NULL
7042 +       || tmp != data)
7043 +    nntp_delete_data (data);
7044 +}
7045 +
7046 +/* commit changes and terminate connection */
7047 +int nntp_close_mailbox (CONTEXT *ctx)
7048 +{
7049 +  if (!ctx)
7050 +    return -1;
7051 +  mutt_message _("Quitting newsgroup...");
7052 +  if (ctx->data)
7053 +  {
7054 +    NNTP_DATA *data = (NNTP_DATA *) ctx->data;
7055 +    int ret;
7056 +
7057 +    if (data->nserv && data->nserv->conn && ctx->unread)
7058 +    {
7059 +      ret = query_quadoption (OPT_CATCHUP, _("Mark all articles read?"));
7060 +      if (ret == M_YES)
7061 +       mutt_newsgroup_catchup (data->nserv, data->group);
7062 +      else if (ret < 0)
7063 +       return -1;
7064 +    }
7065 +  }
7066 +  nntp_sync_mailbox (ctx);
7067 +  if (ctx->data && ((NNTP_DATA *)ctx->data)->nserv)
7068 +  {
7069 +    NNTP_SERVER *news;
7070 +
7071 +    news = ((NNTP_DATA *)ctx->data)->nserv;
7072 +    newsrc_gen_entries (ctx);
7073 +    ((NNTP_DATA *)ctx->data)->unread = ctx->unread;
7074 +    mutt_newsrc_update (news);
7075 +  }
7076 +  mutt_clear_error();
7077 +  return 0;
7078 +}
7079 +
7080 +/* use the GROUP command to poll for new mail */
7081 +static int _nntp_check_mailbox (CONTEXT *ctx, NNTP_DATA *nntp_data)
7082 +{
7083 +  char buf[LONG_STRING];
7084 +  int count = 0;
7085 +
7086 +  if (nntp_data->nserv->check_time + NewsPollTimeout > time (NULL))
7087 +    return 0;
7088 +
7089 +  buf[0] = 0;
7090 +  if (mutt_nntp_query (nntp_data, buf, sizeof (buf)) < 0)
7091 +  {
7092 +#ifdef DEBUG
7093 +    nntp_error ("nntp_check_mailbox()", buf);
7094 +#endif
7095 +    return -1;
7096 +  }
7097 +  if (mutt_strncmp ("211", buf, 3))
7098 +  {
7099 +    buf[0] = 0;
7100 +    if (mutt_nntp_query (nntp_data, buf, sizeof (buf)) < 0)
7101 +    {
7102 +#ifdef DEBUG
7103 +      nntp_error ("nntp_check_mailbox()", buf);
7104 +#endif
7105 +      return -1;
7106 +    }
7107 +  }
7108 +  if (!mutt_strncmp ("211", buf, 3))
7109 +  {
7110 +    int first;
7111 +    int last;
7112 +
7113 +    sscanf (buf + 4, "%d %d %d", &count, &first, &last);
7114 +    nntp_data->firstMessage = first;
7115 +    nntp_data->lastMessage = last;
7116 +    if (ctx && last > nntp_data->lastLoaded)
7117 +    {
7118 +      nntp_fetch_headers (ctx, nntp_data->lastLoaded + 1, last);
7119 +      time (&nntp_data->nserv->check_time);
7120 +      return 1;
7121 +    }
7122 +    if (!last || (!nntp_data->rc && !nntp_data->lastCached))
7123 +      nntp_data->unread = count;
7124 +    else
7125 +      mutt_newsgroup_stat (nntp_data);
7126 +    /* active was renumbered? */
7127 +    if (last < nntp_data->lastLoaded)
7128 +    {
7129 +      if (!nntp_data->max)
7130 +      {
7131 +       nntp_data->entries = safe_calloc (5, sizeof (NEWSRC_ENTRY));
7132 +       nntp_data->max = 5;
7133 +      }
7134 +      nntp_data->lastCached = 0;
7135 +      nntp_data->num = 1;
7136 +      nntp_data->entries[0].first = 1;
7137 +      nntp_data->entries[0].last = 0;
7138 +    }
7139 +  }
7140 +
7141 +  time (&nntp_data->nserv->check_time);
7142 +  return 0;
7143 +}
7144 +
7145 +int nntp_check_mailbox (CONTEXT *ctx)
7146 +{
7147 +  return _nntp_check_mailbox (ctx, (NNTP_DATA *)ctx->data);
7148 +}
7149 +
7150 +static int add_group (char *buf, void *serv)
7151 +{
7152 +#define s ((NNTP_SERVER *) serv)
7153 +  char group[LONG_STRING], mod, desc[HUGE_STRING];
7154 +  int first, last;
7155 +  NNTP_DATA *nntp_data;
7156 +  static int n = 0;
7157 +
7158 +  _checked = n;        /* _checked have N, where N = number of groups */
7159 +  if (!buf)    /* at EOF must be zerouth */
7160 +    n = 0;
7161 +
7162 +  if (!s || !buf)
7163 +    return 0;
7164 +
7165 +  *desc = 0;
7166 +  sscanf (buf, "%s %d %d %c %[^\n]", group, &last, &first, &mod, desc);
7167 +  if (!group)
7168 +    return 0;
7169 +  if ((nntp_data = (NNTP_DATA *) hash_find (s->newsgroups, group)) == NULL)
7170 +  {
7171 +    n++;
7172 +    nntp_data = safe_calloc (1, sizeof (NNTP_DATA) + strlen (group) + 1);
7173 +    nntp_data->group = (char *) nntp_data + sizeof (NNTP_DATA);
7174 +    strcpy (nntp_data->group, group);
7175 +    nntp_data->nserv = s;
7176 +    if (s->newsgroups->nelem < s->newsgroups->curnelem * 2)
7177 +      s->newsgroups = hash_resize (s->newsgroups, s->newsgroups->nelem * 2);
7178 +    hash_insert (s->newsgroups, nntp_data->group, nntp_data, 0);
7179 +    nntp_add_to_list (s, nntp_data);
7180 +  }
7181 +  nntp_data->deleted = 0;
7182 +  nntp_data->firstMessage = first;
7183 +  nntp_data->lastMessage = last;
7184 +  if (mod == 'y')
7185 +    nntp_data->allowed = 1;
7186 +  else
7187 +    nntp_data->allowed = 0;
7188 +  if (nntp_data->desc)
7189 +    FREE (&nntp_data->desc);
7190 +  if (*desc)
7191 +    nntp_data->desc = safe_strdup (desc);
7192 +  if (nntp_data->rc || nntp_data->lastCached)
7193 +    mutt_newsgroup_stat (nntp_data);
7194 +  else if (nntp_data->lastMessage &&
7195 +       nntp_data->firstMessage <= nntp_data->lastMessage)
7196 +    nntp_data->unread = nntp_data->lastMessage - nntp_data->firstMessage + 1;
7197 +  else
7198 +    nntp_data->unread = 0;
7199 +
7200 +  return 0;
7201 +#undef s
7202 +}
7203 +
7204 +int nntp_check_newgroups (NNTP_SERVER *serv, int force)
7205 +{
7206 +  char buf[LONG_STRING];
7207 +  NNTP_DATA nntp_data;
7208 +  LIST *l;
7209 +  LIST emp;
7210 +  time_t now;
7211 +  struct tm *t;
7212 +
7213 +  if (!serv || !serv->newgroups_time)
7214 +    return -1;
7215 +
7216 +  if (nntp_open_connection (serv) < 0)
7217 +    return -1;
7218 +
7219 +  /* check subscribed groups for new news */
7220 +  if (option (OPTSHOWNEWNEWS))
7221 +  {
7222 +    mutt_message _("Checking for new messages...");
7223 +    for (l = serv->list; l; l = l->next)
7224 +    {
7225 +      serv->check_time = 0;    /* really check! */
7226 +      if (l->data && ((NNTP_DATA *) l->data)->subscribed)
7227 +       _nntp_check_mailbox (NULL, (NNTP_DATA *) l->data);
7228 +    }
7229 +  }
7230 +  else if (!force)
7231 +    return 0;
7232 +
7233 +  mutt_message _("Checking for new newsgroups...");
7234 +  now = serv->newgroups_time;
7235 +  time (&serv->newgroups_time);
7236 +  t = gmtime (&now);
7237 +  snprintf (buf, sizeof (buf), "NEWGROUPS %02d%02d%02d %02d%02d%02d GMT\r\n",
7238 +       (t->tm_year % 100), t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min,
7239 +       t->tm_sec);
7240 +  nntp_data.nserv = serv;
7241 +  if (Context && Context->magic == M_NNTP)
7242 +    nntp_data.group = ((NNTP_DATA *)Context->data)->group;
7243 +  else
7244 +    nntp_data.group = NULL;
7245 +  l = serv->tail;
7246 +  if (mutt_nntp_fetch (&nntp_data, buf, _("Adding new newsgroups..."),
7247 +       add_group, serv, 0) != 0)
7248 +  {
7249 +#ifdef DEBUG
7250 +    nntp_error ("nntp_check_newgroups()", buf);
7251 +#endif
7252 +    return -1;
7253 +  }
7254 +
7255 +  mutt_message _("Loading descriptions...");
7256 +  if (l)
7257 +    emp.next = l->next;
7258 +  else
7259 +    emp.next = serv->list;
7260 +  l = &emp;
7261 +  while (l->next)
7262 +  {
7263 +    l = l->next;
7264 +    ((NNTP_DATA *) l->data)->new = 1;
7265 +    nntp_get_desc ((NNTP_DATA *) l->data, ((NNTP_DATA *) l->data)->group, NULL);
7266 +  }
7267 +  if (emp.next)
7268 +    nntp_save_cache_index (serv);
7269 +  mutt_clear_error ();
7270 +  return _checked;
7271 +}
7272 +
7273 +/* Load list of all newsgroups from cache ALL */
7274 +int nntp_get_cache_all (NNTP_SERVER *serv)
7275 +{
7276 +  char buf[HUGE_STRING];
7277 +  FILE *f;
7278 +
7279 +  nntp_cache_expand (buf, serv->cache);
7280 +  if ((f = safe_fopen (buf, "r")))
7281 +  {
7282 +    int i = 0;
7283 +
7284 +    while (fgets (buf, sizeof(buf), f) != NULL)
7285 +    {
7286 +      if (ReadInc && (i % ReadInc == 0))
7287 +       mutt_message (_("Loading list from cache... %d"), i);
7288 +      add_group (buf, serv);
7289 +      i++;
7290 +    }
7291 +    add_group (NULL, NULL);
7292 +    fclose (f);
7293 +    mutt_clear_error ();
7294 +    return 0;
7295 +  }
7296 +  else
7297 +  {
7298 +    FREE (&serv->cache);
7299 +    return -1;
7300 +  }
7301 +}
7302 +
7303 +/* Load list of all newsgroups from active */
7304 +int nntp_get_active (NNTP_SERVER *serv)
7305 +{
7306 +  char msg[SHORT_STRING];
7307 +  NNTP_DATA nntp_data;
7308 +  LIST *tmp;
7309 +
7310 +  if (nntp_open_connection (serv) < 0)
7311 +    return -1;
7312 +
7313 +  snprintf (msg, sizeof(msg), _("Loading list of all newsgroups on server %s..."),
7314 +               serv->conn->account.host);
7315 +  mutt_message (msg);
7316 +  time (&serv->newgroups_time);
7317 +  nntp_data.nserv = serv;
7318 +  nntp_data.group = NULL;
7319 +
7320 +  if (mutt_nntp_fetch (&nntp_data, "LIST\r\n", msg, add_group, serv, 0) < 0)
7321 +  {
7322 +#ifdef DEBUG
7323 +    nntp_error ("nntp_get_active()", "LIST\r\n");
7324 +#endif
7325 +    return -1;
7326 +  }
7327 +
7328 +  strfcpy (msg, _("Loading descriptions..."), sizeof (msg));
7329 +  mutt_message (msg);
7330 +  nntp_get_desc (&nntp_data, "*", msg);
7331 +
7332 +  for (tmp = serv->list; tmp; tmp = tmp->next)
7333 +  {
7334 +    NNTP_DATA *data = (NNTP_DATA *)tmp->data;
7335 +
7336 +    if (data && data->deleted && !data->rc)
7337 +    {
7338 +      nntp_delete_cache (data);
7339 +      hash_delete (serv->newsgroups, data->group, NULL, nntp_delete_data);
7340 +      tmp->data = NULL;
7341 +    }
7342 +  }
7343 +  nntp_save_cache_index (serv);
7344 +
7345 +  mutt_clear_error ();
7346 +  return _checked;
7347 +}
7348 +
7349 +/*
7350 + * returns -1 if error ocurred while retrieving header,
7351 + * number of articles which ones exist in context on success.
7352 + */
7353 +int nntp_check_msgid (CONTEXT *ctx, const char *msgid)
7354 +{
7355 +  int ret;
7356 +
7357 +  /* if msgid is already in context, don't reload them */
7358 +  if (hash_find (ctx->id_hash, msgid))
7359 +    return 1;
7360 +  if (ctx->msgcount == ctx->hdrmax)
7361 +    mx_alloc_memory (ctx);
7362 +  ctx->hdrs[ctx->msgcount] = mutt_new_header ();
7363 +  ctx->hdrs[ctx->msgcount]->index = ctx->msgcount;
7364 +  
7365 +  mutt_message (_("Fetching %s from server..."), msgid);
7366 +  ret = nntp_read_header (ctx, msgid, 0);
7367 +  /* since nntp_read_header() may set read flag, we must reset it */
7368 +  ctx->hdrs[ctx->msgcount]->read = 0;
7369 +  if (ret != 0)
7370 +    mutt_free_header (&ctx->hdrs[ctx->msgcount]);
7371 +  else
7372 +  {
7373 +    ctx->msgcount++;
7374 +    mx_update_context (ctx, 1);
7375 +    ctx->changed = 1;
7376 +  }
7377 +  return ret;
7378 +}
7379 +
7380 +typedef struct
7381 +{
7382 +  CONTEXT *ctx;
7383 +  unsigned int num;
7384 +  unsigned int max;
7385 +  unsigned int *child;
7386 +} CHILD_CONTEXT;
7387 +
7388 +static int check_children (char *s, void *c)
7389 +{
7390 +#define cc ((CHILD_CONTEXT *) c)
7391 +  unsigned int i, n;
7392 +
7393 +  if (!s || (n = atoi (s)) == 0)
7394 +    return 0;
7395 +  for (i = 0; i < cc->ctx->msgcount; i++)
7396 +    if (cc->ctx->hdrs[i]->article_num == n)
7397 +      return 0;
7398 +  if (cc->num >= cc->max)
7399 +    safe_realloc ((void **) &cc->child, sizeof (unsigned int) * (cc->max += 25));
7400 +  cc->child[cc->num++] = n;
7401 +
7402 +  return 0;
7403 +#undef cc
7404 +}
7405 +
7406 +int nntp_check_children (CONTEXT *ctx, const char *msgid)
7407 +{
7408 +  NNTP_DATA *nntp_data = (NNTP_DATA *)ctx->data;
7409 +  char buf[STRING];
7410 +  int i, ret = 0, tmp = 0;
7411 +  CHILD_CONTEXT cc;
7412 +
7413 +  if (!nntp_data || !nntp_data->nserv || !nntp_data->nserv->conn ||
7414 +       !nntp_data->nserv->conn->account.host)
7415 +    return -1;
7416 +  if (nntp_data->firstMessage > nntp_data->lastLoaded)
7417 +    return 0;
7418 +  if (!nntp_data->nserv->hasXPAT)
7419 +  {
7420 +    mutt_error (_("Server %s does not support this operation!"),
7421 +         nntp_data->nserv->conn->account.host);
7422 +    return -1;
7423 +  }
7424 +
7425 +  snprintf (buf, sizeof (buf), "XPAT References %d-%d *%s*\r\n", 
7426 +       nntp_data->firstMessage, nntp_data->lastLoaded, msgid);
7427 +
7428 +  cc.ctx = ctx;
7429 +  cc.num = 0;
7430 +  cc.max = 25;
7431 +  cc.child = safe_malloc (sizeof (unsigned int) * 25);
7432 +  if (mutt_nntp_fetch (nntp_data, buf, NULL, check_children, &cc, 0))
7433 +  {
7434 +    safe_free ((void **) &cc.child);
7435 +    return -1;
7436 +  }
7437 +  /* dont try to read the xover cache. check_children() already
7438 +   * made sure that we dont have the article, so we need to visit
7439 +   * the server. Reading the cache at this point is also bad
7440 +   * because it would duplicate messages */
7441 +  if (option (OPTNEWSCACHE))
7442 +  {
7443 +    tmp++;
7444 +    unset_option (OPTNEWSCACHE);
7445 +  }
7446 +  for (i = 0; i < cc.num; i++)
7447 +  {
7448 +    if ((ret = nntp_fetch_headers (ctx, cc.child[i], cc.child[i])))
7449 +      break;
7450 +    if (ctx->msgcount &&
7451 +         ctx->hdrs[ctx->msgcount - 1]->article_num == cc.child[i])
7452 +      ctx->hdrs[ctx->msgcount - 1]->read = 0;
7453 +  }
7454 +  if (tmp)
7455 +    set_option (OPTNEWSCACHE);
7456 +  safe_free ((void **) &cc.child);
7457 +  return ret;
7458 +}
7459 diff -uNr mutt-1.4.orig/nntp.h mutt-1.4/nntp.h
7460 --- mutt-1.4.orig/nntp.h        Thu Jan  1 01:00:00 1970
7461 +++ mutt-1.4/nntp.h     Sun Nov  3 21:57:20 2002
7462 @@ -0,0 +1,135 @@
7463 +/*
7464 + * Copyright (C) 1998 Brandon Long <blong@fiction.net>
7465 + * Copyright (C) 1999 Andrej Gritsenko <andrej@lucky.net>
7466 + * Copyright (C) 2000-2002 Vsevolod Volkov <vvv@mutt.org.ua>
7467 + * 
7468 + *     This program is free software; you can redistribute it and/or modify
7469 + *     it under the terms of the GNU General Public License as published by
7470 + *     the Free Software Foundation; either version 2 of the License, or
7471 + *     (at your option) any later version.
7472 + * 
7473 + *     This program is distributed in the hope that it will be useful,
7474 + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
7475 + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7476 + *     GNU General Public License for more details.
7477 + * 
7478 + *     You should have received a copy of the GNU General Public License
7479 + *     along with this program; if not, write to the Free Software
7480 + *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7481 + */ 
7482 +
7483 +#ifndef _NNTP_H_
7484 +#define _NNTP_H_ 1
7485 +
7486 +#include "mutt_socket.h"
7487 +#include "mailbox.h"
7488 +
7489 +#include <time.h>
7490 +
7491 +#define NNTP_PORT 119
7492 +#define NNTP_SSL_PORT 563
7493 +
7494 +/* number of entries in the hash table */
7495 +#define NNTP_CACHE_LEN 10
7496 +
7497 +enum
7498 +{
7499 +  NNTP_NONE = 0,
7500 +  NNTP_OK,
7501 +  NNTP_BYE
7502 +};
7503 +
7504 +typedef struct
7505 +{
7506 +  int first;
7507 +  int last;
7508 +} NEWSRC_ENTRY;
7509 +
7510 +typedef struct
7511 +{
7512 +  unsigned int hasXPAT : 1;
7513 +  unsigned int hasXGTITLE : 1;
7514 +  unsigned int hasXOVER : 1;
7515 +  unsigned int status : 3;
7516 +  char *newsrc;
7517 +  char *cache;
7518 +  int stat;
7519 +  off_t size;
7520 +  time_t mtime;
7521 +  time_t newgroups_time;
7522 +  time_t check_time;
7523 +  HASH *newsgroups;
7524 +  LIST *list;  /* list of newsgroups */
7525 +  LIST *tail;  /* last entry of list */
7526 +  CONNECTION *conn;
7527 +} NNTP_SERVER;
7528 +
7529 +typedef struct
7530 +{
7531 +  unsigned int index;
7532 +  char *path;
7533 +} NNTP_CACHE;
7534 +
7535 +typedef struct
7536 +{
7537 +  NEWSRC_ENTRY *entries;
7538 +  unsigned int num;    /* number of used entries */
7539 +  unsigned int max;    /* number of allocated entries */
7540 +  unsigned int unread;
7541 +  unsigned int firstMessage;
7542 +  unsigned int lastMessage;
7543 +  unsigned int lastLoaded;
7544 +  unsigned int lastCached;
7545 +  unsigned int subscribed : 1;
7546 +  unsigned int rc : 1;
7547 +  unsigned int new : 1;
7548 +  unsigned int allowed : 1;
7549 +  unsigned int deleted : 1;
7550 +  char *group;
7551 +  char *desc;
7552 +  char *cache;
7553 +  NNTP_SERVER *nserv;
7554 +  NNTP_CACHE acache[NNTP_CACHE_LEN];
7555 +} NNTP_DATA;
7556 +
7557 +/* internal functions */
7558 +int nntp_get_active (NNTP_SERVER *);
7559 +int nntp_get_cache_all (NNTP_SERVER *);
7560 +int nntp_save_cache_index (NNTP_SERVER *);
7561 +int nntp_check_newgroups (NNTP_SERVER *, int);
7562 +int nntp_save_cache_group (CONTEXT *);
7563 +int nntp_parse_url (const char *, ACCOUNT *, char *, size_t);
7564 +void newsrc_gen_entries (CONTEXT *);
7565 +void nntp_get_status (CONTEXT *, HEADER *, char *, int);
7566 +void mutt_newsgroup_stat (NNTP_DATA *);
7567 +void nntp_delete_cache (NNTP_DATA *);
7568 +void nntp_add_to_list (NNTP_SERVER *, NNTP_DATA *);
7569 +void nntp_cache_expand (char *, const char *);
7570 +void nntp_delete_data (void *);
7571 +
7572 +/* exposed interface */
7573 +NNTP_SERVER *mutt_select_newsserver (char *);
7574 +NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER *, char *);
7575 +NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER *, char *);
7576 +NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER *, char *);
7577 +NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER *, char *);
7578 +void nntp_clear_cacheindex (NNTP_SERVER *);
7579 +int mutt_newsrc_update (NNTP_SERVER *);
7580 +int nntp_open_mailbox (CONTEXT *);
7581 +int nntp_sync_mailbox (CONTEXT *);
7582 +int nntp_check_mailbox (CONTEXT *);
7583 +int nntp_close_mailbox (CONTEXT *);
7584 +void nntp_fastclose_mailbox (CONTEXT *);
7585 +int nntp_fetch_message (MESSAGE *, CONTEXT *, int);
7586 +int nntp_post (const char *);
7587 +int nntp_check_msgid (CONTEXT *, const char *);
7588 +int nntp_check_children (CONTEXT *, const char *);
7589 +void nntp_buffy (char *);
7590 +void nntp_expand_path (char *, size_t, ACCOUNT *);
7591 +void nntp_logout_all ();
7592 +const char *nntp_format_str (char *, size_t, char, const char *, const char *,
7593 +               const char *, const char *, unsigned long, format_flag);
7594 +
7595 +NNTP_SERVER *CurrentNewsSrv INITVAL (NULL);
7596 +
7597 +#endif /* _NNTP_H_ */
7598 diff -uNr mutt-1.4.orig/pager.c mutt-1.4/pager.c
7599 --- mutt-1.4.orig/pager.c       Sun Nov  3 21:42:52 2002
7600 +++ mutt-1.4/pager.c    Sun Nov  3 21:57:20 2002
7601 @@ -33,6 +33,11 @@
7602  #include "imap.h"
7603  #endif
7604  
7605 +#ifdef USE_NNTP
7606 +#include "mx.h"
7607 +#include "nntp.h"
7608 +#endif
7609 +
7610  
7611  #ifdef HAVE_PGP
7612  #include "pgp.h"
7613 @@ -1445,6 +1450,16 @@
7614    { NULL,      0 }
7615  };
7616  
7617 +#ifdef USE_NNTP
7618 +static struct mapping_t PagerNewsHelpExtra[] = {
7619 +  { N_("Post"),     OP_POST },
7620 +  { N_("Followup"), OP_FOLLOWUP },
7621 +  { N_("Del"),      OP_DELETE },
7622 +  { N_("Next"),     OP_MAIN_NEXT_UNDELETED },
7623 +  { NULL,           0 }
7624 +};
7625 +#endif
7626 +
7627  
7628  
7629  /* This pager is actually not so simple as it once was.  It now operates in
7630 @@ -1486,6 +1501,10 @@
7631    int old_PagerIndexLines;             /* some people want to resize it
7632                                          * while inside the pager... */
7633  
7634 +#ifdef USE_NNTP
7635 +  char *followup_to;
7636 +#endif
7637 +
7638    if (!(flags & M_SHOWCOLOR))
7639      flags |= M_SHOWFLAT;
7640  
7641 @@ -1525,7 +1544,11 @@
7642    if (IsHeader (extra))
7643    {
7644      strfcpy (tmphelp, helpstr, sizeof (tmphelp));
7645 -    mutt_compile_help (buffer, sizeof (buffer), MENU_PAGER, PagerHelpExtra);
7646 +    mutt_compile_help (buffer, sizeof (buffer), MENU_PAGER,
7647 +#ifdef USE_NNTP
7648 +       (Context && (Context->magic == M_NNTP)) ? PagerNewsHelpExtra :
7649 +#endif
7650 +       PagerHelpExtra);
7651      snprintf (helpstr, sizeof (helpstr), "%s %s", tmphelp, buffer);
7652    }
7653    if (!InHelp)
7654 @@ -2300,6 +2323,15 @@
7655         }
7656  #endif
7657  
7658 +#ifdef USE_NNTP
7659 +       if (Context->magic == M_NNTP)
7660 +       {
7661 +         mutt_flushinp ();
7662 +         mutt_error _("Can't change 'important' flag on NNTP server.");
7663 +         break;
7664 +       }
7665 +#endif
7666 +
7667         mutt_set_flag (Context, extra->hdr, M_FLAG, !extra->hdr->flagged);
7668         redraw = REDRAW_STATUS | REDRAW_INDEX;
7669         if (option (OPTRESOLVE))
7670 @@ -2333,6 +2365,60 @@
7671         redraw = REDRAW_FULL;
7672         break;
7673  
7674 +#ifdef USE_NNTP
7675 +      case OP_POST:
7676 +       CHECK_MODE(IsHeader (extra) && !IsAttach (extra));
7677 +       CHECK_ATTACH;
7678 +       if (extra->ctx && extra->ctx->magic == M_NNTP &&
7679 +           !((NNTP_DATA *)extra->ctx->data)->allowed &&
7680 +           query_quadoption (OPT_TOMODERATED,_("Posting to this group not allowed, may be moderated. Continue?")) != M_YES)
7681 +         break;
7682 +       ci_send_message (SENDNEWS, NULL, NULL, extra->ctx, NULL);
7683 +       redraw = REDRAW_FULL;
7684 +       break;
7685 +
7686 +      case OP_FORWARD_TO_GROUP:
7687 +       CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
7688 +       CHECK_ATTACH;
7689 +       if (extra->ctx && extra->ctx->magic == M_NNTP &&
7690 +           !((NNTP_DATA *)extra->ctx->data)->allowed &&
7691 +           query_quadoption (OPT_TOMODERATED,_("Posting to this group not allowed, may be moderated. Continue?")) != M_YES)
7692 +         break;
7693 +       if (IsMsgAttach (extra))
7694 +         mutt_attach_forward (extra->fp, extra->hdr, extra->idx,
7695 +                              extra->idxlen, extra->bdy, SENDNEWS);
7696 +       else
7697 +         ci_send_message (SENDNEWS|SENDFORWARD, NULL, NULL, extra->ctx, extra->hdr);
7698 +       redraw = REDRAW_FULL;
7699 +       break;
7700 +
7701 +      case OP_FOLLOWUP:
7702 +       CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
7703 +       CHECK_ATTACH;
7704 +
7705 +        if (IsMsgAttach (extra))
7706 +         followup_to = extra->bdy->hdr->env->followup_to;
7707 +        else
7708 +         followup_to = extra->hdr->env->followup_to;
7709 +
7710 +       if (!followup_to || mutt_strcasecmp (followup_to, "poster") ||
7711 +           query_quadoption (OPT_FOLLOWUPTOPOSTER,_("Reply by mail as poster prefers?")) != M_YES)
7712 +       {
7713 +         if (extra->ctx && extra->ctx->magic == M_NNTP &&
7714 +             !((NNTP_DATA *)extra->ctx->data)->allowed &&
7715 +             query_quadoption (OPT_TOMODERATED,_("Posting to this group not allowed, may be moderated. Continue?")) != M_YES)
7716 +           break;
7717 +         if (IsMsgAttach (extra))
7718 +           mutt_attach_reply (extra->fp, extra->hdr, extra->idx,
7719 +                              extra->idxlen, extra->bdy, SENDNEWS|SENDREPLY);
7720 +         else
7721 +           ci_send_message (SENDNEWS|SENDREPLY, NULL, NULL,
7722 +                            extra->ctx, extra->hdr);
7723 +         redraw = REDRAW_FULL;
7724 +         break;
7725 +       }
7726 +#endif
7727 +
7728        case OP_REPLY:
7729         CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
7730          CHECK_ATTACH;      
7731 @@ -2379,7 +2465,7 @@
7732          CHECK_ATTACH;
7733          if (IsMsgAttach (extra))
7734           mutt_attach_forward (extra->fp, extra->hdr, extra->idx,
7735 -                              extra->idxlen, extra->bdy);
7736 +                              extra->idxlen, extra->bdy, 0);
7737          else
7738           ci_send_message (SENDFORWARD, NULL, NULL, extra->ctx, extra->hdr);
7739         redraw = REDRAW_FULL;
7740 diff -uNr mutt-1.4.orig/parse.c mutt-1.4/parse.c
7741 --- mutt-1.4.orig/parse.c       Tue Jan 29 11:05:20 2002
7742 +++ mutt-1.4/parse.c    Sun Nov  3 21:57:20 2002
7743 @@ -90,7 +90,7 @@
7744    /* not reached */
7745  }
7746  
7747 -static LIST *mutt_parse_references (char *s, int in_reply_to)
7748 +LIST *mutt_parse_references (char *s, int in_reply_to)
7749  {
7750    LIST *t, *lst = NULL;
7751    int m, n = 0;
7752 @@ -1047,6 +1047,17 @@
7753        e->from = rfc822_parse_adrlist (e->from, p);
7754        matched = 1;
7755      }
7756 +#ifdef USE_NNTP
7757 +    else if (!mutt_strcasecmp (line+1, "ollowup-to"))
7758 +    {
7759 +      if (!e->followup_to)
7760 +      {
7761 +       mutt_remove_trailing_ws (p);
7762 +       e->followup_to = safe_strdup (mutt_skip_whitespace (p));
7763 +      }
7764 +      matched = 1;
7765 +    }
7766 +#endif
7767      break;
7768      
7769      case 'i':
7770 @@ -1098,6 +1109,27 @@
7771      }
7772      break;
7773      
7774 +#ifdef USE_NNTP
7775 +    case 'n':
7776 +    if (!mutt_strcasecmp (line + 1, "ewsgroups"))
7777 +    {
7778 +      safe_free ((void **)&e->newsgroups);
7779 +      mutt_remove_trailing_ws (p);
7780 +      e->newsgroups = safe_strdup (mutt_skip_whitespace (p));
7781 +      matched = 1;
7782 +    }
7783 +    break;
7784 +#endif
7785 +
7786 +    case 'o':
7787 +    /* field `Organization:' saves only for pager! */
7788 +    if (!mutt_strcasecmp (line + 1, "rganization"))
7789 +    {
7790 +      if (!e->organization && mutt_strcasecmp (p, "unknown"))
7791 +       e->organization = safe_strdup (p);
7792 +    }
7793 +    break;
7794 +
7795      case 'r':
7796      if (!ascii_strcasecmp (line + 1, "eferences"))
7797      {
7798 @@ -1207,7 +1239,21 @@
7799        e->x_label = safe_strdup(p);
7800        matched = 1;
7801      }
7802 -    
7803 +#ifdef USE_NNTP
7804 +    else if (!mutt_strcasecmp (line + 1, "-comment-to"))
7805 +    {
7806 +      if (!e->x_comment_to)
7807 +       e->x_comment_to = safe_strdup (p);
7808 +      matched = 1;
7809 +    }
7810 +    else if (!mutt_strcasecmp (line + 1, "ref"))
7811 +    {
7812 +      if (!e->xref)
7813 +       e->xref = safe_strdup (p);
7814 +      matched = 1;
7815 +    }
7816 +#endif
7817 +
7818      default:
7819      break;
7820    }
7821 diff -uNr mutt-1.4.orig/pattern.c mutt-1.4/pattern.c
7822 --- mutt-1.4.orig/pattern.c     Sun Nov  3 21:42:52 2002
7823 +++ mutt-1.4/pattern.c  Sun Nov  3 21:57:20 2002
7824 @@ -87,6 +87,9 @@
7825    { 't', M_TO,                 0,              eat_regexp },
7826    { 'U', M_UNREAD,             0,              NULL },
7827    { 'v', M_COLLAPSED,          0,              NULL },
7828 +#ifdef USE_NNTP
7829 +  { 'w', M_NEWSGROUPS,         0,              eat_regexp },
7830 +#endif
7831    { 'x', M_REFERENCE,          0,              eat_regexp },
7832    { 'y', M_XLABEL,             0,              eat_regexp },
7833    { 'z', M_SIZE,               0,              eat_range },
7834 @@ -1053,6 +1056,10 @@
7835        return (pat->not ^ (h->env->x_label && regexec (pat->rx, h->env->x_label, 0, NULL, 0) == 0));
7836      case M_DUPLICATED:
7837        return (pat->not ^ (h->thread && h->thread->duplicate_thread));
7838 +#ifdef USE_NNTP
7839 +    case M_NEWSGROUPS:
7840 +      return (pat->not ^ (h->env->newsgroups && regexec (pat->rx, h->env->newsgroups, 0, NULL, 0) == 0));
7841 +#endif
7842    }
7843    mutt_error (_("error: unknown op %d (report this error)."), pat->op);
7844    return (-1);
7845 @@ -1120,6 +1127,7 @@
7846    int i;
7847  
7848    strfcpy (buf, NONULL (Context->pattern), sizeof (buf));
7849 +  if (prompt || op != M_LIMIT)
7850    if (mutt_get_field (prompt, buf, sizeof (buf), M_PATTERN | M_CLEAR) != 0 || !buf[0])
7851      return (-1);
7852  
7853 diff -uNr mutt-1.4.orig/po/POTFILES.in mutt-1.4/po/POTFILES.in
7854 --- mutt-1.4.orig/po/POTFILES.in        Sun Nov  3 21:42:51 2002
7855 +++ mutt-1.4/po/POTFILES.in     Sun Nov  3 21:57:20 2002
7856 @@ -41,6 +41,8 @@
7857  mutt_socket.c
7858  mutt_ssl.c
7859  mx.c
7860 +newsrc.c
7861 +nntp.c
7862  pager.c
7863  parse.c
7864  pattern.c
7865 diff -uNr mutt-1.4.orig/postpone.c mutt-1.4/postpone.c
7866 --- mutt-1.4.orig/postpone.c    Sun Nov  3 21:42:52 2002
7867 +++ mutt-1.4/postpone.c Sun Nov  3 21:57:20 2002
7868 @@ -125,15 +125,26 @@
7869  
7870    if (LastModify < st.st_mtime)
7871    {
7872 +#ifdef USE_NNTP
7873 +    int optnews = option (OPTNEWS);
7874 +#endif
7875      LastModify = st.st_mtime;
7876  
7877      if (access (Postponed, R_OK | F_OK) != 0)
7878        return (PostCount = 0);
7879 +#ifdef USE_NNTP
7880 +    if (optnews)
7881 +       unset_option (OPTNEWS);
7882 +#endif
7883      if (mx_open_mailbox (Postponed, M_NOSORT | M_QUIET, &ctx) == NULL)
7884        PostCount = 0;
7885      else
7886        PostCount = ctx.msgcount;
7887      mx_fastclose_mailbox (&ctx);
7888 +#ifdef USE_NNTP
7889 +    if (optnews)
7890 +       set_option (OPTNEWS);
7891 +#endif
7892    }
7893  
7894    return (PostCount);
7895 diff -uNr mutt-1.4.orig/protos.h mutt-1.4/protos.h
7896 --- mutt-1.4.orig/protos.h      Sun Nov  3 21:42:52 2002
7897 +++ mutt-1.4/protos.h   Sun Nov  3 21:57:20 2002
7898 @@ -95,6 +95,7 @@
7899  HASH *mutt_make_subj_hash (CONTEXT *);
7900  
7901  LIST *mutt_make_references(ENVELOPE *e);
7902 +LIST *mutt_parse_references (char *, int);
7903  
7904  ENVELOPE *mutt_read_rfc822_header (FILE *, HEADER *, short, short);
7905  HEADER *mutt_dup_header (HEADER *);
7906 @@ -230,6 +231,7 @@
7907  void mutt_update_tree (ATTACHPTR **, short);
7908  void mutt_version (void);
7909  void mutt_view_attachments (HEADER *);
7910 +void mutt_write_references (LIST *, FILE *);
7911  void mutt_set_virtual (CONTEXT *);
7912  
7913  int mutt_addr_is_user (ADDRESS *);
7914 @@ -316,6 +318,7 @@
7915  int mutt_search_command (int, int);
7916  int mutt_compose_menu (HEADER *, char *, size_t, HEADER *);
7917  int mutt_thread_set_flag (HEADER *, int, int, int);
7918 +int mutt_update_list_file (char *, char *, char *, char *);
7919  int mutt_user_is_recipient (HEADER *);
7920  void mutt_update_num_postponed (void);
7921  int mutt_view_attachment (FILE*, BODY *, int, HEADER *, ATTACHPTR **, short);
7922 diff -uNr mutt-1.4.orig/recvattach.c mutt-1.4/recvattach.c
7923 --- mutt-1.4.orig/recvattach.c  Wed Sep 26 12:33:09 2001
7924 +++ mutt-1.4/recvattach.c       Sun Nov  3 21:57:20 2002
7925 @@ -989,6 +989,15 @@
7926         }
7927  #endif
7928  
7929 +#ifdef USE_NNTP
7930 +       if (Context->magic == M_NNTP)
7931 +       {
7932 +         mutt_flushinp ();
7933 +         mutt_error _("Can't delete attachment from newsserver.");
7934 +         break;
7935 +       }
7936 +#endif
7937 +
7938  
7939  
7940  #ifdef HAVE_PGP
7941 @@ -1084,10 +1093,33 @@
7942        case OP_FORWARD_MESSAGE:
7943          CHECK_ATTACH;
7944          mutt_attach_forward (fp, hdr, idx, idxlen,
7945 -                            menu->tagprefix ? NULL : idx[menu->current]->content);
7946 +                            menu->tagprefix ? NULL : idx[menu->current]->content, 0);
7947          menu->redraw = REDRAW_FULL;
7948          break;
7949        
7950 +#ifdef USE_NNTP
7951 +      case OP_FORWARD_TO_GROUP:
7952 +       CHECK_ATTACH;
7953 +       mutt_attach_forward (fp, hdr, idx, idxlen,
7954 +               menu->tagprefix ? NULL : idx[menu->current]->content, SENDNEWS);
7955 +       menu->redraw = REDRAW_FULL;
7956 +       break;
7957 +
7958 +      case OP_FOLLOWUP:
7959 +       CHECK_ATTACH;
7960 +
7961 +       if (!idx[menu->current]->content->hdr->env->followup_to ||
7962 +           mutt_strcasecmp (idx[menu->current]->content->hdr->env->followup_to, "poster") ||
7963 +           query_quadoption (OPT_FOLLOWUPTOPOSTER,_("Reply by mail as poster prefers?")) != M_YES)
7964 +       {
7965 +         mutt_attach_reply (fp, hdr, idx, idxlen,
7966 +               menu->tagprefix ? NULL : idx[menu->current]->content,
7967 +               SENDNEWS|SENDREPLY);
7968 +         menu->redraw = REDRAW_FULL;
7969 +         break;
7970 +       }
7971 +#endif
7972 +
7973        case OP_REPLY:
7974        case OP_GROUP_REPLY:
7975        case OP_LIST_REPLY:
7976 diff -uNr mutt-1.4.orig/recvcmd.c mutt-1.4/recvcmd.c
7977 --- mutt-1.4.orig/recvcmd.c     Wed Jan  2 10:33:38 2002
7978 +++ mutt-1.4/recvcmd.c  Sun Nov  3 21:57:20 2002
7979 @@ -334,7 +334,7 @@
7980  static void attach_forward_bodies (FILE * fp, HEADER * hdr,
7981                                    ATTACHPTR ** idx, short idxlen,
7982                                    BODY * cur,
7983 -                                  short nattach)
7984 +                                  short nattach, int flags)
7985  {
7986    short i;
7987    short mime_fwd_all = 0;
7988 @@ -480,7 +480,7 @@
7989    tmpfp = NULL;
7990  
7991    /* now that we have the template, send it. */
7992 -  ci_send_message (0, tmphdr, tmpbody, NULL, parent);
7993 +  ci_send_message (flags, tmphdr, tmpbody, NULL, parent);
7994    return;
7995    
7996    bail:
7997 @@ -507,7 +507,7 @@
7998   */
7999  
8000  static void attach_forward_msgs (FILE * fp, HEADER * hdr, 
8001 -              ATTACHPTR ** idx, short idxlen, BODY * cur)
8002 +              ATTACHPTR ** idx, short idxlen, BODY * cur, int flags)
8003  {
8004    HEADER *curhdr = NULL;
8005    HEADER *tmphdr;
8006 @@ -612,23 +612,23 @@
8007    else
8008      mutt_free_header (&tmphdr);
8009  
8010 -  ci_send_message (0, tmphdr, *tmpbody ? tmpbody : NULL, 
8011 +  ci_send_message (flags, tmphdr, *tmpbody ? tmpbody : NULL, 
8012                    NULL, curhdr);
8013  
8014  }
8015  
8016  void mutt_attach_forward (FILE * fp, HEADER * hdr, 
8017 -                         ATTACHPTR ** idx, short idxlen, BODY * cur)
8018 +                         ATTACHPTR ** idx, short idxlen, BODY * cur, int flags)
8019  {
8020    short nattach;
8021    
8022  
8023    if (check_all_msg (idx, idxlen, cur, 0) == 0)
8024 -    attach_forward_msgs (fp, hdr, idx, idxlen, cur);
8025 +    attach_forward_msgs (fp, hdr, idx, idxlen, cur, flags);
8026    else
8027    {
8028      nattach = count_tagged (idx, idxlen);
8029 -    attach_forward_bodies (fp, hdr, idx, idxlen, cur, nattach);
8030 +    attach_forward_bodies (fp, hdr, idx, idxlen, cur, nattach, flags);
8031    }
8032  }
8033  
8034 @@ -686,28 +686,40 @@
8035      return -1;
8036    }
8037  
8038 -  if (parent)
8039 +#ifdef USE_NNTP
8040 +  if ((flags & SENDNEWS))
8041    {
8042 -    if (mutt_fetch_recips (env, curenv, flags) == -1)
8043 -      return -1;
8044 +    /* in case followup set Newsgroups: with Followup-To: if it present */
8045 +    if (!env->newsgroups && curenv &&
8046 +       mutt_strcasecmp (curenv->followup_to, "poster"))
8047 +      env->newsgroups = safe_strdup (curenv->followup_to);
8048    }
8049    else
8050 +#endif
8051    {
8052 -    for (i = 0; i < idxlen; i++)
8053 +    if (parent)
8054      {
8055 -      if (idx[i]->content->tagged
8056 -         && mutt_fetch_recips (env, idx[i]->content->hdr->env, flags) == -1)
8057 +      if (mutt_fetch_recips (env, curenv, flags) == -1)
8058         return -1;
8059      }
8060 +    else
8061 +    {
8062 +      for (i = 0; i < idxlen; i++)
8063 +      {
8064 +       if (idx[i]->content->tagged
8065 +           && mutt_fetch_recips (env, idx[i]->content->hdr->env, flags) == -1)
8066 +         return -1;
8067 +      }
8068 +    }
8069 +
8070 +    if ((flags & SENDLISTREPLY) && !env->to)
8071 +    {
8072 +      mutt_error _("No mailing lists found!");
8073 +      return (-1);
8074 +    }
8075 +
8076 +    mutt_fix_reply_recipients (env);
8077    }
8078 -  
8079 -  if ((flags & SENDLISTREPLY) && !env->to)
8080 -  {
8081 -    mutt_error _("No mailing lists found!");
8082 -    return (-1);
8083 -  }
8084 -  
8085 -  mutt_fix_reply_recipients (env);
8086    mutt_make_misc_reply_headers (env, Context, curhdr, curenv);
8087  
8088    if (parent)
8089 @@ -768,6 +780,13 @@
8090    char prefix[SHORT_STRING];
8091    int rc;
8092    
8093 +#ifdef USE_NNTP
8094 +  if (flags & SENDNEWS)
8095 +    set_option (OPTNEWSSEND);
8096 +  else
8097 +    unset_option (OPTNEWSSEND);
8098 +#endif
8099 +
8100    if (check_all_msg (idx, idxlen, cur, 0) == -1)
8101    {
8102      nattach = count_tagged (idx, idxlen);
8103 diff -uNr mutt-1.4.orig/rfc1524.c mutt-1.4/rfc1524.c
8104 --- mutt-1.4.orig/rfc1524.c     Tue May 15 09:23:49 2001
8105 +++ mutt-1.4/rfc1524.c  Sun Nov  3 21:57:20 2002
8106 @@ -563,13 +563,13 @@
8107   * safe_fopen().
8108   */
8109  
8110 -int mutt_rename_file (char *oldfile, char *newfile)
8111 +int _mutt_rename_file (char *oldfile, char *newfile, int overwrite)
8112  {
8113    FILE *ofp, *nfp;
8114  
8115    if (access (oldfile, F_OK) != 0)
8116      return 1;
8117 -  if (access (newfile, F_OK) == 0)
8118 +  if (!overwrite && access (newfile, F_OK) == 0)
8119      return 2;
8120    if ((ofp = fopen (oldfile,"r")) == NULL)
8121      return 3;
8122 @@ -584,3 +584,8 @@
8123    mutt_unlink (oldfile);
8124    return 0;
8125  }
8126 +
8127 +int mutt_rename_file (char *oldfile, char *newfile)
8128 +{
8129 +  return _mutt_rename_file (oldfile, newfile, 0);
8130 +}
8131 diff -uNr mutt-1.4.orig/rfc1524.h mutt-1.4/rfc1524.h
8132 --- mutt-1.4.orig/rfc1524.h     Fri Mar  3 11:10:13 2000
8133 +++ mutt-1.4/rfc1524.h  Sun Nov  3 21:57:20 2002
8134 @@ -40,5 +40,6 @@
8135  int rfc1524_expand_filename (char *, char *, char *, size_t);
8136  int rfc1524_mailcap_lookup (BODY *, char *, rfc1524_entry *, int);
8137  int mutt_rename_file (char *, char *);
8138 +int _mutt_rename_file (char *, char *, int);
8139  
8140  #endif /* _RFC1524_H */
8141 diff -uNr mutt-1.4.orig/send.c mutt-1.4/send.c
8142 --- mutt-1.4.orig/send.c        Wed Jan 30 23:50:40 2002
8143 +++ mutt-1.4/send.c     Sun Nov  3 21:57:20 2002
8144 @@ -41,6 +41,10 @@
8145  #include "pgp.h"
8146  #endif
8147  
8148 +#ifdef USE_NNTP
8149 +#include "nntp.h"
8150 +#endif
8151 +
8152  #ifdef MIXMASTER
8153  #include "remailer.h"
8154  #endif
8155 @@ -196,17 +200,51 @@
8156    return 0;
8157  }
8158  
8159 -static int edit_envelope (ENVELOPE *en)
8160 +static int edit_envelope (ENVELOPE *en, int flags)
8161  {
8162    char buf[HUGE_STRING];
8163    LIST *uh = UserHeader;
8164  
8165 -  if (edit_address (&en->to, "To: ") == -1 || en->to == NULL)
8166 -    return (-1);
8167 -  if (option (OPTASKCC) && edit_address (&en->cc, "Cc: ") == -1)
8168 -    return (-1);
8169 -  if (option (OPTASKBCC) && edit_address (&en->bcc, "Bcc: ") == -1)
8170 -    return (-1);
8171 +#ifdef USE_NNTP
8172 +  if (option (OPTNEWSSEND))
8173 +  {
8174 +    if (en->newsgroups)
8175 +      strfcpy (buf, en->newsgroups, sizeof (buf));
8176 +    else
8177 +      buf[0] = 0;
8178 +    if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) != 0)
8179 +      return (-1);
8180 +    safe_free ((void **)&en->newsgroups);
8181 +    en->newsgroups = safe_strdup (buf);
8182 +
8183 +    if (en->followup_to)
8184 +      strfcpy (buf, en->followup_to, sizeof (buf));
8185 +    else
8186 +      buf[0] = 0;
8187 +    if (option (OPTASKFOLLOWUP) && mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) != 0)
8188 +      return (-1);
8189 +    safe_free ((void **)&en->followup_to);
8190 +    en->followup_to = safe_strdup (buf);
8191 +
8192 +    if (en->x_comment_to)
8193 +      strfcpy (buf, en->x_comment_to, sizeof (buf));
8194 +    else
8195 +      buf[0] = 0;
8196 +    if (option (OPTXCOMMENTTO) && option (OPTASKXCOMMENTTO) && mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) != 0)
8197 +      return (-1);
8198 +    safe_free ((void **)&en->x_comment_to);
8199 +    en->x_comment_to = safe_strdup (buf);
8200 +  }
8201 +  else
8202 +#endif
8203 +  {
8204 +    if (edit_address (&en->to, "To: ") == -1 || en->to == NULL)
8205 +      return (-1);
8206 +    if (option (OPTASKCC) && edit_address (&en->cc, "Cc: ") == -1)
8207 +      return (-1);
8208 +    if (option (OPTASKBCC) && edit_address (&en->bcc, "Bcc: ") == -1)
8209 +      return (-1);
8210 +  }
8211  
8212    if (en->subject)
8213    {
8214 @@ -242,6 +280,14 @@
8215    return 0;
8216  }
8217  
8218 +#ifdef USE_NNTP
8219 +char *nntp_get_header (const char *s)
8220 +{
8221 +  SKIPWS (s);
8222 +  return safe_strdup (s);
8223 +}
8224 +#endif
8225 +
8226  static void process_user_recips (ENVELOPE *env)
8227  {
8228    LIST *uh = UserHeader;
8229 @@ -254,6 +300,14 @@
8230        env->cc = rfc822_parse_adrlist (env->cc, uh->data + 3);
8231      else if (ascii_strncasecmp ("bcc:", uh->data, 4) == 0)
8232        env->bcc = rfc822_parse_adrlist (env->bcc, uh->data + 4);
8233 +#ifdef USE_NNTP
8234 +    else if (ascii_strncasecmp ("newsgroups:", uh->data, 11) == 0)
8235 +      env->newsgroups = nntp_get_header (uh->data + 11);
8236 +    else if (ascii_strncasecmp ("followup-to:", uh->data, 12) == 0)
8237 +      env->followup_to = nntp_get_header (uh->data + 12);
8238 +    else if (ascii_strncasecmp ("x-comment-to:", uh->data, 13) == 0)
8239 +      env->x_comment_to = nntp_get_header (uh->data + 13);
8240 +#endif
8241    }
8242  }
8243  
8244 @@ -284,6 +338,12 @@
8245      else if (ascii_strncasecmp ("to:", uh->data, 3) != 0 &&
8246              ascii_strncasecmp ("cc:", uh->data, 3) != 0 &&
8247              ascii_strncasecmp ("bcc:", uh->data, 4) != 0 &&
8248 +#ifdef USE_NNTP
8249 +            ascii_strncasecmp ("newsgroups:", uh->data, 11) != 0 &&
8250 +            ascii_strncasecmp ("followup-to:", uh->data, 12) != 0 &&
8251 +            ascii_strncasecmp ("x-comment-to:", uh->data, 13) != 0 &&
8252 +#endif
8253 +            ascii_strncasecmp ("supersedes:", uh->data, 11) != 0 &&
8254              ascii_strncasecmp ("subject:", uh->data, 8) != 0)
8255      {
8256        if (last)
8257 @@ -597,6 +657,10 @@
8258    else
8259      env->subject = safe_strdup ("Re: your mail");
8260    
8261 +#ifdef USE_NNTP
8262 +  if (option (OPTNEWSSEND) && option (OPTXCOMMENTTO) && curenv->from)
8263 +    env->x_comment_to = safe_strdup (mutt_get_name (curenv->from));
8264 +#endif
8265  }
8266  
8267  void mutt_add_to_reference_headers (ENVELOPE *env, ENVELOPE *curenv, LIST ***pp, LIST ***qq)
8268 @@ -679,27 +743,39 @@
8269  
8270    if (flags & SENDREPLY)
8271    {
8272 -    if (tag)
8273 +#ifdef USE_NNTP
8274 +    if ((flags & SENDNEWS))
8275      {
8276 -      HEADER *h;
8277 -
8278 -      for (i = 0; i < ctx->vcount; i++)
8279 +      /* in case followup set Newsgroups: with Followup-To: if it present */
8280 +      if (!env->newsgroups && curenv &&
8281 +         mutt_strcasecmp (curenv->followup_to, "poster"))
8282 +       env->newsgroups = safe_strdup (curenv->followup_to);
8283 +    }
8284 +    else
8285 +#endif
8286 +    {
8287 +      if (tag)
8288        {
8289 -       h = ctx->hdrs[ctx->v2r[i]];
8290 -       if (h->tagged && mutt_fetch_recips (env, h->env, flags) == -1)
8291 +       HEADER *h;
8292 +
8293 +       for (i = 0; i < ctx->vcount; i++)
8294 +       {
8295 +         h = ctx->hdrs[ctx->v2r[i]];
8296 +         if (h->tagged && mutt_fetch_recips (env, h->env, flags) == -1)
8297 +           return -1;
8298 +       }
8299 +       }
8300 +       else if (mutt_fetch_recips (env, curenv, flags) == -1)
8301           return -1;
8302 +
8303 +       if ((flags & SENDLISTREPLY) && !env->to)
8304 +       {
8305 +         mutt_error _("No mailing lists found!");
8306 +       return (-1);
8307        }
8308 -    }
8309 -    else if (mutt_fetch_recips (env, curenv, flags) == -1)
8310 -      return -1;
8311  
8312 -    if ((flags & SENDLISTREPLY) && !env->to)
8313 -    {
8314 -      mutt_error _("No mailing lists found!");
8315 -      return (-1);
8316 +      mutt_fix_reply_recipients (env);
8317      }
8318 -
8319 -    mutt_fix_reply_recipients (env);
8320      mutt_make_misc_reply_headers (env, ctx, cur, curenv);
8321      mutt_make_reference_headers (tag ? NULL : curenv, env, ctx);
8322    }
8323 @@ -828,7 +904,18 @@
8324     * it hasn't already been set
8325     */
8326  
8327 -  if (option (OPTFOLLOWUPTO) && !e->mail_followup_to)
8328 +  if (!option (OPTFOLLOWUPTO))
8329 +    return;
8330 +#ifdef USE_NNTP
8331 +  if (option (OPTNEWSSEND))
8332 +  {
8333 +    if (!e->followup_to && e->newsgroups && (strrchr (e->newsgroups, ',')))
8334 +      e->followup_to = safe_strdup (e->newsgroups);
8335 +    return;
8336 +  }
8337 +#endif
8338 +
8339 +  if (!e->mail_followup_to)
8340    {
8341      if (mutt_is_list_cc (0, e->to, e->cc))
8342      {
8343 @@ -1084,6 +1171,13 @@
8344  
8345    int rv = -1;
8346    
8347 +#ifdef USE_NNTP
8348 +  if (flags & SENDNEWS)
8349 +    set_option (OPTNEWSSEND);
8350 +  else
8351 +    unset_option (OPTNEWSSEND);
8352 +#endif
8353 +
8354    if (!flags && !msg && quadoption (OPT_RECALL) != M_NO &&
8355        mutt_num_postponed (1))
8356    {
8357 @@ -1115,6 +1209,22 @@
8358      {
8359        if ((flags = mutt_get_postponed (ctx, msg, &cur, fcc, sizeof (fcc))) < 0)
8360         goto cleanup;
8361 +#ifdef USE_NNTP
8362 +      /*
8363 +       * If postponed message is a news article, it have
8364 +       * a "Newsgroups:" header line, then set appropriate flag.
8365 +       */
8366 +      if (msg->env->newsgroups)
8367 +      {
8368 +       flags |= SENDNEWS;
8369 +       set_option (OPTNEWSSEND);
8370 +      }
8371 +      else
8372 +      {
8373 +       flags &= ~SENDNEWS;
8374 +       unset_option (OPTNEWSSEND);
8375 +      }
8376 +#endif
8377      }
8378  
8379      if (flags & (SENDPOSTPONED|SENDRESEND))
8380 @@ -1195,11 +1305,16 @@
8381      if (option (OPTHDRS))
8382        process_user_recips (msg->env);
8383  
8384 +#ifdef USE_NNTP
8385 +    if ((flags & SENDNEWS) && ctx && ctx->magic == M_NNTP && !msg->env->newsgroups)
8386 +      msg->env->newsgroups = safe_strdup (((NNTP_DATA *)ctx->data)->group);
8387 +#endif
8388 +
8389      if (! (flags & SENDMAILX) &&
8390         ! (option (OPTAUTOEDIT) && option (OPTEDITHDRS)) &&
8391         ! ((flags & SENDREPLY) && option (OPTFASTREPLY)))
8392      {
8393 -      if (edit_envelope (msg->env) == -1)
8394 +      if (edit_envelope (msg->env, flags) == -1)
8395         goto cleanup;
8396      }
8397  
8398 @@ -1349,6 +1464,11 @@
8399      if (i == -1)
8400      {
8401        /* abort */
8402 +#ifdef USE_NNTP
8403 +      if (flags & SENDNEWS)
8404 +       mutt_message _("Article not posted.");
8405 +      else
8406 +#endif
8407        mutt_message _("Mail not sent.");
8408        goto cleanup;
8409      }
8410 @@ -1380,6 +1500,9 @@
8411      }
8412    }
8413  
8414 +#ifdef USE_NNTP
8415 +  if (!(flags & SENDNEWS))
8416 +#endif
8417    if (!msg->env->to && !msg->env->cc && !msg->env->bcc)
8418    {
8419      if (! (flags & SENDBATCH))
8420 @@ -1402,6 +1525,19 @@
8421        mutt_error _("No subject specified.");
8422      goto main_loop;
8423    }
8424 +#ifdef USE_NNTP
8425 +  if ((flags & SENDNEWS) && !msg->env->subject)
8426 +  {
8427 +    mutt_error _("No subject specified.");
8428 +    goto main_loop;
8429 +  }
8430 +
8431 +  if ((flags & SENDNEWS) && !msg->env->newsgroups)
8432 +  {
8433 +    mutt_error _("No newsgroup specified.");
8434 +    goto main_loop;
8435 +  }
8436 +#endif
8437  
8438    if (msg->content->next)
8439      msg->content = mutt_make_multipart (msg->content);
8440 @@ -1588,7 +1724,12 @@
8441      }
8442    }
8443    else if (!option (OPTNOCURSES) && ! (flags & SENDMAILX))
8444 -    mutt_message (i == 0 ? _("Mail sent.") : _("Sending in background."));
8445 +    mutt_message (i != 0 ? _("Sending in background.") :
8446 +#ifdef USE_NNTP
8447 +                 (flags & SENDNEWS) ? _("Article posted.") : _("Mail sent."));
8448 +#else
8449 +                 _("Mail sent."));
8450 +#endif
8451  
8452  #ifdef HAVE_PGP
8453    if (msg->pgp & PGPENCRYPT)
8454 diff -uNr mutt-1.4.orig/sendlib.c mutt-1.4/sendlib.c
8455 --- mutt-1.4.orig/sendlib.c     Sat Apr 20 09:25:49 2002
8456 +++ mutt-1.4/sendlib.c  Sun Nov  3 21:57:20 2002
8457 @@ -40,6 +40,10 @@
8458  #include <sys/wait.h>
8459  #include <fcntl.h>
8460  
8461 +#ifdef USE_NNTP
8462 +#include <nntp.h>
8463 +#endif
8464 +
8465  #ifdef HAVE_SYSEXITS_H
8466  #include <sysexits.h>
8467  #else /* Make sure EX_OK is defined <philiph@pobox.com> */
8468 @@ -1537,7 +1541,7 @@
8469  /* need to write the list in reverse because they are stored in reverse order
8470   * when parsed to speed up threading
8471   */
8472 -static void write_references (LIST *r, FILE *f)
8473 +void mutt_write_references (LIST *r, FILE *f)
8474  {
8475    LIST **ref = NULL;
8476    int refcnt = 0, refmax = 0;
8477 @@ -1579,6 +1583,9 @@
8478    char *p;
8479    LIST *tmp = env->userhdrs;
8480    
8481 +#ifdef USE_NNTP
8482 +  if (!option (OPTNEWSSEND))
8483 +#endif
8484    if (mode == 0 && !privacy)
8485      fputs (mutt_make_date (buffer, sizeof(buffer)), fp);
8486  
8487 @@ -1598,6 +1605,9 @@
8488      mutt_write_address_list (env->to, fp, 4);
8489    }
8490    else if (mode > 0)
8491 +#ifdef USE_NNTP
8492 +  if (!option (OPTNEWSSEND))
8493 +#endif
8494      fputs ("To: \n", fp);
8495  
8496    if (env->cc)
8497 @@ -1606,6 +1616,9 @@
8498      mutt_write_address_list (env->cc, fp, 4);
8499    }
8500    else if (mode > 0)
8501 +#ifdef USE_NNTP
8502 +  if (!option (OPTNEWSSEND))
8503 +#endif
8504      fputs ("Cc: \n", fp);
8505  
8506    if (env->bcc)
8507 @@ -1617,8 +1630,28 @@
8508      }
8509    }
8510    else if (mode > 0)
8511 +#ifdef USE_NNTP
8512 +  if (!option (OPTNEWSSEND))
8513 +#endif
8514      fputs ("Bcc: \n", fp);
8515  
8516 +#ifdef USE_NNTP
8517 +  if (env->newsgroups)
8518 +    fprintf (fp, "Newsgroups: %s\n", env->newsgroups);
8519 +  else if (mode == 1 && option (OPTNEWSSEND))
8520 +    fputs ("Newsgroups: \n", fp);
8521 +
8522 +  if (env->followup_to)
8523 +    fprintf (fp, "Followup-To: %s\n", env->followup_to);
8524 +  else if (mode == 1 && option (OPTNEWSSEND))
8525 +    fputs ("Followup-To: \n", fp);
8526 +
8527 +  if (env->x_comment_to)
8528 +    fprintf (fp, "X-Comment-To: %s\n", env->x_comment_to);
8529 +  else if (mode == 1 && option (OPTNEWSSEND) && option (OPTXCOMMENTTO))
8530 +    fputs ("X-Comment-To: \n", fp);
8531 +#endif
8532 +
8533    if (env->subject)
8534      fprintf (fp, "Subject: %s\n", env->subject);
8535    else if (mode == 1)
8536 @@ -1637,6 +1670,9 @@
8537      fputs ("Reply-To: \n", fp);
8538  
8539    if (env->mail_followup_to)
8540 +#ifdef USE_NNTP
8541 +  if (!option (OPTNEWSSEND))
8542 +#endif
8543    {
8544      fputs ("Mail-Followup-To: ", fp);
8545      mutt_write_address_list (env->mail_followup_to, fp, 18);
8546 @@ -1647,7 +1683,7 @@
8547      if (env->references)
8548      {
8549        fputs ("References:", fp);
8550 -      write_references (env->references, fp);
8551 +      mutt_write_references (env->references, fp);
8552        fputc('\n', fp);
8553      }
8554  
8555 @@ -1659,7 +1695,7 @@
8556    if (env->in_reply_to)
8557    {
8558      fputs ("In-Reply-To:", fp);
8559 -    write_references (env->in_reply_to, fp);
8560 +    mutt_write_references (env->in_reply_to, fp);
8561      fputc ('\n', fp);
8562    }
8563    
8564 @@ -1967,11 +2003,30 @@
8565                  const char *msg, /* file containing message */
8566                  int eightbit) /* message contains 8bit chars */
8567  {
8568 -  char *ps = NULL, *path = NULL, *s = safe_strdup (Sendmail), *childout = NULL;
8569 +  char *ps = NULL, *path = NULL, *s = NULL, *childout = NULL;
8570    char **args = NULL;
8571    size_t argslen = 0, argsmax = 0;
8572    int i;
8573  
8574 +#ifdef USE_NNTP
8575 +  if (option (OPTNEWSSEND))
8576 +  {
8577 +    char cmd[LONG_STRING];
8578 +
8579 +    mutt_FormatString (cmd, sizeof (cmd), NONULL (Inews), nntp_format_str, 0, 0);
8580 +    if (!*cmd)
8581 +    {
8582 +      i = nntp_post (msg);
8583 +      unlink (msg);
8584 +      return i;
8585 +    }
8586 +
8587 +    s = safe_strdup (cmd);
8588 +  }
8589 +  else
8590 +#endif
8591 +    s = safe_strdup (Sendmail);
8592 +
8593    ps = s;
8594    i = 0;
8595    while ((ps = strtok (ps, " ")))
8596 @@ -1995,6 +2050,10 @@
8597      i++;
8598    }
8599  
8600 +#ifdef USE_NNTP
8601 +  if (!option (OPTNEWSSEND))
8602 +  {
8603 +#endif
8604    if (eightbit && option (OPTUSE8BITMIME))
8605      args = add_option (args, &argslen, &argsmax, "-B8BITMIME");
8606  
8607 @@ -2017,6 +2076,9 @@
8608    args = add_args (args, &argslen, &argsmax, to);
8609    args = add_args (args, &argslen, &argsmax, cc);
8610    args = add_args (args, &argslen, &argsmax, bcc);
8611 +#ifdef USE_NNTP
8612 +  }
8613 +#endif
8614  
8615    if (argslen == argsmax)
8616      safe_realloc ((void **) &args, sizeof (char *) * (++argsmax));
8617 @@ -2148,6 +2210,9 @@
8618    rfc2047_encode_adrlist (env->reply_to, "Reply-To");
8619  
8620    if (env->subject)
8621 +#ifdef USE_NNTP
8622 +  if (!option (OPTNEWSSEND) || option (OPTMIMESUBJECT))
8623 +#endif
8624    {
8625      rfc2047_encode_string (&env->subject);
8626    }
8627 @@ -2234,6 +2299,10 @@
8628    
8629    rfc822_write_address (resent_from, sizeof (resent_from), from);
8630  
8631 +#ifdef USE_NNTP
8632 +  unset_option (OPTNEWSSEND);
8633 +#endif
8634 +
8635    _mutt_bounce_message (fp, h, to, resent_from, from);
8636  
8637    rfc822_free_address (&from);
8638 diff -uNr mutt-1.4.orig/sort.c mutt-1.4/sort.c
8639 --- mutt-1.4.orig/sort.c        Thu Dec 13 13:10:59 2001
8640 +++ mutt-1.4/sort.c     Sun Nov  3 21:57:20 2002
8641 @@ -144,6 +144,15 @@
8642    HEADER **ha = (HEADER **) a;
8643    HEADER **hb = (HEADER **) b;
8644  
8645 +#ifdef USE_NNTP
8646 +  if ((*ha)->article_num && (*hb)->article_num)
8647 +  {
8648 +    int result = (*ha)->article_num - (*hb)->article_num;
8649 +    AUXSORT(result,a,b);
8650 +    return (SORTCODE (result));
8651 +  }
8652 +  else
8653 +#endif
8654    /* no need to auxsort because you will never have equality here */
8655    return (SORTCODE ((*ha)->index - (*hb)->index));
8656  }
8657 diff -uNr mutt-1.4.orig/url.c mutt-1.4/url.c
8658 --- mutt-1.4.orig/url.c Mon Oct 29 12:53:45 2001
8659 +++ mutt-1.4/url.c      Sun Nov  3 21:57:20 2002
8660 @@ -35,6 +35,8 @@
8661    { "imaps",   U_IMAPS },
8662    { "pop",     U_POP  },
8663    { "pops",    U_POPS  },
8664 +  { "nntp",    U_NNTP },
8665 +  { "nntps",   U_NNTPS },
8666    { "mailto",  U_MAILTO },
8667    { NULL,      U_UNKNOWN}
8668  };
8669 diff -uNr mutt-1.4.orig/url.h mutt-1.4/url.h
8670 --- mutt-1.4.orig/url.h Tue Sep  4 11:30:04 2001
8671 +++ mutt-1.4/url.h      Sun Nov  3 21:57:20 2002
8672 @@ -8,6 +8,8 @@
8673    U_POPS,
8674    U_IMAP,
8675    U_IMAPS,
8676 +  U_NNTP,
8677 +  U_NNTPS,
8678    U_MAILTO,
8679    U_UNKNOWN
8680  }
This page took 0.949229 seconds and 3 git commands to generate.