]> git.pld-linux.org Git - packages/mutt.git/blob - mutt-vvv.nntp.patch
- versioned runtime dependencies for gpgme and libgpg-error
[packages/mutt.git] / mutt-vvv.nntp.patch
1 WARNING: Run the following script before configure:
2
3 aclocal -I m4
4 autoheader
5 automake --foreign
6 autoconf
7
8 -- 
9 Vsevolod Volkov <vvv@mutt.org.ua>
10
11
12 diff -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 +
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 +
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 +
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 +
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 +
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>
177 +- fixed SIGSEGV when posting article
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>
373 +- get default news server name from file /etc/nntpserver
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
464 diff -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
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"
482 +OP_COMPOSE_ATTACH_NEWS_MESSAGE "attach news article(s) to this message"
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)"
497 @@ -89,8 +94,13 @@ OP_EXIT "exit this menu"
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"
511 @@ -98,11 +108,14 @@ OP_HELP "this screen"
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"
515 +OP_LOAD_ACTIVE "load list of all newsgroups from NNTP server"
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"
526 @@ -142,6 +155,7 @@ OP_PAGER_HIDE_QUOTED "toggle display of
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"
534 @@ -151,6 +165,7 @@ OP_QUERY "query external program for add
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)"
542 @@ -165,18 +180,22 @@ OP_SEARCH_TOGGLE "toggle search pattern
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"
565 diff -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
568 @@ -0,0 +1 @@
569 +vvv.nntp
570 diff -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
574      user = PopUser;
575  #endif
576    
577 +#ifdef USE_NNTP
578 +  if (a1->type == MUTT_ACCT_TYPE_NNTP && NntpUser)
579 +    user = NntpUser;
580 +#endif
581 +
582    if (a1->flags & a2->flags & MUTT_ACCT_USER)
583      return (!strcmp (a1->user, a2->user));
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
592    }
593  #endif
594  
595 +#ifdef USE_NNTP
596 +  if (account->type == MUTT_ACCT_TYPE_NNTP)
597 +  {
598 +    if (account->flags & MUTT_ACCT_SSL)
599 +      url->scheme = U_NNTPS;
600 +    else
601 +      url->scheme = U_NNTP;
602 +  }
603 +#endif
604 +
605    url->host = account->host;
606    if (account->flags & MUTT_ACCT_PORT)
607      url->port = account->port;
608 @@ -155,6 +174,10 @@ int mutt_account_getuser (ACCOUNT* accou
609    else if ((account->type == MUTT_ACCT_TYPE_POP) && PopUser)
610      strfcpy (account->user, PopUser, sizeof (account->user));
611  #endif
612 +#ifdef USE_NNTP
613 +  else if ((account->type == MUTT_ACCT_TYPE_NNTP) && NntpUser)
614 +    strfcpy (account->user, NntpUser, sizeof (account->user));
615 +#endif
616    else if (option (OPTNOCURSES))
617      return -1;
618    /* prompt (defaults to unix username), copy into account->user */
619 @@ -217,6 +240,10 @@ int mutt_account_getpass (ACCOUNT* accou
620    else if ((account->type == MUTT_ACCT_TYPE_SMTP) && SmtpPass)
621      strfcpy (account->pass, SmtpPass, sizeof (account->pass));
622  #endif
623 +#ifdef USE_NNTP
624 +  else if ((account->type == MUTT_ACCT_TYPE_NNTP) && NntpPass)
625 +    strfcpy (account->pass, NntpPass, sizeof (account->pass));
626 +#endif
627    else if (option (OPTNOCURSES))
628      return -1;
629    else
630 diff -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
633 @@ -29,7 +29,8 @@ enum
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
640  };
641  
642  /* account flags */
643 diff -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);
655 diff -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
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>
668 @@ -50,6 +53,19 @@ static const struct mapping_t FolderHelp
669    { NULL,       0 }
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 },
681 +  { NULL,              0 }
682 +};
683 +#endif
684 +
685  typedef struct folder_t
686  {
687    struct folder_file *ff;
688 @@ -134,9 +150,17 @@ static void browser_sort (struct browser
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;
705      case SORT_COUNT:
706 @@ -367,8 +391,112 @@ folder_format_str (char *dest, size_t de
707    return (src);
708  }
709  
710 +#ifdef USE_NNTP
711 +static const char *
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)
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;
725 +
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
737 +       snprintf (dest, destlen, tmp, folder->ff->nd->new ? 'N' : 'u');
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':
749 +      if (flags & MUTT_FORMAT_OPTIONAL)
750 +      {
751 +       if (folder->ff->nd->unread != 0)
752 +         mutt_FormatString (dest, destlen, col, cols, ifstring,
753 +               newsgroup_format_str, data, flags);
754 +       else
755 +         mutt_FormatString (dest, destlen, col, cols, elsestring,
756 +               newsgroup_format_str, data, flags);
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 +      {
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 +
798 +       snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
799 +       snprintf (dest, destlen, tmp, buf);
800 +       FREE (&buf);
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,
814 -                       const char *name, const struct stat *s, BUFFY *b)
815 +                       const char *name, const struct stat *s, BUFFY *b,
816 +                       void *data)
817  {
818    if (state->entrylen == state->entrymax)
819    {
820 @@ -406,6 +534,10 @@ static void add_folder (MUTTMENU *m, str
821  #ifdef USE_IMAP
822    (state->entry)[state->entrylen].imap = 0;
823  #endif
824 +#ifdef USE_NNTP
825 +  if (option (OPTNEWS))
826 +    (state->entry)[state->entrylen].nd = (NNTP_DATA *)data;
827 +#endif
828    (state->entrylen)++;
829  }
830  
831 @@ -421,9 +553,35 @@ static void init_state (struct browser_s
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 +  {
842 +    NNTP_SERVER *nserv = CurrentNewsSrv;
843 +    unsigned int i;
844 +
845 +/*  mutt_buffy_check (0); */
846 +    init_state (state, menu);
847 +
848 +    for (i = 0; i < nserv->groups_num; i++)
849 +    {
850 +      NNTP_DATA *nntp_data = nserv->groups_list[i];
851 +      if (!nntp_data)
852 +       continue;
853 +      if (prefix && *prefix &&
854 +         strncmp (prefix, nntp_data->group, strlen (prefix)))
855 +       continue;
856 +      if (!((regexec (Mask.rx, nntp_data->group, 0, NULL, 0) == 0) ^ Mask.not))
857 +       continue;
858 +      add_folder (menu, state, nntp_data->group, NULL, NULL, nntp_data);
859 +    }
860 +  }
861 +  else
862 +#endif /* USE_NNTP */
863 +  {
864    struct stat s;
865    DIR *dp;
866    struct dirent *de;
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);
873    }
874    closedir (dp);  
875 +  }
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 +  {
889 +    NNTP_SERVER *nserv = CurrentNewsSrv;
890 +    unsigned int i;
891 +
892 +/*  mutt_buffy_check (0); */
893 +    init_state (state, menu);
894 +
895 +    for (i = 0; i < nserv->groups_num; i++)
896 +    {
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);
901 +    }
902 +  }
903 +  else
904 +#endif
905 +  {
906    BUFFY *tmp = Incoming;
907  
908    if (!Incoming)
909 @@ -527,14 +708,21 @@ static int examine_mailboxes (MUTTMENU *
910  #ifdef USE_IMAP
911      if (mx_is_imap (tmp->path))
912      {
913 -      add_folder (menu, state, buffer, NULL, tmp);
914 +      add_folder (menu, state, buffer, NULL, tmp, NULL);
915        continue;
916      }
917  #endif
918  #ifdef USE_POP
919      if (mx_is_pop (tmp->path))
920      {
921 -      add_folder (menu, state, buffer, NULL, tmp);
922 +      add_folder (menu, state, buffer, NULL, tmp, NULL);
923 +      continue;
924 +    }
925 +#endif
926 +#ifdef USE_NNTP
927 +    if (mx_is_nntp (tmp->path))
928 +    {
929 +      add_folder (menu, state, buffer, NULL, tmp, NULL);
930        continue;
931      }
932  #endif
933 @@ -560,15 +748,20 @@ static int examine_mailboxes (MUTTMENU *
934         s.st_mtime = st2.st_mtime;
935      }
936  
937 -    add_folder (menu, state, buffer, &s, tmp);
938 +    add_folder (menu, state, buffer, &s, tmp, NULL);
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  
955 @@ -579,6 +772,12 @@ static void folder_entry (char *s, size_
956    folder.ff = &((struct folder_file *) menu->data)[num];
957    folder.num = num;
958    
959 +#ifdef USE_NNTP
960 +  if (option (OPTNEWS))
961 +    mutt_FormatString (s, slen, 0, MuttIndexWindow->cols, NONULL(GroupFormat),
962 +       newsgroup_format_str, (unsigned long) &folder, MUTT_FORMAT_ARROWCURSOR);
963 +  else
964 +#endif
965    mutt_FormatString (s, slen, 0, MuttIndexWindow->cols, NONULL(FolderFormat), folder_format_str, 
966        (unsigned long) &folder, MUTT_FORMAT_ARROWCURSOR);
967  }
968 @@ -599,6 +798,17 @@ static void init_menu (struct browser_st
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
986 @@ -654,6 +864,31 @@ void _mutt_select_file (char *f, size_t
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 +    {
997 +      NNTP_SERVER *nserv = CurrentNewsSrv;
998 +      unsigned int i;
999 +
1000 +      /* default state for news reader mode is browse subscribed newsgroups */
1001 +      buffy = 0;
1002 +      for (i = 0; i < nserv->groups_num; i++)
1003 +      {
1004 +       NNTP_DATA *nntp_data = nserv->groups_list[i];
1005 +       if (nntp_data && nntp_data->subscribed)
1006 +       {
1007 +         buffy = 1;
1008 +         break;
1009 +       }
1010 +      }
1011 +    }
1012 +  }
1013 +  else
1014 +#endif
1015    if (*f)
1016    {
1017      mutt_expand_path (f, flen);
1018 @@ -750,6 +985,9 @@ void _mutt_select_file (char *f, size_t
1019      menu->tag = file_tag;
1020  
1021    menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_FOLDER,
1022 +#ifdef USE_NNTP
1023 +    option (OPTNEWS) ? FolderNewsHelp :
1024 +#endif
1025      FolderHelp);
1026    mutt_push_current_menu (menu);
1027  
1028 @@ -889,7 +1127,11 @@ void _mutt_select_file (char *f, size_t
1029           }
1030         }
1031  
1032 +#ifdef USE_NNTP
1033 +       if (buffy || option (OPTNEWS))
1034 +#else
1035         if (buffy)
1036 +#endif
1037         {
1038           strfcpy (f, state.entry[menu->current].name, flen);
1039           mutt_expand_path (f, flen);
1040 @@ -946,14 +1188,6 @@ void _mutt_select_file (char *f, size_t
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))
1054           unset_option (OPTIMAPLSUB);
1055 @@ -1055,6 +1289,11 @@ void _mutt_select_file (char *f, size_t
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)
1067 @@ -1321,6 +1560,209 @@ void _mutt_select_file (char *f, size_t
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];
1079 +         int rc;
1080 +         NNTP_DATA *nntp_data;
1081 +
1082 +         rc = nntp_newsrc_parse (CurrentNewsSrv);
1083 +         if (rc < 0)
1084 +           break;
1085 +
1086 +         if (i == OP_CATCHUP)
1087 +           nntp_data = mutt_newsgroup_catchup (CurrentNewsSrv, f->name);
1088 +         else
1089 +           nntp_data = mutt_newsgroup_uncatchup (CurrentNewsSrv, f->name);
1090 +
1091 +         if (nntp_data)
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;
1100 +           folder.ff->is_new = nntp_data->new;
1101 +           folder.ff->nntp_data = nntp_data;
1102 +           FREE (&f->desc);
1103 +           mutt_FormatString (buffer, sizeof (buffer), 0, MuttIndexWindow->cols,
1104 +                       NONULL(GroupFormat), newsgroup_format_str,
1105 +                       (unsigned long) &folder, MUTT_FORMAT_ARROWCURSOR);
1106 +           f->desc = safe_strdup (buffer); */
1107 +           nntp_newsrc_update (CurrentNewsSrv);
1108 +           if (menu->current + 1 < menu->max)
1109 +             menu->current++;
1110 +           menu->redraw = REDRAW_MOTION_RESYNCH;
1111 +         }
1112 +         if (rc)
1113 +           menu->redraw = REDRAW_INDEX;
1114 +         nntp_newsrc_close (CurrentNewsSrv);
1115 +       }
1116 +       break;
1117 +
1118 +      case OP_LOAD_ACTIVE:
1119 +       if (option (OPTNEWS))
1120 +       {
1121 +         NNTP_SERVER *nserv = CurrentNewsSrv;
1122 +         unsigned int i;
1123 +
1124 +         if (nntp_newsrc_parse (nserv) < 0)
1125 +           break;
1126 +
1127 +         for (i = 0; i < nserv->groups_num; i++)
1128 +         {
1129 +           NNTP_DATA *nntp_data = nserv->groups_list[i];
1130 +           if (nntp_data)
1131 +             nntp_data->deleted = 1;
1132 +         }
1133 +         nntp_active_fetch (nserv, 1);
1134 +         nntp_newsrc_update (nserv);
1135 +         nntp_newsrc_close (nserv);
1136 +
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 +       }
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:
1154 +       if (option (OPTNEWS))
1155 +       {
1156 +         NNTP_SERVER *nserv = CurrentNewsSrv;
1157 +         NNTP_DATA *nntp_data;
1158 +         regex_t *rx = (regex_t *) safe_malloc (sizeof (regex_t));
1159 +         char *s = buf;
1160 +         int rc, j = menu->current;
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 +
1178 +           err = REGCOMP (rx, s, REG_NOSUB);
1179 +           if (err)
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 +
1196 +         rc = nntp_newsrc_parse (nserv);
1197 +         if (rc < 0)
1198 +           break;
1199 +
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)
1208 +               nntp_data = mutt_newsgroup_subscribe (nserv, f->name);
1209 +             else
1210 +               nntp_data = mutt_newsgroup_unsubscribe (nserv, f->name);
1211 +/*           if (nntp_data)
1212 +             {
1213 +               FOLDER folder;
1214 +               char buffer[_POSIX_PATH_MAX + SHORT_STRING];
1215 +
1216 +               folder.name = f->name;
1217 +               folder.f = NULL;
1218 +               folder.new = nntp_data->new;
1219 +               folder.nd = nntp_data;
1220 +               FREE (&f->desc);
1221 +               mutt_FormatString (buffer, sizeof (buffer), 0, MuttIndexWindow->cols,
1222 +                               NONULL(GroupFormat), newsgroup_format_str,
1223 +                               (unsigned long) &folder, MUTT_FORMAT_ARROWCURSOR);
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 +         {
1237 +           unsigned int i;
1238 +
1239 +           for (i = 0; nserv && i < nserv->groups_num; i++)
1240 +           {
1241 +             nntp_data = nserv->groups_list[i];
1242 +             if (nntp_data && nntp_data->group && !nntp_data->subscribed)
1243 +             {
1244 +               if (regexec (rx, nntp_data->group, 0, NULL, 0) == 0)
1245 +               {
1246 +                 mutt_newsgroup_subscribe (nserv, nntp_data->group);
1247 +                 add_folder (menu, &state, nntp_data->group, NULL, NULL, nntp_data);
1248 +               }
1249 +             }
1250 +           }
1251 +           init_menu (&state, menu, title, sizeof (title), buffy);
1252 +         }
1253 +         if (rc > 0)
1254 +           menu->redraw = REDRAW_FULL;
1255 +         nntp_newsrc_update (nserv);
1256 +         nntp_clear_cache (nserv);
1257 +         nntp_newsrc_close (nserv);
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    
1277 diff -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
1280 @@ -19,6 +19,10 @@
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;
1291 @@ -44,6 +48,9 @@ struct folder_file
1292  #endif
1293    unsigned has_buffy : 1;
1294    unsigned local : 1; /* folder is on local filesystem */
1295 +#ifdef USE_NNTP
1296 +  NNTP_DATA *nd;
1297 +#endif
1298    unsigned tagged : 1;
1299  };
1300  
1301 diff -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)
1305  
1306    /* check device ID and serial number instead of comparing paths */
1307    if (!Context || Context->magic == MUTT_IMAP || Context->magic == MUTT_POP
1308 +#ifdef USE_NNTP
1309 +      || Context->magic == MUTT_NNTP
1310 +#endif
1311        || stat (Context->path, &contex_sb) != 0)
1312    {
1313      contex_sb.st_dev=0;
1314 @@ -535,6 +538,11 @@ int mutt_buffy_check (int force)
1315         tmp->magic = MUTT_POP;
1316        else
1317  #endif
1318 +#ifdef USE_NNTP
1319 +      if ((tmp->magic == MUTT_NNTP) || mx_is_nntp (tmp->path))
1320 +       tmp->magic = MUTT_NNTP;
1321 +      else
1322 +#endif
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        {
1326 @@ -550,7 +558,11 @@ int mutt_buffy_check (int force)
1327      /* check to see if the folder is the currently selected folder
1328       * before polling */
1329      if (!Context || !Context->path ||
1330 +#ifdef USE_NNTP
1331 +       (( tmp->magic == MUTT_IMAP || tmp->magic == MUTT_POP || tmp->magic == MUTT_NNTP )
1332 +#else
1333         (( tmp->magic == MUTT_IMAP || tmp->magic == MUTT_POP )
1334 +#endif
1335             ? mutt_strcmp (tmp->path, Context->path) :
1336               (sb.st_dev != contex_sb.st_dev || sb.st_ino != contex_sb.st_ino)))
1337      {
1338 diff -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
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>
1351 @@ -48,9 +51,70 @@ int mutt_complete (char *s, size_t slen)
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 +  {
1362 +    NNTP_SERVER *nserv = CurrentNewsSrv;
1363 +    unsigned int n = 0;
1364 +
1365 +    strfcpy (filepart, s, sizeof (filepart));
1366 +
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)
1371 +    {
1372 +      for (; n < nserv->groups_num; n++)
1373 +      {
1374 +       NNTP_DATA *nntp_data = nserv->groups_list[n];
1375 +
1376 +       if (nntp_data && nntp_data->subscribed)
1377 +       {
1378 +         strfcpy (filepart, nntp_data->group, sizeof (filepart));
1379 +         init = 1;
1380 +         n++;
1381 +         break;
1382 +       }
1383 +      }
1384 +    }
1385 +
1386 +    for (; n < nserv->groups_num; n++)
1387 +    {
1388 +      NNTP_DATA *nntp_data = nserv->groups_list[n];
1389 +
1390 +      if (nntp_data && nntp_data->subscribed &&
1391 +         mutt_strncmp (nntp_data->group, filepart, len) == 0)
1392 +      {
1393 +       if (init)
1394 +       {
1395 +         for (i = 0; filepart[i] && nntp_data->group[i]; i++)
1396 +         {
1397 +           if (filepart[i] != nntp_data->group[i])
1398 +           {
1399 +             filepart[i] = 0;
1400 +             break;
1401 +           }
1402 +         }
1403 +         filepart[i] = 0;
1404 +       }
1405 +       else
1406 +       {
1407 +         strfcpy (filepart, nntp_data->group, sizeof (filepart));
1408 +         init = 1;
1409 +       }
1410 +      }
1411 +    }
1412 +
1413 +    strcpy (s, filepart);
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    {
1422 diff -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 @@
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
1434  
1435 +#ifdef USE_NNTP
1436 +#include "nntp.h"
1437 +#endif
1438 +
1439  #include <errno.h>
1440  #include <string.h>
1441  #include <sys/stat.h>
1442 @@ -68,10 +73,20 @@ enum
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  
1455 +#ifdef USE_NNTP
1456 +int HeaderPadding[HDR_XCOMMENTTO + 1] = {0};
1457 +#else
1458  int HeaderPadding[HDR_CRYPTINFO + 1] = {0};
1459 +#endif
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: ")
1474 +#endif
1475  };
1476  
1477  static const struct mapping_t ComposeHelp[] = {
1478 @@ -126,6 +149,21 @@ static const struct mapping_t ComposeHel
1479    { NULL,      0 }
1480  };
1481  
1482 +#ifdef USE_NNTP
1483 +static struct mapping_t ComposeNewsHelp[] = {
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 }
1494 +};
1495 +#endif
1496 +
1497  static void calc_header_width_padding (int idx, const char *header, int calc_max)
1498  {
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);
1503  
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
1512    {
1513      HeaderPadding[i] += MaxHeaderWidth;
1514      if (HeaderPadding[i] < 0)
1515 @@ -357,9 +402,37 @@ static void draw_envelope_addr (int line
1516  static void draw_envelope (HEADER *msg, char *fcc)
1517  {
1518    draw_envelope_addr (HDR_FROM, msg->env->from);
1519 +#ifdef USE_NNTP
1520 +  if (option (OPTNEWSSEND))
1521 +  {
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;
1526 +    mutt_paddstr (W, NONULL (msg->env->newsgroups));
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;
1532 +    mutt_paddstr (W, NONULL (msg->env->followup_to));
1533 +
1534 +    if (option (OPTXCOMMENTTO))
1535 +    {
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;
1540 +      mutt_paddstr (W, NONULL (msg->env->x_comment_to));
1541 +    }
1542 +  }
1543 +  else
1544 +#endif
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,   /*
1554    int oldSort, oldSortAux;
1555    struct stat st;
1556    compose_redraw_data_t rd;
1557 +#ifdef USE_NNTP
1558 +  int news = 0;                /* is it a news article ? */
1559 +
1560 +  if (option (OPTNEWSSEND))
1561 +    news++;
1562 +#endif
1563  
1564    init_header_padding ();
1565  
1566 @@ -722,6 +801,11 @@ int mutt_compose_menu (HEADER *msg,   /*
1567    menu->offset = HDR_ATTACH;
1568    menu->make_entry = snd_entry;
1569    menu->tag = mutt_tag_attach;
1570 +#ifdef USE_NNTP
1571 +  if (news)
1572 +    menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeNewsHelp);
1573 +  else
1574 +#endif
1575    menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp);
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  
1580    while (loop)
1581    {
1582 +#ifdef USE_NNTP
1583 +    unset_option (OPTNEWS);    /* for any case */
1584 +#endif
1585      switch (op = mutt_menuLoop (menu))
1586      {
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);
1590         break;
1591        case OP_COMPOSE_EDIT_TO:
1592 +#ifdef USE_NNTP
1593 +       if (news)
1594 +         break;
1595 +#endif
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);
1601          break;
1602        case OP_COMPOSE_EDIT_BCC:
1603 +#ifdef USE_NNTP
1604 +       if (news)
1605 +         break;
1606 +#endif
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);
1612         break;
1613        case OP_COMPOSE_EDIT_CC:
1614 +#ifdef USE_NNTP
1615 +       if (news)
1616 +         break;
1617 +#endif
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); 
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;
1633 +         if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0)
1634 +         {
1635 +           mutt_str_replace (&msg->env->newsgroups, buf);
1636 +           move (HDR_TO, HDR_XOFFSET);
1637 +           if (msg->env->newsgroups)
1638 +             mutt_paddstr (W, msg->env->newsgroups);
1639 +           else
1640 +             clrtoeol ();
1641 +         }
1642 +       }
1643 +       break;
1644 +      case OP_COMPOSE_EDIT_FOLLOWUP_TO:
1645 +       if (news)
1646 +       {
1647 +         if (msg->env->followup_to)
1648 +           strfcpy (buf, msg->env->followup_to, sizeof (buf));
1649 +         else
1650 +           buf[0] = 0;
1651 +         if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0)
1652 +         {
1653 +           mutt_str_replace (&msg->env->followup_to, buf);
1654 +           move (HDR_CC, HDR_XOFFSET);
1655 +           if (msg->env->followup_to)
1656 +             mutt_paddstr (W, msg->env->followup_to);
1657 +           else
1658 +             clrtoeol ();
1659 +         }
1660 +       }
1661 +       break;
1662 +      case OP_COMPOSE_EDIT_X_COMMENT_TO:
1663 +       if (news && option (OPTXCOMMENTTO))
1664 +       {
1665 +         if (msg->env->x_comment_to)
1666 +           strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
1667 +         else
1668 +           buf[0] = 0;
1669 +         if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0)
1670 +         {
1671 +           mutt_str_replace (&msg->env->x_comment_to, buf);
1672 +           move (HDR_BCC, HDR_XOFFSET);
1673 +           if (msg->env->x_comment_to)
1674 +             mutt_paddstr (W, msg->env->x_comment_to);
1675 +           else
1676 +             clrtoeol ();
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));
1684 @@ -910,6 +1065,9 @@ int mutt_compose_menu (HEADER *msg,   /*
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;
1694 @@ -917,7 +1075,22 @@ int mutt_compose_menu (HEADER *msg,   /*
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 +         {
1702 +           if (!(CurrentNewsSrv = nntp_select_server (NewsServer, 0)))
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
1712 +         if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == MUTT_NNTP))
1713 +#endif
1714           {
1715             strfcpy (fname, NONULL (Context->path), sizeof (fname));
1716             mutt_pretty_mailbox (fname, sizeof (fname));
1717 @@ -926,6 +1099,11 @@ int mutt_compose_menu (HEADER *msg,   /*
1718           if (mutt_enter_fname (prompt, fname, sizeof (fname), 1) == -1 || !fname[0])
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))
1729 @@ -933,6 +1111,9 @@ int mutt_compose_menu (HEADER *msg,   /*
1730  #ifdef USE_POP
1731            if (!mx_is_pop (fname))
1732  #endif
1733 +#ifdef USE_NNTP
1734 +         if (!mx_is_nntp (fname) && !option (OPTNEWS))
1735 +#endif
1736           /* check to make sure the file exists and is readable */
1737           if (access (fname, R_OK) == -1)
1738           {
1739 diff -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. */
1747 +#undef USE_NNTP
1748 +
1749  /* Define if you want support for the POP3 protocol. */
1750  #undef USE_POP
1751  
1752 diff -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)
1758  
1759 +AC_ARG_ENABLE(nntp, AC_HELP_STRING([--enable-nntp],[Enable NNTP support]),
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"
1763 +               need_nntp="yes"
1764 +               need_socket="yes"
1765 +       fi
1766 +])
1767 +
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
1779  
1780 diff -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
1783 @@ -22,6 +22,7 @@
1784  
1785  #include "mutt.h"
1786  #include "mutt_curses.h"
1787 +#include "mx.h"
1788  #include "mutt_menu.h"
1789  #include "mailbox.h"
1790  #include "mapping.h"
1791 @@ -43,6 +44,10 @@
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>
1802 @@ -547,12 +552,27 @@ static void index_menu_redraw (MUTTMENU
1803    menu->redraw = 0;
1804  }
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 },
1816 +  { NULL,           0 }
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;
1830 @@ -571,7 +591,11 @@ int mutt_index_menu (void)
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
1837 +       (Context && (Context->magic == MUTT_NNTP)) ? IndexNewsHelp :
1838 +#endif
1839 +       IndexHelp);
1840    menu->custom_menu_redraw = index_menu_redraw;
1841    mutt_push_current_menu (menu);
1842  
1843 @@ -786,6 +810,9 @@ int mutt_index_menu (void)
1844        mutt_curs_set (1);       /* fallback from the pager */
1845      }
1846  
1847 +#ifdef USE_NNTP
1848 +    unset_option (OPTNEWS);    /* for any case */
1849 +#endif
1850      switch (op)
1851      {
1852  
1853 @@ -836,6 +863,161 @@ int mutt_index_menu (void)
1854         menu_current_bottom (menu);
1855         break;
1856  
1857 +#ifdef USE_NNTP
1858 +      case OP_GET_PARENT:
1859 +       CHECK_MSGCOUNT;
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)
1867 +       {
1868 +         HEADER *hdr;
1869 +
1870 +         if (op == OP_GET_MESSAGE)
1871 +         {
1872 +           buf[0] = 0;
1873 +           if (mutt_get_field (_("Enter Message-Id: "),
1874 +               buf, sizeof (buf), 0) != 0 || !buf[0])
1875 +             break;
1876 +         }
1877 +         else
1878 +         {
1879 +           LIST *ref = CURHDR->env->references;
1880 +           if (!ref)
1881 +           {
1882 +             mutt_error _("Article has no parent reference.");
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);
1889 +         hdr = hash_find (Context->id_hash, buf);
1890 +         if (hdr)
1891 +         {
1892 +           if (hdr->virtual != -1)
1893 +           {
1894 +             menu->current = hdr->virtual;
1895 +             menu->redraw = REDRAW_MOTION_RESYNCH;
1896 +           }
1897 +           else if (hdr->collapsed)
1898 +           {
1899 +             mutt_uncollapse_thread (Context, hdr);
1900 +             mutt_set_virtual (Context);
1901 +             menu->current = hdr->virtual;
1902 +             menu->redraw = REDRAW_MOTION_RESYNCH;
1903 +           }
1904 +           else
1905 +             mutt_error _("Message is not visible in limited view.");
1906 +         }
1907 +         else
1908 +         {
1909 +           int rc;
1910 +
1911 +           mutt_message (_("Fetching %s from server..."), buf);
1912 +           rc = nntp_check_msgid (Context, buf);
1913 +           if (rc == 0)
1914 +           {
1915 +             hdr = Context->hdrs[Context->msgcount - 1];
1916 +             mutt_sort_headers (Context, 0);
1917 +             menu->current = hdr->virtual;
1918 +             menu->redraw = REDRAW_FULL;
1919 +           }
1920 +           else if (rc > 0)
1921 +             mutt_error (_("Article %s not found on the server."), buf);
1922 +         }
1923 +       }
1924 +       break;
1925 +
1926 +      case OP_GET_CHILDREN:
1927 +      case OP_RECONSTRUCT_THREAD:
1928 +       CHECK_MSGCOUNT;
1929 +       CHECK_VISIBLE;
1930 +       CHECK_READONLY;
1931 +       CHECK_ATTACH;
1932 +       if (Context->magic == MUTT_NNTP)
1933 +       {
1934 +         int oldmsgcount = Context->msgcount;
1935 +         int oldindex = CURHDR->index;
1936 +         int rc = 0;
1937 +
1938 +         if (!CURHDR->env->message_id)
1939 +         {
1940 +           mutt_error _("No Message-Id. Unable to perform operation.");
1941 +           break;
1942 +         }
1943 +
1944 +         mutt_message _("Fetching message headers...");
1945 +         if (!Context->id_hash)
1946 +           Context->id_hash = mutt_make_id_hash (Context);
1947 +         strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
1948 +
1949 +         /* trying to find msgid of the root message */
1950 +         if (op == OP_RECONSTRUCT_THREAD)
1951 +         {
1952 +           LIST *ref = CURHDR->env->references;
1953 +           while (ref)
1954 +           {
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 +
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 +         }
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)
1975 +         {
1976 +           HEADER *hdr;
1977 +           int i, quiet = Context->quiet;
1978 +
1979 +           if (rc < 0)
1980 +             Context->quiet = 1;
1981 +           mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
1982 +           Context->quiet = quiet;
1983 +
1984 +           /* if the root message was retrieved, move to it */
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 +           {
1992 +             for (i = 0; i < Context->msgcount; i++)
1993 +             {
1994 +               if (Context->hdrs[i]->index == oldindex)
1995 +               {
1996 +                 menu->current = Context->hdrs[i]->virtual;
1997 +                 /* as an added courtesy, recenter the menu
1998 +                  * with the current entry at the middle of the screen */
1999 +                 menu_check_recenter (menu);
2000 +                 menu_current_middle (menu);
2001 +               }
2002 +             }
2003 +           }
2004 +           menu->redraw = REDRAW_FULL;
2005 +         }
2006 +         else if (rc >= 0)
2007 +           mutt_error _("No deleted messages found in the thread.");
2008 +       }
2009 +       break;
2010 +#endif
2011 +
2012        case OP_JUMP:
2013  
2014         CHECK_MSGCOUNT;
2015 @@ -946,11 +1128,33 @@ int mutt_index_menu (void)
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;
2024 -       if (mutt_pattern_func (MUTT_LIMIT, _("Limit to messages matching: ")) == 0)
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 +       }
2045 +       if ((op == OP_TOGGLE_READ && mutt_pattern_func (MUTT_LIMIT, NULL) == 0) ||
2046 +           mutt_pattern_func (MUTT_LIMIT, _("Limit to messages matching: ")) == 0)
2047         {
2048           if (menu->oldcurrent >= 0)
2049           {
2050 @@ -1195,15 +1399,22 @@ int mutt_index_menu (void)
2051  #endif
2052        case OP_MAIN_CHANGE_FOLDER:
2053        case OP_MAIN_NEXT_UNREAD_MAILBOX:
2054 -
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)
2071 +         flags = MUTT_READONLY;
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");
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            }
2084 +#ifdef USE_NNTP
2085 +         if (op == OP_MAIN_CHANGE_GROUP ||
2086 +             op == OP_MAIN_CHANGE_GROUP_READONLY)
2087 +         {
2088 +           set_option (OPTNEWS);
2089 +           CurrentNewsSrv = nntp_select_server (NewsServer, 0);
2090 +           if (!CurrentNewsSrv)
2091 +             break;
2092 +           if (flags)
2093 +             cp = _("Open newsgroup in read-only mode");
2094 +           else
2095 +             cp = _("Open newsgroup");
2096 +           nntp_buffy (buf, sizeof (buf));
2097 +         }
2098 +         else
2099 +#endif
2100           mutt_buffy (buf, sizeof (buf));
2101  
2102            if (mutt_enter_fname (cp, buf, sizeof (buf), 1) == -1)
2103 @@ -1255,6 +1482,14 @@ int mutt_index_menu (void)
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         {
2118 @@ -1307,9 +1542,7 @@ int mutt_index_menu (void)
2119           * switch statement would need to be run. */
2120         mutt_folder_hook (buf);
2121  
2122 -       if ((Context = mx_open_mailbox (buf,
2123 -                                       (option (OPTREADONLY) || op == OP_MAIN_CHANGE_FOLDER_READONLY) ?
2124 -                                       MUTT_READONLY : 0, NULL)) != NULL)
2125 +       if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL)
2126         {
2127           menu->current = ci_first_message ();
2128         }
2129 @@ -1320,6 +1553,12 @@ int mutt_index_menu (void)
2130          mutt_sb_set_open_buffy ();
2131  #endif
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,
2136 +         (Context && (Context->magic == MUTT_NNTP)) ? IndexNewsHelp : IndexHelp);
2137 +#endif
2138 +
2139         mutt_clear_error ();
2140         mutt_buffy_check(1); /* force the buffy check after we have changed
2141                               the folder */
2142 @@ -1397,6 +1636,7 @@ int mutt_index_menu (void)
2143         CHECK_MSGCOUNT;
2144          CHECK_VISIBLE;
2145         CHECK_READONLY;
2146 +       CHECK_ACL(MUTT_ACL_WRITE, _("Cannot break thread"));
2147  
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)
2160         }
2161         break;
2162  
2163 +#ifdef USE_NNTP
2164 +      case OP_CATCHUP:
2165 +       CHECK_MSGCOUNT;
2166 +       CHECK_READONLY;
2167 +       CHECK_ATTACH
2168 +       if (Context && Context->magic == MUTT_NNTP)
2169 +       {
2170 +         NNTP_DATA *nntp_data = Context->data;
2171 +         if (mutt_newsgroup_catchup (nntp_data->nserv, nntp_data->group))
2172 +           menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2173 +       }
2174 +       break;
2175 +#endif
2176 +
2177        case OP_DISPLAY_ADDRESS:
2178  
2179         CHECK_MSGCOUNT;
2180 @@ -2326,6 +2580,39 @@ int mutt_index_menu (void)
2181          menu->redraw = REDRAW_FULL;
2182          break;
2183  
2184 +#ifdef USE_NNTP
2185 +      case OP_FOLLOWUP:
2186 +      case OP_FORWARD_TO_GROUP:
2187 +
2188 +       CHECK_MSGCOUNT;
2189 +       CHECK_VISIBLE;
2190 +
2191 +      case OP_POST:
2192 +
2193 +       CHECK_ATTACH;
2194 +       if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2195 +           mutt_strcasecmp (CURHDR->env->followup_to, "poster") ||
2196 +           query_quadoption (OPT_FOLLOWUPTOPOSTER,
2197 +           _("Reply by mail as poster prefers?")) != MUTT_YES)
2198 +       {
2199 +         if (Context && Context->magic == MUTT_NNTP &&
2200 +             !((NNTP_DATA *)Context->data)->allowed &&
2201 +             query_quadoption (OPT_TOMODERATED,
2202 +             _("Posting to this group not allowed, may be moderated. Continue?")) != MUTT_YES)
2203 +           break;
2204 +         if (op == OP_POST)
2205 +           ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2206 +         else
2207 +         {
2208 +           CHECK_MSGCOUNT;
2209 +           ci_send_message ((op == OP_FOLLOWUP ? SENDREPLY : SENDFORWARD) |
2210 +                       SENDNEWS, NULL, NULL, Context, tag ? NULL : CURHDR);
2211 +         }
2212 +         menu->redraw = REDRAW_FULL;
2213 +         break;
2214 +       }
2215 +#endif
2216 +
2217        case OP_REPLY:
2218  
2219         CHECK_ATTACH;
2220 diff -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
2224  
2225  </sect1>
2226  
2227 +<sect1 id="nntp">
2228 +<title>Reading news via NNTP</title>
2229 +
2230 +<para>
2231 +If compiled with <emphasis>--enable-nntp</emphasis> option, Mutt can
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.
2243 +</para>
2244 +
2245 +</sect1>
2246 +
2247  </chapter>
2248  
2249  <chapter id="configuration">
2250 diff -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
2253 @@ -23,8 +23,8 @@ mutt \- The Mutt Mail User Agent
2254  .SH SYNOPSIS
2255  .PP
2256  .B mutt
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]
2261  .PP
2262  .B mutt 
2263  [\-Enx] 
2264 @@ -104,6 +104,10 @@ files.
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"
2269 +Start Mutt with a listing of subscribed newsgroups at specified news server.
2270 +.IP "-G"
2271 +Start Mutt with a listing of subscribed newsgroups.
2272  .IP "-h"
2273  Display help.
2274  .IP "-H \fIdraft\fP"
2275 diff -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
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
2283 +  { "change-newsgroup",                OP_MAIN_CHANGE_GROUP,           "i" },
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" },
2289 @@ -103,7 +107,15 @@ const struct binding_t OpMain[] = { /* m
2290    { "edit-label",              OP_EDIT_LABEL,                  "Y" },
2291    { "edit-type",               OP_EDIT_TYPE,                   "\005" },
2292    { "forward-message",         OP_FORWARD_MESSAGE,             "f" },
2293 -  { "flag-message",            OP_FLAG_MESSAGE,                "F" },
2294 +#ifdef USE_NNTP
2295 +  { "forward-to-group",                OP_FORWARD_TO_GROUP,            "\033F" },
2296 +  { "followup-message",                OP_FOLLOWUP,                    "F" },
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
2302 +  { "flag-message",            OP_FLAG_MESSAGE,                "\033f" },
2303    { "group-reply",             OP_GROUP_REPLY,                 "g" },
2304  #ifdef USE_POP
2305    { "fetch-mail",              OP_MAIN_FETCH_MAIL,             "G" },
2306 @@ -131,6 +143,9 @@ const struct binding_t OpMain[] = { /* m
2307    { "sort-mailbox",            OP_SORT,                        "o" },
2308    { "sort-reverse",            OP_SORT_REVERSE,                "O" },
2309    { "print-message",           OP_PRINT,                       "p" },
2310 +#ifdef USE_NNTP
2311 +  { "post-message",            OP_POST,                        "P" },
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" },
2316 @@ -150,6 +165,10 @@ const struct binding_t OpMain[] = { /* m
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
2324    { "display-message",         OP_DISPLAY_MESSAGE,             MUTT_ENTER_S },
2325    { "mark-message",            OP_MARK_MSG,                    "~" },
2326    { "buffy-list",              OP_BUFFY_LIST,                  "." },
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[] = { /*
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
2341 +  { "change-newsgroup",                OP_MAIN_CHANGE_GROUP,           "i" },
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" },
2347 @@ -204,8 +227,12 @@ const struct binding_t OpPager[] = { /*
2348    { "edit",            OP_EDIT_MESSAGE,                "e" },
2349    { "edit-label",      OP_EDIT_LABEL,                  "Y" },
2350    { "edit-type",       OP_EDIT_TYPE,                   "\005" },
2351 +#ifdef USE_NNTP
2352 +  { "followup-message",        OP_FOLLOWUP,                    "F" },
2353 +  { "forward-to-group",        OP_FORWARD_TO_GROUP,            "\033F" },
2354 +#endif
2355    { "forward-message", OP_FORWARD_MESSAGE,             "f" },
2356 -  { "flag-message",    OP_FLAG_MESSAGE,                "F" },
2357 +  { "flag-message",    OP_FLAG_MESSAGE,                "\033f" },
2358    { "group-reply",     OP_GROUP_REPLY,                 "g" },
2359  #ifdef USE_IMAP
2360    { "imap-fetch-mail",  OP_MAIN_IMAP_FETCH,            NULL },
2361 @@ -227,6 +254,9 @@ const struct binding_t OpPager[] = { /*
2362    { "sort-mailbox",    OP_SORT,                        "o" },
2363    { "sort-reverse",    OP_SORT_REVERSE,                "O" },
2364    { "print-message",   OP_PRINT,                       "p" },
2365 +#ifdef USE_NNTP
2366 +  { "post-message",    OP_POST,                        "P" },
2367 +#endif
2368    { "previous-thread", OP_MAIN_PREV_THREAD,            "\020" },
2369    { "previous-subthread",OP_MAIN_PREV_SUBTHREAD,       "\033p" },
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[] = { /*
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
2385 +  { "followup-message",        OP_FOLLOWUP,                    "F" },
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,                        "|" },
2391 @@ -334,6 +368,7 @@ const struct binding_t OpAttach[] = { /*
2392  const struct binding_t OpCompose[] = { /* map: compose */
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" },
2399 @@ -353,6 +388,11 @@ const struct binding_t OpCompose[] = { /
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" },
2410    { "rename-attachment",OP_COMPOSE_RENAME_ATTACHMENT,  "\017" },
2411 @@ -405,14 +445,25 @@ const struct binding_t OpBrowser[] = { /
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 }
2437 diff -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;
2450  #endif
2451  
2452  WHERE char *Muttrc INITVAL (NULL);
2453 +#ifdef USE_NNTP
2454 +WHERE char *GroupFormat;
2455 +WHERE char *Inews;
2456 +WHERE char *NewsCacheDir;
2457 +WHERE char *NewsServer;
2458 +WHERE char *NewsgroupsCharset;
2459 +WHERE char *NewsRc;
2460 +WHERE char *NntpAuthenticators;
2461 +WHERE char *NntpUser;
2462 +WHERE char *NntpPass;
2463 +#endif
2464  WHERE char *Outbox;
2465  WHERE char *Pager;
2466  WHERE char *PagerFmt;
2467 @@ -207,6 +218,11 @@ extern unsigned char QuadOptions[];
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;
2477  WHERE short ErrorHistSize;
2478  WHERE short HistSize;
2479 diff -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);
2485  
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
2491 +
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);
2499 +
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
2505  }
2506  
2507  static int
2508 diff -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
2512   * %E = number of messages in current thread
2513   * %f = entire from line
2514   * %F = like %n, unless from self
2515 + * %g = newsgroup name (if compiled with NNTP support)
2516   * %i = message-id
2517   * %l = number of lines in the message
2518   * %L = like %F, except `lists' are displayed first
2519 @@ -243,6 +244,8 @@ static char *apply_subject_mods (ENVELOP
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)
2524 + * %x = `x-comment-to:' field (if present and compiled with NNTP support)
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)
2528 @@ -474,6 +477,12 @@ hdr_format_str (char *dest,
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;
2541 @@ -678,6 +687,22 @@ hdr_format_str (char *dest,
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;
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
2560 +
2561      case 'Z':
2562      
2563        ch = ' ';
2564 diff -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
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 */
2571 +#ifdef USE_NNTP
2572 +  if (!option (OPTNEWSSEND))
2573 +#endif
2574    if (msg->env->in_reply_to &&
2575        (!n->in_reply_to || mutt_strcmp (n->in_reply_to->data,
2576                                        msg->env->in_reply_to->data) != 0))
2577 diff -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  
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);
2593 +      p = buffer;
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")))
2609 diff -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[] = {
2613    ** If \fIset\fP, Mutt will prompt you for carbon-copy (Cc) recipients before
2614    ** editing the body of an outgoing message.
2615    */
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.
2622 +  */
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.
2628 +  */
2629 +#endif
2630    { "assumed_charset", DT_STR, R_NONE, UL &AssumedCharset, UL 0},
2631    /*
2632    ** .pp
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.
2636    */
2637 +#ifdef USE_NNTP
2638 +  { "catchup_newsgroup", DT_QUAD, R_NONE, OPT_CATCHUP, MUTT_ASKYES },
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
2645  #if defined(USE_SSL)
2646    { "certificate_file",        DT_PATH, R_NONE, UL &SslCertFile, UL "~/.mutt_certificates" },
2647    /*
2648 @@ -926,6 +948,16 @@ struct option_t MuttVars[] = {
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
2653 +  { "followup_to_poster", DT_QUAD, R_NONE, OPT_FOLLOWUPTOPOSTER, MUTT_ASKYES },
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
2665 @@ -1024,6 +1056,26 @@ struct option_t MuttVars[] = {
2666    ** a regular expression that will match the whole name so mutt will expand
2667    ** ``Franklin'' to ``Franklin, Steve''.
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:
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
2687 +  */
2688 +#endif
2689    { "hdr_format",      DT_SYN,  R_NONE, UL "index_format", 0 },
2690    /*
2691    */
2692 @@ -1445,6 +1497,7 @@ struct option_t MuttVars[] = {
2693    ** .dt %E .dd number of messages in current thread
2694    ** .dt %f .dd sender (address + real name), either From: or Return-Path:
2695    ** .dt %F .dd author name, or recipient name if the message is from you
2696 +  ** .dt %g .dd newsgroup name (if compiled with NNTP support)
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,
2700 @@ -1468,6 +1521,8 @@ struct option_t MuttVars[] = {
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
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)
2706    ** .dt %X .dd number of attachments
2707    **            (please see the ``$attachments'' section for possible speed effects)
2708    ** .dt %y .dd ``X-Label:'' field, if present
2709 @@ -1506,6 +1561,25 @@ struct option_t MuttVars[] = {
2710    ** Note that these expandos are supported in
2711    ** ``$save-hook'', ``$fcc-hook'' and ``$fcc-save-hook'', too.
2712    */
2713 +#ifdef USE_NNTP
2714 +  { "inews",           DT_PATH, R_NONE, UL &Inews, UL "" },
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:
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
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
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.
2738    */
2739 +#ifdef USE_NNTP
2740 +  { "mime_subject",    DT_BOOL, R_NONE, OPTMIMESUBJECT, 1 },
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
2748  #ifdef MIXMASTER
2749    { "mix_entry_format", DT_STR,  R_NONE, UL &MixEntryFormat, UL "%4n %c %-16s %a" },
2750    /*
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    */
2755 +#ifdef USE_NNTP
2756 +  { "news_cache_dir",  DT_PATH, R_NONE, UL &NewsCacheDir, UL "~/.mutt" },
2757 +  /*
2758 +  ** .pp
2759 +  ** This variable pointing to directory where Mutt will save cached news
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.
2762 +  */
2763 +  { "news_server",     DT_STR, R_NONE, UL &NewsServer, 0 },
2764 +  /*
2765 +  ** .pp
2766 +  ** This variable specifies domain name or address of NNTP server. It
2767 +  ** defaults to the news server specified in the environment variable
2768 +  ** $$$NNTPSERVER or contained in the file /etc/nntpserver.  You can also
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 +  /*
2775 +  ** .pp
2776 +  ** Character set of newsgroups descriptions.
2777 +  */
2778 +  { "newsrc",          DT_PATH, R_NONE, UL &NewsRc, UL "~/.newsrc" },
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:
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.
2803 +  ** .pp
2804 +  ** Example:
2805 +  ** .ts
2806 +  ** set nntp_authenticators="digest-md5:user"
2807 +  ** .te
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.
2812 +  */
2813 +  { "nntp_context",    DT_NUM, R_NONE, UL &NntpContext, 1000 },
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 +  */
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 +  */
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 +  */
2834 +  { "nntp_user",       DT_STR, R_NONE, UL &NntpUser, UL "" },
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
2839 +  ** connect to news server.
2840 +  */
2841 +  { "nntp_pass",       DT_STR, R_NONE, UL &NntpPass, UL "" },
2842 +  /*
2843 +  ** .pp
2844 +  ** Your password for NNTP account.
2845 +  */
2846 +  { "nntp_poll",       DT_NUM, R_NONE, UL &NewsPollTimeout, 60 },
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 +  */
2854 +#endif
2855    { "pager",           DT_PATH, R_NONE, UL &Pager, UL "builtin" },
2856    /*
2857    ** .pp
2858 @@ -2395,6 +2578,16 @@ struct option_t MuttVars[] = {
2859    { "post_indent_str",  DT_SYN,  R_NONE, UL "post_indent_string", 0 },
2860    /*
2861    */
2862 +#ifdef USE_NNTP
2863 +  { "post_moderated",  DT_QUAD, R_NONE, OPT_TOMODERATED, MUTT_ASKYES },
2864 +  /*
2865 +  ** .pp
2866 +  ** If set to \fIyes\fP, Mutt will post article to newsgroup that have
2867 +  ** not permissions to posting (e.g. moderated).  \fBNote:\fP if news server
2868 +  ** does not support posting to that newsgroup or totally read-only, that
2869 +  ** posting will not have an effect.
2870 +  */
2871 +#endif
2872    { "postpone",                DT_QUAD, R_NONE, OPT_POSTPONE, MUTT_ASKYES },
2873    /*
2874    ** .pp
2875 @@ -2875,6 +3068,28 @@ struct option_t MuttVars[] = {
2876    ** Command to use when spawning a subshell.  By default, the user's login
2877    ** shell from \fC/etc/passwd\fP is used.
2878    */
2879 +#ifdef USE_NNTP
2880 +  { "save_unsubscribed", DT_BOOL, R_NONE, OPTSAVEUNSUB, 0 },
2881 +  /*
2882 +  ** .pp
2883 +  ** When \fIset\fP, info about unsubscribed newsgroups will be saved into
2884 +  ** ``newsrc'' file and into cache.
2885 +  */
2886 +  { "show_new_news",   DT_BOOL, R_NONE, OPTSHOWNEWNEWS, 1 },
2887 +  /*
2888 +  ** .pp
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.
2891 +  ** Also controls whether or not number of new articles of subscribed
2892 +  ** newsgroups will be then checked.
2893 +  */
2894 +  { "show_only_unread",        DT_BOOL, R_NONE, OPTSHOWONLYUNREAD, 0 },
2895 +  /*
2896 +  ** .pp
2897 +  ** If \fIset\fP, only subscribed newsgroups that contain unread articles
2898 +  ** will be displayed in browser.
2899 +  */
2900 +#endif
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 },
2906    /*
2907    */
2908 +#ifdef USE_NNTP
2909 +  { "x_comment_to",    DT_BOOL, R_NONE, OPTXCOMMENTTO, 0 },
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    /*--*/
2917    { NULL, 0, 0, 0, 0 }
2918  };
2919 diff -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);
2930 diff -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 *);
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 *);
2943 diff -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>
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\
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\
2959    -f <file>\tspecify which mailbox to read\n\
2960    -F <file>\tspecify an alternate muttrc file\n\
2961 +  -g <server>\tspecify a news server (if compiled with NNTP)\n\
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\
2966 @@ -298,6 +304,12 @@ static void show_version (void)
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
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 */
2984  
2985  int main (int argc, char **argv, char **environ)
2986  {
2987 @@ -682,7 +695,11 @@ int main (int argc, char **argv, char **
2988          argv[nargc++] = argv[optind];
2989      }
2990  
2991 +#ifdef USE_NNTP
2992 +    if ((i = getopt (argc, argv, "+A:a:b:F:f:c:Dd:Ee:g:GH:s:i:hm:npQ:RvxyzZ")) != EOF)
2993 +#else
2994      if ((i = getopt (argc, argv, "+A:a:b:F:f:c:Dd:Ee:H:s:i:hm:npQ:RvxyzZ")) != EOF)
2995 +#endif
2996        switch (i)
2997        {
2998        case 'A':
2999 @@ -783,6 +800,20 @@ int main (int argc, char **argv, char **
3000         flags |= MUTT_SELECT;
3001         break;
3002  
3003 +#ifdef USE_NNTP
3004 +      case 'g': /* Specify a news server */
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 */
3013 +       flags |= MUTT_SELECT | MUTT_NEWS;
3014 +       break;
3015 +#endif
3016 +
3017        case 'z':
3018         flags |= MUTT_IGNORE;
3019         break;
3020 @@ -1229,6 +1260,18 @@ int main (int argc, char **argv, char **
3021      }
3022      else if (flags & MUTT_SELECT)
3023      {
3024 +#ifdef USE_NNTP
3025 +      if (flags & MUTT_NEWS)
3026 +      {
3027 +       set_option (OPTNEWS);
3028 +       if(!(CurrentNewsSrv = nntp_select_server (NewsServer, 0)))
3029 +       {
3030 +         mutt_endwin (Errorbuf);
3031 +         exit (1);
3032 +       }
3033 +      }
3034 +      else
3035 +#endif
3036        if (!Incoming)
3037        {
3038          exit_endwin_msg = _("No incoming mailboxes defined.");
3039 @@ -1244,6 +1287,15 @@ int main (int argc, char **argv, char **
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);
3055 diff -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,
3062 +#ifdef USE_NNTP
3063 +  MUTT_NEWSGROUPS,
3064 +#endif
3065    
3066    /* Options for Mailcap lookup */
3067    MUTT_EDIT,
3068 @@ -311,6 +314,11 @@ enum
3069  #endif
3070    OPT_SUBJECT,
3071    OPT_VERIFYSIG,      /* verify PGP signatures */
3072 +#ifdef USE_NNTP
3073 +  OPT_TOMODERATED,
3074 +  OPT_CATCHUP,
3075 +  OPT_FOLLOWUPTOPOSTER,
3076 +#endif
3077      
3078    /* THIS MUST BE THE LAST VALUE. */
3079    OPT_MAX
3080 @@ -329,6 +337,7 @@ enum
3081  #define SENDNOFREEHEADER       (1<<10)   /* Used by the -E flag */
3082  #define SENDDRAFTFILE          (1<<11)   /* Used by the -H flag */
3083  #define SENDTOSENDER    (1<<12)
3084 +#define SENDNEWS       (1<<13)
3085  
3086  /* flags for mutt_compose_menu() */
3087  #define MUTT_COMPOSE_NOFREEHEADER (1<<0)
3088 @@ -351,6 +360,8 @@ enum
3089    OPTASCIICHARS,
3090    OPTASKBCC,
3091    OPTASKCC,
3092 +  OPTASKFOLLOWUP,
3093 +  OPTASKXCOMMENTTO,
3094    OPTATTACHSPLIT,
3095    OPTAUTOEDIT,
3096    OPTAUTOTAG,
3097 @@ -441,6 +452,9 @@ enum
3098    OPTMETOO,
3099    OPTMHPURGE,
3100    OPTMIMEFORWDECODE,
3101 +#ifdef USE_NNTP
3102 +  OPTMIMESUBJECT,      /* encode subject line with RFC2047 */
3103 +#endif
3104    OPTMIMETYPEQUERYFIRST,
3105    OPTNARROWTREE,
3106    OPTPAGERSTOP,
3107 @@ -542,6 +556,17 @@ enum
3108    OPTPGPAUTOINLINE,
3109    OPTPGPREPLYINLINE,
3110  
3111 +  /* news options */
3112 +
3113 +#ifdef USE_NNTP
3114 +  OPTSHOWNEWNEWS,
3115 +  OPTSHOWONLYUNREAD,
3116 +  OPTSAVEUNSUB,
3117 +  OPTLISTGROUP,
3118 +  OPTLOADDESC,
3119 +  OPTXCOMMENTTO,
3120 +#endif
3121 +
3122    /* pseudo options */
3123  
3124    OPTAUXSORT,          /* (pseudo) using auxiliary sort function */
3125 @@ -559,6 +584,7 @@ enum
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.
3133 @@ -569,6 +595,11 @@ enum
3134    OPTDONTHANDLEPGPKEYS,        /* (pseudo) used to extract PGP keys */
3135    OPTIGNOREMACROEVENTS, /* (pseudo) don't process macro/push/exec events while set */
3136  
3137 +#ifdef USE_NNTP
3138 +  OPTNEWS,             /* (pseudo) used to change reader mode */
3139 +  OPTNEWSSEND,         /* (pseudo) used to change behavior when posting */
3140 +#endif
3141 +
3142    OPTMAX
3143  };
3144  
3145 @@ -649,6 +680,13 @@ typedef struct envelope
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 */
3159 @@ -836,7 +874,7 @@ typedef struct header
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    
3168 diff -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;
3183 diff -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)
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__ */
3195 @@ -740,6 +740,13 @@ void mutt_free_envelope (ENVELOPE **p)
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  
3209 @@ -1663,6 +1670,14 @@ int mutt_save_confirm (const char *s, st
3210      }
3211    }
3212  
3213 +#ifdef USE_NNTP
3214 +  if (magic == MUTT_NNTP)
3215 +  {
3216 +    mutt_error _("Can't save message to news server.");
3217 +    return 0;
3218 +  }
3219 +#endif
3220 +
3221    if (stat (s, st) != -1)
3222    {
3223      if (magic == -1)
3224 diff -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)
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;
3272 @@ -395,6 +419,11 @@ int mx_get_magic (const char *path)
3273      return MUTT_POP;
3274  #endif /* USE_POP */
3275  
3276 +#ifdef USE_NNTP
3277 +  if (mx_is_nntp (path))
3278 +    return MUTT_NNTP;
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",
3284 @@ -803,6 +832,25 @@ int mx_close_mailbox (CONTEXT *ctx, int
3285      return 0;
3286    }
3287  
3288 +#ifdef USE_NNTP
3289 +  if (ctx->unread && ctx->magic == MUTT_NNTP)
3290 +  {
3291 +    NNTP_DATA *nntp_data = ctx->data;
3292 +
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 +    }
3304 +  }
3305 +#endif
3306 +
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++;
3312    }
3313  
3314 +#ifdef USE_NNTP
3315 +  /* don't need to move articles from newsgroup */
3316 +  if (ctx->magic == MUTT_NNTP)
3317 +    read_msgs = 0;
3318 +#endif
3319 +
3320    if (read_msgs && quadoption (OPT_MOVE) != MUTT_NO)
3321    {
3322      char *p;
3323 diff -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
3336 diff -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 @@
3340 +/*
3341 + * Copyright (C) 1998 Brandon Long <blong@fiction.net>
3342 + * Copyright (C) 1999 Andrej Gritsenko <andrej@lucky.net>
3343 + * Copyright (C) 2000-2017 Vsevolod Volkov <vvv@mutt.org.ua>
3344 + *
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.
3349 + *
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.
3354 + *
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.
3358 + */
3359 +
3360 +#if HAVE_CONFIG_H
3361 +#include "config.h"
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"
3374 +#include "bcache.h"
3375 +
3376 +#if USE_HCACHE
3377 +#include "hcache.h"
3378 +#endif
3379 +
3380 +#include <unistd.h>
3381 +#include <string.h>
3382 +#include <ctype.h>
3383 +#include <stdlib.h>
3384 +#include <sys/stat.h>
3385 +#include <sys/types.h>
3386 +#include <dirent.h>
3387 +#include <errno.h>
3388 +
3389 +/* Find NNTP_DATA for given newsgroup or add it */
3390 +static NNTP_DATA *nntp_data_find (NNTP_SERVER *nserv, const char *group)
3391 +{
3392 +  NNTP_DATA *nntp_data = hash_find (nserv->groups_hash, group);
3393 +
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);
3403 +
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;
3414 +}
3415 +
3416 +/* Remove all temporarily cache files */
3417 +void nntp_acache_free (NNTP_DATA *nntp_data)
3418 +{
3419 +  int i;
3420 +
3421 +  for (i = 0; i < NNTP_ACACHE_LEN; i++)
3422 +  {
3423 +    if (nntp_data->acache[i].path)
3424 +    {
3425 +      unlink (nntp_data->acache[i].path);
3426 +      FREE (&nntp_data->acache[i].path);
3427 +    }
3428 +  }
3429 +}
3430 +
3431 +/* Free NNTP_DATA, used to destroy hash elements */
3432 +void nntp_data_free (void *data)
3433 +{
3434 +  NNTP_DATA *nntp_data = data;
3435 +
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 +}
3444 +
3445 +/* Unlock and close .newsrc file */
3446 +void nntp_newsrc_close (NNTP_SERVER *nserv)
3447 +{
3448 +  if (!nserv->newsrc_fp)
3449 +    return;
3450 +
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);
3454 +}
3455 +
3456 +/* Parse .newsrc file:
3457 + *  0 - not changed
3458 + *  1 - parsed
3459 + * -1 - error */
3460 +int nntp_newsrc_parse (NNTP_SERVER *nserv)
3461 +{
3462 +  unsigned int i;
3463 +  char *line;
3464 +  struct stat sb;
3465 +
3466 +  /* if file doesn't exist, create it */
3467 +  nserv->newsrc_fp = safe_fopen (nserv->newsrc_file, "a");
3468 +  safe_fclose (&nserv->newsrc_fp);
3469 +
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);
3476 +    return -1;
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))
3482 +  {
3483 +    safe_fclose (&nserv->newsrc_fp);
3484 +    return -1;
3485 +  }
3486 +
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 +  }
3494 +
3495 +  if (nserv->size == sb.st_size && nserv->mtime == sb.st_mtime)
3496 +    return 0;
3497 +
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));
3502 +
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];
3507 +
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 +  }
3515 +
3516 +  line = safe_malloc (sb.st_size + 1);
3517 +  while (sb.st_size && fgets (line, sb.st_size + 1, nserv->newsrc_fp))
3518 +  {
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)
3548 +    {
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++;
3566 +    }
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 +}
3583 +
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;
3592 +
3593 +  if (Sort != SORT_ORDER)
3594 +  {
3595 +    save_sort = Sort;
3596 +    Sort = SORT_ORDER;
3597 +    mutt_sort_headers (ctx, 0);
3598 +  }
3599 +
3600 +  entries = nntp_data->newsrc_len;
3601 +  if (!entries)
3602 +  {
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)
3615 +    {
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 +      }
3632 +    }
3633 +
3634 +    /* search for first read */
3635 +    else
3636 +    {
3637 +      if (ctx->hdrs[i]->deleted || ctx->hdrs[i]->read)
3638 +      {
3639 +       first = last + 1;
3640 +       series = 1;
3641 +      }
3642 +      last = NHDR (ctx->hdrs[i])->article_num;
3643 +    }
3644 +  }
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 +  }
3665 +}
3666 +
3667 +/* Update file with new contents */
3668 +static int update_file (char *filename, char *buf)
3669 +{
3670 +  FILE *fp;
3671 +  char tmpfile[_POSIX_PATH_MAX];
3672 +  int rc = -1;
3673 +
3674 +  while (1)
3675 +  {
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);
3699 +      break;
3700 +    }
3701 +    *tmpfile = '\0';
3702 +    rc = 0;
3703 +    break;
3704 +  }
3705 +  if (fp)
3706 +    fclose (fp);
3707 +  if (*tmpfile)
3708 +    unlink (tmpfile);
3709 +  if (rc)
3710 +    mutt_sleep (2);
3711 +  return rc;
3712 +}
3713 +
3714 +/* Update .newsrc file */
3715 +int nntp_newsrc_update (NNTP_SERVER *nserv)
3716 +{
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;
3737 +
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);
3747 +
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';
3768 +
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)
3772 +  {
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
3782 +    {
3783 +      mutt_perror (nserv->newsrc_file);
3784 +      mutt_sleep (2);
3785 +    }
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];
3796 +
3797 +  /* server subdirectory */
3798 +  if (acct)
3799 +  {
3800 +    ciss_url_t url;
3801 +
3802 +    mutt_account_tourl (acct, &url);
3803 +    url.path = src;
3804 +    url_ciss_tostring (&url, file, sizeof (file), U_PATH);
3805 +  }
3806 +  else
3807 +    strfcpy (file, src ? src : "", sizeof (file));
3808 +
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);
3816 +}
3817 +
3818 +/* Make fully qualified url from newsgroup name */
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 +
3829 +/* Parse newsgroup */
3830 +int nntp_add_group (char *line, void *data)
3831 +{
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;
3838 +
3839 +  if (!nserv || !line)
3840 +    return 0;
3841 +
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;
3875 +
3876 +  if (fgets (buf, sizeof (buf), fp) == NULL ||
3877 +      sscanf (buf, "%ld%s", &t, file) != 1 || t == 0)
3878 +  {
3879 +    fclose (fp);
3880 +    return -1;
3881 +  }
3882 +  nserv->newgroups_time = t;
3883 +
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 +}
3892 +
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;
3901 +
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++)
3911 +  {
3912 +    NNTP_DATA *nntp_data = nserv->groups_list[i];
3913 +
3914 +    if (!nntp_data || nntp_data->deleted)
3915 +      continue;
3916 +
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);
3922 +    }
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);
3928 +  }
3929 +
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 +}
3936 +
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);
3942 +}
3943 +
3944 +/* Open newsgroup hcache */
3945 +header_cache_t *nntp_hcache_open (NNTP_DATA *nntp_data)
3946 +{
3947 +  ciss_url_t url;
3948 +  char file[_POSIX_PATH_MAX];
3949 +
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;
3955 +
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)
3971 +    return;
3972 +
3973 +  /* fetch previous values of first and last */
3974 +  hdata = mutt_hcache_fetch_raw (hc, "index", strlen);
3975 +  if (hdata)
3976 +  {
3977 +    dprint (2, (debugfile,
3978 +               "nntp_hcache_update: mutt_hcache_fetch index: %s\n", hdata));
3979 +    if (sscanf (hdata, ANUM " " ANUM, &first, &last) == 2)
3980 +    {
3981 +      old = 1;
3982 +      nntp_data->lastCached = last;
3983 +
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;
3990 +
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 +  }
3999 +
4000 +  /* store current values of first and last */
4001 +  if (!old || nntp_data->firstMessage != first ||
4002 +             nntp_data->lastMessage != last)
4003 +  {
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);
4009 +  }
4010 +}
4011 +#endif
4012 +
4013 +/* Remove bcache file */
4014 +static int nntp_bcache_delete (const char *id, body_cache_t *bcache, void *data)
4015 +{
4016 +  NNTP_DATA *nntp_data = data;
4017 +  anum_t anum;
4018 +  char c;
4019 +
4020 +  if (!nntp_data || sscanf (id, ANUM "%c", &anum, &c) != 1 ||
4021 +      anum < nntp_data->firstMessage || anum > nntp_data->lastMessage)
4022 +  {
4023 +    if (nntp_data)
4024 +      dprint (2, (debugfile, "nntp_bcache_delete: mutt_bcache_del %s\n", id));
4025 +    mutt_bcache_del (bcache, id);
4026 +  }
4027 +  return 0;
4028 +}
4029 +
4030 +/* Remove stale cached messages */
4031 +void nntp_bcache_update (NNTP_DATA *nntp_data)
4032 +{
4033 +  mutt_bcache_list (nntp_data->bcache, nntp_bcache_delete, nntp_data);
4034 +}
4035 +
4036 +/* Remove hcache and bcache of newsgroup */
4037 +void nntp_delete_group_cache (NNTP_DATA *nntp_data)
4038 +{
4039 +  char file[_POSIX_PATH_MAX];
4040 +
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));
4050 +#endif
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);
4060 +  }
4061 +}
4062 +
4063 +/* Remove hcache and bcache of all unexistent and unsubscribed newsgroups */
4064 +void nntp_clear_cache (NNTP_SERVER *nserv)
4065 +{
4066 +  char file[_POSIX_PATH_MAX];
4067 +  char *fp;
4068 +  struct dirent *entry;
4069 +  DIR *dp;
4070 +
4071 +  if (!nserv || !nserv->cacheable)
4072 +    return;
4073 +
4074 +  cache_expand (file, sizeof (file), &nserv->conn->account, NULL);
4075 +  dp = opendir (file);
4076 +  if (dp)
4077 +  {
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;
4086 +
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;
4094 +
4095 +#ifdef USE_HCACHE
4096 +      if (S_ISREG (sb.st_mode))
4097 +      {
4098 +       char *ext = group + strlen (group) - 7;
4099 +       if (strlen (group) < 8 || mutt_strcmp (ext, ".hcache"))
4100 +         continue;
4101 +       *ext = '\0';
4102 +      }
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)
4110 +      {
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));
4125 +      }
4126 +    }
4127 +    closedir (dp);
4128 +  }
4129 +  return;
4130 +}
4131 +
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)
4149 +  {
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;
4190 +  }
4191 +  return (src);
4192 +}
4193 +
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)
4199 +{
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;
4209 +
4210 +  if (!server || !*server)
4211 +  {
4212 +    mutt_error _("No news server defined!");
4213 +    mutt_sleep (2);
4214 +    return NULL;
4215 +  }
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)
4227 +  {
4228 +    mutt_error (_("%s is an invalid news server specification!"), server);
4229 +    mutt_sleep (2);
4230 +    return NULL;
4231 +  }
4232 +  if (url.scheme == U_NNTPS)
4233 +  {
4234 +    acct.flags |= MUTT_ACCT_SSL;
4235 +    acct.port = NNTP_SSL_PORT;
4236 +  }
4237 +
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)
4243 +  {
4244 +    conn->account.flags |= MUTT_ACCT_USER;
4245 +    conn->account.user[0] = '\0';
4246 +  }
4247 +
4248 +  /* news server already exists */
4249 +  nserv = conn->data;
4250 +  if (nserv)
4251 +  {
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)
4289 +    {
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))
4295 +      {
4296 +       mutt_error (_("Can't create %s: %s."), file, strerror (errno));
4297 +       mutt_sleep (2);
4298 +       break;
4299 +      }
4300 +      if (!p)
4301 +      {
4302 +       nserv->cacheable = 1;
4303 +       break;
4304 +      }
4305 +      *p++ = '/';
4306 +    }
4307 +  }
4308 +
4309 +  /* load .newsrc */
4310 +  if (rc >= 0)
4311 +  {
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);
4317 +  }
4318 +  if (rc >= 0)
4319 +  {
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);
4323 +
4324 +    /* load list of newsgroups from server */
4325 +    else
4326 +      rc = nntp_active_fetch (nserv, 0);
4327 +  }
4328 +
4329 +  if (rc >= 0)
4330 +    nntp_clear_cache (nserv);
4331 +
4332 +#ifdef USE_HCACHE
4333 +  /* check cache files */
4334 +  if (rc >= 0 && nserv->cacheable)
4335 +  {
4336 +    struct dirent *entry;
4337 +    DIR *dp = opendir (file);
4338 +
4339 +    if (dp)
4340 +    {
4341 +      while ((entry = readdir (dp)))
4342 +      {
4343 +       header_cache_t *hc;
4344 +       void *hdata;
4345 +       char *group = entry->d_name;
4346 +
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;
4354 +
4355 +       hc = nntp_hcache_open (nntp_data);
4356 +       if (!hc)
4357 +         continue;
4358 +
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;
4364 +
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);
4383 +      }
4384 +      closedir (dp);
4385 +    }
4386 +  }
4387 +#endif
4388 +
4389 +  if (rc < 0 || !leave_lock)
4390 +    nntp_newsrc_close (nserv);
4391 +
4392 +  if (rc < 0)
4393 +  {
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;
4402 +  }
4403 +
4404 +  conn->data = nserv;
4405 +  return nserv;
4406 +}
4407 +
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)
4413 +{
4414 +  NNTP_DATA *nntp_data = ctx->data;
4415 +  unsigned int i;
4416 +
4417 +  if (group)
4418 +    nntp_data = hash_find (nntp_data->nserv->groups_hash, group);
4419 +
4420 +  if (!nntp_data)
4421 +    return;
4422 +
4423 +  for (i = 0; i < nntp_data->newsrc_len; i++)
4424 +  {
4425 +    if ((anum >= nntp_data->newsrc_ent[i].first) &&
4426 +       (anum <= nntp_data->newsrc_ent[i].last))
4427 +    {
4428 +      /* can't use mutt_set_flag() because mx_update_context()
4429 +        didn't called yet */
4430 +      hdr->read = 1;
4431 +      return;
4432 +    }
4433 +  }
4434 +
4435 +  /* article was not cached yet, it's new */
4436 +  if (anum > nntp_data->lastCached)
4437 +    return;
4438 +
4439 +  /* article isn't read but cached, it's old */
4440 +  if (option (OPTMARKOLD))
4441 +    hdr->old = 1;
4442 +}
4443 +
4444 +/* calculate number of unread articles using .newsrc data */
4445 +void nntp_group_unread_stat (NNTP_DATA *nntp_data)
4446 +{
4447 +  unsigned int i;
4448 +  anum_t first, last;
4449 +
4450 +  nntp_data->unread = 0;
4451 +  if (nntp_data->lastMessage == 0 ||
4452 +      nntp_data->firstMessage > nntp_data->lastMessage)
4453 +    return;
4454 +
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 +  }
4467 +}
4468 +
4469 +/* Subscribe newsgroup */
4470 +NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER *nserv, char *group)
4471 +{
4472 +  NNTP_DATA *nntp_data;
4473 +
4474 +  if (!nserv || !nserv->groups_hash || !group || !*group)
4475 +    return NULL;
4476 +
4477 +  nntp_data = nntp_data_find (nserv, group);
4478 +  nntp_data->subscribed = 1;
4479 +  if (!nntp_data->newsrc_ent)
4480 +  {
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;
4485 +  }
4486 +  return nntp_data;
4487 +}
4488 +
4489 +/* Unsubscribe newsgroup */
4490 +NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER *nserv, char *group)
4491 +{
4492 +  NNTP_DATA *nntp_data;
4493 +
4494 +  if (!nserv || !nserv->groups_hash || !group || !*group)
4495 +    return NULL;
4496 +
4497 +  nntp_data = hash_find (nserv->groups_hash, group);
4498 +  if (!nntp_data)
4499 +    return NULL;
4500 +
4501 +  nntp_data->subscribed = 0;
4502 +  if (!option (OPTSAVEUNSUB))
4503 +  {
4504 +    nntp_data->newsrc_len = 0;
4505 +    FREE (&nntp_data->newsrc_ent);
4506 +  }
4507 +  return nntp_data;
4508 +}
4509 +
4510 +/* Catchup newsgroup */
4511 +NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER *nserv, char *group)
4512 +{
4513 +  NNTP_DATA *nntp_data;
4514 +
4515 +  if (!nserv || !nserv->groups_hash || !group || !*group)
4516 +    return NULL;
4517 +
4518 +  nntp_data = hash_find (nserv->groups_hash, group);
4519 +  if (!nntp_data)
4520 +    return NULL;
4521 +
4522 +  if (nntp_data->newsrc_ent)
4523 +  {
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;
4528 +  }
4529 +  nntp_data->unread = 0;
4530 +  if (Context && Context->data == nntp_data)
4531 +  {
4532 +    unsigned int i;
4533 +
4534 +    for (i = 0; i < Context->msgcount; i++)
4535 +      mutt_set_flag (Context, Context->hdrs[i], MUTT_READ, 1);
4536 +  }
4537 +  return nntp_data;
4538 +}
4539 +
4540 +/* Uncatchup newsgroup */
4541 +NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER *nserv, char *group)
4542 +{
4543 +  NNTP_DATA *nntp_data;
4544 +
4545 +  if (!nserv || !nserv->groups_hash || !group || !*group)
4546 +    return NULL;
4547 +
4548 +  nntp_data = hash_find (nserv->groups_hash, group);
4549 +  if (!nntp_data)
4550 +    return NULL;
4551 +
4552 +  if (nntp_data->newsrc_ent)
4553 +  {
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;
4558 +  }
4559 +  if (Context && Context->data == nntp_data)
4560 +  {
4561 +    unsigned int i;
4562 +
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);
4566 +  }
4567 +  else
4568 +    nntp_data->unread = nntp_data->lastMessage - nntp_data->newsrc_ent[0].last;
4569 +  return nntp_data;
4570 +}
4571 +
4572 +/* Get first newsgroup with new messages */
4573 +void nntp_buffy (char *buf, size_t len)
4574 +{
4575 +  unsigned int i;
4576 +
4577 +  for (i = 0; i < CurrentNewsSrv->groups_num; i++)
4578 +  {
4579 +    NNTP_DATA *nntp_data = CurrentNewsSrv->groups_list[i];
4580 +
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))
4586 +    {
4587 +      unsigned int i, unread = 0;
4588 +
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;
4594 +    }
4595 +    strfcpy (buf, nntp_data->group, len);
4596 +    break;
4597 +  }
4598 +}
4599 diff -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 @@
4603 +/*
4604 + * Copyright (C) 1998 Brandon Long <blong@fiction.net>
4605 + * Copyright (C) 1999 Andrej Gritsenko <andrej@lucky.net>
4606 + * Copyright (C) 2000-2017 Vsevolod Volkov <vvv@mutt.org.ua>
4607 + *
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.
4612 + *
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.
4617 + *
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.
4621 + */
4622 +
4623 +#if HAVE_CONFIG_H
4624 +#include "config.h"
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"
4635 +#include "mutt_crypt.h"
4636 +#include "nntp.h"
4637 +
4638 +#if defined(USE_SSL)
4639 +#include "mutt_ssl.h"
4640 +#endif
4641 +
4642 +#ifdef HAVE_PGP
4643 +#include "pgp.h"
4644 +#endif
4645 +
4646 +#ifdef HAVE_SMIME
4647 +#include "smime.h"
4648 +#endif
4649 +
4650 +#if USE_HCACHE
4651 +#include "hcache.h"
4652 +#endif
4653 +
4654 +#include <unistd.h>
4655 +#include <string.h>
4656 +#include <ctype.h>
4657 +#include <stdlib.h>
4658 +
4659 +#ifdef USE_SASL
4660 +#include <sasl/sasl.h>
4661 +#include <sasl/saslutil.h>
4662 +
4663 +#include "mutt_sasl.h"
4664 +#endif
4665 +
4666 +static int nntp_connect_error (NNTP_SERVER *nserv)
4667 +{
4668 +  nserv->status = NNTP_NONE;
4669 +  mutt_error _("Server closed connection!");
4670 +  mutt_sleep (2);
4671 +  return -1;
4672 +}
4673 +
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)
4679 +{
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;
4702 +
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 "))
4751 +  {
4752 +    if (*buf)
4753 +      safe_strcat (buf, sizeof (buf), " ");
4754 +    safe_strcat (buf, sizeof (buf), "USER");
4755 +  }
4756 +  mutt_str_replace (&nserv->authenticators, buf);
4757 +
4758 +  /* current mode is reader */
4759 +  if (nserv->hasDATE)
4760 +    return 0;
4761 +
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 +    }
4817 +  }
4818 +
4819 +  /* no LIST NEWSGROUPS, trying XGTITLE */
4820 +  if (!nserv->hasLIST_NEWSGROUPS)
4821 +  {
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;
4827 +  }
4828 +
4829 +  /* no OVER, trying XOVER */
4830 +  if (!nserv->hasOVER)
4831 +  {
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;
4837 +  }
4838 +
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 +  }
4905 +  return 0;
4906 +}
4907 +
4908 +/* Get login, password and authenticate */
4909 +static int nntp_auth (NNTP_SERVER *nserv)
4910 +{
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;
4916 +
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;
4923 +
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 +    }
4945 +
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 +      }
4957 +
4958 +      method = a;
4959 +      a = strchr (a, ':');
4960 +      if (a)
4961 +       *a++ = '\0';
4962 +
4963 +      /* check authenticator */
4964 +      if (nserv->hasCAPABILITIES)
4965 +      {
4966 +       char *m;
4967 +
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));
4980 +
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;
4989 +
4990 +       /* authenticated, password is not required */
4991 +       if (!mutt_strncmp ("281", buf, 3))
4992 +         return 0;
4993 +
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;
5189 +  }
5190 +
5191 +  /* error */
5192 +  nserv->status = NNTP_BYE;
5193 +  conn->account.flags = flags;
5194 +  if (conn->fd < 0)
5195 +  {
5196 +    mutt_error _("Server closed connection!");
5197 +    mutt_sleep (2);
5198 +  }
5199 +  else
5200 +    mutt_socket_close (conn);
5201 +  return -1;
5202 +}
5203 +
5204 +/* Connect to server, authenticate and get capabilities */
5205 +int nntp_open_connection (NNTP_SERVER *nserv)
5206 +{
5207 +  CONNECTION *conn = nserv->conn;
5208 +  char buf[STRING];
5209 +  int cap;
5210 +  unsigned int posting = 0, auth = 1;
5211 +
5212 +  if (nserv->status == NNTP_OK)
5213 +    return 0;
5214 +  if (nserv->status == NNTP_BYE)
5215 +    return -1;
5216 +  nserv->status = NNTP_NONE;
5217 +
5218 +  if (mutt_socket_open (conn) < 0)
5219 +    return -1;
5220 +
5221 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5222 +    return nntp_connect_error (nserv);
5223 +
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;
5239 +
5240 +  /* tell news server to switch to mode reader if it isn't so */
5241 +  if (cap > 0)
5242 +  {
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)
5262 +    {
5263 +      cap = nntp_capabilities (nserv);
5264 +      if (cap < 0)
5265 +       return -1;
5266 +    }
5267 +  }
5268 +
5269 +  mutt_message (_("Connected to %s. %s"), conn->account.host,
5270 +               posting ? _("Posting is ok.") : _("Posting is NOT ok."));
5271 +  mutt_sleep (1);
5272 +
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
5311 +
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 +  }
5326 +
5327 +  /* authenticate */
5328 +  if (auth && nntp_auth (nserv) < 0)
5329 +      return -1;
5330 +
5331 +  /* get final capabilities after authentication */
5332 +  if (nserv->hasCAPABILITIES && (auth || cap > 0))
5333 +  {
5334 +    cap = nntp_capabilities (nserv);
5335 +    if (cap < 0)
5336 +      return -1;
5337 +    if (cap > 0)
5338 +    {
5339 +      mutt_socket_close (conn);
5340 +      mutt_error _("Could not switch to reader mode.");
5341 +      mutt_sleep (2);
5342 +      return -1;
5343 +    }
5344 +  }
5345 +
5346 +  /* attempt features */
5347 +  if (nntp_attempt_features (nserv) < 0)
5348 +    return -1;
5349 +
5350 +  nserv->status = NNTP_OK;
5351 +  return 0;
5352 +}
5353 +
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)
5356 +{
5357 +  NNTP_SERVER *nserv = nntp_data->nserv;
5358 +  char buf[LONG_STRING];
5359 +
5360 +  if (nserv->status == NNTP_BYE)
5361 +    return -1;
5362 +
5363 +  while (1)
5364 +  {
5365 +    if (nserv->status == NNTP_OK)
5366 +    {
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;
5380 +    }
5381 +
5382 +    /* reconnect */
5383 +    while (1)
5384 +    {
5385 +      nserv->status = NNTP_NONE;
5386 +      if (nntp_open_connection (nserv) == 0)
5387 +       break;
5388 +
5389 +      snprintf (buf, sizeof (buf), _("Connection to %s lost. Reconnect?"),
5390 +               nserv->conn->account.host);
5391 +      if (mutt_yesorno (buf, MUTT_YES) != MUTT_YES)
5392 +      {
5393 +       nserv->status = NNTP_BYE;
5394 +       return -1;
5395 +      }
5396 +    }
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 +  }
5409 +
5410 +  strfcpy (line, buf, linelen);
5411 +  return 0;
5412 +}
5413 +
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)
5422 +{
5423 +  int done = FALSE;
5424 +  int rc;
5425 +
5426 +  while (!done)
5427 +  {
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 +
5437 +    strfcpy (buf, query, sizeof (buf));
5438 +    if (nntp_query (nntp_data, buf, sizeof (buf)) < 0)
5439 +      return -1;
5440 +    if (buf[0] != '2')
5441 +    {
5442 +      strfcpy (query, buf, qlen);
5443 +      return 1;
5444 +    }
5445 +
5446 +    line = safe_malloc (sizeof (buf));
5447 +    rc = 0;
5448 +
5449 +    while (1)
5450 +    {
5451 +      char *p;
5452 +      int chunk = mutt_socket_readln_d (buf, sizeof (buf),
5453 +                 nntp_data->nserv->conn, MUTT_SOCK_LOG_HDR);
5454 +      if (chunk < 0)
5455 +      {
5456 +       nntp_data->nserv->status = NNTP_NONE;
5457 +       break;
5458 +      }
5459 +
5460 +      p = buf;
5461 +      if (!off && buf[0] == '.')
5462 +      {
5463 +       if (buf[1] == '\0')
5464 +       {
5465 +         done = TRUE;
5466 +         break;
5467 +       }
5468 +       if (buf[1] == '.')
5469 +         p++;
5470 +      }
5471 +
5472 +      strfcpy (line + off, p, sizeof (buf));
5473 +
5474 +      if (chunk >= sizeof (buf))
5475 +       off += strlen (p);
5476 +      else
5477 +      {
5478 +       if (msg)
5479 +         mutt_progress_update (&progress, ++lines, -1);
5480 +
5481 +       if (rc == 0 && funct (line, data) < 0)
5482 +         rc = -2;
5483 +       off = 0;
5484 +      }
5485 +
5486 +      safe_realloc (&line, off + sizeof (buf));
5487 +    }
5488 +    FREE (&line);
5489 +    funct (NULL, data);
5490 +  }
5491 +  return rc;
5492 +}
5493 +
5494 +/* Parse newsgroup description */
5495 +static int fetch_description (char *line, void *data)
5496 +{
5497 +  NNTP_SERVER *nserv = data;
5498 +  NNTP_DATA *nntp_data;
5499 +  char *desc;
5500 +
5501 +  if (!line)
5502 +    return 0;
5503 +
5504 +  desc = strpbrk (line, " \t");
5505 +  if (desc)
5506 +  {
5507 +    *desc++ = '\0';
5508 +    desc += strspn (desc, " \t");
5509 +  }
5510 +  else
5511 +    desc = strchr (line, '\0');
5512 +
5513 +  nntp_data = hash_find (nserv->groups_hash, line);
5514 +  if (nntp_data && mutt_strcmp (desc, nntp_data->desc))
5515 +  {
5516 +    mutt_str_replace (&nntp_data->desc, desc);
5517 +    dprint (2, (debugfile, "group: %s, desc: %s\n", line, desc));
5518 +  }
5519 +  return 0;
5520 +}
5521 +
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)
5525 +{
5526 +  NNTP_SERVER *nserv;
5527 +  char buf[STRING];
5528 +  char *cmd;
5529 +  int rc;
5530 +
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";
5539 +  else
5540 +    return 0;
5541 +
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)
5546 +  {
5547 +    mutt_error ("%s: %s", cmd, buf);
5548 +    mutt_sleep (2);
5549 +  }
5550 +  return rc;
5551 +}
5552 +
5553 +/* Update read flag and set article number if empty */
5554 +static void nntp_parse_xref (CONTEXT *ctx, HEADER *hdr)
5555 +{
5556 +  NNTP_DATA *nntp_data = ctx->data;
5557 +  char *buf, *p;
5558 +
5559 +  buf = p = safe_strdup (hdr->env->xref);
5560 +  while (p)
5561 +  {
5562 +    char *grp, *colon;
5563 +    anum_t anum;
5564 +
5565 +    /* skip to next word */
5566 +    p += strspn (p, " \t");
5567 +    grp = p;
5568 +
5569 +    /* skip to end of word */
5570 +    p = strpbrk (p, " \t");
5571 +    if (p)
5572 +      *p++ = '\0';
5573 +
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;
5585 +  }
5586 +  FREE (&buf);
5587 +}
5588 +
5589 +/* Write line to temporarily file */
5590 +static int fetch_tempfile (char *line, void *data)
5591 +{
5592 +  FILE *fp = data;
5593 +
5594 +  if (!line)
5595 +    rewind (fp);
5596 +  else if (fputs (line, fp) == EOF || fputc ('\n', fp) == EOF)
5597 +    return -1;
5598 +  return 0;
5599 +}
5600 +
5601 +typedef struct
5602 +{
5603 +  CONTEXT *ctx;
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)
5616 +{
5617 +  FETCH_CTX *fc = data;
5618 +  anum_t anum;
5619 +
5620 +  if (!line)
5621 +    return 0;
5622 +  if (sscanf (line, ANUM, &anum) != 1)
5623 +    return 0;
5624 +  if (anum < fc->first || anum > fc->last)
5625 +    return 0;
5626 +  fc->messages[anum - fc->first] = 1;
5627 +  return 0;
5628 +}
5629 +
5630 +/* Parse overview line */
5631 +static int parse_overview_line (char *line, void *data)
5632 +{
5633 +  FETCH_CTX *fc = data;
5634 +  CONTEXT *ctx = fc->ctx;
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;
5642 +
5643 +  if (!line)
5644 +    return 0;
5645 +
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 */
5702 +  if (ctx->msgcount >= ctx->hdrmax)
5703 +    mx_alloc_memory (ctx);
5704 +
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
5756 +
5757 +  if (save)
5758 +  {
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;
5775 +  }
5776 +  else
5777 +    mutt_free_header (&hdr);
5778 +
5779 +  /* progress */
5780 +  if (!ctx->quiet)
5781 +    mutt_progress_update (&fc->progress, anum - fc->first + 1, -1);
5782 +  return 0;
5783 +}
5784 +
5785 +/* Fetch headers */
5786 +static int nntp_fetch_headers (CONTEXT *ctx, void *hc,
5787 +                              anum_t first, anum_t last, int restore)
5788 +{
5789 +  NNTP_DATA *nntp_data = ctx->data;
5790 +  FETCH_CTX fc;
5791 +  HEADER *hdr;
5792 +  char buf[HUGE_STRING];
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
5800 +
5801 +  /* if empty group or nothing to do */
5802 +  if (!last || first > last)
5803 +    return 0;
5804 +
5805 +  /* init fetch context */
5806 +  fc.ctx = ctx;
5807 +  fc.first = first;
5808 +  fc.last = last;
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)
5829 +    {
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 +       }
5855 +#endif
5856 +      }
5857 +    }
5858 +  }
5859 +  else
5860 +    for (current = first; current <= last; current++)
5861 +      fc.messages[current - first] = 1;
5862 +
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++)
5868 +  {
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)
5888 +    {
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;
5911 +    }
5912 +    else
5913 +#endif
5914 +
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
5928 +    {
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 +      }
5942 +
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;
5952 +
5953 +       /* invalid response */
5954 +       if (mutt_strncmp ("423", buf, 3))
5955 +       {
5956 +         mutt_error ("HEAD: %s", buf);
5957 +         mutt_sleep (2);
5958 +         break;
5959 +       }
5960 +
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 +      }
5972 +
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);
5979 +    }
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;
5990 +    else
5991 +    {
5992 +      nntp_article_status (ctx, hdr, NULL, NHDR (hdr)->article_num);
5993 +      if (!hdr->read)
5994 +       nntp_parse_xref (ctx, hdr);
5995 +    }
5996 +    if (current > nntp_data->lastLoaded)
5997 +      nntp_data->lastLoaded = current;
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 +    }
6015 +  }
6016 +
6017 +  if (ctx->msgcount > oldmsgcount)
6018 +    mx_update_context (ctx, ctx->msgcount - oldmsgcount);
6019 +
6020 +  FREE (&fc.messages);
6021 +  if (rc != 0)
6022 +    return -1;
6023 +  mutt_clear_error ();
6024 +  return 0;
6025 +}
6026 +
6027 +/* Open newsgroup */
6028 +static int nntp_open_mailbox (CONTEXT *ctx)
6029 +{
6030 +  NNTP_SERVER *nserv;
6031 +  NNTP_DATA *nntp_data;
6032 +  char buf[HUGE_STRING];
6033 +  char server[LONG_STRING];
6034 +  char *group;
6035 +  int rc;
6036 +  void *hc = NULL;
6037 +  anum_t first, last, count = 0;
6038 +  ciss_url_t url;
6039 +
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))
6043 +  {
6044 +    mutt_error (_("%s is an invalid newsgroup specification!"), ctx->path);
6045 +    mutt_sleep (2);
6046 +    return -1;
6047 +  }
6048 +
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)
6054 +    return -1;
6055 +  CurrentNewsSrv = nserv;
6056 +
6057 +  /* find news group data structure */
6058 +  nntp_data = hash_find (nserv->groups_hash, group);
6059 +  if (!nntp_data)
6060 +  {
6061 +    nntp_newsrc_close (nserv);
6062 +    mutt_error (_("Newsgroup %s not found on the server."), group);
6063 +    mutt_sleep (2);
6064 +    return -1;
6065 +  }
6066 +
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;
6071 +
6072 +  /* select newsgroup */
6073 +  mutt_message (_("Selecting %s..."), group);
6074 +  buf[0] = '\0';
6075 +  if (nntp_query (nntp_data, buf, sizeof (buf)) < 0)
6076 +  {
6077 +    nntp_newsrc_close (nserv);
6078 +    return -1;
6079 +  }
6080 +
6081 +  /* newsgroup not found, remove it */
6082 +  if (!mutt_strncmp ("411", buf, 3))
6083 +  {
6084 +    mutt_error (_("Newsgroup %s has been removed from the server."),
6085 +               nntp_data->group);
6086 +    if (!nntp_data->deleted)
6087 +    {
6088 +      nntp_data->deleted = 1;
6089 +      nntp_active_save_cache (nserv);
6090 +    }
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);
6100 +  }
6101 +
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;
6114 +
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 +  }
6127 +
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);
6134 +
6135 +  /* strip off extra articles if adding context is greater than $nntp_context */
6136 +  first = nntp_data->firstMessage;
6137 +  if (NntpContext && nntp_data->lastMessage - first + 1 > NntpContext)
6138 +    first = nntp_data->lastMessage - NntpContext + 1;
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;
6163 +}
6164 +
6165 +/* Fetch message */
6166 +static int nntp_open_message (CONTEXT *ctx, MESSAGE *msg, int msgno)
6167 +{
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;
6175 +
6176 +  /* try to get article from cache */
6177 +  acache = &nntp_data->acache[hdr->index % NNTP_ACACHE_LEN];
6178 +  if (acache->path)
6179 +  {
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;
6199 +  }
6200 +  else
6201 +  {
6202 +    /* don't try to fetch article from removed newsgroup */
6203 +    if (nntp_data->deleted)
6204 +      return -1;
6205 +
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 */
6225 +    snprintf (buf, sizeof (buf), "ARTICLE %s\r\n",
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 +    }
6247 +
6248 +    if (!acache->path)
6249 +      mutt_bcache_commit (nntp_data->bcache, article);
6250 +  }
6251 +
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);
6266 +
6267 +  /* fix content length */
6268 +  fseek (msg->fp, 0, SEEK_END);
6269 +  hdr->content->length = ftell (msg->fp) - hdr->content->offset;
6270 +
6271 +  /* this is called in mutt before the open which fetches the message,
6272 +   * which is probably wrong, but we just call it again here to handle
6273 +   * the problem instead of fixing it */
6274 +  NHDR (hdr)->parsed = 1;
6275 +  mutt_parse_mime_message (ctx, hdr);
6276 +
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);
6282 +
6283 +  rewind (msg->fp);
6284 +  mutt_clear_error();
6285 +  return 0;
6286 +}
6287 +
6288 +/* Close message */
6289 +static int nntp_close_message (CONTEXT *ctx, MESSAGE *msg)
6290 +{
6291 +  return safe_fclose (&msg->fp);
6292 +}
6293 +
6294 +/* Post article */
6295 +int nntp_post (const char *msg) {
6296 +  NNTP_DATA *nntp_data, nntp_tmp;
6297 +  FILE *fp;
6298 +  char buf[LONG_STRING];
6299 +  size_t len;
6300 +
6301 +  if (Context && Context->magic == MUTT_NNTP)
6302 +    nntp_data = Context->data;
6303 +  else
6304 +  {
6305 +    CurrentNewsSrv = nntp_select_server (NewsServer, 0);
6306 +    if (!CurrentNewsSrv)
6307 +      return -1;
6308 +
6309 +    nntp_data = &nntp_tmp;
6310 +    nntp_data->nserv = CurrentNewsSrv;
6311 +    nntp_data->group = NULL;
6312 +  }
6313 +
6314 +  fp = safe_fopen (msg, "r");
6315 +  if (!fp)
6316 +  {
6317 +    mutt_perror (msg);
6318 +    return -1;
6319 +  }
6320 +
6321 +  strfcpy (buf, "POST\r\n", sizeof (buf));
6322 +  if (nntp_query (nntp_data, buf, sizeof (buf)) < 0)
6323 +    return -1;
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';
6332 +  while (fgets (buf + 1, sizeof (buf) - 2, fp))
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 +    }
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);
6345 +  }
6346 +  fclose (fp);
6347 +
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);
6353 +  if (buf[0] != '2')
6354 +  {
6355 +    mutt_error (_("Can't post article: %s"), buf);
6356 +    return -1;
6357 +  }
6358 +  return 0;
6359 +}
6360 +
6361 +/* Free up memory associated with the newsgroup context */
6362 +static int nntp_close_mailbox (CONTEXT *ctx)
6363 +{
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;
6374 +
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 +}
6380 +
6381 +/* Get date and time from server */
6382 +int nntp_date (NNTP_SERVER *nserv, time_t *now)
6383 +{
6384 +  if (nserv->hasDATE)
6385 +  {
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;
6395 +
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)
6398 +    {
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 +      }
6407 +    }
6408 +  }
6409 +  time (now);
6410 +  return 0;
6411 +}
6412 +
6413 +/* Fetch list of all newsgroups from server */
6414 +int nntp_active_fetch (NNTP_SERVER *nserv, unsigned int new)
6415 +{
6416 +  NNTP_DATA nntp_data;
6417 +  char msg[SHORT_STRING];
6418 +  char buf[LONG_STRING];
6419 +  unsigned int i;
6420 +  int rc;
6421 +
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)
6435 +  {
6436 +    if (rc > 0)
6437 +    {
6438 +      mutt_error ("LIST: %s", buf);
6439 +      mutt_sleep (2);
6440 +    }
6441 +    return -1;
6442 +  }
6443 +
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 +  }
6452 +
6453 +  for (i = 0; i < nserv->groups_num; i++)
6454 +  {
6455 +    NNTP_DATA *nntp_data = nserv->groups_list[i];
6456 +
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 +  }
6464 +
6465 +  if (option (OPTLOADDESC))
6466 +    rc = get_description (&nntp_data, "*", _("Loading descriptions..."));
6467 +
6468 +  nntp_active_save_cache (nserv);
6469 +  if (rc < 0)
6470 +    return -1;
6471 +  mutt_clear_error ();
6472 +  return 0;
6473 +}
6474 +
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)
6480 +{
6481 +  char buf[LONG_STRING] = "";
6482 +  anum_t count, first, last;
6483 +
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)
6488 +    return 0;
6489 +  if (first == nntp_data->firstMessage && last == nntp_data->lastMessage)
6490 +    return 0;
6491 +
6492 +  /* articles have been renumbered */
6493 +  if (last < nntp_data->lastMessage)
6494 +  {
6495 +    nntp_data->lastCached = 0;
6496 +    if (nntp_data->newsrc_len)
6497 +    {
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;
6502 +    }
6503 +  }
6504 +  nntp_data->firstMessage = first;
6505 +  nntp_data->lastMessage = last;
6506 +  if (!update_stat)
6507 +    return 1;
6508 +
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;
6515 +}
6516 +
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)
6523 +{
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)
6532 +    return 0;
6533 +
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)
6541 +  {
6542 +    nntp_newsrc_close (nserv);
6543 +    return -1;
6544 +  }
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)
6550 +  {
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)
6557 +    {
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;
6562 +    }
6563 +    ret = MUTT_REOPENED;
6564 +  }
6565 +
6566 +  /* .newsrc has been externally modified */
6567 +  if (nserv->newsrc_modified)
6568 +  {
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;
6576 +
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++)
6587 +    {
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];
6634 +    }
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++)
6641 +    {
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)
6648 +      {
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);
6678 +      }
6679 +    }
6680 +    FREE (&messages);
6681 +#endif
6682 +
6683 +    nserv->newsrc_modified = 0;
6684 +    ret = MUTT_REOPENED;
6685 +  }
6686 +
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;
6736 +}
6737 +
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)
6744 +{
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;
6753 +}
6754 +
6755 +/* Save changes to .newsrc and cache */
6756 +static int nntp_sync_mailbox (CONTEXT *ctx, int *index_hint)
6757 +{
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
6774 +
6775 +  for (i = 0; i < ctx->msgcount; i++)
6776 +  {
6777 +    HEADER *hdr = ctx->hdrs[i];
6778 +    char buf[16];
6779 +
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 +    }
6786 +
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)
6798 +  {
6799 +    mutt_hcache_close (hc);
6800 +    nntp_data->lastCached = nntp_data->lastLoaded;
6801 +  }
6802 +#endif
6803 +
6804 +  /* save .newsrc entries */
6805 +  nntp_newsrc_gen_entries (ctx);
6806 +  nntp_newsrc_update (nntp_data->nserv);
6807 +  nntp_newsrc_close (nntp_data->nserv);
6808 +  return 0;
6809 +}
6810 +
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)
6816 +{
6817 +  NNTP_DATA nntp_data;
6818 +  time_t now;
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;
6824 +
6825 +  if (!nserv || !nserv->newgroups_time)
6826 +    return -1;
6827 +
6828 +  /* check subscribed newsgroups for new articles */
6829 +  if (option (OPTSHOWNEWNEWS))
6830 +  {
6831 +    mutt_message _("Checking for new messages...");
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)
6847 +    {
6848 +      buf[0] = '\0';
6849 +      if (nntp_query ((NNTP_DATA *)Context->data, buf, sizeof (buf)) < 0)
6850 +       return -1;
6851 +    }
6852 +  }
6853 +  else if (nserv->newgroups_time)
6854 +    return 0;
6855 +
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)
6862 +    nntp_data.group = ((NNTP_DATA *)Context->data)->group;
6863 +  else
6864 +    nntp_data.group = NULL;
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)
6873 +  {
6874 +    if (rc > 0)
6875 +    {
6876 +      mutt_error ("NEWGROUPS: %s", buf);
6877 +      mutt_sleep (2);
6878 +    }
6879 +    return -1;
6880 +  }
6881 +
6882 +  /* new groups found */
6883 +  rc = 0;
6884 +  if (nserv->groups_num != i)
6885 +  {
6886 +    int groups_num = i;
6887 +
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 +    }
6894 +
6895 +    /* loading descriptions */
6896 +    if (option (OPTLOADDESC))
6897 +    {
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 +      }
6911 +    }
6912 +    update_active = TRUE;
6913 +    rc = 1;
6914 +  }
6915 +  if (update_active)
6916 +    nntp_active_save_cache (nserv);
6917 +  mutt_clear_error ();
6918 +  return rc;
6919 +}
6920 +
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)
6926 +{
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;
6933 +
6934 +  mutt_mktemp (tempfile, sizeof (tempfile));
6935 +  fp = safe_fopen (tempfile, "w+");
6936 +  if (!fp)
6937 +  {
6938 +    mutt_perror (tempfile);
6939 +    unlink (tempfile);
6940 +    return -1;
6941 +  }
6942 +
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)
6947 +  {
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;
6956 +  }
6957 +
6958 +  /* parse header */
6959 +  if (ctx->msgcount == ctx->hdrmax)
6960 +    mx_alloc_memory (ctx);
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);
6970 +  else
6971 +  {
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);
6979 +  }
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;
6990 +}
6991 +
6992 +typedef struct
6993 +{
6994 +  CONTEXT *ctx;
6995 +  unsigned int num;
6996 +  unsigned int max;
6997 +  anum_t *child;
6998 +} CHILD_CTX;
6999 +
7000 +/* Parse XPAT line */
7001 +static int fetch_children (char *line, void *data)
7002 +{
7003 +  CHILD_CTX *cc = data;
7004 +  anum_t anum;
7005 +  unsigned int i;
7006 +
7007 +  if (!line || sscanf (line, ANUM, &anum) != 1)
7008 +    return 0;
7009 +  for (i = 0; i < cc->ctx->msgcount; i++)
7010 +    if (NHDR (cc->ctx->hdrs[i])->article_num == anum)
7011 +      return 0;
7012 +  if (cc->num >= cc->max)
7013 +  {
7014 +    cc->max *= 2;
7015 +    safe_realloc (&cc->child, sizeof (anum_t) * cc->max);
7016 +  }
7017 +  cc->child[cc->num++] = anum;
7018 +  return 0;
7019 +}
7020 +
7021 +/* Fetch children of article with the Message-ID */
7022 +int nntp_check_children (CONTEXT *ctx, const char *msgid)
7023 +{
7024 +  NNTP_DATA *nntp_data = ctx->data;
7025 +  CHILD_CTX cc;
7026 +  char buf[STRING];
7027 +  int i, rc, quiet;
7028 +  void *hc = NULL;
7029 +
7030 +  if (!nntp_data || !nntp_data->nserv)
7031 +    return -1;
7032 +  if (nntp_data->firstMessage > nntp_data->lastLoaded)
7033 +    return 0;
7034 +
7035 +  /* init context */
7036 +  cc.ctx = ctx;
7037 +  cc.num = 0;
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)
7047 +  {
7048 +    FREE (&cc.child);
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 +    }
7055 +    return -1;
7056 +  }
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
7064 +  for (i = 0; i < cc.num; i++)
7065 +  {
7066 +    rc = nntp_fetch_headers (ctx, hc, cc.child[i], cc.child[i], 1);
7067 +    if (rc < 0)
7068 +      break;
7069 +  }
7070 +#ifdef USE_HCACHE
7071 +  mutt_hcache_close (hc);
7072 +#endif
7073 +  ctx->quiet = quiet;
7074 +  FREE (&cc.child);
7075 +  return rc < 0 ? -1 : 0;
7076 +}
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 +};
7089 diff -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 @@
7093 +/*
7094 + * Copyright (C) 1998 Brandon Long <blong@fiction.net>
7095 + * Copyright (C) 1999 Andrej Gritsenko <andrej@lucky.net>
7096 + * Copyright (C) 2000-2016 Vsevolod Volkov <vvv@mutt.org.ua>
7097 + *
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.
7102 + *
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.
7107 + *
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.
7111 + */
7112 +
7113 +#ifndef _NNTP_H_
7114 +#define _NNTP_H_ 1
7115 +
7116 +#include "mutt_socket.h"
7117 +#include "mailbox.h"
7118 +#include "bcache.h"
7119 +
7120 +#if USE_HCACHE
7121 +#include "hcache.h"
7122 +#endif
7123 +
7124 +#include <time.h>
7125 +#include <sys/types.h>
7126 +#include <stdint.h>
7127 +
7128 +#define NNTP_PORT 119
7129 +#define NNTP_SSL_PORT 563
7130 +
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"
7137 +
7138 +enum
7139 +{
7140 +  NNTP_NONE = 0,
7141 +  NNTP_OK,
7142 +  NNTP_BYE
7143 +};
7144 +
7145 +typedef struct
7146 +{
7147 +  unsigned int hasCAPABILITIES : 1;
7148 +  unsigned int hasSTARTTLS : 1;
7149 +  unsigned int hasDATE : 1;
7150 +  unsigned int hasLIST_NEWSGROUPS : 1;
7151 +  unsigned int hasXGTITLE : 1;
7152 +  unsigned int hasLISTGROUP : 1;
7153 +  unsigned int hasLISTGROUPrange : 1;
7154 +  unsigned int hasOVER : 1;
7155 +  unsigned int hasXOVER : 1;
7156 +  unsigned int use_tls : 3;
7157 +  unsigned int status : 3;
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;
7164 +  off_t size;
7165 +  time_t mtime;
7166 +  time_t newgroups_time;
7167 +  time_t check_time;
7168 +  unsigned int groups_num;
7169 +  unsigned int groups_max;
7170 +  void **groups_list;
7171 +  HASH *groups_hash;
7172 +  CONNECTION *conn;
7173 +} NNTP_SERVER;
7174 +
7175 +typedef struct
7176 +{
7177 +  anum_t first;
7178 +  anum_t last;
7179 +} NEWSRC_ENTRY;
7180 +
7181 +typedef struct
7182 +{
7183 +  unsigned int index;
7184 +  char *path;
7185 +} NNTP_ACACHE;
7186 +
7187 +typedef struct
7188 +{
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;
7196 +  unsigned int subscribed : 1;
7197 +  unsigned int new : 1;
7198 +  unsigned int allowed : 1;
7199 +  unsigned int deleted : 1;
7200 +  unsigned int newsrc_len;
7201 +  NEWSRC_ENTRY *newsrc_ent;
7202 +  NNTP_SERVER *nserv;
7203 +  NNTP_ACACHE acache[NNTP_ACACHE_LEN];
7204 +  body_cache_t *bcache;
7205 +} NNTP_DATA;
7206 +
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 +
7215 +/* internal functions */
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 *);
7227 +
7228 +/* exposed interface */
7229 +NNTP_SERVER *nntp_select_server (char *, int);
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 *);
7234 +int nntp_active_fetch (NNTP_SERVER *, unsigned int);
7235 +int nntp_newsrc_update (NNTP_SERVER *);
7236 +int nntp_post (const char *);
7237 +int nntp_check_msgid (CONTEXT *, const char *);
7238 +int nntp_check_children (CONTEXT *, const char *);
7239 +int nntp_newsrc_parse (NNTP_SERVER *);
7240 +void nntp_newsrc_close (NNTP_SERVER *);
7241 +void nntp_buffy (char *, size_t);
7242 +void nntp_expand_path (char *, size_t, ACCOUNT *);
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);
7247 +
7248 +NNTP_SERVER *CurrentNewsSrv INITVAL (NULL);
7249 +
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 +
7257 +#endif /* _NNTP_H_ */
7258 diff -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,
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,
7273 @@ -1584,6 +1589,15 @@ static const struct mapping_t PagerHelpE
7274    { N_("Next"),        OP_MAIN_NEXT_UNDELETED },
7275    { NULL,      0 }
7276  };
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
7286  
7287  void mutt_clear_pager_position (void)
7288  {
7289 @@ -1923,6 +1937,10 @@ mutt_pager (const char *banner, const ch
7290  
7291    pager_redraw_data_t rd;
7292  
7293 +#ifdef USE_NNTP
7294 +  char *followup_to;
7295 +#endif
7296 +
7297    if (!(flags & MUTT_SHOWCOLOR))
7298      flags |= MUTT_SHOWFLAT;
7299  
7300 @@ -1972,7 +1990,11 @@ mutt_pager (const char *banner, const ch
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
7307 +       (Context && (Context->magic == MUTT_NNTP)) ? PagerNewsHelpExtra :
7308 +#endif
7309 +       PagerHelpExtra);
7310      snprintf (helpstr, sizeof (helpstr), "%s %s", tmphelp, buffer);
7311    }
7312    if (!InHelp)
7313 @@ -2639,6 +2661,60 @@ search_next:
7314         pager_menu->redraw = REDRAW_FULL;
7315         break;
7316  
7317 +#ifdef USE_NNTP
7318 +      case OP_POST:
7319 +       CHECK_MODE(IsHeader (extra) && !IsAttach (extra));
7320 +       CHECK_ATTACH;
7321 +       if (extra->ctx && extra->ctx->magic == MUTT_NNTP &&
7322 +           !((NNTP_DATA *)extra->ctx->data)->allowed &&
7323 +           query_quadoption (OPT_TOMODERATED,_("Posting to this group not allowed, may be moderated. Continue?")) != MUTT_YES)
7324 +         break;
7325 +       ci_send_message (SENDNEWS, NULL, NULL, extra->ctx, NULL);
7326 +       pager_menu->redraw = REDRAW_FULL;
7327 +       break;
7328 +
7329 +      case OP_FORWARD_TO_GROUP:
7330 +       CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
7331 +       CHECK_ATTACH;
7332 +       if (extra->ctx && extra->ctx->magic == MUTT_NNTP &&
7333 +           !((NNTP_DATA *)extra->ctx->data)->allowed &&
7334 +           query_quadoption (OPT_TOMODERATED,_("Posting to this group not allowed, may be moderated. Continue?")) != MUTT_YES)
7335 +         break;
7336 +       if (IsMsgAttach (extra))
7337 +         mutt_attach_forward (extra->fp, extra->hdr, extra->actx,
7338 +                              extra->bdy, SENDNEWS);
7339 +       else
7340 +         ci_send_message (SENDNEWS|SENDFORWARD, NULL, NULL, extra->ctx, extra->hdr);
7341 +       pager_menu->redraw = REDRAW_FULL;
7342 +       break;
7343 +
7344 +      case OP_FOLLOWUP:
7345 +       CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
7346 +       CHECK_ATTACH;
7347 +
7348 +       if (IsMsgAttach (extra))
7349 +         followup_to = extra->bdy->hdr->env->followup_to;
7350 +       else
7351 +         followup_to = extra->hdr->env->followup_to;
7352 +
7353 +       if (!followup_to || mutt_strcasecmp (followup_to, "poster") ||
7354 +           query_quadoption (OPT_FOLLOWUPTOPOSTER,_("Reply by mail as poster prefers?")) != MUTT_YES)
7355 +       {
7356 +         if (extra->ctx && extra->ctx->magic == MUTT_NNTP &&
7357 +             !((NNTP_DATA *)extra->ctx->data)->allowed &&
7358 +             query_quadoption (OPT_TOMODERATED,_("Posting to this group not allowed, may be moderated. Continue?")) != MUTT_YES)
7359 +           break;
7360 +         if (IsMsgAttach (extra))
7361 +           mutt_attach_reply (extra->fp, extra->hdr, extra->actx,
7362 +                              extra->bdy, SENDNEWS|SENDREPLY);
7363 +         else
7364 +           ci_send_message (SENDNEWS|SENDREPLY, NULL, NULL,
7365 +                            extra->ctx, extra->hdr);
7366 +         pager_menu->redraw = REDRAW_FULL;
7367 +         break;
7368 +       }
7369 +#endif
7370 +
7371        case OP_REPLY:
7372         CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
7373          CHECK_ATTACH;      
7374 @@ -2684,7 +2760,7 @@ search_next:
7375          CHECK_ATTACH;
7376          if (IsMsgAttach (extra))
7377           mutt_attach_forward (extra->fp, extra->hdr, extra->actx,
7378 -                              extra->bdy);
7379 +                              extra->bdy, 0);
7380          else
7381           ci_send_message (SENDFORWARD, NULL, NULL, extra->ctx, extra->hdr);
7382         pager_menu->redraw = REDRAW_FULL;
7383 diff -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
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;
7394    char *m;
7395 @@ -1077,6 +1077,17 @@ int mutt_parse_rfc822_line (ENVELOPE *e,
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':
7413 @@ -1159,6 +1170,27 @@ int mutt_parse_rfc822_line (ENVELOPE *e,
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      {
7441 @@ -1271,6 +1303,20 @@ int mutt_parse_rfc822_line (ENVELOPE *e,
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;
7462 diff -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:
7478        return (pat->not ^ (h->thread && !h->thread->child));
7479 +#ifdef USE_NNTP
7480 +    case MUTT_NEWSGROUPS:
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);
7486 @@ -1449,6 +1456,7 @@ int mutt_pattern_func (int op, char *pro
7487    progress_t progress;
7488  
7489    strfcpy (buf, NONULL (Context->pattern), sizeof (buf));
7490 +  if (prompt || op != MUTT_LIMIT)
7491    if (mutt_get_field (prompt, buf, sizeof (buf), MUTT_PATTERN | MUTT_CLEAR) != 0 || !buf[0])
7492      return (-1);
7493  
7494 diff -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
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
7506 diff -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
7509 @@ -125,15 +125,26 @@ int mutt_num_postponed (int force)
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
7524      if (mx_open_mailbox (Postponed, MUTT_NOSORT | MUTT_QUIET, &ctx) == NULL)
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);
7536 diff -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 *);
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);
7547 diff -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)
7551         }
7552  #endif
7553  
7554 +#ifdef USE_NNTP
7555 +       if (Context->magic == MUTT_NNTP)
7556 +       {
7557 +         mutt_flushinp ();
7558 +         mutt_error _("Can't delete attachment from news server.");
7559 +         break;
7560 +       }
7561 +#endif
7562 +
7563          if (WithCrypto && (hdr->security & ENCRYPT))
7564          {
7565            mutt_message _(
7566 @@ -1318,10 +1327,32 @@ void mutt_view_attachments (HEADER *hdr)
7567        case OP_FORWARD_MESSAGE:
7568          CHECK_ATTACH;
7569          mutt_attach_forward (CURATTACH->fp, hdr, actx,
7570 -                            menu->tagprefix ? NULL : CURATTACH->content);
7571 +                            menu->tagprefix ? NULL : CURATTACH->content, 0);
7572          menu->redraw = REDRAW_FULL;
7573          break;
7574  
7575 +#ifdef USE_NNTP
7576 +      case OP_FORWARD_TO_GROUP:
7577 +       CHECK_ATTACH;
7578 +       mutt_attach_forward (CURATTACH->fp, hdr, actx,
7579 +                            menu->tagprefix ? NULL : CURATTACH->content, SENDNEWS);
7580 +       menu->redraw = REDRAW_FULL;
7581 +       break;
7582 +
7583 +      case OP_FOLLOWUP:
7584 +       CHECK_ATTACH;
7585 +
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)
7589 +       {
7590 +         mutt_attach_reply (CURATTACH->fp, hdr, actx,
7591 +                            menu->tagprefix ? NULL : CURATTACH->content, SENDNEWS|SENDREPLY);
7592 +         menu->redraw = REDRAW_FULL;
7593 +         break;
7594 +       }
7595 +#endif
7596 +
7597        case OP_COMPOSE_TO_SENDER:
7598          CHECK_ATTACH;
7599          mutt_attach_mail_sender (CURATTACH->fp, hdr, actx,
7600 diff -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
7604  static void attach_forward_bodies (FILE * fp, HEADER * hdr,
7605                                    ATTACH_CONTEXT *actx,
7606                                    BODY * cur,
7607 -                                  short nattach)
7608 +                                  short nattach, int flags)
7609  {
7610    short i;
7611    short mime_fwd_all = 0;
7612 @@ -554,7 +554,7 @@ _("Can't decode all tagged attachments.
7613    tmpfp = NULL;
7614  
7615    /* now that we have the template, send it. */
7616 -  ci_send_message (0, tmphdr, tmpbody, NULL, parent_hdr);
7617 +  ci_send_message (flags, tmphdr, tmpbody, NULL, parent_hdr);
7618    return;
7619    
7620    bail:
7621 @@ -581,7 +581,7 @@ _("Can't decode all tagged attachments.
7622   */
7623  
7624  static void attach_forward_msgs (FILE * fp, HEADER * hdr, 
7625 -              ATTACH_CONTEXT *actx, BODY * cur)
7626 +              ATTACH_CONTEXT *actx, BODY * cur, int flags)
7627  {
7628    HEADER *curhdr = NULL;
7629    HEADER *tmphdr;
7630 @@ -686,23 +686,23 @@ static void attach_forward_msgs (FILE *
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, 
7641 -                         ATTACH_CONTEXT *actx, BODY * cur)
7642 +                         ATTACH_CONTEXT *actx, BODY * cur, int flags)
7643  {
7644    short nattach;
7645    
7646  
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);
7650    else
7651    {
7652      nattach = count_tagged (actx);
7653 -    attach_forward_bodies (fp, hdr, actx, cur, nattach);
7654 +    attach_forward_bodies (fp, hdr, actx, cur, nattach, flags);
7655    }
7656  }
7657  
7658 @@ -760,6 +760,17 @@ attach_reply_envelope_defaults (ENVELOPE
7659      return -1;
7660    }
7661  
7662 +#ifdef USE_NNTP
7663 +  if ((flags & SENDNEWS))
7664 +  {
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);
7669 +  }
7670 +  else
7671 +#endif
7672 + {
7673    if (parent)
7674    {
7675      if (mutt_fetch_recips (env, curenv, flags) == -1)
7676 @@ -782,6 +793,7 @@ attach_reply_envelope_defaults (ENVELOPE
7677    }
7678    
7679    mutt_fix_reply_recipients (env);
7680 + }
7681    mutt_make_misc_reply_headers (env, Context, curhdr, curenv);
7682  
7683    if (parent)
7684 @@ -844,6 +856,13 @@ void mutt_attach_reply (FILE * fp, HEADE
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 +
7695    if (check_all_msg (actx, cur, 0) == -1)
7696    {
7697      nattach = count_tagged (actx);
7698 diff -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 @@
7702  #include <sys/types.h>
7703  #include <utime.h>
7704  
7705 +#ifdef USE_NNTP
7706 +#include "nntp.h"
7707 +#include "mx.h"
7708 +#endif
7709 +
7710  #ifdef MIXMASTER
7711  #include "remailer.h"
7712  #endif
7713 @@ -214,17 +219,51 @@ static int edit_address (ADDRESS **a, /*
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  
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
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 + }
7763  
7764    if (en->subject)
7765    {
7766 @@ -259,6 +298,14 @@ static int edit_envelope (ENVELOPE *en)
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;
7781 @@ -271,6 +318,14 @@ static void process_user_recips (ENVELOP
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  
7796 @@ -309,6 +364,12 @@ static void process_user_header (ENVELOP
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 &&
7806              ascii_strncasecmp ("subject:", uh->data, 8) != 0 &&
7807              ascii_strncasecmp ("return-path:", uh->data, 12) != 0)
7808      {
7809 @@ -656,6 +717,10 @@ void mutt_add_to_reference_headers (ENVE
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 
7820 @@ -718,6 +783,16 @@ envelope_defaults (ENVELOPE *env, CONTEX
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;
7837 @@ -864,7 +939,18 @@ void mutt_set_followup_to (ENVELOPE *e)
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      {
7857 @@ -1026,6 +1112,9 @@ static int send_message (HEADER *msg)
7858  #endif
7859  
7860  #if USE_SMTP
7861 +#ifdef USE_NNTP
7862 +  if (!option (OPTNEWSSEND))
7863 +#endif
7864    if (SmtpUrl)
7865        return mutt_smtp_send (msg->env->from, msg->env->to, msg->env->cc,
7866                               msg->env->bcc, tempfile,
7867 @@ -1189,6 +1278,13 @@ ci_send_message (int flags,              /* send mod
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 +
7878    if (!flags && !msg && quadoption (OPT_RECALL) != MUTT_NO &&
7879        mutt_num_postponed (1))
7880    {
7881 @@ -1224,6 +1320,22 @@ ci_send_message (int flags,              /* send mod
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))
7904 @@ -1325,11 +1437,16 @@ ci_send_message (int flags,             /* send mod
7905      if (flags & SENDREPLY)
7906        mutt_fix_reply_recipients (msg->env);
7907  
7908 +#ifdef USE_NNTP
7909 +    if ((flags & SENDNEWS) && ctx && ctx->magic == MUTT_NNTP && !msg->env->newsgroups)
7910 +      msg->env->newsgroups = safe_strdup (((NNTP_DATA *)ctx->data)->group);
7911 +#endif
7912 +
7913      if (! (flags & (SENDMAILX|SENDBATCH)) &&
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  
7922 @@ -1640,6 +1757,11 @@ main_loop:
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      }
7934 @@ -1706,6 +1828,9 @@ main_loop:
7935      }
7936    }
7937  
7938 +#ifdef USE_NNTP
7939 +  if (!(flags & SENDNEWS))
7940 +#endif
7941    if (!has_recips (msg->env->to) && !has_recips (msg->env->cc) &&
7942        !has_recips (msg->env->bcc))
7943    {
7944 @@ -1739,6 +1864,19 @@ main_loop:
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 +  }
7954 +
7955 +  if ((flags & SENDNEWS) && !msg->env->newsgroups)
7956 +  {
7957 +    mutt_error _("No newsgroup specified.");
7958 +    goto main_loop;
7959 +  }
7960 +#endif
7961  
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:
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);
7978 diff -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
7981 @@ -46,6 +46,10 @@
7982  #include <sys/wait.h>
7983  #include <fcntl.h>
7984  
7985 +#ifdef USE_NNTP
7986 +#include "nntp.h"
7987 +#endif
7988 +
7989  #ifdef HAVE_SYSEXITS_H
7990  #include <sysexits.h>
7991  #else /* Make sure EX_OK is defined <philiph@pobox.com> */
7992 @@ -1576,6 +1580,14 @@ void mutt_write_references (LIST *r, FIL
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    {
8007 @@ -1586,9 +1598,11 @@ void mutt_write_references (LIST *r, FIL
8008  
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  
8021 @@ -2002,6 +2016,9 @@ int mutt_write_rfc822_header (FILE *fp,
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)
8031 @@ -2010,6 +2027,9 @@ int mutt_write_rfc822_header (FILE *fp,
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)
8041 @@ -2021,8 +2041,28 @@ int mutt_write_rfc822_header (FILE *fp,
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
8066 +
8067    if (env->subject)
8068      mutt_write_one_header (fp, "Subject", env->subject, NULL, 0, 0);
8069    else if (mode == 1)
8070 @@ -2041,6 +2081,9 @@ int mutt_write_rfc822_header (FILE *fp,
8071      fputs ("Reply-To: \n", fp);
8072  
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);
8080 @@ -2388,6 +2431,24 @@ mutt_invoke_sendmail (ADDRESS *from,     /*
8081    size_t extra_argslen = 0, extra_argsmax = 0;
8082    int i;
8083  
8084 +#ifdef USE_NNTP
8085 +  if (option (OPTNEWSSEND))
8086 +  {
8087 +    char cmd[LONG_STRING];
8088 +
8089 +    mutt_FormatString (cmd, sizeof (cmd), 0, MuttIndexWindow->cols,
8090 +                      NONULL (Inews), nntp_format_str, 0, 0);
8091 +    if (!*cmd)
8092 +    {
8093 +      i = nntp_post (msg);
8094 +      unlink (msg);
8095 +      return i;
8096 +    }
8097 +
8098 +    s = safe_strdup (cmd);
8099 +  }
8100 +#endif
8101 +
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      }
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  
8116 @@ -2470,6 +2535,9 @@ mutt_invoke_sendmail (ADDRESS *from,      /*
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));
8126 @@ -2558,6 +2626,9 @@ void mutt_prepare_envelope (ENVELOPE *en
8127    rfc2047_encode_string (&env->x_label);
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    }
8136 @@ -2678,6 +2749,10 @@ int mutt_bounce_message (FILE *fp, HEADE
8137    }
8138    rfc822_write_address (resent_from, sizeof (resent_from), from, 0);
8139  
8140 +#ifdef USE_NNTP
8141 +  unset_option (OPTNEWSSEND);
8142 +#endif
8143 +
8144    /*
8145     * prepare recipient list. idna conversion appears to happen before this
8146     * function is called, since the user receives confirmation of the address
8147 diff -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"
8153  
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,
8163    HEADER **ha = (HEADER **) a;
8164    HEADER **hb = (HEADER **) b;
8165  
8166 +#ifdef USE_NNTP
8167 +  if (Context && Context->magic == MUTT_NNTP)
8168 +  {
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);
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  }
8180 diff -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[] =
8184    { "imaps",   U_IMAPS },
8185    { "pop",     U_POP },
8186    { "pops",    U_POPS },
8187 +  { "news",    U_NNTP },
8188 +  { "snews",   U_NNTPS },
8189    { "mailto",  U_MAILTO },
8190    { "smtp",     U_SMTP },
8191    { "smtps",    U_SMTPS },
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);
8201 diff -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
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,
8213 diff -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
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 \
8221         sidebar.c smime.c smtp.c utf8.c wcwidth.c \
8222         bcache.h browser.h hcache.h mbyte.h mutt_idna.h remailer.h url.h
8223  
8224 @@ -71,6 +72,7 @@ EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP O
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 \
8229         _mutt_regex.h OPS.MIX README.SECURITY remailer.c remailer.h browser.h \
8230         mbyte.h lib.h extlib.c pgpewrap.c smime_keys.pl pgplib.h \
8231         README.SSL smime.h group.h \
8232 diff -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
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 \
8240         sidebar.c smime.c smtp.c utf8.c wcwidth.c \
8241         bcache.h browser.h hcache.h mbyte.h mutt_idna.h remailer.h url.h
8242  
8243 @@ -515,6 +516,7 @@ EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP O
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 \
8248         _mutt_regex.h OPS.MIX README.SECURITY remailer.c remailer.h browser.h \
8249         mbyte.h lib.h extlib.c pgpewrap.c smime_keys.pl pgplib.h \
8250         README.SSL smime.h group.h \
8251 @@ -784,6 +786,8 @@ distclean-compile:
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
8260 diff -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:
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
8279 @@ -9750,6 +9752,20 @@ else
8280  fi
8281  
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
8288 +
8289 +               MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS nntp.o newsrc.o"
8290 +               need_nntp="yes"
8291 +               need_socket="yes"
8292 +       fi
8293 +
8294 +fi
8295 +
8296 +
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
8302  
8303  
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
8308  
8309 diff -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.
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 +# 
8338  # set assumed_charset=""
8339  #
8340  # Name: assumed_charset
8341 @@ -516,6 +538,17 @@ attachments   -I message/external-body
8342  # desirable to unset this variable.
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 +# 
8356  # set certificate_file="~/.mutt_certificates"
8357  #
8358  # Name: certificate_file
8359 @@ -1294,6 +1327,19 @@ attachments   -I message/external-body
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
8379 @@ -1430,6 +1476,27 @@ attachments   -I message/external-body
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:
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
8407 @@ -2046,6 +2113,7 @@ attachments   -I message/external-body
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
8411 +# %g      newsgroup name (if compiled with NNTP support)
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,
8415 @@ -2069,6 +2137,8 @@ attachments   -I message/external-body
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
8419 +# %W      name of organization of author (``Organization:'' field)
8420 +# %x      ``X-Comment-To:'' field (if present and compiled with NNTP support)
8421  # %X      number of attachments
8422  #         (please see the ``attachments'' section for possible speed effects)
8423  # %y      ``X-Label:'' field, if present
8424 @@ -2108,6 +2178,27 @@ attachments   -I message/external-body
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:
8438 +# %a      account url
8439 +# %p      port
8440 +# %P      port if specified
8441 +# %s      news server name
8442 +# %S      url schema
8443 +# %u      username
8444 +# 
8445 +# 
8446 +# Example: set inews="/usr/local/bin/inews -hS"
8447 +# 
8448 +# 
8449  # set ispell="/usr/bin/ispell"
8450  #
8451  # Name: ispell
8452 @@ -2555,6 +2646,18 @@ attachments   -I message/external-body
8453  # mime.types lookup.
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
8471 @@ -2633,6 +2736,144 @@ attachments   -I message/external-body
8472  # into this command.
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
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.
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
8495 +# defaults to the news server specified in the environment variable
8496 +# $NNTPSERVER or contained in the file /etc/nntpserver.  You can also
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 +# 
8508 +# 
8509 +# Character set of newsgroups descriptions.
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:
8522 +# %a      account url
8523 +# %p      port
8524 +# %P      port if specified
8525 +# %s      news server name
8526 +# %S      url schema
8527 +# %u      username
8528 +# 
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.
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
8587 +# connect to news server.
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 +# 
8612 +# 
8613  # set pager="builtin"
8614  #
8615  # Name: pager
8616 @@ -3411,6 +3652,19 @@ attachments   -I message/external-body
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
8628 +# not permissions to posting (e.g. moderated).  Note: if news server
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
8636 @@ -4285,6 +4539,41 @@ attachments   -I message/external-body
8637  # Chinese characters.
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 +# 
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.
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
8678 @@ -5671,3 +5960,14 @@ attachments   -I message/external-body
8679  # ``tuning'' section of the manual for performance considerations.
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.029213 seconds and 3 git commands to generate.