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