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