1 WARNING: Run the following script before configure:
9 Vsevolod Volkov <vvv@mutt.org.ua>
12 diff -udprP mutt-1.12.1.orig/ChangeLog.nntp mutt-1.12.1/ChangeLog.nntp
13 --- mutt-1.12.1.orig/ChangeLog.nntp 1970-01-01 03:00:00.000000000 +0300
14 +++ mutt-1.12.1/ChangeLog.nntp 2019-08-11 20:31:26.130940734 +0300
16 +* Sun Aug 11 2019 Vsevolod Volkov <vvv@mutt.org.ua>
19 +* Sun Aug 11 2019 Vsevolod Volkov <vvv@mutt.org.ua>
22 +* Sun Dec 9 2018 Vsevolod Volkov <vvv@mutt.org.ua>
25 +* Sun Dec 9 2018 Vsevolod Volkov <vvv@mutt.org.ua>
27 +- FREE(&hdata) replaced with mutt_hcache_free(&hdata)
28 + (thanks to Steffen Wolf)
29 +- fixed SIGSEGV when pressing OP_FOLLOWUP in attachment menu
30 + (thanks to Moritz Barsnick)
32 +* Sat Jun 16 2018 Vsevolod Volkov <vvv@mutt.org.ua>
35 +* Thu Apr 19 2018 Vsevolod Volkov <vvv@mutt.org.ua>
38 +* Sat Sep 9 2017 Vsevolod Volkov <vvv@mutt.org.ua>
41 +* Sun Feb 26 2017 Vsevolod Volkov <vvv@mutt.org.ua>
44 +* Sun Dec 18 2016 Vsevolod Volkov <vvv@mutt.org.ua>
47 +* Sun Oct 9 2016 Vsevolod Volkov <vvv@mutt.org.ua>
50 +* Wed Aug 31 2016 Vsevolod Volkov <vvv@mutt.org.ua>
51 +- newsgroups aren't marked as new on first load
53 +* Wed Aug 24 2016 Vsevolod Volkov <vvv@mutt.org.ua>
55 +- fixed new groups marking
56 +- fixed unread messages counter update
58 +* Sat Aug 6 2016 Vsevolod Volkov <vvv@mutt.org.ua>
61 +* Sat Aug 6 2016 Vsevolod Volkov <vvv@mutt.org.ua>
64 +* Wed Apr 6 2016 Vsevolod Volkov <vvv@mutt.org.ua>
66 +- %R changed to %x in format strings
68 +* Wed Nov 25 2015 Vsevolod Volkov <vvv@mutt.org.ua>
70 +- fixed SIGSEGV when reading hcache in some cases
72 +* Tue Nov 10 2015 Vsevolod Volkov <vvv@mutt.org.ua>
73 +- fixed error compiling with nntp and without imap or pop3
74 +- fixed error loading articles after <change-newsgroup> and <quit>
76 +* Wed Sep 2 2015 Vsevolod Volkov <vvv@mutt.org.ua>
78 +- new option nntp_listgroup
79 +- use range in LISTGROUP command if possible
81 +* Thu Mar 13 2014 Vsevolod Volkov <vvv@mutt.org.ua>
84 +* Tue Oct 29 2013 Vsevolod Volkov <vvv@mutt.org.ua>
85 +- minor bug fixed while removing new articles
87 +* Fri Oct 18 2013 Vsevolod Volkov <vvv@mutt.org.ua>
90 +* Tue Nov 27 2012 Vsevolod Volkov <vvv@mutt.org.ua>
91 +- SASL authentication
92 +- new option nntp_authenticators
94 +* Fri Nov 16 2012 Vsevolod Volkov <vvv@mutt.org.ua>
95 +- support of NNTP commands: CAPABILITIES, STARTTLS, LIST NEWSGROUPS,
96 + LIST OVERVIEW.FMT, OVER, DATE
97 +- added bcache support
98 +- newss URI scheme renamed to snews
99 +- removed option nntp_reconnect
101 +* Sun Sep 16 2012 Vsevolod Volkov <vvv@mutt.org.ua>
102 +- internal header caching replaced with hcache
103 +- new option newsgroups_charset
105 +* Wed Sep 16 2010 Vsevolod Volkov <vvv@mutt.org.ua>
108 +* Thu Aug 13 2009 Vsevolod Volkov <vvv@mutt.org.ua>
109 +- fixed writting references in nntp_save_cache_group()
111 +* Tue Jun 15 2009 Vsevolod Volkov <vvv@mutt.org.ua>
114 +* Tue Mar 20 2009 Vsevolod Volkov <vvv@mutt.org.ua>
115 +- save Date: header of recorded outgoing articles
117 +* Tue Jan 6 2009 Vsevolod Volkov <vvv@mutt.org.ua>
120 +* Mon May 19 2008 Vsevolod Volkov <vvv@mutt.org.ua>
122 +- fixed SIGSEGV when followup or forward to newsgroup
124 +* Sun Nov 4 2007 Vsevolod Volkov <vvv@mutt.org.ua>
127 +* Tue Jul 3 2007 Vsevolod Volkov <vvv@mutt.org.ua>
128 +- fixed arguments of nntp_format_str()
130 +* Fri Jun 15 2007 Vsevolod Volkov <vvv@mutt.org.ua>
131 +- fixed error selecting news group
133 +* Tue Jun 12 2007 Vsevolod Volkov <vvv@mutt.org.ua>
136 +* Wed Apr 11 2007 Vsevolod Volkov <vvv@mutt.org.ua>
137 +- fixed posting error if $smtp_url is set
138 +- added support of print-style sequence %R (x-comment-to)
140 +* Sun Apr 8 2007 Vsevolod Volkov <vvv@mutt.org.ua>
142 +- nntp://... url changed to news://...
143 +- added indicator of fetching descriptions progress
145 +* Tue Feb 28 2007 Vsevolod Volkov <vvv@mutt.org.ua>
148 +* Tue Aug 15 2006 Vsevolod Volkov <vvv@mutt.org.ua>
151 +* Mon Jul 17 2006 Vsevolod Volkov <vvv@mutt.org.ua>
153 +- fixed reading empty .newsrc
155 +* Sat Sep 17 2005 Vsevolod Volkov <vvv@mutt.org.ua>
158 +* Sat Aug 13 2005 Vsevolod Volkov <vvv@mutt.org.ua>
161 +* Sun Mar 13 2005 Vsevolod Volkov <vvv@mutt.org.ua>
164 +* Sun Feb 13 2005 Vsevolod Volkov <vvv@mutt.org.ua>
167 +* Sat Feb 5 2005 Vsevolod Volkov <vvv@mutt.org.ua>
169 +- function mutt_update_list_file() moved to newsrc.c and changed algorithm
171 +* Thu Jul 8 2004 Vsevolod Volkov <vvv@mutt.org.ua>
172 +- fixed error in nntp_logout_all()
174 +* Sat Apr 3 2004 Vsevolod Volkov <vvv@mutt.org.ua>
175 +- fixed debug output in mutt_newsrc_update()
176 +- added optional support of LISTGROUP command
177 +- fixed typo in nntp_parse_xref()
179 +* Tue Feb 3 2004 Vsevolod Volkov <vvv@mutt.org.ua>
182 +* Thu Dec 18 2003 Vsevolod Volkov <vvv@mutt.org.ua>
183 +- fixed compose menu
185 +* Thu Nov 6 2003 Vsevolod Volkov <vvv@mutt.org.ua>
188 +* Wed Nov 5 2003 Vsevolod Volkov <vvv@mutt.org.ua>
190 +- added space after newsgroup name in .newsrc file
192 +* Sun May 18 2003 Vsevolod Volkov <vvv@mutt.org.ua>
193 +- fixed SIGSEGV when posting article
195 +* Sat Mar 22 2003 Vsevolod Volkov <vvv@mutt.org.ua>
198 +* Sat Dec 21 2002 Vsevolod Volkov <vvv@mutt.org.ua>
200 +- replace safe_free calls by the FREE macro
202 +* Fri Dec 6 2002 Vsevolod Volkov <vvv@mutt.org.ua>
204 +- nntp authentication can be passed after any command
206 +* Sat May 4 2002 Vsevolod Volkov <vvv@mutt.org.ua>
209 +* Thu May 2 2002 Vsevolod Volkov <vvv@mutt.org.ua>
212 +* Wed Mar 13 2002 Vsevolod Volkov <vvv@mutt.org.ua>
214 +- fixed SIGSEGV in <get-message>, <get-parent>, <get-children>,
215 + <reconstruct-thread> functions
216 +- fixed message about nntp reconnect
217 +- fixed <attach-news-message> function using browser
218 +- added support of Followup-To: poster
219 +- added %n (new articles) in group_index_format
220 +- posting articles without inews by default
222 +* Wed Jan 23 2002 Vsevolod Volkov <vvv@mutt.org.ua>
225 +* Fri Jan 18 2002 Vsevolod Volkov <vvv@mutt.org.ua>
228 +* Thu Jan 3 2002 Vsevolod Volkov <vvv@mutt.org.ua>
230 +- accelerated speed of access to news->newsgroups hash (by <gul@gul.kiev.ua>)
231 +- added default content disposition
233 +* Mon Dec 3 2001 Vsevolod Volkov <vvv@mutt.org.ua>
236 +* Fri Nov 9 2001 Vsevolod Volkov <vvv@mutt.org.ua>
237 +- update to 1.3.23.2
238 +- fixed segfault if mutt_conn_find() returns null
240 +* Wed Oct 31 2001 Vsevolod Volkov <vvv@mutt.org.ua>
241 +- update to 1.3.23.1
242 +- added support of LISTGROUP command
243 +- added support for servers with broken overview
244 +- disabled <flag-message> function on news server
245 +- fixed error storing bad authentication information
247 +* Wed Oct 10 2001 Vsevolod Volkov <vvv@mutt.org.ua>
249 +- fixed typo in buffy.c
250 +- added substitution of %s parameter in $inews variable
252 +* Fri Aug 31 2001 Vsevolod Volkov <vvv@mutt.org.ua>
253 +- update to 1.3.22.1
256 +* Thu Aug 23 2001 Vsevolod Volkov <vvv@mutt.org.ua>
259 +* Wed Jul 25 2001 Vsevolod Volkov <vvv@mutt.org.ua>
261 +- removed 'server-hook', use 'account-hook' instead
262 +- fixed error opening NNTP server without newsgroup using -f option
264 +* Fri Jun 8 2001 Vsevolod Volkov <vvv@mutt.org.ua>
267 +* Sat May 5 2001 Vsevolod Volkov <vvv@mutt.org.ua>
269 +- fixed typo in nntp_attempt_features()
270 +- changed algorithm of XGTITLE command testing
271 +- disabled writing of NNTP password in debug file
272 +- fixed reading and writing of long newsrc lines
273 +- changed checking of last line while reading lines from server
274 +- fixed possible buffer overrun in nntp_parse_newsrc_line()
275 +- removed checking of XHDR command
276 +- compare NNTP return codes without trailing space
278 +* Thu Mar 29 2001 Vsevolod Volkov <vvv@mutt.org.ua>
280 +- support for 'LIST NEWSGROUPS' command to read descriptions
282 +* Fri Mar 2 2001 Vsevolod Volkov <vvv@mutt.org.ua>
285 +* Wed Feb 14 2001 Vsevolod Volkov <vvv@mutt.org.ua>
288 +* Sun Jan 28 2001 Vsevolod Volkov <vvv@mutt.org.ua>
290 +- show number of tagged messages patch from Felix von Leitner <leitner@fefe.de>
292 +* Sun Dec 31 2000 Vsevolod Volkov <vvv@mutt.org.ua>
295 +* Sat Dec 30 2000 Vsevolod Volkov <vvv@mutt.org.ua>
296 +- Fixed problem if last article in group is deleted
298 +* Fri Dec 22 2000 Vsevolod Volkov <vvv@mutt.org.ua>
299 +- Fixed checking of XGTITLE command on some servers
301 +* Mon Dec 18 2000 Vsevolod Volkov <vvv@mutt.org.ua>
302 +- Added \r in AUTHINFO commands
304 +* Mon Nov 27 2000 Vsevolod Volkov <vvv@mutt.org.ua>
307 +* Wed Nov 1 2000 Vsevolod Volkov <vvv@mutt.org.ua>
309 +- fixed error opening newsgroup from mutt started with -g or -G
311 +* Thu Oct 12 2000 Vsevolod Volkov <vvv@mutt.org.ua>
313 +- hotkey 'G' (get-message) replaced with '^G'
315 +* Thu Sep 21 2000 Vsevolod Volkov <vvv@mutt.org.ua>
317 +- changed delay displaying error messages from 1 to 2 seconds
318 +- fixed error compiling with nntp and without imap
320 +* Wed Sep 6 2000 Vsevolod Volkov <vvv@mutt.org.ua>
321 +- fixed catchup in index
322 +- fixed nntp_open_mailbox()
324 +* Sat Sep 2 2000 Vsevolod Volkov <vvv@mutt.org.ua>
325 +- functions <edit> and <delete-entry> disabled
326 +- format of news mailbox names changed to url form
327 +- option nntp_attempts removed
328 +- option reconnect_news renamed to nntp_reconnect
329 +- default value of nntp_poll changed from 30 to 60
330 +- error handling improved
332 +* Wed Aug 30 2000 Vsevolod Volkov <vvv@mutt.org.ua>
334 +- new option show_only_unread
335 +- add newsgroup completion
337 +* Fri Aug 4 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
340 +* Sat Jul 29 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
343 +* Sun Jul 9 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
345 +- authentication code update
346 +- fix for changing to newsgroup from mailbox with read messages
347 +- socket code optimization
349 +* Wed Jun 21 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
352 +* Wed Jun 14 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
353 +- don't substitute current newsgroup with deleted new messages
355 +* Mon Jun 12 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
357 +- fix for substitution of newsgroup after reconnection
358 +- fix for loading newsgroups with very long names
359 +- fix for loading more than 32768 newsgroups
361 +* Wed May 24 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
364 +* Sat May 20 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
367 +* Fri May 12 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
370 +* Thu May 11 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
373 +* Thu May 4 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
376 +* Sun Apr 23 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
379 +* Fri Apr 7 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
380 +- add substitution of newsgroup with new messages by default
382 +* Wed Apr 5 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
383 +- add attach message from newsgroup
384 +- add one-line help in newsreader mode
385 +- disable 'change-dir' command in newsgroups browser
388 +* Tue Apr 4 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
389 +- get default news server name from file /etc/nntpserver
390 +- use case insensitive server names
391 +- add print-style sequence %s to $newsrc
394 +* Sat Apr 1 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
395 +- remove 'X-FTN-Origin' header processing
397 +* Thu Mar 30 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
401 +* Thu Mar 23 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
402 +- fix mutt_select_newsserver()
403 +- remove 'toggle-mode' function
404 +- add 'change-newsgroup' function
406 +* Wed Mar 22 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
409 +* Tue Mar 21 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
410 +- fix error 'bounce' function after 'post'
411 +- add 'forward to newsgroup' function
413 +* Mon Mar 20 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
414 +- 'forward' function works in newsreader mode
415 +- add 'post' and 'followup' functions to pager and attachment menu
416 +- fix active descriptions and allowed flag reload
418 +* Tue Mar 14 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
420 +- remove deleted newsgroups from list
422 +* Mon Mar 13 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
423 +- update .newsrc in browser
425 +* Sun Mar 12 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
426 +- reload .newsrc if externally modified
427 +- fix active cache update
429 +* Sun Mar 5 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
432 +* Sat Mar 4 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
433 +- patch *.update_list_file is not required
434 +- count lines when loading descriptions
435 +- remove cache of unsubscribed newsgroups
437 +* Thu Mar 2 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
438 +- load list of newsgroups from cache faster
440 +* Wed Mar 1 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
443 +* Tue Feb 29 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
444 +- fix unread messages in browser
445 +- fix newsrc_gen_entries()
447 +* Mon Feb 28 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
448 +- fix mutt_newsgroup_stat()
449 +- fix nntp_delete_cache()
450 +- fix nntp_get_status()
451 +- fix check_children()
452 +- fix nntp_fetch_headers()
454 +* Fri Feb 25 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
457 +* Thu Feb 24 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
458 +- fix updating new messages in cache
460 +* Mon Feb 21 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
461 +- change default cache filenames
462 +- fix updating new messages in cache
464 +* Fri Feb 18 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
465 +- fix segmentation fault in news groups browser
467 +* Tue Feb 15 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
470 +* Thu Feb 10 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
473 +* Sun Jan 30 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
474 +- add X-Comment-To editing
475 +- add my_hdr support for Newsgroups:, Followup-To: and X-Comment-To: headers
476 +- add variables $ask_followup_to and $ask_x_comment_to
478 +* Fri Jan 28 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
480 diff -udprP mutt-1.12.1.orig/Makefile.am mutt-1.12.1/Makefile.am
481 --- mutt-1.12.1.orig/Makefile.am 2019-06-15 18:57:01.000000000 +0300
482 +++ mutt-1.12.1/Makefile.am 2019-08-11 20:31:26.131940718 +0300
483 @@ -60,6 +60,7 @@ EXTRA_mutt_SOURCES = account.c bcache.c
484 mutt_idna.c mutt_sasl.c mutt_socket.c mutt_ssl.c mutt_ssl_gnutls.c \
485 mutt_tunnel.c pgp.c pgpinvoke.c pgpkey.c pgplib.c pgpmicalg.c \
486 pgppacket.c pop.c pop_auth.c pop_lib.c remailer.c resize.c sha1.c \
488 sidebar.c smime.c smtp.c utf8.c wcwidth.c \
489 bcache.h browser.h hcache.h mbyte.h monitor.h mutt_idna.h remailer.h url.h
491 @@ -72,6 +73,7 @@ EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP O
492 mutt_regex.h mutt_sasl.h mutt_socket.h mutt_ssl.h mutt_tunnel.h \
493 mx.h pager.h pgp.h pop.h protos.h rfc1524.h rfc2047.h \
494 rfc2231.h rfc822.h rfc3676.h sha1.h sort.h mime.types VERSION prepare \
495 + nntp.h ChangeLog.nntp \
496 _mutt_regex.h OPS.MIX README.SECURITY remailer.c remailer.h browser.h \
497 mbyte.h lib.h extlib.c pgpewrap.c smime_keys.pl pgplib.h \
498 README.SSL smime.h group.h \
499 diff -udprP mutt-1.12.1.orig/Makefile.in mutt-1.12.1/Makefile.in
500 --- mutt-1.12.1.orig/Makefile.in 2019-06-15 19:07:04.000000000 +0300
501 +++ mutt-1.12.1/Makefile.in 2019-08-11 20:31:38.771749259 +0300
502 @@ -256,6 +256,7 @@ am__depfiles_remade = $(DEPDIR)/mkdtemp.
503 ./$(DEPDIR)/rfc3676.Po ./$(DEPDIR)/rfc822.Po \
504 ./$(DEPDIR)/safe_asprintf.Po ./$(DEPDIR)/score.Po \
505 ./$(DEPDIR)/send.Po ./$(DEPDIR)/sendlib.Po ./$(DEPDIR)/sha1.Po \
506 + ./$(DEPDIR)/newsrc.Po ./$(DEPDIR)/nntp.Po \
507 ./$(DEPDIR)/sidebar.Po ./$(DEPDIR)/signal.Po \
508 ./$(DEPDIR)/smime.Po ./$(DEPDIR)/smtp.Po ./$(DEPDIR)/sort.Po \
509 ./$(DEPDIR)/status.Po ./$(DEPDIR)/system.Po \
510 @@ -570,6 +571,7 @@ EXTRA_mutt_SOURCES = account.c bcache.c
511 mutt_idna.c mutt_sasl.c mutt_socket.c mutt_ssl.c mutt_ssl_gnutls.c \
512 mutt_tunnel.c pgp.c pgpinvoke.c pgpkey.c pgplib.c pgpmicalg.c \
513 pgppacket.c pop.c pop_auth.c pop_lib.c remailer.c resize.c sha1.c \
515 sidebar.c smime.c smtp.c utf8.c wcwidth.c \
516 bcache.h browser.h hcache.h mbyte.h monitor.h mutt_idna.h remailer.h url.h
518 @@ -582,6 +584,7 @@ EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP O
519 mutt_regex.h mutt_sasl.h mutt_socket.h mutt_ssl.h mutt_tunnel.h \
520 mx.h pager.h pgp.h pop.h protos.h rfc1524.h rfc2047.h \
521 rfc2231.h rfc822.h rfc3676.h sha1.h sort.h mime.types VERSION prepare \
522 + nntp.h ChangeLog.nntp \
523 _mutt_regex.h OPS.MIX README.SECURITY remailer.c remailer.h browser.h \
524 mbyte.h lib.h extlib.c pgpewrap.c smime_keys.pl pgplib.h \
525 README.SSL smime.h group.h \
526 @@ -853,6 +856,8 @@ distclean-compile:
527 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mutt_tunnel.Po@am__quote@ # am--include-marker
528 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/muttlib.Po@am__quote@ # am--include-marker
529 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mx.Po@am__quote@ # am--include-marker
530 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/newsrc.Po@am__quote@ # am--include-marker
531 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nntp.Po@am__quote@ # am--include-marker
532 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pager.Po@am__quote@ # am--include-marker
533 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parse.Po@am__quote@ # am--include-marker
534 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/patchlist.Po@am__quote@ # am--include-marker
535 @@ -1356,6 +1361,8 @@ distclean: distclean-recursive
536 -rm -f ./$(DEPDIR)/mutt_tunnel.Po
537 -rm -f ./$(DEPDIR)/muttlib.Po
538 -rm -f ./$(DEPDIR)/mx.Po
539 + -rm -f ./$(DEPDIR)/newsrc.Po
540 + -rm -f ./$(DEPDIR)/nntp.Po
541 -rm -f ./$(DEPDIR)/pager.Po
542 -rm -f ./$(DEPDIR)/parse.Po
543 -rm -f ./$(DEPDIR)/patchlist.Po
544 @@ -1525,6 +1532,8 @@ maintainer-clean: maintainer-clean-recur
545 -rm -f ./$(DEPDIR)/mutt_tunnel.Po
546 -rm -f ./$(DEPDIR)/muttlib.Po
547 -rm -f ./$(DEPDIR)/mx.Po
548 + -rm -f ./$(DEPDIR)/newsrc.Po
549 + -rm -f ./$(DEPDIR)/nntp.Po
550 -rm -f ./$(DEPDIR)/pager.Po
551 -rm -f ./$(DEPDIR)/parse.Po
552 -rm -f ./$(DEPDIR)/patchlist.Po
553 diff -udprP mutt-1.12.1.orig/OPS mutt-1.12.1/OPS
554 --- mutt-1.12.1.orig/OPS 2019-05-25 19:22:39.000000000 +0300
555 +++ mutt-1.12.1/OPS 2019-08-11 20:31:26.132940703 +0300
556 @@ -8,14 +8,16 @@ OP_BOUNCE_MESSAGE "remail a message to a
557 OP_BROWSER_NEW_FILE "select a new file in this directory"
558 OP_BROWSER_VIEW_FILE "view file"
559 OP_BROWSER_TELL "display the currently selected file's name"
560 -OP_BROWSER_SUBSCRIBE "subscribe to current mailbox (IMAP only)"
561 -OP_BROWSER_UNSUBSCRIBE "unsubscribe from current mailbox (IMAP only)"
562 +OP_BROWSER_SUBSCRIBE "subscribe to current mbox (IMAP/NNTP only)"
563 +OP_BROWSER_UNSUBSCRIBE "unsubscribe from current mbox (IMAP/NNTP only)"
564 OP_BROWSER_TOGGLE_LSUB "toggle view all/subscribed mailboxes (IMAP only)"
565 OP_BUFFY_LIST "list mailboxes with new mail"
566 +OP_CATCHUP "mark all articles in newsgroup as read"
567 OP_CHANGE_DIRECTORY "change directories"
568 OP_CHECK_NEW "check mailboxes for new mail"
569 OP_COMPOSE_ATTACH_FILE "attach file(s) to this message"
570 OP_COMPOSE_ATTACH_MESSAGE "attach message(s) to this message"
571 +OP_COMPOSE_ATTACH_NEWS_MESSAGE "attach news article(s) to this message"
572 OP_COMPOSE_EDIT_BCC "edit the BCC list"
573 OP_COMPOSE_EDIT_CC "edit the CC list"
574 OP_COMPOSE_EDIT_DESCRIPTION "edit attachment description"
575 @@ -26,7 +28,10 @@ OP_COMPOSE_EDIT_FROM "edit the from fiel
576 OP_COMPOSE_EDIT_HEADERS "edit the message with headers"
577 OP_COMPOSE_EDIT_MESSAGE "edit the message"
578 OP_COMPOSE_EDIT_MIME "edit attachment using mailcap entry"
579 +OP_COMPOSE_EDIT_NEWSGROUPS "edit the newsgroups list"
580 OP_COMPOSE_EDIT_REPLY_TO "edit the Reply-To field"
581 +OP_COMPOSE_EDIT_FOLLOWUP_TO "edit the Followup-To field"
582 +OP_COMPOSE_EDIT_X_COMMENT_TO "edit the X-Comment-To field"
583 OP_COMPOSE_EDIT_SUBJECT "edit the subject of this message"
584 OP_COMPOSE_EDIT_TO "edit the TO list"
585 OP_CREATE_MAILBOX "create a new mailbox (IMAP only)"
586 @@ -90,8 +95,13 @@ OP_EXIT "exit this menu"
587 OP_FILTER "filter attachment through a shell command"
588 OP_FIRST_ENTRY "move to the first entry"
589 OP_FLAG_MESSAGE "toggle a message's 'important' flag"
590 +OP_FOLLOWUP "followup to newsgroup"
591 +OP_FORWARD_TO_GROUP "forward to newsgroup"
592 OP_FORWARD_MESSAGE "forward a message with comments"
593 OP_GENERIC_SELECT_ENTRY "select the current entry"
594 +OP_GET_CHILDREN "get all children of the current message"
595 +OP_GET_MESSAGE "get message with Message-Id"
596 +OP_GET_PARENT "get parent of the current message"
597 OP_GROUP_CHAT_REPLY "reply to all recipients preserving To/Cc"
598 OP_GROUP_REPLY "reply to all recipients"
599 OP_HALF_DOWN "scroll down 1/2 page"
600 @@ -100,11 +110,14 @@ OP_HELP "this screen"
601 OP_JUMP "jump to an index number"
602 OP_LAST_ENTRY "move to the last entry"
603 OP_LIST_REPLY "reply to specified mailing list"
604 +OP_LOAD_ACTIVE "load list of all newsgroups from NNTP server"
605 OP_MACRO "execute a macro"
606 OP_MAIL "compose a new mail message"
607 OP_MAIN_BREAK_THREAD "break the thread in two"
608 OP_MAIN_CHANGE_FOLDER "open a different folder"
609 OP_MAIN_CHANGE_FOLDER_READONLY "open a different folder in read only mode"
610 +OP_MAIN_CHANGE_GROUP "open a different newsgroup"
611 +OP_MAIN_CHANGE_GROUP_READONLY "open a different newsgroup in read only mode"
612 OP_MAIN_CLEAR_FLAG "clear a status flag from a message"
613 OP_MAIN_DELETE_PATTERN "delete messages matching a pattern"
614 OP_MAIN_IMAP_FETCH "force retrieval of mail from IMAP server"
615 @@ -144,6 +157,7 @@ OP_PAGER_HIDE_QUOTED "toggle display of
616 OP_PAGER_SKIP_QUOTED "skip beyond quoted text"
617 OP_PAGER_TOP "jump to the top of the message"
618 OP_PIPE "pipe message/attachment to a shell command"
619 +OP_POST "post message to newsgroup"
620 OP_PREV_ENTRY "move to the previous entry"
621 OP_PREV_LINE "scroll up one line"
622 OP_PREV_PAGE "move to the previous page"
623 @@ -153,6 +167,7 @@ OP_QUERY "query external program for add
624 OP_QUERY_APPEND "append new query results to current results"
625 OP_QUIT "save changes to mailbox and quit"
626 OP_RECALL_MESSAGE "recall a postponed message"
627 +OP_RECONSTRUCT_THREAD "reconstruct thread containing current message"
628 OP_REDRAW "clear and redraw the screen"
629 OP_REFORMAT_WINCH "{internal}"
630 OP_RENAME_MAILBOX "rename the current mailbox (IMAP only)"
631 @@ -167,18 +182,22 @@ OP_SEARCH_TOGGLE "toggle search pattern
632 OP_SHELL_ESCAPE "invoke a command in a subshell"
633 OP_SORT "sort messages"
634 OP_SORT_REVERSE "sort messages in reverse order"
635 +OP_SUBSCRIBE_PATTERN "subscribe to newsgroups matching a pattern"
636 OP_TAG "tag the current entry"
637 OP_TAG_PREFIX "apply next function to tagged messages"
638 OP_TAG_PREFIX_COND "apply next function ONLY to tagged messages"
639 OP_TAG_SUBTHREAD "tag the current subthread"
640 OP_TAG_THREAD "tag the current thread"
641 OP_TOGGLE_NEW "toggle a message's 'new' flag"
642 +OP_TOGGLE_READ "toggle view of read messages"
643 OP_TOGGLE_WRITE "toggle whether the mailbox will be rewritten"
644 OP_TOGGLE_MAILBOXES "toggle whether to browse mailboxes or all files"
645 OP_TOP_PAGE "move to the top of the page"
646 +OP_UNCATCHUP "mark all articles in newsgroup as unread"
647 OP_UNDELETE "undelete the current entry"
648 OP_UNDELETE_THREAD "undelete all messages in thread"
649 OP_UNDELETE_SUBTHREAD "undelete all messages in subthread"
650 +OP_UNSUBSCRIBE_PATTERN "unsubscribe from newsgroups matching a pattern"
651 OP_VERSION "show the Mutt version number and date"
652 OP_VIEW_ATTACH "view attachment using mailcap entry if necessary"
653 OP_VIEW_ATTACHMENTS "show MIME attachments"
654 diff -udprP mutt-1.12.1.orig/PATCHES mutt-1.12.1/PATCHES
655 --- mutt-1.12.1.orig/PATCHES 2017-12-03 05:10:17.000000000 +0200
656 +++ mutt-1.12.1/PATCHES 2019-08-11 20:31:26.132940703 +0300
659 diff -udprP mutt-1.12.1.orig/account.c mutt-1.12.1/account.c
660 --- mutt-1.12.1.orig/account.c 2019-05-25 19:22:39.000000000 +0300
661 +++ mutt-1.12.1/account.c 2019-08-11 20:31:26.133940688 +0300
662 @@ -51,8 +51,17 @@ int mutt_account_match (const ACCOUNT* a
667 + if (a1->type == MUTT_ACCT_TYPE_NNTP && NntpUser)
671 if (a1->flags & a2->flags & MUTT_ACCT_USER)
672 return (!strcmp (a1->user, a2->user));
674 + if (a1->type == MUTT_ACCT_TYPE_NNTP)
675 + return a1->flags & MUTT_ACCT_USER && a1->user[0] ? 0 : 1;
677 if (a1->flags & MUTT_ACCT_USER)
678 return (!strcmp (a1->user, user));
679 if (a2->flags & MUTT_ACCT_USER)
680 @@ -130,6 +139,16 @@ void mutt_account_tourl (ACCOUNT* accoun
685 + if (account->type == MUTT_ACCT_TYPE_NNTP)
687 + if (account->flags & MUTT_ACCT_SSL)
688 + url->scheme = U_NNTPS;
690 + url->scheme = U_NNTP;
694 url->host = account->host;
695 if (account->flags & MUTT_ACCT_PORT)
696 url->port = account->port;
697 @@ -155,6 +174,10 @@ int mutt_account_getuser (ACCOUNT* accou
698 else if ((account->type == MUTT_ACCT_TYPE_POP) && PopUser)
699 strfcpy (account->user, PopUser, sizeof (account->user));
702 + else if ((account->type == MUTT_ACCT_TYPE_NNTP) && NntpUser)
703 + strfcpy (account->user, NntpUser, sizeof (account->user));
705 else if (option (OPTNOCURSES))
707 /* prompt (defaults to unix username), copy into account->user */
708 @@ -217,6 +240,10 @@ int mutt_account_getpass (ACCOUNT* accou
709 else if ((account->type == MUTT_ACCT_TYPE_SMTP) && SmtpPass)
710 strfcpy (account->pass, SmtpPass, sizeof (account->pass));
713 + else if ((account->type == MUTT_ACCT_TYPE_NNTP) && NntpPass)
714 + strfcpy (account->pass, NntpPass, sizeof (account->pass));
716 else if (option (OPTNOCURSES))
719 diff -udprP mutt-1.12.1.orig/account.h mutt-1.12.1/account.h
720 --- mutt-1.12.1.orig/account.h 2019-05-25 19:22:39.000000000 +0300
721 +++ mutt-1.12.1/account.h 2019-08-11 20:31:26.133940688 +0300
722 @@ -29,7 +29,8 @@ enum
723 MUTT_ACCT_TYPE_NONE = 0,
726 - MUTT_ACCT_TYPE_SMTP
727 + MUTT_ACCT_TYPE_SMTP,
728 + MUTT_ACCT_TYPE_NNTP
732 diff -udprP mutt-1.12.1.orig/attach.h mutt-1.12.1/attach.h
733 --- mutt-1.12.1.orig/attach.h 2019-05-25 19:22:39.000000000 +0300
734 +++ mutt-1.12.1/attach.h 2019-08-11 20:31:26.133940688 +0300
735 @@ -71,7 +71,7 @@ void mutt_print_attachment_list (ATTACH_
737 void mutt_attach_bounce (FILE *, HEADER *, ATTACH_CONTEXT *, BODY *);
738 void mutt_attach_resend (FILE *, HEADER *, ATTACH_CONTEXT *, BODY *);
739 -void mutt_attach_forward (FILE *, HEADER *, ATTACH_CONTEXT *, BODY *);
740 +void mutt_attach_forward (FILE *, HEADER *, ATTACH_CONTEXT *, BODY *, int);
741 void mutt_attach_reply (FILE *, HEADER *, ATTACH_CONTEXT *, BODY *, int);
742 void mutt_attach_mail_sender (FILE *, HEADER *, ATTACH_CONTEXT *, BODY *);
744 diff -udprP mutt-1.12.1.orig/browser.c mutt-1.12.1/browser.c
745 --- mutt-1.12.1.orig/browser.c 2019-05-25 19:22:39.000000000 +0300
746 +++ mutt-1.12.1/browser.c 2019-08-11 20:31:26.133940688 +0300
757 @@ -50,6 +53,19 @@ static const struct mapping_t FolderHelp
762 +static struct mapping_t FolderNewsHelp[] = {
763 + { N_("Exit"), OP_EXIT },
764 + { N_("List"), OP_TOGGLE_MAILBOXES },
765 + { N_("Subscribe"), OP_BROWSER_SUBSCRIBE },
766 + { N_("Unsubscribe"), OP_BROWSER_UNSUBSCRIBE },
767 + { N_("Catchup"), OP_CATCHUP },
768 + { N_("Mask"), OP_ENTER_MASK },
769 + { N_("Help"), OP_HELP },
774 typedef struct folder_t
776 struct folder_file *ff;
777 @@ -140,9 +156,17 @@ static void browser_sort (struct browser
782 + if (option (OPTNEWS))
785 f = browser_compare_date;
789 + if (option (OPTNEWS))
792 f = browser_compare_size;
795 @@ -388,8 +412,112 @@ folder_format_str (char *dest, size_t de
801 +newsgroup_format_str (char *dest, size_t destlen, size_t col, int cols, char op,
802 + const char *src, const char *fmt, const char *ifstring,
803 + const char *elsestring, unsigned long data, format_flag flags)
805 + char fn[SHORT_STRING], tmp[SHORT_STRING];
806 + FOLDER *folder = (FOLDER *) data;
811 + snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
812 + snprintf (dest, destlen, tmp, folder->num + 1);
816 + strncpy (fn, folder->ff->name, sizeof(fn) - 1);
817 + snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
818 + snprintf (dest, destlen, tmp, fn);
822 + snprintf (tmp, sizeof (tmp), "%%%sc", fmt);
823 + if (folder->ff->nd->subscribed)
824 + snprintf (dest, destlen, tmp, ' ');
826 + snprintf (dest, destlen, tmp, folder->ff->nd->new ? 'N' : 'u');
830 + snprintf (tmp, sizeof (tmp), "%%%sc", fmt);
831 + if (folder->ff->nd->deleted)
832 + snprintf (dest, destlen, tmp, 'D');
834 + snprintf (dest, destlen, tmp, folder->ff->nd->allowed ? ' ' : '-');
838 + if (flags & MUTT_FORMAT_OPTIONAL)
840 + if (folder->ff->nd->unread != 0)
841 + mutt_FormatString (dest, destlen, col, cols, ifstring,
842 + newsgroup_format_str, data, flags);
844 + mutt_FormatString (dest, destlen, col, cols, elsestring,
845 + newsgroup_format_str, data, flags);
847 + else if (Context && Context->data == folder->ff->nd)
849 + snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
850 + snprintf (dest, destlen, tmp, Context->unread);
854 + snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
855 + snprintf (dest, destlen, tmp, folder->ff->nd->unread);
860 + if (Context && Context->data == folder->ff->nd)
862 + snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
863 + snprintf (dest, destlen, tmp, Context->new);
865 + else if (option (OPTMARKOLD) &&
866 + folder->ff->nd->lastCached >= folder->ff->nd->firstMessage &&
867 + folder->ff->nd->lastCached <= folder->ff->nd->lastMessage)
869 + snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
870 + snprintf (dest, destlen, tmp, folder->ff->nd->lastMessage - folder->ff->nd->lastCached);
874 + snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
875 + snprintf (dest, destlen, tmp, folder->ff->nd->unread);
880 + if (folder->ff->nd->desc != NULL)
882 + char *buf = safe_strdup (folder->ff->nd->desc);
883 + if (NewsgroupsCharset && *NewsgroupsCharset)
884 + mutt_convert_string (&buf, NewsgroupsCharset, Charset, MUTT_ICONV_HOOK_FROM);
885 + mutt_filter_unprintable (&buf);
887 + snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
888 + snprintf (dest, destlen, tmp, buf);
893 + snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
894 + snprintf (dest, destlen, tmp, "");
900 +#endif /* USE_NNTP */
902 static void add_folder (MUTTMENU *m, struct browser_state *state,
903 - const char *name, const struct stat *s, BUFFY *b)
904 + const char *name, const struct stat *s, BUFFY *b,
907 if (state->entrylen == state->entrymax)
909 @@ -427,6 +555,10 @@ static void add_folder (MUTTMENU *m, str
911 (state->entry)[state->entrylen].imap = 0;
914 + if (option (OPTNEWS))
915 + (state->entry)[state->entrylen].nd = (NNTP_DATA *)data;
920 @@ -442,9 +574,35 @@ static void init_state (struct browser_s
921 menu->data = state->entry;
924 +/* get list of all files/newsgroups with mask */
925 static int examine_directory (MUTTMENU *menu, struct browser_state *state,
926 const char *d, const char *prefix)
929 + if (option (OPTNEWS))
931 + NNTP_SERVER *nserv = CurrentNewsSrv;
934 +/* mutt_buffy_check (0); */
935 + init_state (state, menu);
937 + for (i = 0; i < nserv->groups_num; i++)
939 + NNTP_DATA *nntp_data = nserv->groups_list[i];
942 + if (prefix && *prefix &&
943 + strncmp (prefix, nntp_data->group, strlen (prefix)))
945 + if (!((regexec (Mask.rx, nntp_data->group, 0, NULL, 0) == 0) ^ Mask.not))
947 + add_folder (menu, state, nntp_data->group, NULL, NULL, nntp_data);
951 +#endif /* USE_NNTP */
956 @@ -514,18 +672,41 @@ static int examine_directory (MUTTMENU *
957 tmp->msg_count = Context->msgcount;
958 tmp->msg_unread = Context->unread;
960 - add_folder (menu, state, de->d_name, &s, tmp);
961 + add_folder (menu, state, de->d_name, &s, tmp, NULL);
964 - browser_sort (state);
966 mutt_buffer_pool_release (&buffer);
969 + browser_sort (state);
973 +/* get list of mailboxes/subscribed newsgroups */
974 static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state)
979 + if (option (OPTNEWS))
981 + NNTP_SERVER *nserv = CurrentNewsSrv;
984 +/* mutt_buffy_check (0); */
985 + init_state (state, menu);
987 + for (i = 0; i < nserv->groups_num; i++)
989 + NNTP_DATA *nntp_data = nserv->groups_list[i];
990 + if (nntp_data && (nntp_data->new || (nntp_data->subscribed &&
991 + (nntp_data->unread || !option (OPTSHOWONLYUNREAD)))))
992 + add_folder (menu, state, nntp_data->group, NULL, NULL, nntp_data);
998 BUFFY *tmp = Incoming;
999 BUFFER *mailbox = NULL;
1001 @@ -554,14 +735,21 @@ static int examine_mailboxes (MUTTMENU *
1003 if (mx_is_imap (mutt_b2s (tmp->pathbuf)))
1005 - add_folder (menu, state, mutt_b2s (mailbox), NULL, tmp);
1006 + add_folder (menu, state, mutt_b2s (mailbox), NULL, tmp, NULL);
1011 if (mx_is_pop (mutt_b2s (tmp->pathbuf)))
1013 - add_folder (menu, state, mutt_b2s (mailbox), NULL, tmp);
1014 + add_folder (menu, state, mutt_b2s (mailbox), NULL, tmp, NULL);
1019 + if (mx_is_nntp (mutt_b2s (tmp->pathbuf)))
1021 + add_folder (menu, state, mutt_b2s (mailbox), NULL, tmp, NULL);
1025 @@ -586,18 +774,23 @@ static int examine_mailboxes (MUTTMENU *
1026 s.st_mtime = st2.st_mtime;
1029 - add_folder (menu, state, mutt_b2s (mailbox), &s, tmp);
1030 + add_folder (menu, state, mutt_b2s (mailbox), &s, tmp, NULL);
1032 while ((tmp = tmp->next));
1033 - browser_sort (state);
1035 mutt_buffer_pool_release (&mailbox);
1036 mutt_buffer_pool_release (&md);
1039 + browser_sort (state);
1043 static int select_file_search (MUTTMENU *menu, regex_t *re, int n)
1046 + if (option (OPTNEWS))
1047 + return (regexec (re, ((struct folder_file *) menu->data)[n].desc, 0, NULL, 0));
1049 return (regexec (re, ((struct folder_file *) menu->data)[n].name, 0, NULL, 0));
1052 @@ -608,6 +801,12 @@ static void folder_entry (char *s, size_
1053 folder.ff = &((struct folder_file *) menu->data)[num];
1057 + if (option (OPTNEWS))
1058 + mutt_FormatString (s, slen, 0, MuttIndexWindow->cols, NONULL(GroupFormat),
1059 + newsgroup_format_str, (unsigned long) &folder, MUTT_FORMAT_ARROWCURSOR);
1062 mutt_FormatString (s, slen, 0, MuttIndexWindow->cols, NONULL(FolderFormat), folder_format_str,
1063 (unsigned long) &folder, MUTT_FORMAT_ARROWCURSOR);
1065 @@ -630,6 +829,17 @@ static void init_menu (struct browser_st
1070 + if (option (OPTNEWS))
1073 + snprintf (title, titlelen, _("Subscribed newsgroups"));
1075 + snprintf (title, titlelen, _("Newsgroups on server [%s]"),
1076 + CurrentNewsSrv->conn->account.host);
1081 snprintf (title, titlelen, _("Mailboxes [%d]"), mutt_buffy_check (0));
1083 @@ -717,6 +927,31 @@ void _mutt_buffer_select_file (BUFFER *f
1085 mutt_buffer_strcpy (LastDirBackup, mutt_b2s (LastDir));
1088 + if (option (OPTNEWS))
1090 + if (*(mutt_b2s (f)))
1091 + mutt_buffer_strcpy (prefix, mutt_b2s (f));
1094 + NNTP_SERVER *nserv = CurrentNewsSrv;
1097 + /* default state for news reader mode is browse subscribed newsgroups */
1099 + for (i = 0; i < nserv->groups_num; i++)
1101 + NNTP_DATA *nntp_data = nserv->groups_list[i];
1102 + if (nntp_data && nntp_data->subscribed)
1112 if (*(mutt_b2s (f)))
1114 mutt_buffer_expand_path (f);
1115 @@ -812,6 +1047,9 @@ void _mutt_buffer_select_file (BUFFER *f
1116 menu->tag = file_tag;
1118 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_FOLDER,
1120 + option (OPTNEWS) ? FolderNewsHelp :
1123 mutt_push_current_menu (menu);
1125 @@ -959,7 +1197,11 @@ void _mutt_buffer_select_file (BUFFER *f
1130 + if (buffy || option (OPTNEWS))
1135 mutt_buffer_strcpy (f, state.entry[menu->current].name);
1136 mutt_buffer_expand_path (f);
1137 @@ -1014,14 +1256,6 @@ void _mutt_buffer_select_file (BUFFER *f
1141 - case OP_BROWSER_SUBSCRIBE:
1142 - imap_subscribe (state.entry[menu->current].name, 1);
1145 - case OP_BROWSER_UNSUBSCRIBE:
1146 - imap_subscribe (state.entry[menu->current].name, 0);
1149 case OP_BROWSER_TOGGLE_LSUB:
1150 if (option (OPTIMAPLSUB))
1151 unset_option (OPTIMAPLSUB);
1152 @@ -1123,6 +1357,11 @@ void _mutt_buffer_select_file (BUFFER *f
1154 case OP_CHANGE_DIRECTORY:
1157 + if (option (OPTNEWS))
1161 mutt_buffer_strcpy (buf, mutt_b2s (LastDir));
1163 if (!state.imap_browse)
1164 @@ -1395,6 +1634,210 @@ void _mutt_buffer_select_file (BUFFER *f
1166 mutt_error _("Error trying to view file");
1172 + case OP_UNCATCHUP:
1173 + if (option (OPTNEWS))
1175 + struct folder_file *f = &state.entry[menu->current];
1177 + NNTP_DATA *nntp_data;
1179 + rc = nntp_newsrc_parse (CurrentNewsSrv);
1183 + if (op == OP_CATCHUP)
1184 + nntp_data = mutt_newsgroup_catchup (CurrentNewsSrv, f->name);
1186 + nntp_data = mutt_newsgroup_uncatchup (CurrentNewsSrv, f->name);
1191 + struct folder_file ff;
1192 + char buffer[_POSIX_PATH_MAX + SHORT_STRING];
1195 + folder.ff->name = f->name;
1196 + folder.ff->st = NULL;
1197 + folder.ff->is_new = nntp_data->new;
1198 + folder.ff->nntp_data = nntp_data;
1200 + mutt_FormatString (buffer, sizeof (buffer), 0, MuttIndexWindow->cols,
1201 + NONULL(GroupFormat), newsgroup_format_str,
1202 + (unsigned long) &folder, MUTT_FORMAT_ARROWCURSOR);
1203 + f->desc = safe_strdup (buffer); */
1204 + nntp_newsrc_update (CurrentNewsSrv);
1205 + if (menu->current + 1 < menu->max)
1207 + menu->redraw = REDRAW_MOTION_RESYNCH;
1210 + menu->redraw = REDRAW_INDEX;
1211 + nntp_newsrc_close (CurrentNewsSrv);
1215 + case OP_LOAD_ACTIVE:
1216 + if (option (OPTNEWS))
1218 + NNTP_SERVER *nserv = CurrentNewsSrv;
1221 + if (nntp_newsrc_parse (nserv) < 0)
1224 + for (i = 0; i < nserv->groups_num; i++)
1226 + NNTP_DATA *nntp_data = nserv->groups_list[i];
1228 + nntp_data->deleted = 1;
1230 + nntp_active_fetch (nserv, 1);
1231 + nntp_newsrc_update (nserv);
1232 + nntp_newsrc_close (nserv);
1234 + destroy_state (&state);
1236 + examine_mailboxes (menu, &state);
1238 + examine_directory (menu, &state, NULL, NULL);
1239 + init_menu (&state, menu, title, sizeof (title), buffy);
1242 +#endif /* USE_NNTP */
1244 +#if defined USE_IMAP || defined USE_NNTP
1245 + case OP_BROWSER_SUBSCRIBE:
1246 + case OP_BROWSER_UNSUBSCRIBE:
1249 + case OP_SUBSCRIBE_PATTERN:
1250 + case OP_UNSUBSCRIBE_PATTERN:
1251 + if (option (OPTNEWS))
1253 + NNTP_SERVER *nserv = CurrentNewsSrv;
1254 + NNTP_DATA *nntp_data;
1255 + regex_t *rx = (regex_t *) safe_malloc (sizeof (regex_t));
1256 + char buf[_POSIX_PATH_MAX];
1258 + int rc, j = menu->current;
1260 + if (op == OP_SUBSCRIBE_PATTERN || op == OP_UNSUBSCRIBE_PATTERN)
1266 + if (op == OP_SUBSCRIBE_PATTERN)
1267 + snprintf (tmp, sizeof (tmp), _("Subscribe pattern: "));
1269 + snprintf (tmp, sizeof (tmp), _("Unsubscribe pattern: "));
1270 + if (mutt_get_field (tmp, buf, sizeof (buf), 0) != 0 || !buf[0])
1276 + err = REGCOMP (rx, s, REG_NOSUB);
1279 + regerror (err, rx, buf, sizeof (buf));
1282 + mutt_error ("%s", buf);
1285 + menu->redraw = REDRAW_FULL;
1288 + else if (!state.entrylen)
1290 + mutt_error _("No newsgroups match the mask");
1294 + rc = nntp_newsrc_parse (nserv);
1298 + for ( ; j < state.entrylen; j++)
1300 + struct folder_file *f = &state.entry[j];
1302 + if (op == OP_BROWSER_SUBSCRIBE || op == OP_BROWSER_UNSUBSCRIBE ||
1303 + regexec (rx, f->name, 0, NULL, 0) == 0)
1305 + if (op == OP_BROWSER_SUBSCRIBE || op == OP_SUBSCRIBE_PATTERN)
1306 + nntp_data = mutt_newsgroup_subscribe (nserv, f->name);
1308 + nntp_data = mutt_newsgroup_unsubscribe (nserv, f->name);
1312 + char buffer[_POSIX_PATH_MAX + SHORT_STRING];
1314 + folder.name = f->name;
1316 + folder.new = nntp_data->new;
1317 + folder.nd = nntp_data;
1319 + mutt_FormatString (buffer, sizeof (buffer), 0, MuttIndexWindow->cols,
1320 + NONULL(GroupFormat), newsgroup_format_str,
1321 + (unsigned long) &folder, MUTT_FORMAT_ARROWCURSOR);
1322 + f->desc = safe_strdup (buffer);
1325 + if (op == OP_BROWSER_SUBSCRIBE || op == OP_BROWSER_UNSUBSCRIBE)
1327 + if (menu->current + 1 < menu->max)
1329 + menu->redraw = REDRAW_MOTION_RESYNCH;
1333 + if (op == OP_SUBSCRIBE_PATTERN)
1337 + for (i = 0; nserv && i < nserv->groups_num; i++)
1339 + nntp_data = nserv->groups_list[i];
1340 + if (nntp_data && nntp_data->group && !nntp_data->subscribed)
1342 + if (regexec (rx, nntp_data->group, 0, NULL, 0) == 0)
1344 + mutt_newsgroup_subscribe (nserv, nntp_data->group);
1345 + add_folder (menu, &state, nntp_data->group, NULL, NULL, nntp_data);
1349 + init_menu (&state, menu, title, sizeof (title), buffy);
1352 + menu->redraw = REDRAW_FULL;
1353 + nntp_newsrc_update (nserv);
1354 + nntp_clear_cache (nserv);
1355 + nntp_newsrc_close (nserv);
1356 + if (op != OP_BROWSER_SUBSCRIBE && op != OP_BROWSER_UNSUBSCRIBE)
1362 +#endif /* USE_IMAP && USE_NNTP */
1363 +#endif /* USE_NNTP */
1366 + if (op == OP_BROWSER_SUBSCRIBE)
1367 + imap_subscribe (state.entry[menu->current].name, 1);
1369 + imap_subscribe (state.entry[menu->current].name, 0);
1371 +#endif /* USE_IMAP */
1375 diff -udprP mutt-1.12.1.orig/browser.h mutt-1.12.1/browser.h
1376 --- mutt-1.12.1.orig/browser.h 2019-05-25 19:22:39.000000000 +0300
1377 +++ mutt-1.12.1/browser.h 2019-08-11 20:31:26.133940688 +0300
1380 #define _BROWSER_H 1
1389 @@ -44,6 +48,9 @@ struct folder_file
1391 unsigned has_buffy : 1;
1392 unsigned local : 1; /* folder is on local filesystem */
1396 unsigned tagged : 1;
1399 diff -udprP mutt-1.12.1.orig/buffy.c mutt-1.12.1/buffy.c
1400 --- mutt-1.12.1.orig/buffy.c 2019-05-25 19:22:39.000000000 +0300
1401 +++ mutt-1.12.1/buffy.c 2019-08-11 20:31:26.134940673 +0300
1402 @@ -570,6 +570,9 @@ int mutt_buffy_check (int force)
1404 /* check device ID and serial number instead of comparing paths */
1405 if (!Context || Context->magic == MUTT_IMAP || Context->magic == MUTT_POP
1407 + || Context->magic == MUTT_NNTP
1409 || stat (Context->path, &contex_sb) != 0)
1412 @@ -593,6 +596,11 @@ int mutt_buffy_check (int force)
1413 tmp->magic = MUTT_POP;
1417 + if ((tmp->magic == MUTT_NNTP) || mx_is_nntp (mutt_b2s (tmp->pathbuf)))
1418 + tmp->magic = MUTT_NNTP;
1421 if (stat (mutt_b2s (tmp->pathbuf), &sb) != 0 ||
1422 (S_ISREG(sb.st_mode) && sb.st_size == 0) ||
1424 @@ -610,7 +618,11 @@ int mutt_buffy_check (int force)
1425 /* check to see if the folder is the currently selected folder
1427 if (!Context || !Context->path ||
1429 + (( tmp->magic == MUTT_IMAP || tmp->magic == MUTT_POP || tmp->magic == MUTT_NNTP )
1431 (( tmp->magic == MUTT_IMAP || tmp->magic == MUTT_POP )
1433 ? mutt_strcmp (mutt_b2s (tmp->pathbuf), Context->path) :
1434 (sb.st_dev != contex_sb.st_dev || sb.st_ino != contex_sb.st_ino)))
1436 diff -udprP mutt-1.12.1.orig/complete.c mutt-1.12.1/complete.c
1437 --- mutt-1.12.1.orig/complete.c 2019-05-25 19:22:39.000000000 +0300
1438 +++ mutt-1.12.1/complete.c 2019-08-11 20:31:26.134940673 +0300
1440 #include "mailbox.h"
1449 @@ -48,9 +51,70 @@ int mutt_complete (char *s, size_t slen)
1450 char filepart[_POSIX_PATH_MAX];
1452 char imap_path[LONG_STRING];
1455 dprint (2, (debugfile, "mutt_complete: completing %s\n", s));
1458 + if (option (OPTNEWS))
1460 + NNTP_SERVER *nserv = CurrentNewsSrv;
1461 + unsigned int n = 0;
1463 + strfcpy (filepart, s, sizeof (filepart));
1465 + /* special case to handle when there is no filepart yet
1466 + * find the first subscribed newsgroup */
1467 + len = mutt_strlen (filepart);
1470 + for (; n < nserv->groups_num; n++)
1472 + NNTP_DATA *nntp_data = nserv->groups_list[n];
1474 + if (nntp_data && nntp_data->subscribed)
1476 + strfcpy (filepart, nntp_data->group, sizeof (filepart));
1484 + for (; n < nserv->groups_num; n++)
1486 + NNTP_DATA *nntp_data = nserv->groups_list[n];
1488 + if (nntp_data && nntp_data->subscribed &&
1489 + mutt_strncmp (nntp_data->group, filepart, len) == 0)
1493 + for (i = 0; filepart[i] && nntp_data->group[i]; i++)
1495 + if (filepart[i] != nntp_data->group[i])
1505 + strfcpy (filepart, nntp_data->group, sizeof (filepart));
1511 + strcpy (s, filepart);
1512 + return (init ? 0 : -1);
1517 /* we can use '/' as a delimiter, imap_complete rewrites it */
1518 if (*s == '=' || *s == '+' || *s == '!')
1520 diff -udprP mutt-1.12.1.orig/compose.c mutt-1.12.1/compose.c
1521 --- mutt-1.12.1.orig/compose.c 2019-06-14 18:57:37.000000000 +0300
1522 +++ mutt-1.12.1/compose.c 2019-08-11 20:31:26.134940673 +0300
1524 #include "mailbox.h"
1526 #include "charset.h"
1530 #include "remailer.h"
1539 #include <sys/stat.h>
1540 @@ -69,10 +74,20 @@ enum
1550 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
1554 +int HeaderPadding[HDR_XCOMMENTTO + 1] = {0};
1556 int HeaderPadding[HDR_CRYPTINFO + 1] = {0};
1558 int MaxHeaderWidth = 0;
1560 #define HDR_XOFFSET MaxHeaderWidth
1561 @@ -110,6 +125,14 @@ static const char * const Prompts[] =
1562 * than 15-20 character cells.
1566 + /* L10N: Compose menu field. May not want to translate. */
1567 + ,N_("Newsgroups: ")
1568 + /* L10N: Compose menu field. May not want to translate. */
1569 + ,N_("Followup-To: ")
1570 + /* L10N: Compose menu field. May not want to translate. */
1571 + ,N_("X-Comment-To: ")
1575 static const struct mapping_t ComposeHelp[] = {
1576 @@ -127,6 +150,21 @@ static const struct mapping_t ComposeHel
1581 +static struct mapping_t ComposeNewsHelp[] = {
1582 + { N_("Send"), OP_COMPOSE_SEND_MESSAGE },
1583 + { N_("Abort"), OP_EXIT },
1584 + /* L10N: compose menu help line entry */
1585 + { N_("Newsgroups"), OP_COMPOSE_EDIT_NEWSGROUPS },
1586 + /* L10N: compose menu help line entry */
1587 + { N_("Subj"), OP_COMPOSE_EDIT_SUBJECT },
1588 + { N_("Attach file"), OP_COMPOSE_ATTACH_FILE },
1589 + { N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION },
1590 + { N_("Help"), OP_HELP },
1595 static void calc_header_width_padding (int idx, const char *header, int calc_max)
1598 @@ -162,7 +200,14 @@ static void init_header_padding (void)
1599 * the other fields look funny. */
1600 calc_header_width_padding (HDR_CRYPTINFO, _(Prompts[HDR_CRYPTINFO]), 0);
1603 + for (i = HDR_NEWSGROUPS; i <= HDR_XCOMMENTTO; i++)
1604 + calc_header_width_padding (i, _(Prompts[i]), 1);
1606 + for (i = 0; i <= HDR_XCOMMENTTO; i++)
1608 for (i = 0; i <= HDR_CRYPTINFO; i++)
1611 HeaderPadding[i] += MaxHeaderWidth;
1612 if (HeaderPadding[i] < 0)
1613 @@ -358,9 +403,37 @@ static void draw_envelope_addr (int line
1614 static void draw_envelope (HEADER *msg, char *fcc)
1616 draw_envelope_addr (HDR_FROM, msg->env->from);
1618 + if (option (OPTNEWSSEND))
1620 + SETCOLOR (MT_COLOR_COMPOSE_HEADER);
1621 + mutt_window_mvprintw (MuttIndexWindow, HDR_TO, 0,
1622 + "%*s", HeaderPadding[HDR_NEWSGROUPS], _(Prompts[HDR_NEWSGROUPS]));
1624 + mutt_paddstr (W, NONULL (msg->env->newsgroups));
1626 + SETCOLOR (MT_COLOR_COMPOSE_HEADER);
1627 + mutt_window_mvprintw (MuttIndexWindow, HDR_CC, 0,
1628 + "%*s", HeaderPadding[HDR_FOLLOWUPTO], _(Prompts[HDR_FOLLOWUPTO]));
1630 + mutt_paddstr (W, NONULL (msg->env->followup_to));
1632 + if (option (OPTXCOMMENTTO))
1634 + SETCOLOR (MT_COLOR_COMPOSE_HEADER);
1635 + mutt_window_mvprintw (MuttIndexWindow, HDR_BCC, 0,
1636 + "%*s", HeaderPadding[HDR_XCOMMENTTO], _(Prompts[HDR_XCOMMENTTO]));
1638 + mutt_paddstr (W, NONULL (msg->env->x_comment_to));
1644 draw_envelope_addr (HDR_TO, msg->env->to);
1645 draw_envelope_addr (HDR_CC, msg->env->cc);
1646 draw_envelope_addr (HDR_BCC, msg->env->bcc);
1649 SETCOLOR (MT_COLOR_COMPOSE_HEADER);
1650 mutt_window_mvprintw (MuttIndexWindow, HDR_SUBJECT, 0,
1651 @@ -713,6 +786,12 @@ int mutt_compose_menu (HEADER *msg, /*
1652 int oldSort, oldSortAux;
1654 compose_redraw_data_t rd;
1656 + int news = 0; /* is it a news article ? */
1658 + if (option (OPTNEWSSEND))
1662 init_header_padding ();
1664 @@ -723,6 +802,11 @@ int mutt_compose_menu (HEADER *msg, /*
1665 menu->offset = HDR_ATTACH;
1666 menu->make_entry = snd_entry;
1667 menu->tag = mutt_tag_attach;
1670 + menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeNewsHelp);
1673 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp);
1674 menu->custom_menu_redraw = compose_menu_redraw;
1675 menu->redraw_data = &rd;
1676 @@ -734,6 +818,9 @@ int mutt_compose_menu (HEADER *msg, /*
1681 + unset_option (OPTNEWS); /* for any case */
1683 switch (op = mutt_menuLoop (menu))
1685 case OP_COMPOSE_EDIT_FROM:
1686 @@ -741,6 +828,10 @@ int mutt_compose_menu (HEADER *msg, /*
1687 mutt_message_hook (NULL, msg, MUTT_SEND2HOOK);
1689 case OP_COMPOSE_EDIT_TO:
1694 edit_address_list (HDR_TO, &msg->env->to);
1695 if (option (OPTCRYPTOPPORTUNISTICENCRYPT))
1697 @@ -750,6 +841,10 @@ int mutt_compose_menu (HEADER *msg, /*
1698 mutt_message_hook (NULL, msg, MUTT_SEND2HOOK);
1700 case OP_COMPOSE_EDIT_BCC:
1705 edit_address_list (HDR_BCC, &msg->env->bcc);
1706 if (option (OPTCRYPTOPPORTUNISTICENCRYPT))
1708 @@ -759,6 +854,10 @@ int mutt_compose_menu (HEADER *msg, /*
1709 mutt_message_hook (NULL, msg, MUTT_SEND2HOOK);
1711 case OP_COMPOSE_EDIT_CC:
1716 edit_address_list (HDR_CC, &msg->env->cc);
1717 if (option (OPTCRYPTOPPORTUNISTICENCRYPT))
1719 @@ -767,6 +866,62 @@ int mutt_compose_menu (HEADER *msg, /*
1721 mutt_message_hook (NULL, msg, MUTT_SEND2HOOK);
1724 + case OP_COMPOSE_EDIT_NEWSGROUPS:
1727 + if (msg->env->newsgroups)
1728 + strfcpy (buf, msg->env->newsgroups, sizeof (buf));
1731 + if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0)
1733 + mutt_str_replace (&msg->env->newsgroups, buf);
1734 + move (HDR_TO, HDR_XOFFSET);
1735 + if (msg->env->newsgroups)
1736 + mutt_paddstr (W, msg->env->newsgroups);
1742 + case OP_COMPOSE_EDIT_FOLLOWUP_TO:
1745 + if (msg->env->followup_to)
1746 + strfcpy (buf, msg->env->followup_to, sizeof (buf));
1749 + if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0)
1751 + mutt_str_replace (&msg->env->followup_to, buf);
1752 + move (HDR_CC, HDR_XOFFSET);
1753 + if (msg->env->followup_to)
1754 + mutt_paddstr (W, msg->env->followup_to);
1760 + case OP_COMPOSE_EDIT_X_COMMENT_TO:
1761 + if (news && option (OPTXCOMMENTTO))
1763 + if (msg->env->x_comment_to)
1764 + strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
1767 + if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0)
1769 + mutt_str_replace (&msg->env->x_comment_to, buf);
1770 + move (HDR_BCC, HDR_XOFFSET);
1771 + if (msg->env->x_comment_to)
1772 + mutt_paddstr (W, msg->env->x_comment_to);
1779 case OP_COMPOSE_EDIT_SUBJECT:
1780 if (msg->env->subject)
1781 strfcpy (buf, msg->env->subject, sizeof (buf));
1782 @@ -911,6 +1066,9 @@ int mutt_compose_menu (HEADER *msg, /*
1785 case OP_COMPOSE_ATTACH_MESSAGE:
1787 + case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
1792 @@ -918,7 +1076,22 @@ int mutt_compose_menu (HEADER *msg, /*
1794 prompt = _("Open mailbox to attach message from");
1797 + unset_option (OPTNEWS);
1798 + if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE)
1800 + if (!(CurrentNewsSrv = nntp_select_server (NewsServer, 0)))
1803 + prompt = _("Open newsgroup to attach message from");
1804 + set_option (OPTNEWS);
1810 + if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == MUTT_NNTP))
1813 strfcpy (fname, NONULL (Context->path), sizeof (fname));
1814 mutt_pretty_mailbox (fname, sizeof (fname));
1815 @@ -934,6 +1107,9 @@ int mutt_compose_menu (HEADER *msg, /*
1817 if (!mx_is_pop (fname))
1820 + if (!mx_is_nntp (fname) && !option (OPTNEWS))
1822 /* check to make sure the file exists and is readable */
1823 if (access (fname, R_OK) == -1)
1825 @@ -1219,6 +1395,19 @@ int mutt_compose_menu (HEADER *msg, /*
1830 + if (option (OPTNEWS))
1834 + s_buf = mutt_buffer_pool_get ();
1835 + mutt_buffer_addstr (s_buf, fname);
1836 + nntp_buffer_expand_path (s_buf, &CurrentNewsSrv->conn->account);
1837 + strfcpy (fname, mutt_b2s (s_buf), sizeof (fname));
1838 + mutt_buffer_pool_release (&s_buf);
1842 mutt_expand_path (fname, sizeof (fname));
1843 if (mutt_rename_file (CURATTACH->content->filename, fname))
1845 diff -udprP mutt-1.12.1.orig/config.h.in mutt-1.12.1/config.h.in
1846 --- mutt-1.12.1.orig/config.h.in 2019-06-15 19:07:25.000000000 +0300
1847 +++ mutt-1.12.1/config.h.in 2019-08-11 20:31:26.134940673 +0300
1852 +/* Define if you want support for the NNTP protocol. */
1855 /* Define if you want support for the POP3 protocol. */
1858 diff -udprP mutt-1.12.1.orig/configure mutt-1.12.1/configure
1859 --- mutt-1.12.1.orig/configure 2019-06-15 19:04:19.000000000 +0300
1860 +++ mutt-1.12.1/configure 2019-08-11 20:31:26.136940643 +0300
1861 @@ -813,6 +813,7 @@ with_docdir
1869 @@ -1499,6 +1500,7 @@ Optional Features:
1870 Force use of an external dotlock program
1871 --enable-pop Enable POP3 support
1872 --enable-imap Enable IMAP support
1873 + --enable-nntp Enable NNTP support
1874 --enable-smtp include internal SMTP relay support
1875 --enable-debug Enable debugging support
1876 --enable-flock Use flock() to lock files
1877 @@ -10108,6 +10110,20 @@ else
1881 +# Check whether --enable-nntp was given.
1882 +if test "${enable_nntp+set}" = set; then :
1883 + enableval=$enable_nntp; if test x$enableval = xyes ; then
1885 +$as_echo "#define USE_NNTP 1" >>confdefs.h
1887 + MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS nntp.o newsrc.o"
1895 # Check whether --enable-smtp was given.
1896 if test "${enable_smtp+set}" = set; then :
1897 enableval=$enable_smtp; if test $enableval = yes; then
1898 @@ -10120,7 +10136,7 @@ $as_echo "#define USE_SMTP 1" >>confdefs
1902 -if test x"$need_imap" = xyes -o x"$need_pop" = xyes ; then
1903 +if test x"$need_imap" = xyes -o x"$need_pop" = xyes -o x"$need_nntp" = xyes ; then
1904 MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS bcache.o"
1907 diff -udprP mutt-1.12.1.orig/configure.ac mutt-1.12.1/configure.ac
1908 --- mutt-1.12.1.orig/configure.ac 2019-06-15 18:57:01.000000000 +0300
1909 +++ mutt-1.12.1/configure.ac 2019-08-11 20:31:26.136940643 +0300
1910 @@ -648,6 +648,15 @@ AC_ARG_ENABLE(imap, AS_HELP_STRING([--en
1912 AM_CONDITIONAL(BUILD_IMAP, test x$need_imap = xyes)
1914 +AC_ARG_ENABLE(nntp, AC_HELP_STRING([--enable-nntp],[Enable NNTP support]),
1915 +[ if test x$enableval = xyes ; then
1916 + AC_DEFINE(USE_NNTP,1,[ Define if you want support for the NNTP protocol. ])
1917 + MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS nntp.o newsrc.o"
1923 AC_ARG_ENABLE(smtp, AS_HELP_STRING([--enable-smtp],[include internal SMTP relay support]),
1924 [if test $enableval = yes; then
1925 AC_DEFINE(USE_SMTP, 1, [Include internal SMTP relay support])
1926 @@ -655,7 +664,7 @@ AC_ARG_ENABLE(smtp, AS_HELP_STRING([--en
1930 -if test x"$need_imap" = xyes -o x"$need_pop" = xyes ; then
1931 +if test x"$need_imap" = xyes -o x"$need_pop" = xyes -o x"$need_nntp" = xyes ; then
1932 MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS bcache.o"
1935 diff -udprP mutt-1.12.1.orig/curs_main.c mutt-1.12.1/curs_main.c
1936 --- mutt-1.12.1.orig/curs_main.c 2019-06-11 03:53:09.000000000 +0300
1937 +++ mutt-1.12.1/curs_main.c 2019-08-11 20:31:26.136940643 +0300
1941 #include "mutt_curses.h"
1943 #include "mutt_menu.h"
1944 #include "mailbox.h"
1945 #include "mapping.h"
1948 #include "mutt_crypt.h"
1957 @@ -599,12 +604,27 @@ static void index_menu_redraw (MUTTMENU
1962 +struct mapping_t IndexNewsHelp[] = {
1963 + { N_("Quit"), OP_QUIT },
1964 + { N_("Del"), OP_DELETE },
1965 + { N_("Undel"), OP_UNDELETE },
1966 + { N_("Save"), OP_SAVE },
1967 + { N_("Post"), OP_POST },
1968 + { N_("Followup"), OP_FOLLOWUP },
1969 + { N_("Catchup"), OP_CATCHUP },
1970 + { N_("Help"), OP_HELP },
1975 /* This function handles the message index window as well as commands returned
1976 * from the pager (MENU_PAGER).
1978 int mutt_index_menu (void)
1980 char buf[LONG_STRING], helpstr[LONG_STRING];
1983 int done = 0; /* controls when to exit the "event" loop */
1985 @@ -623,7 +643,11 @@ int mutt_index_menu (void)
1986 menu->make_entry = index_make_entry;
1987 menu->color = index_color;
1988 menu->current = ci_first_message ();
1989 - menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN, IndexHelp);
1990 + menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1992 + (Context && (Context->magic == MUTT_NNTP)) ? IndexNewsHelp :
1995 menu->custom_menu_redraw = index_menu_redraw;
1996 mutt_push_current_menu (menu);
1998 @@ -845,6 +869,9 @@ int mutt_index_menu (void)
1999 mutt_curs_set (1); /* fallback from the pager */
2003 + unset_option (OPTNEWS); /* for any case */
2008 @@ -895,6 +922,161 @@ int mutt_index_menu (void)
2009 menu_current_bottom (menu);
2013 + case OP_GET_PARENT:
2017 + case OP_GET_MESSAGE:
2021 + if (Context->magic == MUTT_NNTP)
2025 + if (op == OP_GET_MESSAGE)
2028 + if (mutt_get_field (_("Enter Message-Id: "),
2029 + buf, sizeof (buf), 0) != 0 || !buf[0])
2034 + LIST *ref = CURHDR->env->references;
2037 + mutt_error _("Article has no parent reference.");
2040 + strfcpy (buf, ref->data, sizeof (buf));
2042 + if (!Context->id_hash)
2043 + Context->id_hash = mutt_make_id_hash (Context);
2044 + hdr = hash_find (Context->id_hash, buf);
2047 + if (hdr->virtual != -1)
2049 + menu->current = hdr->virtual;
2050 + menu->redraw = REDRAW_MOTION_RESYNCH;
2052 + else if (hdr->collapsed)
2054 + mutt_uncollapse_thread (Context, hdr);
2055 + mutt_set_virtual (Context);
2056 + menu->current = hdr->virtual;
2057 + menu->redraw = REDRAW_MOTION_RESYNCH;
2060 + mutt_error _("Message is not visible in limited view.");
2066 + mutt_message (_("Fetching %s from server..."), buf);
2067 + rc = nntp_check_msgid (Context, buf);
2070 + hdr = Context->hdrs[Context->msgcount - 1];
2071 + mutt_sort_headers (Context, 0);
2072 + menu->current = hdr->virtual;
2073 + menu->redraw = REDRAW_FULL;
2076 + mutt_error (_("Article %s not found on the server."), buf);
2081 + case OP_GET_CHILDREN:
2082 + case OP_RECONSTRUCT_THREAD:
2087 + if (Context->magic == MUTT_NNTP)
2089 + int oldmsgcount = Context->msgcount;
2090 + int oldindex = CURHDR->index;
2093 + if (!CURHDR->env->message_id)
2095 + mutt_error _("No Message-Id. Unable to perform operation.");
2099 + mutt_message _("Fetching message headers...");
2100 + if (!Context->id_hash)
2101 + Context->id_hash = mutt_make_id_hash (Context);
2102 + strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
2104 + /* trying to find msgid of the root message */
2105 + if (op == OP_RECONSTRUCT_THREAD)
2107 + LIST *ref = CURHDR->env->references;
2110 + if (hash_find (Context->id_hash, ref->data) == NULL)
2112 + rc = nntp_check_msgid (Context, ref->data);
2117 + /* the last msgid in References is the root message */
2119 + strfcpy (buf, ref->data, sizeof (buf));
2124 + /* fetching all child messages */
2126 + rc = nntp_check_children (Context, buf);
2128 + /* at least one message has been loaded */
2129 + if (Context->msgcount > oldmsgcount)
2132 + int i, quiet = Context->quiet;
2135 + Context->quiet = 1;
2136 + mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
2137 + Context->quiet = quiet;
2139 + /* if the root message was retrieved, move to it */
2140 + hdr = hash_find (Context->id_hash, buf);
2142 + menu->current = hdr->virtual;
2144 + /* try to restore old position */
2147 + for (i = 0; i < Context->msgcount; i++)
2149 + if (Context->hdrs[i]->index == oldindex)
2151 + menu->current = Context->hdrs[i]->virtual;
2152 + /* as an added courtesy, recenter the menu
2153 + * with the current entry at the middle of the screen */
2154 + menu_check_recenter (menu);
2155 + menu_current_middle (menu);
2159 + menu->redraw = REDRAW_FULL;
2162 + mutt_error _("No deleted messages found in the thread.");
2170 @@ -1005,11 +1187,33 @@ int mutt_index_menu (void)
2174 + case OP_TOGGLE_READ:
2177 menu->oldcurrent = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ?
2179 - if (mutt_pattern_func (MUTT_LIMIT, _("Limit to messages matching: ")) == 0)
2180 + if (op == OP_TOGGLE_READ)
2182 + char buf[LONG_STRING];
2184 + if (!Context->pattern || strncmp (Context->pattern, "!~R!~D~s", 8) != 0)
2186 + snprintf (buf, sizeof (buf), "!~R!~D~s%s",
2187 + Context->pattern ? Context->pattern : ".*");
2188 + set_option (OPTHIDEREAD);
2192 + strfcpy (buf, Context->pattern + 8, sizeof(buf));
2193 + if (!*buf || strncmp (buf, ".*", 2) == 0)
2194 + snprintf (buf, sizeof(buf), "~A");
2195 + unset_option (OPTHIDEREAD);
2197 + FREE (&Context->pattern);
2198 + Context->pattern = safe_strdup (buf);
2200 + if ((op == OP_TOGGLE_READ && mutt_pattern_func (MUTT_LIMIT, NULL) == 0) ||
2201 + mutt_pattern_func (MUTT_LIMIT, _("Limit to messages matching: ")) == 0)
2203 if (menu->oldcurrent >= 0)
2205 @@ -1258,20 +1462,30 @@ int mutt_index_menu (void)
2207 case OP_MAIN_CHANGE_FOLDER:
2208 case OP_MAIN_NEXT_UNREAD_MAILBOX:
2211 - op = OP_MAIN_CHANGE_FOLDER_READONLY;
2213 - /* fallback to the readonly case */
2215 case OP_MAIN_CHANGE_FOLDER_READONLY:
2217 + case OP_MAIN_CHANGE_GROUP:
2218 + case OP_MAIN_CHANGE_GROUP_READONLY:
2222 int cont = 0; /* Set if we want to continue instead of break */
2224 folderbuf = mutt_buffer_pool_get ();
2226 - if ((op == OP_MAIN_CHANGE_FOLDER_READONLY) || option (OPTREADONLY))
2228 + unset_option (OPTNEWS);
2230 + if (attach_msg || option (OPTREADONLY) ||
2232 + op == OP_MAIN_CHANGE_GROUP_READONLY ||
2234 + op == OP_MAIN_CHANGE_FOLDER_READONLY)
2235 + flags = MUTT_READONLY;
2240 cp = _("Open mailbox in read-only mode");
2242 cp = _("Open mailbox");
2243 @@ -1303,6 +1517,22 @@ int mutt_index_menu (void)
2244 mutt_buffer_strcpy (folderbuf, Context->path);
2245 mutt_buffer_pretty_mailbox (folderbuf);
2248 + if (op == OP_MAIN_CHANGE_GROUP ||
2249 + op == OP_MAIN_CHANGE_GROUP_READONLY)
2251 + set_option (OPTNEWS);
2252 + CurrentNewsSrv = nntp_select_server (NewsServer, 0);
2253 + if (!CurrentNewsSrv)
2256 + cp = _("Open newsgroup in read-only mode");
2258 + cp = _("Open newsgroup");
2259 + nntp_buffer_buffy (folderbuf);
2263 mutt_buffer_buffy (folderbuf);
2265 if (mutt_buffer_enter_fname (cp, folderbuf, 1) == -1)
2266 @@ -1321,6 +1551,14 @@ int mutt_index_menu (void)
2271 + if (option (OPTNEWS))
2273 + unset_option (OPTNEWS);
2274 + nntp_buffer_expand_path (folderbuf, &CurrentNewsSrv->conn->account);
2278 mutt_buffer_expand_path (folderbuf);
2279 if (mx_get_magic (mutt_b2s (folderbuf)) <= 0)
2281 @@ -1381,9 +1619,7 @@ int mutt_index_menu (void)
2282 * switch statement would need to be run. */
2283 mutt_folder_hook (mutt_b2s (folderbuf));
2285 - if ((Context = mx_open_mailbox (mutt_b2s (folderbuf),
2286 - (option (OPTREADONLY) || op == OP_MAIN_CHANGE_FOLDER_READONLY) ?
2287 - MUTT_READONLY : 0, NULL)) != NULL)
2288 + if ((Context = mx_open_mailbox (mutt_b2s (folderbuf), flags, NULL)) != NULL)
2290 menu->current = ci_first_message ();
2292 @@ -1397,6 +1633,12 @@ int mutt_index_menu (void)
2293 mutt_sb_set_open_buffy ();
2297 + /* mutt_buffy_check() must be done with mail-reader mode! */
2298 + menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
2299 + (Context && (Context->magic == MUTT_NNTP)) ? IndexNewsHelp : IndexHelp);
2302 mutt_clear_error ();
2303 mutt_buffy_check(MUTT_BUFFY_CHECK_FORCE); /* force the buffy check after
2305 @@ -1482,6 +1724,7 @@ int mutt_index_menu (void)
2309 + CHECK_ACL(MUTT_ACL_WRITE, _("Cannot break thread"));
2311 if ((Sort & SORT_MASK) != SORT_THREADS)
2312 mutt_error _("Threading is not enabled.");
2313 @@ -1517,7 +1760,7 @@ int mutt_index_menu (void)
2316 /* L10N: CHECK_ACL */
2317 - CHECK_ACL(MUTT_ACL_DELETE, _("Cannot link threads"));
2318 + CHECK_ACL(MUTT_ACL_WRITE, _("Cannot link threads"));
2320 if ((Sort & SORT_MASK) != SORT_THREADS)
2321 mutt_error _("Threading is not enabled.");
2322 @@ -2170,6 +2413,20 @@ int mutt_index_menu (void)
2331 + if (Context && Context->magic == MUTT_NNTP)
2333 + NNTP_DATA *nntp_data = Context->data;
2334 + if (mutt_newsgroup_catchup (nntp_data->nserv, nntp_data->group))
2335 + menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2340 case OP_DISPLAY_ADDRESS:
2343 @@ -2408,6 +2665,39 @@ int mutt_index_menu (void)
2344 menu->redraw = REDRAW_FULL;
2349 + case OP_FORWARD_TO_GROUP:
2357 + if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2358 + mutt_strcasecmp (CURHDR->env->followup_to, "poster") ||
2359 + query_quadoption (OPT_FOLLOWUPTOPOSTER,
2360 + _("Reply by mail as poster prefers?")) != MUTT_YES)
2362 + if (Context && Context->magic == MUTT_NNTP &&
2363 + !((NNTP_DATA *)Context->data)->allowed &&
2364 + query_quadoption (OPT_TOMODERATED,
2365 + _("Posting to this group not allowed, may be moderated. Continue?")) != MUTT_YES)
2367 + if (op == OP_POST)
2368 + ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2372 + ci_send_message ((op == OP_FOLLOWUP ? SENDREPLY : SENDFORWARD) |
2373 + SENDNEWS, NULL, NULL, Context, tag ? NULL : CURHDR);
2375 + menu->redraw = REDRAW_FULL;
2381 case OP_GROUP_REPLY:
2382 case OP_GROUP_CHAT_REPLY:
2383 diff -udprP mutt-1.12.1.orig/doc/Muttrc mutt-1.12.1/doc/Muttrc
2384 --- mutt-1.12.1.orig/doc/Muttrc 2019-06-15 19:07:32.000000000 +0300
2385 +++ mutt-1.12.1/doc/Muttrc 2019-08-11 20:31:26.137940627 +0300
2386 @@ -275,6 +275,28 @@ attachments -I message/external-body
2387 # editing the body of an outgoing message.
2390 +# set ask_follow_up=no
2392 +# Name: ask_follow_up
2397 +# If set, Mutt will prompt you for follow-up groups before editing
2398 +# the body of an outgoing message.
2401 +# set ask_x_comment_to=no
2403 +# Name: ask_x_comment_to
2408 +# If set, Mutt will prompt you for x-comment-to field before editing
2409 +# the body of an outgoing message.
2412 # set assumed_charset=""
2414 # Name: assumed_charset
2415 @@ -530,6 +552,17 @@ attachments -I message/external-body
2416 # desirable to unset this variable.
2419 +# set catchup_newsgroup=ask-yes
2421 +# Name: catchup_newsgroup
2426 +# If this variable is set, Mutt will mark all articles in newsgroup
2427 +# as read when you quit the newsgroup (catchup newsgroup).
2430 # set certificate_file="~/.mutt_certificates"
2432 # Name: certificate_file
2433 @@ -1410,6 +1443,19 @@ attachments -I message/external-body
2434 # of the same email for you.
2437 +# set followup_to_poster=ask-yes
2439 +# Name: followup_to_poster
2444 +# If this variable is set and the keyword "poster" is present in
2445 +# Followup-To header, follow-up to newsgroup function is not
2446 +# permitted. The message will be mailed to the submitter of the
2447 +# message via mail.
2453 @@ -1560,6 +1606,27 @@ attachments -I message/external-body
2454 # ``Franklin'' to ``Franklin, Steve''.
2457 +# set group_index_format="%4C %M%N %5s %-45.45f %d"
2459 +# Name: group_index_format
2461 +# Default: "%4C %M%N %5s %-45.45f %d"
2464 +# This variable allows you to customize the newsgroup browser display to
2465 +# your personal taste. This string is similar to ``index_format'', but
2466 +# has its own set of printf()-like sequences:
2467 +# %C current newsgroup number
2468 +# %d description of newsgroup (becomes from server)
2469 +# %f newsgroup name
2470 +# %M - if newsgroup not allowed for direct post (moderated for example)
2471 +# %N N if newsgroup is new, u if unsubscribed, blank otherwise
2472 +# %n number of new articles in newsgroup
2473 +# %s number of unread articles in newsgroup
2474 +# %>X right justify the rest of the string and pad with character "X"
2475 +# %|X pad to the end of the line with character "X"
2481 @@ -2252,6 +2319,7 @@ attachments -I message/external-body
2482 # %E number of messages in current thread
2483 # %f sender (address + real name), either From: or Return-Path:
2484 # %F author name, or recipient name if the message is from you
2485 +# %g newsgroup name (if compiled with NNTP support)
2486 # %H spam attribute(s) of this message
2487 # %i message-id of the current message
2488 # %l number of lines in the message (does not work with maildir,
2489 @@ -2275,6 +2343,8 @@ attachments -I message/external-body
2490 # %T the appropriate character from the $to_chars string
2491 # %u user (login) name of the author
2492 # %v first name of the author, or the recipient if the message is from you
2493 +# %W name of organization of author (``Organization:'' field)
2494 +# %x ``X-Comment-To:'' field (if present and compiled with NNTP support)
2495 # %X number of attachments
2496 # (please see the ``attachments'' section for possible speed effects)
2497 # %y ``X-Label:'' field, if present
2498 @@ -2322,6 +2392,27 @@ attachments -I message/external-body
2499 # and $post_indent_string.
2509 +# If set, specifies the program and arguments used to deliver news posted
2510 +# by Mutt. Otherwise, mutt posts article using current connection to
2511 +# news server. The following printf-style sequence is understood:
2514 +# %P port if specified
2515 +# %s news server name
2520 +# Example: set inews="/usr/local/bin/inews -hS"
2523 # set ispell="/usr/bin/ispell"
2526 @@ -2774,6 +2865,18 @@ attachments -I message/external-body
2527 # mime.types lookup.
2530 +# set mime_subject=yes
2532 +# Name: mime_subject
2537 +# If unset, 8-bit ``subject:'' line in article header will not be
2538 +# encoded according to RFC2047 to base64. This is useful when message
2539 +# is Usenet article, because MIME for news is nonstandard feature.
2542 # set mix_entry_format="%4n %c %-16s %a"
2544 # Name: mix_entry_format
2545 @@ -2852,6 +2955,144 @@ attachments -I message/external-body
2546 # into this command.
2549 +# set news_cache_dir="~/.mutt"
2551 +# Name: news_cache_dir
2553 +# Default: "~/.mutt"
2556 +# This variable pointing to directory where Mutt will save cached news
2557 +# articles and headers in. If unset, articles and headers will not be
2558 +# saved at all and will be reloaded from the server each time.
2561 +# set news_server=""
2563 +# Name: news_server
2568 +# This variable specifies domain name or address of NNTP server. It
2569 +# defaults to the news server specified in the environment variable
2570 +# $NNTPSERVER or contained in the file /etc/nntpserver. You can also
2571 +# specify username and an alternative port for each news server, ie:
2573 +# [[s]news://][username[:password]@]server[:port]
2576 +# set newsgroups_charset="utf-8"
2578 +# Name: newsgroups_charset
2583 +# Character set of newsgroups descriptions.
2586 +# set newsrc="~/.newsrc"
2590 +# Default: "~/.newsrc"
2593 +# The file, containing info about subscribed newsgroups - names and
2594 +# indexes of read articles. The following printf-style sequence
2598 +# %P port if specified
2599 +# %s news server name
2604 +# set nntp_authenticators=""
2606 +# Name: nntp_authenticators
2611 +# This is a colon-delimited list of authentication methods mutt may
2612 +# attempt to use to log in to a news server, in the order mutt should
2613 +# try them. Authentication methods are either ``user'' or any
2614 +# SASL mechanism, e.g. ``digest-md5'', ``gssapi'' or ``cram-md5''.
2615 +# This option is case-insensitive. If it's unset (the default)
2616 +# mutt will try all available methods, in order from most-secure to
2620 +# set nntp_authenticators="digest-md5:user"
2622 +# Note: Mutt will only fall back to other authentication methods if
2623 +# the previous methods are unavailable. If a method is available but
2624 +# authentication fails, mutt will not connect to the IMAP server.
2627 +# set nntp_context=1000
2629 +# Name: nntp_context
2634 +# This variable defines number of articles which will be in index when
2635 +# newsgroup entered. If active newsgroup have more articles than this
2636 +# number, oldest articles will be ignored. Also controls how many
2637 +# articles headers will be saved in cache when you quit newsgroup.
2640 +# set nntp_load_description=yes
2642 +# Name: nntp_load_description
2647 +# This variable controls whether or not descriptions for each newsgroup
2648 +# must be loaded when newsgroup is added to list (first time list
2649 +# loading or new newsgroup adding).
2659 +# Your login name on the NNTP server. If unset and NNTP server requires
2660 +# authentification, Mutt will prompt you for your account name when you
2661 +# connect to news server.
2671 +# Your password for NNTP account.
2681 +# The time in seconds until any operations on newsgroup except post new
2682 +# article will cause recheck for new news. If set to 0, Mutt will
2683 +# recheck newsgroup on each operation in index (stepping, read article,
2687 # set pager="builtin"
2690 @@ -3686,6 +3927,19 @@ attachments -I message/external-body
2691 # the section on $index_format.
2694 +# set post_moderated=ask-yes
2696 +# Name: post_moderated
2701 +# If set to yes, Mutt will post article to newsgroup that have
2702 +# not permissions to posting (e.g. moderated). Note: if news server
2703 +# does not support posting to that newsgroup or totally read-only, that
2704 +# posting will not have an effect.
2707 # set postpone=ask-yes
2710 @@ -4567,6 +4821,41 @@ attachments -I message/external-body
2711 # Chinese characters.
2714 +# set save_unsubscribed=no
2716 +# Name: save_unsubscribed
2721 +# When set, info about unsubscribed newsgroups will be saved into
2722 +# ``newsrc'' file and into cache.
2725 +# set show_new_news=yes
2727 +# Name: show_new_news
2732 +# If set, news server will be asked for new newsgroups on entering
2733 +# the browser. Otherwise, it will be done only once for a news server.
2734 +# Also controls whether or not number of new articles of subscribed
2735 +# newsgroups will be then checked.
2738 +# set show_only_unread=no
2740 +# Name: show_only_unread
2745 +# If set, only subscribed newsgroups that contain unread articles
2746 +# will be displayed in browser.
2749 # set sig_dashes=yes
2752 @@ -5971,3 +6260,14 @@ attachments -I message/external-body
2753 # ``tuning'' section of the manual for performance considerations.
2756 +# set x_comment_to=no
2758 +# Name: x_comment_to
2763 +# If set, Mutt will add ``X-Comment-To:'' field (that contains full
2764 +# name of original article author) to article that followuped to newsgroup.
2767 diff -udprP mutt-1.12.1.orig/doc/manual.xml.head mutt-1.12.1/doc/manual.xml.head
2768 --- mutt-1.12.1.orig/doc/manual.xml.head 2019-06-14 04:29:29.000000000 +0300
2769 +++ mutt-1.12.1/doc/manual.xml.head 2019-08-11 20:31:26.138940612 +0300
2770 @@ -1948,6 +1948,26 @@ to update status flags for your certific
2775 +<title>Reading news via NNTP</title>
2778 +If compiled with <emphasis>--enable-nntp</emphasis> option, Mutt can
2779 +read news from news server via NNTP. You can open a newsgroup with
2780 +function ``change-newsgroup'' (default: ``i''). Default news server
2781 +can be obtained from <literal>$NNTPSERVER</literal> environment
2782 +variable or from <literal>/etc/nntpserver</literal> file. Like other
2783 +news readers, info about subscribed newsgroups is saved in file by
2784 +<link linkend="newsrc">$newsrc</link> variable. The variable <link
2785 +linkend="news-cache-dir">$news_cache_dir</link> can be used to point
2786 +to a directory. Mutt will create a hierarchy of subdirectories named
2787 +like the account and newsgroup the cache is for. Also the hierarchy
2788 +is used to store header cache if Mutt was compiled with <link
2789 +linkend="header-caching">header cache</link> support.
2796 <chapter id="configuration">
2797 diff -udprP mutt-1.12.1.orig/doc/mutt.man mutt-1.12.1/doc/mutt.man
2798 --- mutt-1.12.1.orig/doc/mutt.man 2019-05-25 19:22:39.000000000 +0300
2799 +++ mutt-1.12.1/doc/mutt.man 2019-08-11 20:31:26.138940612 +0300
2800 @@ -23,8 +23,8 @@ mutt \- The Mutt Mail User Agent
2805 -[\-e \fIcmd\fP] [\-F \fIfile\fP] [\-m \fItype\fP] [\-f \fIfile\fP]
2807 +[\-e \fIcmd\fP] [\-F \fIfile\fP] [\-g \fIserver\fP] [\-m \fItype\fP] [\-f \fIfile\fP]
2811 @@ -104,6 +104,10 @@ files.
2812 Specify which mailbox to load.
2813 .IP "-F \fImuttrc\fP"
2814 Specify an initialization file to read instead of ~/.muttrc
2815 +.IP "-g \fIserver\fP"
2816 +Start Mutt with a listing of subscribed newsgroups at specified news server.
2818 +Start Mutt with a listing of subscribed newsgroups.
2821 .IP "-H \fIdraft\fP"
2822 diff -udprP mutt-1.12.1.orig/functions.h mutt-1.12.1/functions.h
2823 --- mutt-1.12.1.orig/functions.h 2019-05-25 19:22:39.000000000 +0300
2824 +++ mutt-1.12.1/functions.h 2019-08-11 20:31:26.138940612 +0300
2825 @@ -90,6 +90,10 @@ const struct binding_t OpMain[] = { /* m
2826 { "break-thread", OP_MAIN_BREAK_THREAD, "#" },
2827 { "change-folder", OP_MAIN_CHANGE_FOLDER, "c" },
2828 { "change-folder-readonly", OP_MAIN_CHANGE_FOLDER_READONLY, "\033c" },
2830 + { "change-newsgroup", OP_MAIN_CHANGE_GROUP, "i" },
2831 + { "change-newsgroup-readonly",OP_MAIN_CHANGE_GROUP_READONLY, "\033i" },
2833 { "next-unread-mailbox", OP_MAIN_NEXT_UNREAD_MAILBOX, NULL },
2834 { "collapse-thread", OP_MAIN_COLLAPSE_THREAD, "\033v" },
2835 { "collapse-all", OP_MAIN_COLLAPSE_ALL, "\033V" },
2836 @@ -105,7 +109,15 @@ const struct binding_t OpMain[] = { /* m
2837 { "edit-label", OP_EDIT_LABEL, "Y" },
2838 { "edit-type", OP_EDIT_TYPE, "\005" },
2839 { "forward-message", OP_FORWARD_MESSAGE, "f" },
2840 - { "flag-message", OP_FLAG_MESSAGE, "F" },
2842 + { "forward-to-group", OP_FORWARD_TO_GROUP, "\033F" },
2843 + { "followup-message", OP_FOLLOWUP, "F" },
2844 + { "get-children", OP_GET_CHILDREN, NULL },
2845 + { "get-message", OP_GET_MESSAGE, "\007" },
2846 + { "get-parent", OP_GET_PARENT, "\033G" },
2847 + { "reconstruct-thread", OP_RECONSTRUCT_THREAD, NULL },
2849 + { "flag-message", OP_FLAG_MESSAGE, "\033f" },
2850 { "group-chat-reply", OP_GROUP_CHAT_REPLY, NULL },
2851 { "group-reply", OP_GROUP_REPLY, "g" },
2853 @@ -134,6 +146,9 @@ const struct binding_t OpMain[] = { /* m
2854 { "sort-mailbox", OP_SORT, "o" },
2855 { "sort-reverse", OP_SORT_REVERSE, "O" },
2856 { "print-message", OP_PRINT, "p" },
2858 + { "post-message", OP_POST, "P" },
2860 { "previous-thread", OP_MAIN_PREV_THREAD, "\020" },
2861 { "previous-subthread", OP_MAIN_PREV_SUBTHREAD, "\033p" },
2862 { "recall-message", OP_RECALL_MESSAGE, "R" },
2863 @@ -153,6 +168,10 @@ const struct binding_t OpMain[] = { /* m
2864 { "show-version", OP_VERSION, "V" },
2865 { "set-flag", OP_MAIN_SET_FLAG, "w" },
2866 { "clear-flag", OP_MAIN_CLEAR_FLAG, "W" },
2867 + { "toggle-read", OP_TOGGLE_READ, "X" },
2869 + { "catchup", OP_CATCHUP, "y" },
2871 { "display-message", OP_DISPLAY_MESSAGE, MUTT_ENTER_S },
2872 { "mark-message", OP_MARK_MSG, "~" },
2873 { "buffy-list", OP_BUFFY_LIST, "." },
2874 @@ -165,7 +184,7 @@ const struct binding_t OpMain[] = { /* m
2875 { "previous-new-then-unread", OP_MAIN_PREV_NEW_THEN_UNREAD, "\033\t" },
2876 { "next-unread", OP_MAIN_NEXT_UNREAD, NULL },
2877 { "previous-unread", OP_MAIN_PREV_UNREAD, NULL },
2878 - { "parent-message", OP_MAIN_PARENT_MESSAGE, "P" },
2879 + { "parent-message", OP_MAIN_PARENT_MESSAGE, NULL },
2880 { "root-message", OP_MAIN_ROOT_MESSAGE, NULL },
2883 @@ -196,6 +215,10 @@ const struct binding_t OpPager[] = { /*
2884 { "bounce-message", OP_BOUNCE_MESSAGE, "b" },
2885 { "change-folder", OP_MAIN_CHANGE_FOLDER, "c" },
2886 { "change-folder-readonly", OP_MAIN_CHANGE_FOLDER_READONLY, "\033c" },
2888 + { "change-newsgroup", OP_MAIN_CHANGE_GROUP, "i" },
2889 + { "change-newsgroup-readonly",OP_MAIN_CHANGE_GROUP_READONLY, "\033i" },
2891 { "next-unread-mailbox", OP_MAIN_NEXT_UNREAD_MAILBOX, NULL },
2892 { "compose-to-sender", OP_COMPOSE_TO_SENDER, NULL},
2893 { "copy-message", OP_COPY_MESSAGE, "C" },
2894 @@ -208,8 +231,12 @@ const struct binding_t OpPager[] = { /*
2895 { "edit", OP_EDIT_MESSAGE, "e" },
2896 { "edit-label", OP_EDIT_LABEL, "Y" },
2897 { "edit-type", OP_EDIT_TYPE, "\005" },
2899 + { "followup-message", OP_FOLLOWUP, "F" },
2900 + { "forward-to-group", OP_FORWARD_TO_GROUP, "\033F" },
2902 { "forward-message", OP_FORWARD_MESSAGE, "f" },
2903 - { "flag-message", OP_FLAG_MESSAGE, "F" },
2904 + { "flag-message", OP_FLAG_MESSAGE, "\033f" },
2905 { "group-chat-reply", OP_GROUP_CHAT_REPLY, NULL },
2906 { "group-reply", OP_GROUP_REPLY, "g" },
2908 @@ -233,6 +260,9 @@ const struct binding_t OpPager[] = { /*
2909 { "sort-mailbox", OP_SORT, "o" },
2910 { "sort-reverse", OP_SORT_REVERSE, "O" },
2911 { "print-message", OP_PRINT, "p" },
2913 + { "post-message", OP_POST, "P" },
2915 { "previous-thread", OP_MAIN_PREV_THREAD, "\020" },
2916 { "previous-subthread",OP_MAIN_PREV_SUBTHREAD, "\033p" },
2917 { "purge-message", OP_PURGE_MESSAGE, NULL },
2918 @@ -282,7 +312,7 @@ const struct binding_t OpPager[] = { /*
2919 { "half-down", OP_HALF_DOWN, NULL },
2920 { "previous-line", OP_PREV_LINE, NULL },
2921 { "bottom", OP_PAGER_BOTTOM, NULL },
2922 - { "parent-message", OP_MAIN_PARENT_MESSAGE, "P" },
2923 + { "parent-message", OP_MAIN_PARENT_MESSAGE, NULL },
2924 { "root-message", OP_MAIN_ROOT_MESSAGE, NULL },
2927 @@ -317,6 +347,10 @@ const struct binding_t OpAttach[] = { /*
2928 { "display-toggle-weed", OP_DISPLAY_HEADERS, "h" },
2929 { "compose-to-sender", OP_COMPOSE_TO_SENDER, NULL},
2930 { "edit-type", OP_EDIT_TYPE, "\005" },
2932 + { "followup-message", OP_FOLLOWUP, "F" },
2933 + { "forward-to-group", OP_FORWARD_TO_GROUP, "\033F" },
2935 { "print-entry", OP_PRINT, "p" },
2936 { "save-entry", OP_SAVE, "s" },
2937 { "pipe-entry", OP_PIPE, "|" },
2938 @@ -343,6 +377,7 @@ const struct binding_t OpAttach[] = { /*
2939 const struct binding_t OpCompose[] = { /* map: compose */
2940 { "attach-file", OP_COMPOSE_ATTACH_FILE, "a" },
2941 { "attach-message", OP_COMPOSE_ATTACH_MESSAGE, "A" },
2942 + { "attach-news-message",OP_COMPOSE_ATTACH_NEWS_MESSAGE,"\033a" },
2943 { "edit-bcc", OP_COMPOSE_EDIT_BCC, "b" },
2944 { "edit-cc", OP_COMPOSE_EDIT_CC, "c" },
2945 { "copy-file", OP_SAVE, "C" },
2946 @@ -362,6 +397,11 @@ const struct binding_t OpCompose[] = { /
2947 { "print-entry", OP_PRINT, "l" },
2948 { "edit-mime", OP_COMPOSE_EDIT_MIME, "m" },
2949 { "new-mime", OP_COMPOSE_NEW_MIME, "n" },
2951 + { "edit-newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS, "N" },
2952 + { "edit-followup-to", OP_COMPOSE_EDIT_FOLLOWUP_TO, "o" },
2953 + { "edit-x-comment-to",OP_COMPOSE_EDIT_X_COMMENT_TO, "x" },
2955 { "postpone-message", OP_COMPOSE_POSTPONE_MESSAGE, "P" },
2956 { "edit-reply-to", OP_COMPOSE_EDIT_REPLY_TO, "r" },
2957 { "rename-attachment",OP_COMPOSE_RENAME_ATTACHMENT, "\017" },
2958 @@ -415,14 +455,25 @@ const struct binding_t OpBrowser[] = { /
2959 { "select-new", OP_BROWSER_NEW_FILE, "N" },
2960 { "check-new", OP_CHECK_NEW, NULL },
2961 { "toggle-mailboxes", OP_TOGGLE_MAILBOXES, "\t" },
2963 + { "reload-active", OP_LOAD_ACTIVE, "g" },
2964 + { "subscribe-pattern", OP_SUBSCRIBE_PATTERN, "S" },
2965 + { "unsubscribe-pattern", OP_UNSUBSCRIBE_PATTERN, "U" },
2966 + { "catchup", OP_CATCHUP, "y" },
2967 + { "uncatchup", OP_UNCATCHUP, "Y" },
2969 { "view-file", OP_BROWSER_VIEW_FILE, " " },
2970 { "buffy-list", OP_BUFFY_LIST, "." },
2972 { "create-mailbox", OP_CREATE_MAILBOX, "C" },
2973 { "delete-mailbox", OP_DELETE_MAILBOX, "d" },
2974 { "rename-mailbox", OP_RENAME_MAILBOX, "r" },
2976 +#if defined USE_IMAP || defined USE_NNTP
2977 { "subscribe", OP_BROWSER_SUBSCRIBE, "s" },
2978 { "unsubscribe", OP_BROWSER_UNSUBSCRIBE, "u" },
2981 { "toggle-subscribed", OP_BROWSER_TOGGLE_LSUB, "T" },
2984 diff -udprP mutt-1.12.1.orig/globals.h mutt-1.12.1/globals.h
2985 --- mutt-1.12.1.orig/globals.h 2019-05-25 19:22:39.000000000 +0300
2986 +++ mutt-1.12.1/globals.h 2019-08-11 20:31:26.139940597 +0300
2987 @@ -73,7 +73,7 @@ WHERE char *Inbox;
2989 WHERE char *MailcapPath;
2990 WHERE char *Maildir;
2991 -#if defined(USE_IMAP) || defined(USE_POP)
2992 +#if defined(USE_IMAP) || defined(USE_POP) || defined(USE_NNTP)
2993 WHERE char *MessageCachedir;
2996 @@ -101,6 +101,17 @@ WHERE char *MixEntryFormat;
2999 WHERE char *Muttrc INITVAL (NULL);
3001 +WHERE char *GroupFormat;
3003 +WHERE char *NewsCacheDir;
3004 +WHERE char *NewsServer;
3005 +WHERE char *NewsgroupsCharset;
3006 +WHERE char *NewsRc;
3007 +WHERE char *NntpAuthenticators;
3008 +WHERE char *NntpUser;
3009 +WHERE char *NntpPass;
3013 WHERE char *PagerFmt;
3014 @@ -213,6 +224,11 @@ extern unsigned char QuadOptions[];
3016 WHERE unsigned short Counter INITVAL (0);
3019 +WHERE short NewsPollTimeout;
3020 +WHERE short NntpContext;
3023 WHERE short ConnectTimeout;
3024 WHERE short ErrorHistSize;
3025 WHERE short HistSize;
3026 diff -udprP mutt-1.12.1.orig/hcache.c mutt-1.12.1/hcache.c
3027 --- mutt-1.12.1.orig/hcache.c 2019-05-25 19:22:39.000000000 +0300
3028 +++ mutt-1.12.1/hcache.c 2019-08-11 20:31:26.139940597 +0300
3029 @@ -543,6 +543,12 @@ dump_envelope(ENVELOPE * e, unsigned cha
3030 d = dump_list(e->in_reply_to, d, off, 0);
3031 d = dump_list(e->userhdrs, d, off, convert);
3034 + d = dump_char(e->xref, d, off, 0);
3035 + d = dump_char(e->followup_to, d, off, 0);
3036 + d = dump_char(e->x_comment_to, d, off, convert);
3042 @@ -582,6 +588,12 @@ restore_envelope(ENVELOPE * e, const uns
3043 restore_list(&e->references, d, off, 0);
3044 restore_list(&e->in_reply_to, d, off, 0);
3045 restore_list(&e->userhdrs, d, off, convert);
3048 + restore_char(&e->xref, d, off, 0);
3049 + restore_char(&e->followup_to, d, off, 0);
3050 + restore_char(&e->x_comment_to, d, off, convert);
3055 diff -udprP mutt-1.12.1.orig/hdrline.c mutt-1.12.1/hdrline.c
3056 --- mutt-1.12.1.orig/hdrline.c 2019-05-25 19:22:39.000000000 +0300
3057 +++ mutt-1.12.1/hdrline.c 2019-08-11 20:31:26.139940597 +0300
3058 @@ -227,6 +227,7 @@ static char *apply_subject_mods (ENVELOP
3059 * %E = number of messages in current thread
3060 * %f = entire from line
3061 * %F = like %n, unless from self
3062 + * %g = newsgroup name (if compiled with NNTP support)
3064 * %l = number of lines in the message
3065 * %L = like %F, except `lists' are displayed first
3066 @@ -243,6 +244,8 @@ static char *apply_subject_mods (ENVELOP
3068 * %u = user (login) name of author
3069 * %v = first name of author, unless from self
3070 + * %W = where user is (organization)
3071 + * %x = `x-comment-to:' field (if present and compiled with NNTP support)
3072 * %X = number of MIME attachments
3073 * %y = `x-label:' field (if present)
3074 * %Y = `x-label:' field (if present, tree unfolded, and != parent's x-label)
3075 @@ -476,6 +479,12 @@ hdr_format_str (char *dest,
3081 + mutt_format_s (dest, destlen, prefix, hdr->env->newsgroups ? hdr->env->newsgroups : "");
3086 mutt_format_s (dest, destlen, prefix, hdr->env->message_id ? hdr->env->message_id : "<no.id>");
3088 @@ -680,6 +689,22 @@ hdr_format_str (char *dest,
3089 mutt_format_s (dest, destlen, prefix, buf2);
3094 + mutt_format_s (dest, destlen, prefix, hdr->env->organization ? hdr->env->organization : "");
3095 + else if (!hdr->env->organization)
3102 + mutt_format_s (dest, destlen, prefix, hdr->env->x_comment_to ? hdr->env->x_comment_to : "");
3103 + else if (!hdr->env->x_comment_to)
3111 diff -udprP mutt-1.12.1.orig/headers.c mutt-1.12.1/headers.c
3112 --- mutt-1.12.1.orig/headers.c 2019-05-25 19:22:39.000000000 +0300
3113 +++ mutt-1.12.1/headers.c 2019-08-11 20:31:26.139940597 +0300
3114 @@ -115,6 +115,9 @@ void mutt_edit_headers (const char *edit
3115 $edit_headers set, we remove References: as they're likely invalid;
3116 we can simply compare strings as we don't generate References for
3117 multiple Message-Ids in IRT anyways */
3119 + if (!option (OPTNEWSSEND))
3121 if (msg->env->in_reply_to &&
3122 (!n->in_reply_to || mutt_strcmp (n->in_reply_to->data,
3123 msg->env->in_reply_to->data) != 0))
3124 diff -udprP mutt-1.12.1.orig/init.c mutt-1.12.1/init.c
3125 --- mutt-1.12.1.orig/init.c 2019-05-25 19:22:39.000000000 +0300
3126 +++ mutt-1.12.1/init.c 2019-08-11 20:31:26.139940597 +0300
3127 @@ -3517,6 +3517,28 @@ void mutt_init (int skip_sys_rc, LIST *c
3128 Fqdn = safe_strdup(utsname.nodename);
3136 + if ((f = safe_fopen (SYSCONFDIR "/nntpserver", "r")))
3139 + fgets (buffer, sizeof (buffer), f);
3143 + while (*i && (*i != ' ') && (*i != '\t') && (*i != '\r') && (*i != '\n')) i++;
3145 + NewsServer = safe_strdup (p);
3149 + if ((p = getenv ("NNTPSERVER")))
3150 + NewsServer = safe_strdup (p);
3153 if ((p = getenv ("MAIL")))
3154 Spoolfile = safe_strdup (p);
3155 else if ((p = getenv ("MAILDIR")))
3156 diff -udprP mutt-1.12.1.orig/init.h mutt-1.12.1/init.h
3157 --- mutt-1.12.1.orig/init.h 2019-06-15 18:57:01.000000000 +0300
3158 +++ mutt-1.12.1/init.h 2019-08-11 20:31:26.140940582 +0300
3159 @@ -202,6 +202,20 @@ struct option_t MuttVars[] = {
3160 ** If \fIset\fP, Mutt will prompt you for carbon-copy (Cc) recipients before
3161 ** editing the body of an outgoing message.
3164 + { "ask_follow_up", DT_BOOL, R_NONE, OPTASKFOLLOWUP, 0 },
3167 + ** If set, Mutt will prompt you for follow-up groups before editing
3168 + ** the body of an outgoing message.
3170 + { "ask_x_comment_to", DT_BOOL, R_NONE, OPTASKXCOMMENTTO, 0 },
3173 + ** If set, Mutt will prompt you for x-comment-to field before editing
3174 + ** the body of an outgoing message.
3177 { "assumed_charset", DT_STR, R_NONE, UL &AssumedCharset, UL 0},
3180 @@ -383,6 +397,14 @@ struct option_t MuttVars[] = {
3181 ** doesn't make intuitive sense. In those cases, it may be
3182 ** desirable to \fIunset\fP this variable.
3185 + { "catchup_newsgroup", DT_QUAD, R_NONE, OPT_CATCHUP, MUTT_ASKYES },
3188 + ** If this variable is \fIset\fP, Mutt will mark all articles in newsgroup
3189 + ** as read when you quit the newsgroup (catchup newsgroup).
3192 #if defined(USE_SSL)
3193 { "certificate_file", DT_PATH, R_NONE, UL &SslCertFile, UL "~/.mutt_certificates" },
3195 @@ -1018,6 +1040,16 @@ struct option_t MuttVars[] = {
3196 ** sent to both the list and your address, resulting in two copies
3197 ** of the same email for you.
3200 + { "followup_to_poster", DT_QUAD, R_NONE, OPT_FOLLOWUPTOPOSTER, MUTT_ASKYES },
3203 + ** If this variable is \fIset\fP and the keyword "poster" is present in
3204 + ** \fIFollowup-To\fP header, follow-up to newsgroup function is not
3205 + ** permitted. The message will be mailed to the submitter of the
3206 + ** message via mail.
3209 { "force_name", DT_BOOL, R_NONE, OPTFORCENAME, 0 },
3212 @@ -1125,6 +1157,26 @@ struct option_t MuttVars[] = {
3213 ** a regular expression that will match the whole name so mutt will expand
3214 ** ``Franklin'' to ``Franklin, Steve''.
3217 + { "group_index_format", DT_STR, R_BOTH, {.p=&GroupFormat}, {.p="%4C %M%N %5s %-45.45f %d"} },
3220 + ** This variable allows you to customize the newsgroup browser display to
3221 + ** your personal taste. This string is similar to ``$index_format'', but
3222 + ** has its own set of printf()-like sequences:
3224 + ** .dt %C .dd current newsgroup number
3225 + ** .dt %d .dd description of newsgroup (becomes from server)
3226 + ** .dt %f .dd newsgroup name
3227 + ** .dt %M .dd - if newsgroup not allowed for direct post (moderated for example)
3228 + ** .dt %N .dd N if newsgroup is new, u if unsubscribed, blank otherwise
3229 + ** .dt %n .dd number of new articles in newsgroup
3230 + ** .dt %s .dd number of unread articles in newsgroup
3231 + ** .dt %>X .dd right justify the rest of the string and pad with character "X"
3232 + ** .dt %|X .dd pad to the end of the line with character "X"
3236 { "hdr_format", DT_SYN, R_NONE, UL "index_format", 0 },
3239 @@ -1597,6 +1649,7 @@ struct option_t MuttVars[] = {
3240 ** .dt %E .dd number of messages in current thread
3241 ** .dt %f .dd sender (address + real name), either From: or Return-Path:
3242 ** .dt %F .dd author name, or recipient name if the message is from you
3243 + ** .dt %g .dd newsgroup name (if compiled with NNTP support)
3244 ** .dt %H .dd spam attribute(s) of this message
3245 ** .dt %i .dd message-id of the current message
3246 ** .dt %l .dd number of lines in the message (does not work with maildir,
3247 @@ -1620,6 +1673,8 @@ struct option_t MuttVars[] = {
3248 ** .dt %T .dd the appropriate character from the $$to_chars string
3249 ** .dt %u .dd user (login) name of the author
3250 ** .dt %v .dd first name of the author, or the recipient if the message is from you
3251 + ** .dt %W .dd name of organization of author (``Organization:'' field)
3252 + ** .dt %x .dd ``X-Comment-To:'' field (if present and compiled with NNTP support)
3253 ** .dt %X .dd number of attachments
3254 ** (please see the ``$attachments'' section for possible speed effects)
3255 ** .dt %y .dd ``X-Label:'' field, if present
3256 @@ -1666,6 +1721,25 @@ struct option_t MuttVars[] = {
3257 ** $$forward_format, $$indent_string, $$message_format, $$pager_format,
3258 ** and $$post_indent_string.
3261 + { "inews", DT_PATH, R_NONE, {.p={&Inews}, {.p=""} },
3264 + ** If set, specifies the program and arguments used to deliver news posted
3265 + ** by Mutt. Otherwise, mutt posts article using current connection to
3266 + ** news server. The following printf-style sequence is understood:
3268 + ** .dt %a .dd account url
3269 + ** .dt %p .dd port
3270 + ** .dt %P .dd port if specified
3271 + ** .dt %s .dd news server name
3272 + ** .dt %S .dd url schema
3273 + ** .dt %u .dd username
3276 + ** Example: set inews="/usr/local/bin/inews -hS"
3279 { "ispell", DT_PATH, R_NONE, UL &Ispell, UL ISPELL },
3282 @@ -1958,6 +2032,15 @@ struct option_t MuttVars[] = {
3283 ** When \fIset\fP, the $$mime_type_query_command will be run before the
3284 ** mime.types lookup.
3287 + { "mime_subject", DT_BOOL, R_NONE, OPTMIMESUBJECT, 1 },
3290 + ** If \fIunset\fP, 8-bit ``subject:'' line in article header will not be
3291 + ** encoded according to RFC2047 to base64. This is useful when message
3292 + ** is Usenet article, because MIME for news is nonstandard feature.
3296 { "mix_entry_format", DT_STR, R_NONE, UL &MixEntryFormat, UL "%4n %c %-16s %a" },
3298 @@ -2012,6 +2095,106 @@ struct option_t MuttVars[] = {
3299 ** See the $$status_format documentation for the values that can be formatted
3300 ** into this command.
3303 + { "news_cache_dir", DT_PATH, R_NONE, {.p=&NewsCacheDir}, {.p="~/.mutt"} },
3306 + ** This variable pointing to directory where Mutt will save cached news
3307 + ** articles and headers in. If \fIunset\fP, articles and headers will not be
3308 + ** saved at all and will be reloaded from the server each time.
3310 + { "news_server", DT_STR, R_NONE, {.p=&NewsServer}, {.l=0} },
3313 + ** This variable specifies domain name or address of NNTP server. It
3314 + ** defaults to the news server specified in the environment variable
3315 + ** $$$NNTPSERVER or contained in the file /etc/nntpserver. You can also
3316 + ** specify username and an alternative port for each news server, ie:
3318 + ** [[s]news://][username[:password]@]server[:port]
3320 + { "newsgroups_charset", DT_STR, R_NONE, &{.p=NewsgroupsCharset}, "{.p=utf-8"} },
3323 + ** Character set of newsgroups descriptions.
3325 + { "newsrc", DT_PATH, R_NONE, &{.p=NewsRc}, "{.p=~/.newsrc"} },
3328 + ** The file, containing info about subscribed newsgroups - names and
3329 + ** indexes of read articles. The following printf-style sequence
3332 + ** .dt %a .dd account url
3333 + ** .dt %p .dd port
3334 + ** .dt %P .dd port if specified
3335 + ** .dt %s .dd news server name
3336 + ** .dt %S .dd url schema
3337 + ** .dt %u .dd username
3340 + { "nntp_authenticators", DT_STR, R_NONE, &{.p=NntpAuthenticators}, {.l=0} },
3343 + ** This is a colon-delimited list of authentication methods mutt may
3344 + ** attempt to use to log in to a news server, in the order mutt should
3345 + ** try them. Authentication methods are either ``user'' or any
3346 + ** SASL mechanism, e.g. ``digest-md5'', ``gssapi'' or ``cram-md5''.
3347 + ** This option is case-insensitive. If it's \fIunset\fP (the default)
3348 + ** mutt will try all available methods, in order from most-secure to
3353 + ** set nntp_authenticators="digest-md5:user"
3356 + ** \fBNote:\fP Mutt will only fall back to other authentication methods if
3357 + ** the previous methods are unavailable. If a method is available but
3358 + ** authentication fails, mutt will not connect to the IMAP server.
3360 + { "nntp_context", DT_NUM, R_NONE, &{.p=NntpContext}, {.l=1000} },
3363 + ** This variable defines number of articles which will be in index when
3364 + ** newsgroup entered. If active newsgroup have more articles than this
3365 + ** number, oldest articles will be ignored. Also controls how many
3366 + ** articles headers will be saved in cache when you quit newsgroup.
3368 + { "nntp_listgroup", DT_BOOL, R_NONE, OPTLISTGROUP, 1 },
3371 + ** This variable controls whether or not existence of each article is
3372 + ** checked when newsgroup is entered.
3374 + { "nntp_load_description", DT_BOOL, R_NONE, OPTLOADDESC, 1 },
3377 + ** This variable controls whether or not descriptions for each newsgroup
3378 + ** must be loaded when newsgroup is added to list (first time list
3379 + ** loading or new newsgroup adding).
3381 + { "nntp_user", DT_STR, R_NONE, {.p=&NntpUser}, {.p=""} },
3384 + ** Your login name on the NNTP server. If \fIunset\fP and NNTP server requires
3385 + ** authentification, Mutt will prompt you for your account name when you
3386 + ** connect to news server.
3388 + { "nntp_pass", DT_STR, R_NONE, &{.p=NntpPass}, {.p=""} },
3391 + ** Your password for NNTP account.
3393 + { "nntp_poll", DT_NUM, R_NONE, &{.p=NewsPollTimeout}, {.l=60} },
3396 + ** The time in seconds until any operations on newsgroup except post new
3397 + ** article will cause recheck for new news. If set to 0, Mutt will
3398 + ** recheck newsgroup on each operation in index (stepping, read article,
3402 { "pager", DT_PATH, R_NONE, UL &Pager, UL "builtin" },
3405 @@ -2606,6 +2789,16 @@ struct option_t MuttVars[] = {
3406 { "post_indent_str", DT_SYN, R_NONE, UL "post_indent_string", 0 },
3410 + { "post_moderated", DT_QUAD, R_NONE, OPT_TOMODERATED, MUTT_ASKYES },
3413 + ** If set to \fIyes\fP, Mutt will post article to newsgroup that have
3414 + ** not permissions to posting (e.g. moderated). \fBNote:\fP if news server
3415 + ** does not support posting to that newsgroup or totally read-only, that
3416 + ** posting will not have an effect.
3419 { "postpone", DT_QUAD, R_NONE, OPT_POSTPONE, MUTT_ASKYES },
3422 @@ -3093,6 +3286,28 @@ struct option_t MuttVars[] = {
3423 ** Command to use when spawning a subshell. By default, the user's login
3424 ** shell from \fC/etc/passwd\fP is used.
3427 + { "save_unsubscribed", DT_BOOL, R_NONE, OPTSAVEUNSUB, 0 },
3430 + ** When \fIset\fP, info about unsubscribed newsgroups will be saved into
3431 + ** ``newsrc'' file and into cache.
3433 + { "show_new_news", DT_BOOL, R_NONE, OPTSHOWNEWNEWS, 1 },
3436 + ** If \fIset\fP, news server will be asked for new newsgroups on entering
3437 + ** the browser. Otherwise, it will be done only once for a news server.
3438 + ** Also controls whether or not number of new articles of subscribed
3439 + ** newsgroups will be then checked.
3441 + { "show_only_unread", DT_BOOL, R_NONE, OPTSHOWONLYUNREAD, 0 },
3444 + ** If \fIset\fP, only subscribed newsgroups that contain unread articles
3445 + ** will be displayed in browser.
3449 { "sidebar_delim_chars", DT_STR, R_SIDEBAR, UL &SidebarDelimChars, UL "/." },
3451 @@ -4234,6 +4449,14 @@ struct option_t MuttVars[] = {
3452 {"xterm_set_titles", DT_SYN, R_NONE, UL "ts_enabled", 0 },
3456 + { "x_comment_to", DT_BOOL, R_NONE, OPTXCOMMENTTO, 0 },
3459 + ** If \fIset\fP, Mutt will add ``X-Comment-To:'' field (that contains full
3460 + ** name of original article author) to article that followuped to newsgroup.
3464 { NULL, 0, 0, 0, 0 }
3466 diff -udprP mutt-1.12.1.orig/keymap.c mutt-1.12.1/keymap.c
3467 --- mutt-1.12.1.orig/keymap.c 2019-05-25 19:22:39.000000000 +0300
3468 +++ mutt-1.12.1/keymap.c 2019-08-11 20:31:26.140940582 +0300
3469 @@ -808,7 +808,6 @@ void km_init (void)
3470 km_bindkey ("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
3472 km_bindkey ("x", MENU_PAGER, OP_EXIT);
3473 - km_bindkey ("i", MENU_PAGER, OP_EXIT);
3474 km_bindkey ("<backspace>", MENU_PAGER, OP_PREV_LINE);
3475 km_bindkey ("<pagedown>", MENU_PAGER, OP_NEXT_PAGE);
3476 km_bindkey ("<pageup>", MENU_PAGER, OP_PREV_PAGE);
3477 diff -udprP mutt-1.12.1.orig/mailbox.h mutt-1.12.1/mailbox.h
3478 --- mutt-1.12.1.orig/mailbox.h 2019-06-11 03:53:09.000000000 +0300
3479 +++ mutt-1.12.1/mailbox.h 2019-08-11 20:31:26.140940582 +0300
3480 @@ -78,6 +78,9 @@ int mx_is_imap (const char *);
3482 int mx_is_pop (const char *);
3485 +int mx_is_nntp (const char *);
3488 int mx_access (const char*, int);
3489 int mx_check_empty (const char *);
3490 diff -udprP mutt-1.12.1.orig/main.c mutt-1.12.1/main.c
3491 --- mutt-1.12.1.orig/main.c 2019-05-25 19:22:39.000000000 +0300
3492 +++ mutt-1.12.1/main.c 2019-08-11 20:31:26.140940582 +0300
3494 #include <idn/stringprep.h>
3501 static const char *ReachingUs = N_("\
3502 To contact the developers, please mail to <mutt-dev@mutt.org>.\n\
3503 To report a bug, please contact the Mutt maintainers via gitlab:\n\
3504 @@ -149,6 +153,8 @@ options:\n\
3505 -e <command>\tspecify a command to be executed after initialization\n\
3506 -f <file>\tspecify which mailbox to read\n\
3507 -F <file>\tspecify an alternate muttrc file\n\
3508 + -g <server>\tspecify a news server (if compiled with NNTP)\n\
3509 + -G\t\tselect a newsgroup (if compiled with NNTP)\n\
3510 -H <file>\tspecify a draft file to read header and body from\n\
3511 -i <file>\tspecify a file which Mutt should include in the body\n\
3512 -m <type>\tspecify a default mailbox type\n\
3513 @@ -302,6 +308,12 @@ static void show_version (void)
3526 @@ -605,6 +617,7 @@ static void start_curses (void)
3527 #define MUTT_NOSYSRC (1<<2) /* -n */
3528 #define MUTT_RO (1<<3) /* -R */
3529 #define MUTT_SELECT (1<<4) /* -y */
3530 +#define MUTT_NEWS (1<<5) /* -g and -G */
3532 int main (int argc, char **argv, char **environ)
3534 @@ -696,7 +709,11 @@ int main (int argc, char **argv, char **
3535 argv[nargc++] = argv[optind];
3539 + if ((i = getopt (argc, argv, "+A:a:b:F:f:c:Dd:Ee:g:GH:s:i:hm:npQ:RvxyzZ")) != EOF)
3541 if ((i = getopt (argc, argv, "+A:a:b:F:f:c:Dd:Ee:H:s:i:hm:npQ:RvxyzZ")) != EOF)
3546 @@ -799,6 +816,20 @@ int main (int argc, char **argv, char **
3547 flags |= MUTT_SELECT;
3551 + case 'g': /* Specify a news server */
3553 + char buf[LONG_STRING];
3555 + snprintf (buf, sizeof (buf), "set news_server=%s", optarg);
3556 + commands = mutt_add_list (commands, buf);
3559 + case 'G': /* List of newsgroups */
3560 + flags |= MUTT_SELECT | MUTT_NEWS;
3565 flags |= MUTT_IGNORE;
3567 @@ -1284,6 +1315,18 @@ int main (int argc, char **argv, char **
3569 else if (flags & MUTT_SELECT)
3572 + if (flags & MUTT_NEWS)
3574 + set_option (OPTNEWS);
3575 + if (!(CurrentNewsSrv = nntp_select_server (NewsServer, 0)))
3577 + exit_endwin_msg = Errorbuf;
3578 + goto cleanup_and_exit;
3585 exit_endwin_msg = _("No incoming mailboxes defined.");
3586 @@ -1300,6 +1343,14 @@ int main (int argc, char **argv, char **
3588 if (!mutt_buffer_len (folder))
3589 mutt_buffer_strcpy (folder, NONULL(Spoolfile));
3591 + if (option (OPTNEWS))
3593 + unset_option (OPTNEWS);
3594 + nntp_buffer_expand_path (folder, &CurrentNewsSrv->conn->account);
3598 mutt_buffer_expand_path (folder);
3600 mutt_str_replace (&CurrentFolder, mutt_b2s (folder));
3601 diff -udprP mutt-1.12.1.orig/mutt.h mutt-1.12.1/mutt.h
3602 --- mutt-1.12.1.orig/mutt.h 2019-06-14 04:29:29.000000000 +0300
3603 +++ mutt-1.12.1/mutt.h 2019-08-11 20:31:26.141940567 +0300
3604 @@ -271,6 +271,9 @@ enum
3612 /* Options for Mailcap lookup */
3614 @@ -329,6 +332,11 @@ enum
3617 OPT_VERIFYSIG, /* verify PGP signatures */
3621 + OPT_FOLLOWUPTOPOSTER,
3624 /* THIS MUST BE THE LAST VALUE. */
3626 @@ -349,6 +357,7 @@ enum
3627 #define SENDDRAFTFILE (1<<11) /* Used by the -H flag */
3628 #define SENDTOSENDER (1<<12)
3629 #define SENDGROUPCHATREPLY (1<<13)
3630 +#define SENDNEWS (1<<14)
3632 /* flags for mutt_compose_menu() */
3633 #define MUTT_COMPOSE_NOFREEHEADER (1<<0)
3634 @@ -371,6 +380,8 @@ enum
3643 @@ -466,6 +477,9 @@ enum
3648 + OPTMIMESUBJECT, /* encode subject line with RFC2047 */
3650 OPTMIMETYPEQUERYFIRST,
3653 @@ -568,6 +582,17 @@ enum
3657 + /* news options */
3661 + OPTSHOWONLYUNREAD,
3668 /* pseudo options */
3670 OPTAUXSORT, /* (pseudo) using auxiliary sort function */
3671 @@ -585,6 +610,7 @@ enum
3672 OPTSORTSUBTHREADS, /* (pseudo) used when $sort_aux changes */
3673 OPTNEEDRESCORE, /* (pseudo) set when the `score' command is used */
3674 OPTATTACHMSG, /* (pseudo) used by attach-message */
3675 + OPTHIDEREAD, /* (pseudo) whether or not hide read messages */
3676 OPTKEEPQUIET, /* (pseudo) shut up the message and refresh
3677 * functions while we are executing an
3679 @@ -595,6 +621,11 @@ enum
3680 OPTDONTHANDLEPGPKEYS, /* (pseudo) used to extract PGP keys */
3681 OPTIGNOREMACROEVENTS, /* (pseudo) don't process macro/push/exec events while set */
3684 + OPTNEWS, /* (pseudo) used to change reader mode */
3685 + OPTNEWSSEND, /* (pseudo) used to change behavior when posting */
3691 @@ -680,6 +711,13 @@ typedef struct envelope
3695 + char *organization;
3699 + char *followup_to;
3700 + char *x_comment_to;
3703 LIST *references; /* message references (in reverse order) */
3704 LIST *in_reply_to; /* in-reply-to header content */
3705 @@ -869,7 +907,7 @@ typedef struct header
3706 int refno; /* message number on server */
3709 -#if defined USE_POP || defined USE_IMAP
3710 +#if defined USE_POP || defined USE_IMAP || defined USE_NNTP
3711 void *data; /* driver-specific data */
3714 diff -udprP mutt-1.12.1.orig/mutt_sasl.c mutt-1.12.1/mutt_sasl.c
3715 --- mutt-1.12.1.orig/mutt_sasl.c 2019-05-25 19:22:39.000000000 +0300
3716 +++ mutt-1.12.1/mutt_sasl.c 2019-08-11 20:31:26.141940567 +0300
3717 @@ -192,6 +192,11 @@ int mutt_sasl_client_new (CONNECTION* co
3718 case MUTT_ACCT_TYPE_SMTP:
3722 + case MUTT_ACCT_TYPE_NNTP:
3727 mutt_error (_("Unknown SASL profile"));
3729 diff -udprP mutt-1.12.1.orig/muttlib.c mutt-1.12.1/muttlib.c
3730 --- mutt-1.12.1.orig/muttlib.c 2019-05-25 19:22:39.000000000 +0300
3731 +++ mutt-1.12.1/muttlib.c 2019-08-11 20:31:26.141940567 +0300
3732 @@ -364,7 +364,7 @@ void mutt_free_header (HEADER **h)
3734 mutt_free_list (&(*h)->chain);
3736 -#if defined USE_POP || defined USE_IMAP
3737 +#if defined USE_POP || defined USE_IMAP || defined USE_NNTP
3740 FREE (h); /* __FREE_CHECKED__ */
3741 @@ -778,6 +778,13 @@ void mutt_free_envelope (ENVELOPE **p)
3742 FREE (&(*p)->supersedes);
3744 FREE (&(*p)->x_label);
3745 + FREE (&(*p)->organization);
3747 + FREE (&(*p)->newsgroups);
3748 + FREE (&(*p)->xref);
3749 + FREE (&(*p)->followup_to);
3750 + FREE (&(*p)->x_comment_to);
3753 mutt_buffer_free (&(*p)->spam);
3755 @@ -1803,6 +1810,14 @@ int mutt_save_confirm (const char *s, st
3760 + if (magic == MUTT_NNTP)
3762 + mutt_error _("Can't save message to news server.");
3767 if (stat (s, st) != -1)
3770 diff -udprP mutt-1.12.1.orig/mx.c mutt-1.12.1/mx.c
3771 --- mutt-1.12.1.orig/mx.c 2019-05-25 19:22:39.000000000 +0300
3772 +++ mutt-1.12.1/mx.c 2019-08-11 20:31:26.141940567 +0300
3784 @@ -88,6 +92,10 @@ struct mx_ops* mx_get_ops (int magic)
3785 case MUTT_COMPRESSED:
3786 return &mx_comp_ops;
3790 + return &mx_nntp_ops;
3795 @@ -387,6 +395,22 @@ int mx_is_pop (const char *p)
3800 +int mx_is_nntp (const char *p)
3802 + url_scheme_t scheme;
3807 + scheme = url_check_scheme (p);
3808 + if (scheme == U_NNTP || scheme == U_NNTPS)
3815 int mx_get_magic (const char *path)
3818 @@ -404,6 +428,11 @@ int mx_get_magic (const char *path)
3820 #endif /* USE_POP */
3823 + if (mx_is_nntp (path))
3825 +#endif /* USE_NNTP */
3827 if (stat (path, &st) == -1)
3829 dprint (1, (debugfile, "mx_get_magic(): unable to stat %s: %s (errno %d).\n",
3830 @@ -849,6 +878,25 @@ int mx_close_mailbox (CONTEXT *ctx, int
3835 + if (ctx->unread && ctx->magic == MUTT_NNTP)
3837 + NNTP_DATA *nntp_data = ctx->data;
3839 + if (nntp_data && nntp_data->nserv && nntp_data->group)
3841 + int rc = query_quadoption (OPT_CATCHUP, _("Mark all articles read?"));
3847 + else if (rc == MUTT_YES)
3848 + mutt_newsgroup_catchup (nntp_data->nserv, nntp_data->group);
3853 for (i = 0; i < ctx->msgcount; i++)
3855 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->read
3856 @@ -856,6 +904,12 @@ int mx_close_mailbox (CONTEXT *ctx, int
3861 + /* don't need to move articles from newsgroup */
3862 + if (ctx->magic == MUTT_NNTP)
3866 if (read_msgs && quadoption (OPT_MOVE) != MUTT_NO)
3869 diff -udprP mutt-1.12.1.orig/mx.h mutt-1.12.1/mx.h
3870 --- mutt-1.12.1.orig/mx.h 2019-05-25 19:22:39.000000000 +0300
3871 +++ mutt-1.12.1/mx.h 2019-08-11 20:31:26.141940567 +0300
3872 @@ -35,6 +35,9 @@ enum
3881 #ifdef USE_COMPRESSED
3882 diff -udprP mutt-1.12.1.orig/newsrc.c mutt-1.12.1/newsrc.c
3883 --- mutt-1.12.1.orig/newsrc.c 1970-01-01 03:00:00.000000000 +0300
3884 +++ mutt-1.12.1/newsrc.c 2019-08-11 20:31:26.142940552 +0300
3887 + * Copyright (C) 1998 Brandon Long <blong@fiction.net>
3888 + * Copyright (C) 1999 Andrej Gritsenko <andrej@lucky.net>
3889 + * Copyright (C) 2000-2019 Vsevolod Volkov <vvv@mutt.org.ua>
3891 + * This program is free software; you can redistribute it and/or modify
3892 + * it under the terms of the GNU General Public License as published by
3893 + * the Free Software Foundation; either version 2 of the License, or
3894 + * (at your option) any later version.
3896 + * This program is distributed in the hope that it will be useful,
3897 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3898 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3899 + * GNU General Public License for more details.
3901 + * You should have received a copy of the GNU General Public License
3902 + * along with this program; if not, write to the Free Software
3903 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
3907 +#include "config.h"
3911 +#include "mutt_curses.h"
3915 +#include "mailbox.h"
3917 +#include "rfc822.h"
3918 +#include "rfc1524.h"
3919 +#include "rfc2047.h"
3920 +#include "bcache.h"
3923 +#include "hcache.h"
3926 +#include <unistd.h>
3927 +#include <string.h>
3929 +#include <stdlib.h>
3930 +#include <sys/stat.h>
3931 +#include <sys/types.h>
3932 +#include <dirent.h>
3935 +/* Find NNTP_DATA for given newsgroup or add it */
3936 +static NNTP_DATA *nntp_data_find (NNTP_SERVER *nserv, const char *group)
3938 + NNTP_DATA *nntp_data = hash_find (nserv->groups_hash, group);
3942 + /* create NNTP_DATA structure and add it to hash */
3943 + nntp_data = safe_calloc (1, sizeof (NNTP_DATA) + strlen (group) + 1);
3944 + nntp_data->group = (char *)nntp_data + sizeof (NNTP_DATA);
3945 + strcpy (nntp_data->group, group);
3946 + nntp_data->nserv = nserv;
3947 + nntp_data->deleted = 1;
3948 + hash_insert (nserv->groups_hash, nntp_data->group, nntp_data);
3950 + /* add NNTP_DATA to list */
3951 + if (nserv->groups_num >= nserv->groups_max)
3953 + nserv->groups_max *= 2;
3954 + safe_realloc (&nserv->groups_list,
3955 + nserv->groups_max * sizeof (nntp_data));
3957 + nserv->groups_list[nserv->groups_num++] = nntp_data;
3962 +/* Remove all temporarily cache files */
3963 +void nntp_acache_free (NNTP_DATA *nntp_data)
3967 + for (i = 0; i < NNTP_ACACHE_LEN; i++)
3969 + if (nntp_data->acache[i].path)
3971 + unlink (nntp_data->acache[i].path);
3972 + FREE (&nntp_data->acache[i].path);
3977 +/* Free NNTP_DATA, used to destroy hash elements */
3978 +void nntp_data_free (void *data)
3980 + NNTP_DATA *nntp_data = data;
3984 + nntp_acache_free (nntp_data);
3985 + mutt_bcache_close (&nntp_data->bcache);
3986 + FREE (&nntp_data->newsrc_ent);
3987 + FREE (&nntp_data->desc);
3991 +/* Unlock and close .newsrc file */
3992 +void nntp_newsrc_close (NNTP_SERVER *nserv)
3994 + if (!nserv->newsrc_fp)
3997 + dprint (1, (debugfile, "Unlocking %s\n", nserv->newsrc_file));
3998 + mx_unlock_file (nserv->newsrc_file, fileno (nserv->newsrc_fp), 0);
3999 + safe_fclose (&nserv->newsrc_fp);
4002 +/* Parse .newsrc file:
4006 +int nntp_newsrc_parse (NNTP_SERVER *nserv)
4012 + /* if file doesn't exist, create it */
4013 + nserv->newsrc_fp = safe_fopen (nserv->newsrc_file, "a");
4014 + safe_fclose (&nserv->newsrc_fp);
4016 + /* open .newsrc */
4017 + nserv->newsrc_fp = safe_fopen (nserv->newsrc_file, "r");
4018 + if (!nserv->newsrc_fp)
4020 + mutt_perror (nserv->newsrc_file);
4026 + dprint (1, (debugfile, "Locking %s\n", nserv->newsrc_file));
4027 + if (mx_lock_file (nserv->newsrc_file, fileno (nserv->newsrc_fp), 0, 0, 1))
4029 + safe_fclose (&nserv->newsrc_fp);
4033 + if (stat (nserv->newsrc_file, &sb))
4035 + mutt_perror (nserv->newsrc_file);
4036 + nntp_newsrc_close (nserv);
4041 + if (nserv->size == sb.st_size && nserv->mtime == sb.st_mtime)
4044 + nserv->size = sb.st_size;
4045 + nserv->mtime = sb.st_mtime;
4046 + nserv->newsrc_modified = 1;
4047 + dprint (1, (debugfile, "Parsing %s\n", nserv->newsrc_file));
4049 + /* .newsrc has been externally modified or hasn't been loaded yet */
4050 + for (i = 0; i < nserv->groups_num; i++)
4052 + NNTP_DATA *nntp_data = nserv->groups_list[i];
4057 + nntp_data->subscribed = 0;
4058 + nntp_data->newsrc_len = 0;
4059 + FREE (&nntp_data->newsrc_ent);
4062 + line = safe_malloc (sb.st_size + 1);
4063 + while (sb.st_size && fgets (line, sb.st_size + 1, nserv->newsrc_fp))
4066 + unsigned int subs = 0, i = 1;
4067 + NNTP_DATA *nntp_data;
4069 + /* find end of newsgroup name */
4070 + p = strpbrk (line, ":!");
4074 + /* ":" - subscribed, "!" - unsubscribed */
4079 + /* get newsgroup data */
4080 + nntp_data = nntp_data_find (nserv, line);
4081 + FREE (&nntp_data->newsrc_ent);
4083 + /* count number of entries */
4088 + nntp_data->newsrc_ent = safe_calloc (i, sizeof (NEWSRC_ENTRY));
4089 + nntp_data->subscribed = subs;
4091 + /* parse entries */
4097 + /* find end of entry */
4098 + p = strchr (p, ',');
4102 + /* first-last or single number */
4103 + h = strchr (b, '-');
4109 + if (sscanf (b, ANUM, &nntp_data->newsrc_ent[i].first) == 1 &&
4110 + sscanf (h, ANUM, &nntp_data->newsrc_ent[i].last) == 1)
4115 + nntp_data->newsrc_ent[i].first = 1;
4116 + nntp_data->newsrc_ent[i].last = 0;
4119 + if (nntp_data->lastMessage == 0)
4120 + nntp_data->lastMessage = nntp_data->newsrc_ent[i - 1].last;
4121 + nntp_data->newsrc_len = i;
4122 + safe_realloc (&nntp_data->newsrc_ent, i * sizeof (NEWSRC_ENTRY));
4123 + nntp_group_unread_stat (nntp_data);
4124 + dprint (2, (debugfile, "nntp_newsrc_parse: %s\n", nntp_data->group));
4130 +/* Generate array of .newsrc entries */
4131 +void nntp_newsrc_gen_entries (CONTEXT *ctx)
4133 + NNTP_DATA *nntp_data = ctx->data;
4134 + anum_t last = 0, first = 1;
4136 + int save_sort = SORT_ORDER;
4137 + unsigned int entries;
4139 + if (Sort != SORT_ORDER)
4142 + Sort = SORT_ORDER;
4143 + mutt_sort_headers (ctx, 0);
4146 + entries = nntp_data->newsrc_len;
4150 + nntp_data->newsrc_ent = safe_calloc (entries, sizeof (NEWSRC_ENTRY));
4153 + /* Set up to fake initial sequence from 1 to the article before the
4154 + * first article in our list */
4155 + nntp_data->newsrc_len = 0;
4157 + for (i = 0; i < ctx->msgcount; i++)
4159 + /* search for first unread */
4162 + /* We don't actually check sequential order, since we mark
4163 + * "missing" entries as read/deleted */
4164 + last = NHDR (ctx->hdrs[i])->article_num;
4165 + if (last >= nntp_data->firstMessage && !ctx->hdrs[i]->deleted &&
4166 + !ctx->hdrs[i]->read)
4168 + if (nntp_data->newsrc_len >= entries)
4171 + safe_realloc (&nntp_data->newsrc_ent, entries * sizeof (NEWSRC_ENTRY));
4173 + nntp_data->newsrc_ent[nntp_data->newsrc_len].first = first;
4174 + nntp_data->newsrc_ent[nntp_data->newsrc_len].last = last - 1;
4175 + nntp_data->newsrc_len++;
4180 + /* search for first read */
4183 + if (ctx->hdrs[i]->deleted || ctx->hdrs[i]->read)
4188 + last = NHDR (ctx->hdrs[i])->article_num;
4192 + if (series && first <= nntp_data->lastLoaded)
4194 + if (nntp_data->newsrc_len >= entries)
4197 + safe_realloc (&nntp_data->newsrc_ent, entries * sizeof (NEWSRC_ENTRY));
4199 + nntp_data->newsrc_ent[nntp_data->newsrc_len].first = first;
4200 + nntp_data->newsrc_ent[nntp_data->newsrc_len].last = nntp_data->lastLoaded;
4201 + nntp_data->newsrc_len++;
4203 + safe_realloc (&nntp_data->newsrc_ent,
4204 + nntp_data->newsrc_len * sizeof (NEWSRC_ENTRY));
4206 + if (save_sort != Sort)
4209 + mutt_sort_headers (ctx, 0);
4213 +/* Update file with new contents */
4214 +static int update_file (char *filename, char *buf)
4217 + char tmpfile[_POSIX_PATH_MAX];
4222 + snprintf (tmpfile, sizeof (tmpfile), "%s.tmp", filename);
4223 + fp = fopen (tmpfile, "w");
4226 + mutt_perror (tmpfile);
4230 + if (fputs (buf, fp) == EOF)
4232 + mutt_perror (tmpfile);
4235 + if (fclose (fp) == EOF)
4237 + mutt_perror (tmpfile);
4242 + if (rename (tmpfile, filename) < 0)
4244 + mutt_perror (filename);
4260 +/* Update .newsrc file */
4261 +int nntp_newsrc_update (NNTP_SERVER *nserv)
4264 + size_t buflen, off;
4271 + buflen = 10 * LONG_STRING;
4272 + buf = safe_calloc (1, buflen);
4275 + /* we will generate full newsrc here */
4276 + for (i = 0; i < nserv->groups_num; i++)
4278 + NNTP_DATA *nntp_data = nserv->groups_list[i];
4281 + if (!nntp_data || !nntp_data->newsrc_ent)
4284 + /* write newsgroup name */
4285 + if (off + strlen (nntp_data->group) + 3 > buflen)
4288 + safe_realloc (&buf, buflen);
4290 + snprintf (buf + off, buflen - off, "%s%c ", nntp_data->group,
4291 + nntp_data->subscribed ? ':' : '!');
4292 + off += strlen (buf + off);
4294 + /* write entries */
4295 + for (n = 0; n < nntp_data->newsrc_len; n++)
4297 + if (off + LONG_STRING > buflen)
4300 + safe_realloc (&buf, buflen);
4304 + if (nntp_data->newsrc_ent[n].first == nntp_data->newsrc_ent[n].last)
4305 + snprintf (buf + off, buflen - off, "%d", nntp_data->newsrc_ent[n].first);
4306 + else if (nntp_data->newsrc_ent[n].first < nntp_data->newsrc_ent[n].last)
4307 + snprintf (buf + off, buflen - off, "%d-%d",
4308 + nntp_data->newsrc_ent[n].first, nntp_data->newsrc_ent[n].last);
4309 + off += strlen (buf + off);
4311 + buf[off++] = '\n';
4315 + /* newrc being fully rewritten */
4316 + dprint (1, (debugfile, "Updating %s\n", nserv->newsrc_file));
4317 + if (nserv->newsrc_file && update_file (nserv->newsrc_file, buf) == 0)
4321 + rc = stat (nserv->newsrc_file, &sb);
4324 + nserv->size = sb.st_size;
4325 + nserv->mtime = sb.st_mtime;
4329 + mutt_perror (nserv->newsrc_file);
4337 +/* Make fully qualified cache file name */
4338 +static void cache_expand (char *dst, size_t dstlen, ACCOUNT *acct, char *src)
4341 + char file[_POSIX_PATH_MAX];
4343 + /* server subdirectory */
4348 + mutt_account_tourl (acct, &url);
4350 + url_ciss_tostring (&url, file, sizeof (file), U_PATH);
4353 + strfcpy (file, src ? src : "", sizeof (file));
4355 + snprintf (dst, dstlen, "%s/%s", NewsCacheDir, file);
4357 + /* remove trailing slash */
4358 + c = dst + strlen (dst) - 1;
4361 + mutt_expand_path (dst, dstlen);
4364 +/* Make fully qualified url from newsgroup name */
4365 +void nntp_buffer_expand_path (BUFFER *line, ACCOUNT *acct)
4369 + url.path = safe_strdup (mutt_b2s (line));
4370 + mutt_account_tourl (acct, &url);
4371 + url_ciss_tobuffer (&url, line, 0);
4375 +/* Parse newsgroup */
4376 +int nntp_add_group (char *line, void *data)
4378 + NNTP_SERVER *nserv = data;
4379 + NNTP_DATA *nntp_data;
4380 + char group[LONG_STRING];
4381 + char desc[HUGE_STRING] = "";
4383 + anum_t first, last;
4385 + if (!nserv || !line)
4388 + if (sscanf (line, "%s " ANUM " " ANUM " %c %[^\n]", group,
4389 + &last, &first, &mod, desc) < 4)
4392 + nntp_data = nntp_data_find (nserv, group);
4393 + nntp_data->deleted = 0;
4394 + nntp_data->firstMessage = first;
4395 + nntp_data->lastMessage = last;
4396 + nntp_data->allowed = mod == 'y' || mod == 'm' ? 1 : 0;
4397 + mutt_str_replace (&nntp_data->desc, desc);
4398 + if (nntp_data->newsrc_ent || nntp_data->lastCached)
4399 + nntp_group_unread_stat (nntp_data);
4400 + else if (nntp_data->lastMessage &&
4401 + nntp_data->firstMessage <= nntp_data->lastMessage)
4402 + nntp_data->unread = nntp_data->lastMessage - nntp_data->firstMessage + 1;
4404 + nntp_data->unread = 0;
4408 +/* Load list of all newsgroups from cache */
4409 +static int active_get_cache (NNTP_SERVER *nserv)
4411 + char buf[HUGE_STRING];
4412 + char file[_POSIX_PATH_MAX];
4416 + cache_expand (file, sizeof (file), &nserv->conn->account, ".active");
4417 + dprint (1, (debugfile, "Parsing %s\n", file));
4418 + fp = safe_fopen (file, "r");
4422 + if (fgets (buf, sizeof (buf), fp) == NULL ||
4423 + sscanf (buf, "%ld%s", &t, file) != 1 || t == 0)
4428 + nserv->newgroups_time = t;
4430 + mutt_message _("Loading list of groups from cache...");
4431 + while (fgets (buf, sizeof (buf), fp))
4432 + nntp_add_group (buf, nserv);
4433 + nntp_add_group (NULL, NULL);
4435 + mutt_clear_error ();
4439 +/* Save list of all newsgroups to cache */
4440 +int nntp_active_save_cache (NNTP_SERVER *nserv)
4442 + char file[_POSIX_PATH_MAX];
4444 + size_t buflen, off;
4448 + if (!nserv->cacheable)
4451 + buflen = 10 * LONG_STRING;
4452 + buf = safe_calloc (1, buflen);
4453 + snprintf (buf, buflen, "%lu\n", (unsigned long)nserv->newgroups_time);
4454 + off = strlen (buf);
4456 + for (i = 0; i < nserv->groups_num; i++)
4458 + NNTP_DATA *nntp_data = nserv->groups_list[i];
4460 + if (!nntp_data || nntp_data->deleted)
4463 + if (off + strlen (nntp_data->group) +
4464 + (nntp_data->desc ? strlen (nntp_data->desc) : 0) + 50 > buflen)
4467 + safe_realloc (&buf, buflen);
4469 + snprintf (buf + off, buflen - off, "%s %d %d %c%s%s\n", nntp_data->group,
4470 + nntp_data->lastMessage, nntp_data->firstMessage,
4471 + nntp_data->allowed ? 'y' : 'n', nntp_data->desc ? " " : "",
4472 + nntp_data->desc ? nntp_data->desc : "");
4473 + off += strlen (buf + off);
4476 + cache_expand (file, sizeof (file), &nserv->conn->account, ".active");
4477 + dprint (1, (debugfile, "Updating %s\n", file));
4478 + rc = update_file (file, buf);
4484 +/* Used by mutt_hcache_open() to compose hcache file name */
4485 +static int nntp_hcache_namer (const char *path, char *dest, size_t destlen)
4487 + return snprintf (dest, destlen, "%s.hcache", path);
4490 +/* Open newsgroup hcache */
4491 +header_cache_t *nntp_hcache_open (NNTP_DATA *nntp_data)
4494 + char file[_POSIX_PATH_MAX];
4496 + if (!nntp_data->nserv || !nntp_data->nserv->cacheable ||
4497 + !nntp_data->nserv->conn || !nntp_data->group ||
4498 + !(nntp_data->newsrc_ent || nntp_data->subscribed ||
4499 + option (OPTSAVEUNSUB)))
4502 + mutt_account_tourl (&nntp_data->nserv->conn->account, &url);
4503 + url.path = nntp_data->group;
4504 + url_ciss_tostring (&url, file, sizeof (file), U_PATH);
4505 + return mutt_hcache_open (NewsCacheDir, file, nntp_hcache_namer);
4508 +/* Remove stale cached headers */
4509 +void nntp_hcache_update (NNTP_DATA *nntp_data, header_cache_t *hc)
4514 + anum_t first, last, current;
4519 + /* fetch previous values of first and last */
4520 + hdata = mutt_hcache_fetch_raw (hc, "index", strlen);
4523 + dprint (2, (debugfile,
4524 + "nntp_hcache_update: mutt_hcache_fetch index: %s\n", hdata));
4525 + if (sscanf (hdata, ANUM " " ANUM, &first, &last) == 2)
4528 + nntp_data->lastCached = last;
4530 + /* clean removed headers from cache */
4531 + for (current = first; current <= last; current++)
4533 + if (current >= nntp_data->firstMessage &&
4534 + current <= nntp_data->lastMessage)
4537 + snprintf (buf, sizeof (buf), "%d", current);
4538 + dprint (2, (debugfile,
4539 + "nntp_hcache_update: mutt_hcache_delete %s\n", buf));
4540 + mutt_hcache_delete (hc, buf, strlen);
4543 + mutt_hcache_free (&hdata);
4546 + /* store current values of first and last */
4547 + if (!old || nntp_data->firstMessage != first ||
4548 + nntp_data->lastMessage != last)
4550 + snprintf (buf, sizeof (buf), "%u %u", nntp_data->firstMessage,
4551 + nntp_data->lastMessage);
4552 + dprint (2, (debugfile,
4553 + "nntp_hcache_update: mutt_hcache_store index: %s\n", buf));
4554 + mutt_hcache_store_raw (hc, "index", buf, strlen (buf) + 1, strlen);
4559 +/* Remove bcache file */
4560 +static int nntp_bcache_delete (const char *id, body_cache_t *bcache, void *data)
4562 + NNTP_DATA *nntp_data = data;
4566 + if (!nntp_data || sscanf (id, ANUM "%c", &anum, &c) != 1 ||
4567 + anum < nntp_data->firstMessage || anum > nntp_data->lastMessage)
4570 + dprint (2, (debugfile, "nntp_bcache_delete: mutt_bcache_del %s\n", id));
4571 + mutt_bcache_del (bcache, id);
4576 +/* Remove stale cached messages */
4577 +void nntp_bcache_update (NNTP_DATA *nntp_data)
4579 + mutt_bcache_list (nntp_data->bcache, nntp_bcache_delete, nntp_data);
4582 +/* Remove hcache and bcache of newsgroup */
4583 +void nntp_delete_group_cache (NNTP_DATA *nntp_data)
4585 + char file[_POSIX_PATH_MAX];
4587 + if (!nntp_data || !nntp_data->nserv || !nntp_data->nserv->cacheable)
4591 + nntp_hcache_namer (nntp_data->group, file, sizeof (file));
4592 + cache_expand (file, sizeof (file), &nntp_data->nserv->conn->account, file);
4594 + nntp_data->lastCached = 0;
4595 + dprint (2, (debugfile, "nntp_delete_group_cache: %s\n", file));
4598 + if (!nntp_data->bcache)
4599 + nntp_data->bcache = mutt_bcache_open (&nntp_data->nserv->conn->account,
4600 + nntp_data->group);
4601 + if (nntp_data->bcache)
4603 + dprint (2, (debugfile, "nntp_delete_group_cache: %s/*\n", nntp_data->group));
4604 + mutt_bcache_list (nntp_data->bcache, nntp_bcache_delete, NULL);
4605 + mutt_bcache_close (&nntp_data->bcache);
4609 +/* Remove hcache and bcache of all unexistent and unsubscribed newsgroups */
4610 +void nntp_clear_cache (NNTP_SERVER *nserv)
4612 + char file[_POSIX_PATH_MAX];
4614 + struct dirent *entry;
4617 + if (!nserv || !nserv->cacheable)
4620 + cache_expand (file, sizeof (file), &nserv->conn->account, NULL);
4621 + dp = opendir (file);
4624 + safe_strncat (file, sizeof (file), "/", 1);
4625 + fp = file + strlen (file);
4626 + while ((entry = readdir (dp)))
4628 + char *group = entry->d_name;
4630 + NNTP_DATA *nntp_data;
4631 + NNTP_DATA nntp_tmp;
4633 + if (mutt_strcmp (group, ".") == 0 ||
4634 + mutt_strcmp (group, "..") == 0)
4637 + safe_strncat (file, sizeof (file), group, strlen (group));
4638 + if (stat (file, &sb))
4642 + if (S_ISREG (sb.st_mode))
4644 + char *ext = group + strlen (group) - 7;
4645 + if (strlen (group) < 8 || mutt_strcmp (ext, ".hcache"))
4651 + if (!S_ISDIR (sb.st_mode))
4654 + nntp_data = hash_find (nserv->groups_hash, group);
4657 + nntp_data = &nntp_tmp;
4658 + nntp_data->nserv = nserv;
4659 + nntp_data->group = group;
4660 + nntp_data->bcache = NULL;
4662 + else if (nntp_data->newsrc_ent || nntp_data->subscribed ||
4663 + option (OPTSAVEUNSUB))
4666 + nntp_delete_group_cache (nntp_data);
4667 + if (S_ISDIR (sb.st_mode))
4670 + dprint (2, (debugfile, "nntp_clear_cache: %s\n", file));
4678 +/* %a = account url
4680 + * %P = port if specified
4681 + * %s = news server name
4683 + * %u = username */
4685 +nntp_format_str (char *dest, size_t destlen, size_t col, int cols, char op,
4686 + const char *src, const char *fmt, const char *ifstring,
4687 + const char *elsestring, unsigned long data, format_flag flags)
4689 + NNTP_SERVER *nserv = (NNTP_SERVER *)data;
4690 + ACCOUNT *acct = &nserv->conn->account;
4692 + char fn[SHORT_STRING], tmp[SHORT_STRING], *p;
4697 + mutt_account_tourl (acct, &url);
4698 + url_ciss_tostring (&url, fn, sizeof (fn), U_PATH);
4699 + p = strchr (fn, '/');
4702 + snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
4703 + snprintf (dest, destlen, tmp, fn);
4706 + snprintf (tmp, sizeof (tmp), "%%%su", fmt);
4707 + snprintf (dest, destlen, tmp, acct->port);
4711 + if (acct->flags & MUTT_ACCT_PORT)
4713 + snprintf (tmp, sizeof (tmp), "%%%su", fmt);
4714 + snprintf (dest, destlen, tmp, acct->port);
4718 + strncpy (fn, acct->host, sizeof (fn) - 1);
4719 + mutt_strlower (fn);
4720 + snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
4721 + snprintf (dest, destlen, tmp, fn);
4724 + mutt_account_tourl (acct, &url);
4725 + url_ciss_tostring (&url, fn, sizeof (fn), U_PATH);
4726 + p = strchr (fn, ':');
4729 + snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
4730 + snprintf (dest, destlen, tmp, fn);
4733 + snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
4734 + snprintf (dest, destlen, tmp, acct->user);
4740 +/* Automatically loads a newsrc into memory, if necessary.
4741 + * Checks the size/mtime of a newsrc file, if it doesn't match, load
4742 + * again. Hmm, if a system has broken mtimes, this might mean the file
4743 + * is reloaded every time, which we'd have to fix. */
4744 +NNTP_SERVER *nntp_select_server (char *server, int leave_lock)
4746 + char file[_POSIX_PATH_MAX];
4751 + NNTP_SERVER *nserv;
4752 + NNTP_DATA *nntp_data;
4756 + if (!server || !*server)
4758 + mutt_error _("No news server defined!");
4763 + /* create account from news server url */
4765 + acct.port = NNTP_PORT;
4766 + acct.type = MUTT_ACCT_TYPE_NNTP;
4767 + snprintf (file, sizeof (file), "%s%s",
4768 + strstr (server, "://") ? "" : "news://", server);
4769 + if (url_parse_ciss (&url, file) < 0 ||
4770 + (url.path && *url.path) ||
4771 + !(url.scheme == U_NNTP || url.scheme == U_NNTPS) ||
4772 + mutt_account_fromurl (&acct, &url) < 0)
4774 + mutt_error (_("%s is an invalid news server specification!"), server);
4778 + if (url.scheme == U_NNTPS)
4780 + acct.flags |= MUTT_ACCT_SSL;
4781 + acct.port = NNTP_SSL_PORT;
4784 + /* find connection by account */
4785 + conn = mutt_conn_find (NULL, &acct);
4788 + if (!(conn->account.flags & MUTT_ACCT_USER) && acct.flags & MUTT_ACCT_USER)
4790 + conn->account.flags |= MUTT_ACCT_USER;
4791 + conn->account.user[0] = '\0';
4794 + /* news server already exists */
4795 + nserv = conn->data;
4798 + if (nserv->status == NNTP_BYE)
4799 + nserv->status = NNTP_NONE;
4800 + if (nntp_open_connection (nserv) < 0)
4803 + rc = nntp_newsrc_parse (nserv);
4807 + /* check for new newsgroups */
4808 + if (!leave_lock && nntp_check_new_groups (nserv) < 0)
4811 + /* .newsrc has been externally modified */
4813 + nntp_clear_cache (nserv);
4814 + if (rc < 0 || !leave_lock)
4815 + nntp_newsrc_close (nserv);
4816 + return rc < 0 ? NULL : nserv;
4819 + /* new news server */
4820 + nserv = safe_calloc (1, sizeof (NNTP_SERVER));
4821 + nserv->conn = conn;
4822 + nserv->groups_hash = hash_create (1009, 0);
4823 + nserv->groups_max = 16;
4824 + nserv->groups_list = safe_malloc (nserv->groups_max * sizeof (nntp_data));
4826 + rc = nntp_open_connection (nserv);
4828 + /* try to create cache directory and enable caching */
4829 + nserv->cacheable = 0;
4830 + if (rc >= 0 && NewsCacheDir && *NewsCacheDir)
4832 + cache_expand (file, sizeof (file), &conn->account, NULL);
4833 + p = *file == '/' ? file + 1 : file;
4836 + p = strchr (p, '/');
4839 + if ((stat (file, &sb) || (sb.st_mode & S_IFDIR) == 0) &&
4840 + mkdir (file, 0700))
4842 + mutt_error (_("Can't create %s: %s."), file, strerror (errno));
4848 + nserv->cacheable = 1;
4855 + /* load .newsrc */
4858 + mutt_FormatString (file, sizeof (file), 0, sizeof (file), NONULL (NewsRc),
4859 + nntp_format_str, (unsigned long)nserv, 0);
4860 + mutt_expand_path (file, sizeof (file));
4861 + nserv->newsrc_file = safe_strdup (file);
4862 + rc = nntp_newsrc_parse (nserv);
4866 + /* try to load list of newsgroups from cache */
4867 + if (nserv->cacheable && active_get_cache (nserv) == 0)
4868 + rc = nntp_check_new_groups (nserv);
4870 + /* load list of newsgroups from server */
4872 + rc = nntp_active_fetch (nserv, 0);
4876 + nntp_clear_cache (nserv);
4879 + /* check cache files */
4880 + if (rc >= 0 && nserv->cacheable)
4882 + struct dirent *entry;
4883 + DIR *dp = opendir (file);
4887 + while ((entry = readdir (dp)))
4889 + header_cache_t *hc;
4891 + char *group = entry->d_name;
4893 + p = group + strlen (group) - 7;
4894 + if (strlen (group) < 8 || strcmp (p, ".hcache"))
4897 + nntp_data = hash_find (nserv->groups_hash, group);
4901 + hc = nntp_hcache_open (nntp_data);
4905 + /* fetch previous values of first and last */
4906 + hdata = mutt_hcache_fetch_raw (hc, "index", strlen);
4909 + anum_t first, last;
4911 + if (sscanf (hdata, ANUM " " ANUM, &first, &last) == 2)
4913 + if (nntp_data->deleted)
4915 + nntp_data->firstMessage = first;
4916 + nntp_data->lastMessage = last;
4918 + if (last >= nntp_data->firstMessage &&
4919 + last <= nntp_data->lastMessage)
4921 + nntp_data->lastCached = last;
4922 + dprint (2, (debugfile, "nntp_select_server: %s lastCached=%u\n",
4923 + nntp_data->group, last));
4926 + mutt_hcache_free (&hdata);
4928 + mutt_hcache_close (hc);
4935 + if (rc < 0 || !leave_lock)
4936 + nntp_newsrc_close (nserv);
4940 + hash_destroy (&nserv->groups_hash, nntp_data_free);
4941 + FREE (&nserv->groups_list);
4942 + FREE (&nserv->newsrc_file);
4943 + FREE (&nserv->authenticators);
4945 + mutt_socket_close (conn);
4946 + mutt_socket_free (conn);
4950 + conn->data = nserv;
4954 +/* Full status flags are not supported by nntp, but we can fake some of them:
4955 + * Read = a read message number is in the .newsrc
4956 + * New = not read and not cached
4957 + * Old = not read but cached */
4958 +void nntp_article_status (CONTEXT *ctx, HEADER *hdr, char *group, anum_t anum)
4960 + NNTP_DATA *nntp_data = ctx->data;
4964 + nntp_data = hash_find (nntp_data->nserv->groups_hash, group);
4969 + for (i = 0; i < nntp_data->newsrc_len; i++)
4971 + if ((anum >= nntp_data->newsrc_ent[i].first) &&
4972 + (anum <= nntp_data->newsrc_ent[i].last))
4974 + /* can't use mutt_set_flag() because mx_update_context()
4975 + didn't called yet */
4981 + /* article was not cached yet, it's new */
4982 + if (anum > nntp_data->lastCached)
4985 + /* article isn't read but cached, it's old */
4986 + if (option (OPTMARKOLD))
4990 +/* calculate number of unread articles using .newsrc data */
4991 +void nntp_group_unread_stat (NNTP_DATA *nntp_data)
4994 + anum_t first, last;
4996 + nntp_data->unread = 0;
4997 + if (nntp_data->lastMessage == 0 ||
4998 + nntp_data->firstMessage > nntp_data->lastMessage)
5001 + nntp_data->unread = nntp_data->lastMessage - nntp_data->firstMessage + 1;
5002 + for (i = 0; i < nntp_data->newsrc_len; i++)
5004 + first = nntp_data->newsrc_ent[i].first;
5005 + if (first < nntp_data->firstMessage)
5006 + first = nntp_data->firstMessage;
5007 + last = nntp_data->newsrc_ent[i].last;
5008 + if (last > nntp_data->lastMessage)
5009 + last = nntp_data->lastMessage;
5010 + if (first <= last)
5011 + nntp_data->unread -= last - first + 1;
5015 +/* Subscribe newsgroup */
5016 +NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER *nserv, char *group)
5018 + NNTP_DATA *nntp_data;
5020 + if (!nserv || !nserv->groups_hash || !group || !*group)
5023 + nntp_data = nntp_data_find (nserv, group);
5024 + nntp_data->subscribed = 1;
5025 + if (!nntp_data->newsrc_ent)
5027 + nntp_data->newsrc_ent = safe_calloc (1, sizeof (NEWSRC_ENTRY));
5028 + nntp_data->newsrc_len = 1;
5029 + nntp_data->newsrc_ent[0].first = 1;
5030 + nntp_data->newsrc_ent[0].last = 0;
5035 +/* Unsubscribe newsgroup */
5036 +NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER *nserv, char *group)
5038 + NNTP_DATA *nntp_data;
5040 + if (!nserv || !nserv->groups_hash || !group || !*group)
5043 + nntp_data = hash_find (nserv->groups_hash, group);
5047 + nntp_data->subscribed = 0;
5048 + if (!option (OPTSAVEUNSUB))
5050 + nntp_data->newsrc_len = 0;
5051 + FREE (&nntp_data->newsrc_ent);
5056 +/* Catchup newsgroup */
5057 +NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER *nserv, char *group)
5059 + NNTP_DATA *nntp_data;
5061 + if (!nserv || !nserv->groups_hash || !group || !*group)
5064 + nntp_data = hash_find (nserv->groups_hash, group);
5068 + if (nntp_data->newsrc_ent)
5070 + safe_realloc (&nntp_data->newsrc_ent, sizeof (NEWSRC_ENTRY));
5071 + nntp_data->newsrc_len = 1;
5072 + nntp_data->newsrc_ent[0].first = 1;
5073 + nntp_data->newsrc_ent[0].last = nntp_data->lastMessage;
5075 + nntp_data->unread = 0;
5076 + if (Context && Context->data == nntp_data)
5080 + for (i = 0; i < Context->msgcount; i++)
5081 + mutt_set_flag (Context, Context->hdrs[i], MUTT_READ, 1);
5086 +/* Uncatchup newsgroup */
5087 +NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER *nserv, char *group)
5089 + NNTP_DATA *nntp_data;
5091 + if (!nserv || !nserv->groups_hash || !group || !*group)
5094 + nntp_data = hash_find (nserv->groups_hash, group);
5098 + if (nntp_data->newsrc_ent)
5100 + safe_realloc (&nntp_data->newsrc_ent, sizeof (NEWSRC_ENTRY));
5101 + nntp_data->newsrc_len = 1;
5102 + nntp_data->newsrc_ent[0].first = 1;
5103 + nntp_data->newsrc_ent[0].last = nntp_data->firstMessage - 1;
5105 + if (Context && Context->data == nntp_data)
5109 + nntp_data->unread = Context->msgcount;
5110 + for (i = 0; i < Context->msgcount; i++)
5111 + mutt_set_flag (Context, Context->hdrs[i], MUTT_READ, 0);
5114 + nntp_data->unread = nntp_data->lastMessage - nntp_data->newsrc_ent[0].last;
5118 +/* Get first newsgroup with new messages */
5119 +void nntp_buffer_buffy (BUFFER *s)
5123 + for (i = 0; i < CurrentNewsSrv->groups_num; i++)
5125 + NNTP_DATA *nntp_data = CurrentNewsSrv->groups_list[i];
5127 + if (!nntp_data || !nntp_data->subscribed || !nntp_data->unread)
5130 + if (Context && Context->magic == MUTT_NNTP &&
5131 + !mutt_strcmp (nntp_data->group, ((NNTP_DATA *)Context->data)->group))
5133 + unsigned int i, unread = 0;
5135 + for (i = 0; i < Context->msgcount; i++)
5136 + if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)
5141 + mutt_buffer_strcpy (s, nntp_data->group);
5144 + mutt_buffer_clear (s);
5146 diff -udprP mutt-1.12.1.orig/nntp.c mutt-1.12.1/nntp.c
5147 --- mutt-1.12.1.orig/nntp.c 1970-01-01 03:00:00.000000000 +0300
5148 +++ mutt-1.12.1/nntp.c 2019-08-11 20:31:26.142940552 +0300
5151 + * Copyright (C) 1998 Brandon Long <blong@fiction.net>
5152 + * Copyright (C) 1999 Andrej Gritsenko <andrej@lucky.net>
5153 + * Copyright (C) 2000-2017 Vsevolod Volkov <vvv@mutt.org.ua>
5155 + * This program is free software; you can redistribute it and/or modify
5156 + * it under the terms of the GNU General Public License as published by
5157 + * the Free Software Foundation; either version 2 of the License, or
5158 + * (at your option) any later version.
5160 + * This program is distributed in the hope that it will be useful,
5161 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5162 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5163 + * GNU General Public License for more details.
5165 + * You should have received a copy of the GNU General Public License
5166 + * along with this program; if not, write to the Free Software
5167 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5171 +#include "config.h"
5175 +#include "mutt_curses.h"
5179 +#include "rfc1524.h"
5180 +#include "rfc2047.h"
5181 +#include "mailbox.h"
5182 +#include "mutt_crypt.h"
5185 +#if defined(USE_SSL)
5186 +#include "mutt_ssl.h"
5198 +#include "hcache.h"
5201 +#include <unistd.h>
5202 +#include <string.h>
5204 +#include <stdlib.h>
5207 +#include <sasl/sasl.h>
5208 +#include <sasl/saslutil.h>
5210 +#include "mutt_sasl.h"
5213 +static int nntp_connect_error (NNTP_SERVER *nserv)
5215 + nserv->status = NNTP_NONE;
5216 + mutt_error _("Server closed connection!");
5221 +/* Get capabilities:
5222 + * -1 - error, connection is closed
5223 + * 0 - mode is reader, capabilities setted up
5224 + * 1 - need to switch to reader mode */
5225 +static int nntp_capabilities (NNTP_SERVER *nserv)
5227 + CONNECTION *conn = nserv->conn;
5228 + unsigned int mode_reader = 0;
5229 + char buf[LONG_STRING];
5230 + char authinfo[LONG_STRING] = "";
5232 + nserv->hasCAPABILITIES = 0;
5233 + nserv->hasSTARTTLS = 0;
5234 + nserv->hasDATE = 0;
5235 + nserv->hasLIST_NEWSGROUPS = 0;
5236 + nserv->hasLISTGROUP = 0;
5237 + nserv->hasLISTGROUPrange = 0;
5238 + nserv->hasOVER = 0;
5239 + FREE (&nserv->authenticators);
5241 + if (mutt_socket_write (conn, "CAPABILITIES\r\n") < 0 ||
5242 + mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5243 + return nntp_connect_error (nserv);
5245 + /* no capabilities */
5246 + if (mutt_strncmp ("101", buf, 3))
5248 + nserv->hasCAPABILITIES = 1;
5250 + /* parse capabilities */
5253 + if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5254 + return nntp_connect_error (nserv);
5255 + if (!mutt_strcmp ("STARTTLS", buf))
5256 + nserv->hasSTARTTLS = 1;
5257 + else if (!mutt_strcmp ("MODE-READER", buf))
5259 + else if (!mutt_strcmp ("READER", buf))
5261 + nserv->hasDATE = 1;
5262 + nserv->hasLISTGROUP = 1;
5263 + nserv->hasLISTGROUPrange = 1;
5265 + else if (!mutt_strncmp ("AUTHINFO ", buf, 9))
5267 + safe_strcat (buf, sizeof (buf), " ");
5268 + strfcpy (authinfo, buf + 8, sizeof (authinfo));
5271 + else if (!mutt_strncmp ("SASL ", buf, 5))
5273 + char *p = buf + 5;
5276 + nserv->authenticators = safe_strdup (p);
5279 + else if (!mutt_strcmp ("OVER", buf))
5280 + nserv->hasOVER = 1;
5281 + else if (!mutt_strncmp ("LIST ", buf, 5))
5283 + char *p = strstr (buf, " NEWSGROUPS");
5287 + if (*p == '\0' || *p == ' ')
5288 + nserv->hasLIST_NEWSGROUPS = 1;
5291 + } while (mutt_strcmp (".", buf));
5294 + if (nserv->authenticators && strcasestr (authinfo, " SASL "))
5295 + strfcpy (buf, nserv->authenticators, sizeof (buf));
5297 + if (strcasestr (authinfo, " USER "))
5300 + safe_strcat (buf, sizeof (buf), " ");
5301 + safe_strcat (buf, sizeof (buf), "USER");
5303 + mutt_str_replace (&nserv->authenticators, buf);
5305 + /* current mode is reader */
5306 + if (nserv->hasDATE)
5309 + /* server is mode-switching, need to switch to reader mode */
5313 + mutt_socket_close (conn);
5314 + nserv->status = NNTP_BYE;
5315 + mutt_error _("Server doesn't support reader mode.");
5320 +char *OverviewFmt =
5326 + "Content-Length:\0"
5330 +/* Detect supported commands */
5331 +static int nntp_attempt_features (NNTP_SERVER *nserv)
5333 + CONNECTION *conn = nserv->conn;
5334 + char buf[LONG_STRING];
5336 + /* no CAPABILITIES, trying DATE, LISTGROUP, LIST NEWSGROUPS */
5337 + if (!nserv->hasCAPABILITIES)
5339 + if (mutt_socket_write (conn, "DATE\r\n") < 0 ||
5340 + mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5341 + return nntp_connect_error (nserv);
5342 + if (mutt_strncmp ("500", buf, 3))
5343 + nserv->hasDATE = 1;
5345 + if (mutt_socket_write (conn, "LISTGROUP\r\n") < 0 ||
5346 + mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5347 + return nntp_connect_error (nserv);
5348 + if (mutt_strncmp ("500", buf, 3))
5349 + nserv->hasLISTGROUP = 1;
5351 + if (mutt_socket_write (conn, "LIST NEWSGROUPS +\r\n") < 0 ||
5352 + mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5353 + return nntp_connect_error (nserv);
5354 + if (mutt_strncmp ("500", buf, 3))
5355 + nserv->hasLIST_NEWSGROUPS = 1;
5356 + if (!mutt_strncmp ("215", buf, 3))
5360 + if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5361 + return nntp_connect_error (nserv);
5362 + } while (mutt_strcmp (".", buf));
5366 + /* no LIST NEWSGROUPS, trying XGTITLE */
5367 + if (!nserv->hasLIST_NEWSGROUPS)
5369 + if (mutt_socket_write (conn, "XGTITLE\r\n") < 0 ||
5370 + mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5371 + return nntp_connect_error (nserv);
5372 + if (mutt_strncmp ("500", buf, 3))
5373 + nserv->hasXGTITLE = 1;
5376 + /* no OVER, trying XOVER */
5377 + if (!nserv->hasOVER)
5379 + if (mutt_socket_write (conn, "XOVER\r\n") < 0 ||
5380 + mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5381 + return nntp_connect_error (nserv);
5382 + if (mutt_strncmp ("500", buf, 3))
5383 + nserv->hasXOVER = 1;
5386 + /* trying LIST OVERVIEW.FMT */
5387 + if (nserv->hasOVER || nserv->hasXOVER)
5389 + if (mutt_socket_write (conn, "LIST OVERVIEW.FMT\r\n") < 0 ||
5390 + mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5391 + return nntp_connect_error (nserv);
5392 + if (mutt_strncmp ("215", buf, 3))
5393 + nserv->overview_fmt = OverviewFmt;
5396 + int chunk, cont = 0;
5397 + size_t buflen = 2 * LONG_STRING, off = 0, b = 0;
5399 + if (nserv->overview_fmt)
5400 + FREE (&nserv->overview_fmt);
5401 + nserv->overview_fmt = safe_malloc (buflen);
5405 + if (buflen - off < LONG_STRING)
5408 + safe_realloc (&nserv->overview_fmt, buflen);
5411 + chunk = mutt_socket_readln (nserv->overview_fmt + off,
5412 + buflen - off, conn);
5415 + FREE (&nserv->overview_fmt);
5416 + return nntp_connect_error (nserv);
5419 + if (!cont && !mutt_strcmp (".", nserv->overview_fmt + off))
5422 + cont = chunk >= buflen - off ? 1 : 0;
5423 + off += strlen (nserv->overview_fmt + off);
5428 + if (nserv->overview_fmt[b] == ':')
5430 + memmove (nserv->overview_fmt + b,
5431 + nserv->overview_fmt + b + 1, off - b - 1);
5432 + nserv->overview_fmt[off - 1] = ':';
5434 + colon = strchr (nserv->overview_fmt + b, ':');
5436 + nserv->overview_fmt[off++] = ':';
5437 + else if (strcmp (colon + 1, "full"))
5438 + off = colon + 1 - nserv->overview_fmt;
5439 + if (!strcasecmp (nserv->overview_fmt + b, "Bytes:"))
5441 + strcpy (nserv->overview_fmt + b, "Content-Length:");
5442 + off = b + strlen (nserv->overview_fmt + b);
5444 + nserv->overview_fmt[off++] = '\0';
5448 + nserv->overview_fmt[off++] = '\0';
5449 + safe_realloc (&nserv->overview_fmt, off);
5455 +/* Get login, password and authenticate */
5456 +static int nntp_auth (NNTP_SERVER *nserv)
5458 + CONNECTION *conn = nserv->conn;
5459 + char buf[LONG_STRING];
5460 + char authenticators[LONG_STRING] = "USER";
5461 + char *method, *a, *p;
5462 + unsigned char flags = conn->account.flags;
5466 + /* get login and password */
5467 + if (mutt_account_getuser (&conn->account) || !conn->account.user[0] ||
5468 + mutt_account_getpass (&conn->account) || !conn->account.pass[0])
5471 + /* get list of authenticators */
5472 + if (NntpAuthenticators && *NntpAuthenticators)
5473 + strfcpy (authenticators, NntpAuthenticators, sizeof (authenticators));
5474 + else if (nserv->hasCAPABILITIES)
5476 + strfcpy (authenticators, NONULL (nserv->authenticators),
5477 + sizeof (authenticators));
5478 + p = authenticators;
5486 + p = authenticators;
5489 + *p = ascii_toupper (*p);
5493 + dprint (1, (debugfile,
5494 + "nntp_auth: available methods: %s\n", nserv->authenticators));
5495 + a = authenticators;
5500 + mutt_error _("No authenticators available");
5506 + a = strchr (a, ':');
5510 + /* check authenticator */
5511 + if (nserv->hasCAPABILITIES)
5515 + if (!nserv->authenticators)
5517 + m = strcasestr (nserv->authenticators, method);
5520 + if (m > nserv->authenticators && *(m - 1) != ' ')
5522 + m += strlen (method);
5523 + if (*m != '\0' && *m != ' ')
5526 + dprint (1, (debugfile, "nntp_auth: trying method %s\n", method));
5528 + /* AUTHINFO USER authentication */
5529 + if (!strcmp (method, "USER"))
5531 + mutt_message (_("Authenticating (%s)..."), method);
5532 + snprintf (buf, sizeof (buf), "AUTHINFO USER %s\r\n", conn->account.user);
5533 + if (mutt_socket_write (conn, buf) < 0 ||
5534 + mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5537 + /* authenticated, password is not required */
5538 + if (!mutt_strncmp ("281", buf, 3))
5541 + /* username accepted, sending password */
5542 + if (!mutt_strncmp ("381", buf, 3))
5545 + if (debuglevel < MUTT_SOCK_LOG_FULL)
5546 + dprint (MUTT_SOCK_LOG_CMD, (debugfile,
5547 + "%d> AUTHINFO PASS *\n", conn->fd));
5549 + snprintf (buf, sizeof (buf), "AUTHINFO PASS %s\r\n",
5550 + conn->account.pass);
5551 + if (mutt_socket_write_d (conn, buf, -1, MUTT_SOCK_LOG_FULL) < 0 ||
5552 + mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5555 + /* authenticated */
5556 + if (!mutt_strncmp ("281", buf, 3))
5560 + /* server doesn't support AUTHINFO USER, trying next method */
5568 + sasl_conn_t *saslconn;
5569 + sasl_interact_t *interaction = NULL;
5571 + char inbuf[LONG_STRING] = "";
5573 + const char *client_out = NULL;
5574 + unsigned int client_len, len;
5576 + if (mutt_sasl_client_new (conn, &saslconn) < 0)
5578 + dprint (1, (debugfile,
5579 + "nntp_auth: error allocating SASL connection.\n"));
5585 + rc = sasl_client_start (saslconn, method, &interaction,
5586 + &client_out, &client_len, &mech);
5587 + if (rc != SASL_INTERACT)
5589 + mutt_sasl_interact (interaction);
5591 + if (rc != SASL_OK && rc != SASL_CONTINUE)
5593 + sasl_dispose (&saslconn);
5594 + dprint (1, (debugfile,
5595 + "nntp_auth: error starting SASL authentication exchange.\n"));
5599 + mutt_message (_("Authenticating (%s)..."), method);
5600 + snprintf (buf, sizeof (buf), "AUTHINFO SASL %s", method);
5602 + /* looping protocol */
5603 + while (rc == SASL_CONTINUE || (rc == SASL_OK && client_len))
5605 + /* send out client response */
5609 + if (debuglevel >= MUTT_SOCK_LOG_FULL)
5611 + char tmp[LONG_STRING];
5612 + memcpy (tmp, client_out, client_len);
5613 + for (p = tmp; p < tmp + client_len; p++)
5619 + dprint (1, (debugfile, "SASL> %s\n", tmp));
5624 + safe_strcat (buf, sizeof (buf), " ");
5625 + len = strlen (buf);
5626 + if (sasl_encode64 (client_out, client_len,
5627 + buf + len, sizeof (buf) - len, &len) != SASL_OK)
5629 + dprint (1, (debugfile,
5630 + "nntp_auth: error base64-encoding client response.\n"));
5635 + safe_strcat (buf, sizeof (buf), "\r\n");
5637 + if (debuglevel < MUTT_SOCK_LOG_FULL)
5639 + if (strchr (buf, ' '))
5640 + dprint (MUTT_SOCK_LOG_CMD, (debugfile, "%d> AUTHINFO SASL %s%s\n",
5641 + conn->fd, method, client_len ? " sasl_data" : ""));
5643 + dprint (MUTT_SOCK_LOG_CMD, (debugfile, "%d> sasl_data\n", conn->fd));
5647 + if (mutt_socket_write_d (conn, buf, -1, MUTT_SOCK_LOG_FULL) < 0 ||
5648 + mutt_socket_readln_d (inbuf, sizeof (inbuf), conn, MUTT_SOCK_LOG_FULL) < 0)
5650 + if (mutt_strncmp (inbuf, "283 ", 4) &&
5651 + mutt_strncmp (inbuf, "383 ", 4))
5654 + if (debuglevel < MUTT_SOCK_LOG_FULL)
5655 + dprint (MUTT_SOCK_LOG_CMD, (debugfile, "%d< %s\n", conn->fd, inbuf));
5660 + if (debuglevel < MUTT_SOCK_LOG_FULL)
5663 + dprint (MUTT_SOCK_LOG_CMD, (debugfile,
5664 + "%d< %s sasl_data\n", conn->fd, inbuf));
5668 + if (!strcmp ("=", inbuf + 4))
5670 + else if (sasl_decode64 (inbuf + 4, strlen (inbuf + 4),
5671 + buf, sizeof (buf) - 1, &len) != SASL_OK)
5673 + dprint (1, (debugfile,
5674 + "nntp_auth: error base64-decoding server response.\n"));
5678 + else if (debuglevel >= MUTT_SOCK_LOG_FULL)
5680 + char tmp[LONG_STRING];
5681 + memcpy (tmp, buf, len);
5682 + for (p = tmp; p < tmp + len; p++)
5688 + dprint (1, (debugfile, "SASL< %s\n", tmp));
5694 + rc = sasl_client_step (saslconn, buf, len,
5695 + &interaction, &client_out, &client_len);
5696 + if (rc != SASL_INTERACT)
5698 + mutt_sasl_interact (interaction);
5700 + if (*inbuf != '3')
5704 + } /* looping protocol */
5706 + if (rc == SASL_OK && client_len == 0 && *inbuf == '2')
5708 + mutt_sasl_setup_conn (conn, saslconn);
5712 + /* terminate SASL sessoin */
5713 + sasl_dispose (&saslconn);
5716 + if (!mutt_strncmp (inbuf, "383 ", 4))
5718 + if (mutt_socket_write (conn, "*\r\n") < 0 ||
5719 + mutt_socket_readln (inbuf, sizeof (inbuf), conn) < 0)
5723 + /* server doesn't support AUTHINFO SASL, trying next method */
5724 + if (*inbuf == '5')
5728 +#endif /* USE_SASL */
5731 + mutt_error (_("%s authentication failed."), method);
5739 + nserv->status = NNTP_BYE;
5740 + conn->account.flags = flags;
5743 + mutt_error _("Server closed connection!");
5747 + mutt_socket_close (conn);
5751 +/* Connect to server, authenticate and get capabilities */
5752 +int nntp_open_connection (NNTP_SERVER *nserv)
5754 + CONNECTION *conn = nserv->conn;
5757 + unsigned int posting = 0, auth = 1;
5759 + if (nserv->status == NNTP_OK)
5761 + if (nserv->status == NNTP_BYE)
5763 + nserv->status = NNTP_NONE;
5765 + if (mutt_socket_open (conn) < 0)
5768 + if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5769 + return nntp_connect_error (nserv);
5771 + if (!mutt_strncmp ("200", buf, 3))
5773 + else if (mutt_strncmp ("201", buf, 3))
5775 + mutt_socket_close (conn);
5776 + mutt_remove_trailing_ws (buf);
5777 + mutt_error ("%s", buf);
5782 + /* get initial capabilities */
5783 + cap = nntp_capabilities (nserv);
5787 + /* tell news server to switch to mode reader if it isn't so */
5790 + if (mutt_socket_write (conn, "MODE READER\r\n") < 0 ||
5791 + mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5792 + return nntp_connect_error (nserv);
5794 + if (!mutt_strncmp ("200", buf, 3))
5796 + else if (!mutt_strncmp ("201", buf, 3))
5798 + /* error if has capabilities, ignore result if no capabilities */
5799 + else if (nserv->hasCAPABILITIES)
5801 + mutt_socket_close (conn);
5802 + mutt_error _("Could not switch to reader mode.");
5807 + /* recheck capabilities after MODE READER */
5808 + if (nserv->hasCAPABILITIES)
5810 + cap = nntp_capabilities (nserv);
5816 + mutt_message (_("Connected to %s. %s"), conn->account.host,
5817 + posting ? _("Posting is ok.") : _("Posting is NOT ok."));
5820 +#if defined(USE_SSL)
5821 + /* Attempt STARTTLS if available and desired. */
5822 + if (nserv->use_tls != 1 && (nserv->hasSTARTTLS || option (OPTSSLFORCETLS)))
5824 + if (nserv->use_tls == 0)
5825 + nserv->use_tls = option (OPTSSLFORCETLS) ||
5826 + query_quadoption (OPT_SSLSTARTTLS,
5827 + _("Secure connection with TLS?")) == MUTT_YES ? 2 : 1;
5828 + if (nserv->use_tls == 2)
5830 + if (mutt_socket_write (conn, "STARTTLS\r\n") < 0 ||
5831 + mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5832 + return nntp_connect_error (nserv);
5833 + if (mutt_strncmp ("382", buf, 3))
5835 + nserv->use_tls = 0;
5836 + mutt_error ("STARTTLS: %s", buf);
5839 + else if (mutt_ssl_starttls (conn))
5841 + nserv->use_tls = 0;
5842 + nserv->status = NNTP_NONE;
5843 + mutt_socket_close (nserv->conn);
5844 + mutt_error _("Could not negotiate TLS connection");
5850 + /* recheck capabilities after STARTTLS */
5851 + cap = nntp_capabilities (nserv);
5859 + /* authentication required? */
5860 + if (conn->account.flags & MUTT_ACCT_USER)
5862 + if (!conn->account.user[0])
5867 + if (mutt_socket_write (conn, "STAT\r\n") < 0 ||
5868 + mutt_socket_readln (buf, sizeof (buf), conn) < 0)
5869 + return nntp_connect_error (nserv);
5870 + if (mutt_strncmp ("480", buf, 3))
5874 + /* authenticate */
5875 + if (auth && nntp_auth (nserv) < 0)
5878 + /* get final capabilities after authentication */
5879 + if (nserv->hasCAPABILITIES && (auth || cap > 0))
5881 + cap = nntp_capabilities (nserv);
5886 + mutt_socket_close (conn);
5887 + mutt_error _("Could not switch to reader mode.");
5893 + /* attempt features */
5894 + if (nntp_attempt_features (nserv) < 0)
5897 + nserv->status = NNTP_OK;
5901 +/* Send data from buffer and receive answer to same buffer */
5902 +static int nntp_query (NNTP_DATA *nntp_data, char *line, size_t linelen)
5904 + NNTP_SERVER *nserv = nntp_data->nserv;
5905 + char buf[LONG_STRING];
5907 + if (nserv->status == NNTP_BYE)
5912 + if (nserv->status == NNTP_OK)
5917 + rc = mutt_socket_write (nserv->conn, line);
5918 + else if (nntp_data->group)
5920 + snprintf (buf, sizeof (buf), "GROUP %s\r\n", nntp_data->group);
5921 + rc = mutt_socket_write (nserv->conn, buf);
5924 + rc = mutt_socket_readln (buf, sizeof (buf), nserv->conn);
5932 + nserv->status = NNTP_NONE;
5933 + if (nntp_open_connection (nserv) == 0)
5936 + snprintf (buf, sizeof (buf), _("Connection to %s lost. Reconnect?"),
5937 + nserv->conn->account.host);
5938 + if (mutt_yesorno (buf, MUTT_YES) != MUTT_YES)
5940 + nserv->status = NNTP_BYE;
5945 + /* select newsgroup after reconnection */
5946 + if (nntp_data->group)
5948 + snprintf (buf, sizeof (buf), "GROUP %s\r\n", nntp_data->group);
5949 + if (mutt_socket_write (nserv->conn, buf) < 0 ||
5950 + mutt_socket_readln (buf, sizeof (buf), nserv->conn) < 0)
5951 + return nntp_connect_error (nserv);
5957 + strfcpy (line, buf, linelen);
5961 +/* This function calls funct(*line, *data) for each received line,
5962 + * funct(NULL, *data) if rewind(*data) needs, exits when fail or done:
5964 + * 1 - bad response (answer in query buffer)
5965 + * -1 - conection lost
5966 + * -2 - error in funct(*line, *data) */
5967 +static int nntp_fetch_lines (NNTP_DATA *nntp_data, char *query, size_t qlen,
5968 + char *msg, int (*funct) (char *, void *), void *data)
5975 + char buf[LONG_STRING];
5977 + unsigned int lines = 0;
5979 + progress_t progress;
5982 + mutt_progress_init (&progress, msg, MUTT_PROGRESS_MSG, ReadInc, -1);
5984 + strfcpy (buf, query, sizeof (buf));
5985 + if (nntp_query (nntp_data, buf, sizeof (buf)) < 0)
5987 + if (buf[0] != '2')
5989 + strfcpy (query, buf, qlen);
5993 + line = safe_malloc (sizeof (buf));
5999 + int chunk = mutt_socket_readln_d (buf, sizeof (buf),
6000 + nntp_data->nserv->conn, MUTT_SOCK_LOG_HDR);
6003 + nntp_data->nserv->status = NNTP_NONE;
6008 + if (!off && buf[0] == '.')
6010 + if (buf[1] == '\0')
6015 + if (buf[1] == '.')
6019 + strfcpy (line + off, p, sizeof (buf));
6021 + if (chunk >= sizeof (buf))
6022 + off += strlen (p);
6026 + mutt_progress_update (&progress, ++lines, -1);
6028 + if (rc == 0 && funct (line, data) < 0)
6033 + safe_realloc (&line, off + sizeof (buf));
6036 + funct (NULL, data);
6041 +/* Parse newsgroup description */
6042 +static int fetch_description (char *line, void *data)
6044 + NNTP_SERVER *nserv = data;
6045 + NNTP_DATA *nntp_data;
6051 + desc = strpbrk (line, " \t");
6055 + desc += strspn (desc, " \t");
6058 + desc = strchr (line, '\0');
6060 + nntp_data = hash_find (nserv->groups_hash, line);
6061 + if (nntp_data && mutt_strcmp (desc, nntp_data->desc))
6063 + mutt_str_replace (&nntp_data->desc, desc);
6064 + dprint (2, (debugfile, "group: %s, desc: %s\n", line, desc));
6069 +/* Fetch newsgroups descriptions.
6070 + * Returns the same code as nntp_fetch_lines() */
6071 +static int get_description (NNTP_DATA *nntp_data, char *wildmat, char *msg)
6073 + NNTP_SERVER *nserv;
6078 + /* get newsgroup description, if possible */
6079 + nserv = nntp_data->nserv;
6081 + wildmat = nntp_data->group;
6082 + if (nserv->hasLIST_NEWSGROUPS)
6083 + cmd = "LIST NEWSGROUPS";
6084 + else if (nserv->hasXGTITLE)
6089 + snprintf (buf, sizeof (buf), "%s %s\r\n", cmd, wildmat);
6090 + rc = nntp_fetch_lines (nntp_data, buf, sizeof (buf), msg,
6091 + fetch_description, nserv);
6094 + mutt_error ("%s: %s", cmd, buf);
6100 +/* Update read flag and set article number if empty */
6101 +static void nntp_parse_xref (CONTEXT *ctx, HEADER *hdr)
6103 + NNTP_DATA *nntp_data = ctx->data;
6106 + buf = p = safe_strdup (hdr->env->xref);
6109 + char *grp, *colon;
6112 + /* skip to next word */
6113 + p += strspn (p, " \t");
6116 + /* skip to end of word */
6117 + p = strpbrk (p, " \t");
6122 + colon = strchr (grp, ':');
6126 + if (sscanf (colon, ANUM, &anum) != 1)
6129 + nntp_article_status (ctx, hdr, grp, anum);
6130 + if (hdr && !NHDR (hdr)->article_num && !mutt_strcmp (nntp_data->group, grp))
6131 + NHDR (hdr)->article_num = anum;
6136 +/* Write line to temporarily file */
6137 +static int fetch_tempfile (char *line, void *data)
6143 + else if (fputs (line, fp) == EOF || fputc ('\n', fp) == EOF)
6154 + unsigned char *messages;
6155 + progress_t progress;
6157 + header_cache_t *hc;
6161 +/* Parse article number */
6162 +static int fetch_numbers (char *line, void *data)
6164 + FETCH_CTX *fc = data;
6169 + if (sscanf (line, ANUM, &anum) != 1)
6171 + if (anum < fc->first || anum > fc->last)
6173 + fc->messages[anum - fc->first] = 1;
6177 +/* Parse overview line */
6178 +static int parse_overview_line (char *line, void *data)
6180 + FETCH_CTX *fc = data;
6181 + CONTEXT *ctx = fc->ctx;
6182 + NNTP_DATA *nntp_data = ctx->data;
6185 + char tempfile[_POSIX_PATH_MAX];
6186 + char *header, *field;
6193 + /* parse article number */
6194 + field = strchr (line, '\t');
6197 + if (sscanf (line, ANUM, &anum) != 1)
6199 + dprint (2, (debugfile, "parse_overview_line: " ANUM "\n", anum));
6201 + /* out of bounds */
6202 + if (anum < fc->first || anum > fc->last)
6205 + /* not in LISTGROUP */
6206 + if (!fc->messages[anum - fc->first])
6210 + mutt_progress_update (&fc->progress, anum - fc->first + 1, -1);
6214 + /* convert overview line to header */
6215 + mutt_mktemp (tempfile, sizeof (tempfile));
6216 + fp = safe_fopen (tempfile, "w+");
6220 + header = nntp_data->nserv->overview_fmt;
6227 + if (strstr (header, ":full") == NULL && fputs (header, fp) == EOF)
6230 + unlink (tempfile);
6233 + header = strchr (header, '\0') + 1;
6236 + field = strchr (field, '\t');
6239 + if (fputs (b, fp) == EOF || fputc ('\n', fp) == EOF)
6242 + unlink (tempfile);
6248 + /* allocate memory for headers */
6249 + if (ctx->msgcount >= ctx->hdrmax)
6250 + mx_alloc_memory (ctx);
6252 + /* parse header */
6253 + hdr = ctx->hdrs[ctx->msgcount] = mutt_new_header ();
6254 + hdr->env = mutt_read_rfc822_header (fp, hdr, 0, 0);
6255 + hdr->env->newsgroups = safe_strdup (nntp_data->group);
6256 + hdr->received = hdr->date_sent;
6258 + unlink (tempfile);
6266 + /* try to replace with header from cache */
6267 + snprintf (buf, sizeof (buf), "%d", anum);
6268 + hdata = mutt_hcache_fetch (fc->hc, buf, strlen);
6271 + dprint (2, (debugfile,
6272 + "parse_overview_line: mutt_hcache_fetch %s\n", buf));
6273 + mutt_free_header (&hdr);
6274 + ctx->hdrs[ctx->msgcount] =
6275 + hdr = mutt_hcache_restore (hdata, NULL);
6276 + mutt_hcache_free (&hdata);
6281 + /* skip header marked as deleted in cache */
6282 + if (hdr->deleted && !fc->restore)
6284 + if (nntp_data->bcache)
6286 + dprint (2, (debugfile,
6287 + "parse_overview_line: mutt_bcache_del %s\n", buf));
6288 + mutt_bcache_del (nntp_data->bcache, buf);
6294 + /* not chached yet, store header */
6297 + dprint (2, (debugfile,
6298 + "parse_overview_line: mutt_hcache_store %s\n", buf));
6299 + mutt_hcache_store (fc->hc, buf, hdr, 0, strlen, MUTT_GENERATE_UIDVALIDITY);
6306 + hdr->index = ctx->msgcount++;
6310 + hdr->data = safe_calloc (1, sizeof (NNTP_HEADER_DATA));
6311 + NHDR (hdr)->article_num = anum;
6316 + nntp_article_status (ctx, hdr, NULL, anum);
6318 + nntp_parse_xref (ctx, hdr);
6320 + if (anum > nntp_data->lastLoaded)
6321 + nntp_data->lastLoaded = anum;
6324 + mutt_free_header (&hdr);
6328 + mutt_progress_update (&fc->progress, anum - fc->first + 1, -1);
6332 +/* Fetch headers */
6333 +static int nntp_fetch_headers (CONTEXT *ctx, void *hc,
6334 + anum_t first, anum_t last, int restore)
6336 + NNTP_DATA *nntp_data = ctx->data;
6339 + char buf[HUGE_STRING];
6341 + int oldmsgcount = ctx->msgcount;
6343 + anum_t first_over = first;
6348 + /* if empty group or nothing to do */
6349 + if (!last || first > last)
6352 + /* init fetch context */
6356 + fc.restore = restore;
6357 + fc.messages = safe_calloc (last - first + 1, sizeof (unsigned char));
6362 + /* fetch list of articles */
6363 + if (option (OPTLISTGROUP) && nntp_data->nserv->hasLISTGROUP &&
6364 + !nntp_data->deleted)
6367 + mutt_message _("Fetching list of articles...");
6368 + if (nntp_data->nserv->hasLISTGROUPrange)
6369 + snprintf (buf, sizeof (buf), "LISTGROUP %s %d-%d\r\n", nntp_data->group,
6372 + snprintf (buf, sizeof (buf), "LISTGROUP %s\r\n", nntp_data->group);
6373 + rc = nntp_fetch_lines (nntp_data, buf, sizeof (buf), NULL,
6374 + fetch_numbers, &fc);
6377 + mutt_error ("LISTGROUP: %s", buf);
6382 + for (current = first; current <= last && rc == 0; current++)
6384 + if (fc.messages[current - first])
6387 + snprintf (buf, sizeof (buf), "%d", current);
6388 + if (nntp_data->bcache)
6390 + dprint (2, (debugfile,
6391 + "nntp_fetch_headers: mutt_bcache_del %s\n", buf));
6392 + mutt_bcache_del (nntp_data->bcache, buf);
6398 + dprint (2, (debugfile,
6399 + "nntp_fetch_headers: mutt_hcache_delete %s\n", buf));
6400 + mutt_hcache_delete (fc.hc, buf, strlen);
6407 + for (current = first; current <= last; current++)
6408 + fc.messages[current - first] = 1;
6410 + /* fetching header from cache or server, or fallback to fetch overview */
6412 + mutt_progress_init (&fc.progress, _("Fetching message headers..."),
6413 + MUTT_PROGRESS_MSG, ReadInc, last - first + 1);
6414 + for (current = first; current <= last && rc == 0; current++)
6417 + mutt_progress_update (&fc.progress, current - first + 1, -1);
6420 + snprintf (buf, sizeof (buf), "%d", current);
6423 + /* delete header from cache that does not exist on server */
6424 + if (!fc.messages[current - first])
6427 + /* allocate memory for headers */
6428 + if (ctx->msgcount >= ctx->hdrmax)
6429 + mx_alloc_memory (ctx);
6432 + /* try to fetch header from cache */
6433 + hdata = mutt_hcache_fetch (fc.hc, buf, strlen);
6436 + dprint (2, (debugfile,
6437 + "nntp_fetch_headers: mutt_hcache_fetch %s\n", buf));
6438 + ctx->hdrs[ctx->msgcount] =
6439 + hdr = mutt_hcache_restore (hdata, NULL);
6440 + mutt_hcache_free (&hdata);
6443 + /* skip header marked as deleted in cache */
6444 + if (hdr->deleted && !restore)
6446 + mutt_free_header (&hdr);
6447 + if (nntp_data->bcache)
6449 + dprint (2, (debugfile,
6450 + "nntp_fetch_headers: mutt_bcache_del %s\n", buf));
6451 + mutt_bcache_del (nntp_data->bcache, buf);
6462 + /* don't try to fetch header from removed newsgroup */
6463 + if (nntp_data->deleted)
6466 + /* fallback to fetch overview */
6467 + else if (nntp_data->nserv->hasOVER || nntp_data->nserv->hasXOVER)
6468 + if (option (OPTLISTGROUP) && nntp_data->nserv->hasLISTGROUP)
6473 + /* fetch header from server */
6477 + char tempfile[_POSIX_PATH_MAX];
6479 + mutt_mktemp (tempfile, sizeof (tempfile));
6480 + fp = safe_fopen (tempfile, "w+");
6483 + mutt_perror (tempfile);
6485 + unlink (tempfile);
6490 + snprintf (buf, sizeof (buf), "HEAD %d\r\n", current);
6491 + rc = nntp_fetch_lines (nntp_data, buf, sizeof (buf), NULL,
6492 + fetch_tempfile, fp);
6496 + unlink (tempfile);
6500 + /* invalid response */
6501 + if (mutt_strncmp ("423", buf, 3))
6503 + mutt_error ("HEAD: %s", buf);
6508 + /* no such article */
6509 + if (nntp_data->bcache)
6511 + snprintf (buf, sizeof (buf), "%d", current);
6512 + dprint (2, (debugfile,
6513 + "nntp_fetch_headers: mutt_bcache_del %s\n", buf));
6514 + mutt_bcache_del (nntp_data->bcache, buf);
6520 + /* parse header */
6521 + hdr = ctx->hdrs[ctx->msgcount] = mutt_new_header ();
6522 + hdr->env = mutt_read_rfc822_header (fp, hdr, 0, 0);
6523 + hdr->received = hdr->date_sent;
6525 + unlink (tempfile);
6528 + /* save header in context */
6529 + hdr->index = ctx->msgcount++;
6533 + hdr->data = safe_calloc (1, sizeof (NNTP_HEADER_DATA));
6534 + NHDR (hdr)->article_num = current;
6539 + nntp_article_status (ctx, hdr, NULL, NHDR (hdr)->article_num);
6541 + nntp_parse_xref (ctx, hdr);
6543 + if (current > nntp_data->lastLoaded)
6544 + nntp_data->lastLoaded = current;
6545 + first_over = current + 1;
6548 + if (!option (OPTLISTGROUP) || !nntp_data->nserv->hasLISTGROUP)
6549 + current = first_over;
6551 + /* fetch overview information */
6552 + if (current <= last && rc == 0 && !nntp_data->deleted) {
6553 + char *cmd = nntp_data->nserv->hasOVER ? "OVER" : "XOVER";
6554 + snprintf (buf, sizeof (buf), "%s %d-%d\r\n", cmd, current, last);
6555 + rc = nntp_fetch_lines (nntp_data, buf, sizeof (buf), NULL,
6556 + parse_overview_line, &fc);
6559 + mutt_error ("%s: %s", cmd, buf);
6564 + if (ctx->msgcount > oldmsgcount)
6565 + mx_update_context (ctx, ctx->msgcount - oldmsgcount);
6567 + FREE (&fc.messages);
6570 + mutt_clear_error ();
6574 +/* Open newsgroup */
6575 +static int nntp_open_mailbox (CONTEXT *ctx)
6577 + NNTP_SERVER *nserv;
6578 + NNTP_DATA *nntp_data;
6579 + char buf[HUGE_STRING];
6580 + char server[LONG_STRING];
6584 + anum_t first, last, count = 0;
6587 + strfcpy (buf, ctx->path, sizeof (buf));
6588 + if (url_parse_ciss (&url, buf) < 0 || !url.path ||
6589 + !(url.scheme == U_NNTP || url.scheme == U_NNTPS))
6591 + mutt_error (_("%s is an invalid newsgroup specification!"), ctx->path);
6597 + url.path = strchr (url.path, '\0');
6598 + url_ciss_tostring (&url, server, sizeof (server), 0);
6599 + nserv = nntp_select_server (server, 1);
6602 + CurrentNewsSrv = nserv;
6604 + /* find news group data structure */
6605 + nntp_data = hash_find (nserv->groups_hash, group);
6608 + nntp_newsrc_close (nserv);
6609 + mutt_error (_("Newsgroup %s not found on the server."), group);
6614 + mutt_bit_unset (ctx->rights, MUTT_ACL_INSERT);
6615 + if (!nntp_data->newsrc_ent && !nntp_data->subscribed &&
6616 + !option (OPTSAVEUNSUB))
6617 + ctx->readonly = 1;
6619 + /* select newsgroup */
6620 + mutt_message (_("Selecting %s..."), group);
6622 + if (nntp_query (nntp_data, buf, sizeof (buf)) < 0)
6624 + nntp_newsrc_close (nserv);
6628 + /* newsgroup not found, remove it */
6629 + if (!mutt_strncmp ("411", buf, 3))
6631 + mutt_error (_("Newsgroup %s has been removed from the server."),
6632 + nntp_data->group);
6633 + if (!nntp_data->deleted)
6635 + nntp_data->deleted = 1;
6636 + nntp_active_save_cache (nserv);
6638 + if (nntp_data->newsrc_ent && !nntp_data->subscribed &&
6639 + !option (OPTSAVEUNSUB))
6641 + FREE (&nntp_data->newsrc_ent);
6642 + nntp_data->newsrc_len = 0;
6643 + nntp_delete_group_cache (nntp_data);
6644 + nntp_newsrc_update (nserv);
6649 + /* parse newsgroup info */
6651 + if (sscanf (buf, "211 " ANUM " " ANUM " " ANUM, &count, &first, &last) != 3)
6653 + nntp_newsrc_close (nserv);
6654 + mutt_error ("GROUP: %s", buf);
6658 + nntp_data->firstMessage = first;
6659 + nntp_data->lastMessage = last;
6660 + nntp_data->deleted = 0;
6662 + /* get description if empty */
6663 + if (option (OPTLOADDESC) && !nntp_data->desc)
6665 + if (get_description (nntp_data, NULL, NULL) < 0)
6667 + nntp_newsrc_close (nserv);
6670 + if (nntp_data->desc)
6671 + nntp_active_save_cache (nserv);
6675 + time (&nserv->check_time);
6676 + ctx->data = nntp_data;
6677 + if (!nntp_data->bcache && (nntp_data->newsrc_ent ||
6678 + nntp_data->subscribed || option (OPTSAVEUNSUB)))
6679 + nntp_data->bcache = mutt_bcache_open (&nserv->conn->account,
6680 + nntp_data->group);
6682 + /* strip off extra articles if adding context is greater than $nntp_context */
6683 + first = nntp_data->firstMessage;
6684 + if (NntpContext && nntp_data->lastMessage - first + 1 > NntpContext)
6685 + first = nntp_data->lastMessage - NntpContext + 1;
6686 + nntp_data->lastLoaded = first ? first - 1 : 0;
6687 + count = nntp_data->firstMessage;
6688 + nntp_data->firstMessage = first;
6689 + nntp_bcache_update (nntp_data);
6690 + nntp_data->firstMessage = count;
6692 + hc = nntp_hcache_open (nntp_data);
6693 + nntp_hcache_update (nntp_data, hc);
6697 + mutt_bit_unset (ctx->rights, MUTT_ACL_WRITE);
6698 + mutt_bit_unset (ctx->rights, MUTT_ACL_DELETE);
6700 + nntp_newsrc_close (nserv);
6701 + rc = nntp_fetch_headers (ctx, hc, first, nntp_data->lastMessage, 0);
6703 + mutt_hcache_close (hc);
6707 + nntp_data->lastLoaded = nntp_data->lastMessage;
6708 + nserv->newsrc_modified = 0;
6712 +/* Fetch message */
6713 +static int nntp_open_message (CONTEXT *ctx, MESSAGE *msg, int msgno)
6715 + NNTP_DATA *nntp_data = ctx->data;
6716 + NNTP_ACACHE *acache;
6717 + HEADER *hdr = ctx->hdrs[msgno];
6718 + char buf[_POSIX_PATH_MAX];
6720 + char *fetch_msg = _("Fetching message...");
6723 + /* try to get article from cache */
6724 + acache = &nntp_data->acache[hdr->index % NNTP_ACACHE_LEN];
6727 + if (acache->index == hdr->index)
6729 + msg->fp = fopen (acache->path, "r");
6733 + /* clear previous entry */
6736 + unlink (acache->path);
6737 + FREE (&acache->path);
6740 + snprintf (article, sizeof (article), "%d", NHDR (hdr)->article_num);
6741 + msg->fp = mutt_bcache_get (nntp_data->bcache, article);
6744 + if (NHDR (hdr)->parsed)
6749 + /* don't try to fetch article from removed newsgroup */
6750 + if (nntp_data->deleted)
6753 + /* create new cache file */
6754 + mutt_message (fetch_msg);
6755 + msg->fp = mutt_bcache_put (nntp_data->bcache, article, 1);
6758 + mutt_mktemp (buf, sizeof (buf));
6759 + acache->path = safe_strdup (buf);
6760 + acache->index = hdr->index;
6761 + msg->fp = safe_fopen (acache->path, "w+");
6764 + mutt_perror (acache->path);
6765 + unlink (acache->path);
6766 + FREE (&acache->path);
6771 + /* fetch message to cache file */
6772 + snprintf (buf, sizeof (buf), "ARTICLE %s\r\n",
6773 + NHDR (hdr)->article_num ? article : hdr->env->message_id);
6774 + rc = nntp_fetch_lines (nntp_data, buf, sizeof (buf), fetch_msg,
6775 + fetch_tempfile, msg->fp);
6778 + safe_fclose (&msg->fp);
6781 + unlink (acache->path);
6782 + FREE (&acache->path);
6786 + if (!mutt_strncmp (NHDR (hdr)->article_num ? "423" : "430", buf, 3))
6787 + mutt_error (_("Article %d not found on the server."),
6788 + NHDR (hdr)->article_num ? article : hdr->env->message_id);
6790 + mutt_error ("ARTICLE: %s", buf);
6795 + if (!acache->path)
6796 + mutt_bcache_commit (nntp_data->bcache, article);
6799 + /* replace envelope with new one
6800 + * hash elements must be updated because pointers will be changed */
6801 + if (ctx->id_hash && hdr->env->message_id)
6802 + hash_delete (ctx->id_hash, hdr->env->message_id, hdr, NULL);
6803 + if (ctx->subj_hash && hdr->env->real_subj)
6804 + hash_delete (ctx->subj_hash, hdr->env->real_subj, hdr, NULL);
6806 + mutt_free_envelope (&hdr->env);
6807 + hdr->env = mutt_read_rfc822_header (msg->fp, hdr, 0, 0);
6809 + if (ctx->id_hash && hdr->env->message_id)
6810 + hash_insert (ctx->id_hash, hdr->env->message_id, hdr);
6811 + if (ctx->subj_hash && hdr->env->real_subj)
6812 + hash_insert (ctx->subj_hash, hdr->env->real_subj, hdr);
6814 + /* fix content length */
6815 + fseek (msg->fp, 0, SEEK_END);
6816 + hdr->content->length = ftell (msg->fp) - hdr->content->offset;
6818 + /* this is called in mutt before the open which fetches the message,
6819 + * which is probably wrong, but we just call it again here to handle
6820 + * the problem instead of fixing it */
6821 + NHDR (hdr)->parsed = 1;
6822 + mutt_parse_mime_message (ctx, hdr);
6824 + /* these would normally be updated in mx_update_context(), but the
6825 + * full headers aren't parsed with overview, so the information wasn't
6826 + * available then */
6828 + hdr->security = crypt_query (hdr->content);
6831 + mutt_clear_error();
6835 +/* Close message */
6836 +static int nntp_close_message (CONTEXT *ctx, MESSAGE *msg)
6838 + return safe_fclose (&msg->fp);
6842 +int nntp_post (const char *msg) {
6843 + NNTP_DATA *nntp_data, nntp_tmp;
6845 + char buf[LONG_STRING];
6848 + if (Context && Context->magic == MUTT_NNTP)
6849 + nntp_data = Context->data;
6852 + CurrentNewsSrv = nntp_select_server (NewsServer, 0);
6853 + if (!CurrentNewsSrv)
6856 + nntp_data = &nntp_tmp;
6857 + nntp_data->nserv = CurrentNewsSrv;
6858 + nntp_data->group = NULL;
6861 + fp = safe_fopen (msg, "r");
6864 + mutt_perror (msg);
6868 + strfcpy (buf, "POST\r\n", sizeof (buf));
6869 + if (nntp_query (nntp_data, buf, sizeof (buf)) < 0)
6871 + if (buf[0] != '3')
6873 + mutt_error (_("Can't post article: %s"), buf);
6879 + while (fgets (buf + 1, sizeof (buf) - 2, fp))
6881 + len = strlen (buf);
6882 + if (buf[len - 1] == '\n')
6884 + buf[len - 1] = '\r';
6889 + if (mutt_socket_write_d (nntp_data->nserv->conn,
6890 + buf[1] == '.' ? buf : buf + 1, -1, MUTT_SOCK_LOG_HDR) < 0)
6891 + return nntp_connect_error (nntp_data->nserv);
6895 + if ((buf[strlen (buf) - 1] != '\n' &&
6896 + mutt_socket_write_d (nntp_data->nserv->conn, "\r\n", -1, MUTT_SOCK_LOG_HDR) < 0) ||
6897 + mutt_socket_write_d (nntp_data->nserv->conn, ".\r\n", -1, MUTT_SOCK_LOG_HDR) < 0 ||
6898 + mutt_socket_readln (buf, sizeof (buf), nntp_data->nserv->conn) < 0)
6899 + return nntp_connect_error (nntp_data->nserv);
6900 + if (buf[0] != '2')
6902 + mutt_error (_("Can't post article: %s"), buf);
6908 +/* Free up memory associated with the newsgroup context */
6909 +static int nntp_close_mailbox (CONTEXT *ctx)
6911 + NNTP_DATA *nntp_data = ctx->data, *nntp_tmp;
6916 + nntp_data->unread = ctx->unread;
6918 + nntp_acache_free (nntp_data);
6919 + if (!nntp_data->nserv || !nntp_data->nserv->groups_hash || !nntp_data->group)
6922 + nntp_tmp = hash_find (nntp_data->nserv->groups_hash, nntp_data->group);
6923 + if (nntp_tmp == NULL || nntp_tmp != nntp_data)
6924 + nntp_data_free (nntp_data);
6928 +/* Get date and time from server */
6929 +int nntp_date (NNTP_SERVER *nserv, time_t *now)
6931 + if (nserv->hasDATE)
6933 + NNTP_DATA nntp_data;
6934 + char buf[LONG_STRING];
6937 + nntp_data.nserv = nserv;
6938 + nntp_data.group = NULL;
6939 + strfcpy (buf, "DATE\r\n", sizeof (buf));
6940 + if (nntp_query (&nntp_data, buf, sizeof (buf)) < 0)
6943 + if (sscanf (buf, "111 %4d%2d%2d%2d%2d%2d%*s", &tm.tm_year, &tm.tm_mon,
6944 + &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec) == 6)
6946 + tm.tm_year -= 1900;
6948 + *now = timegm (&tm);
6951 + dprint (1, (debugfile, "nntp_date: server time is %d\n", *now));
6960 +/* Fetch list of all newsgroups from server */
6961 +int nntp_active_fetch (NNTP_SERVER *nserv, unsigned int new)
6963 + NNTP_DATA nntp_data;
6964 + char msg[SHORT_STRING];
6965 + char buf[LONG_STRING];
6969 + snprintf (msg, sizeof (msg), _("Loading list of groups from server %s..."),
6970 + nserv->conn->account.host);
6971 + mutt_message (msg);
6972 + if (nntp_date (nserv, &nserv->newgroups_time) < 0)
6975 + nntp_data.nserv = nserv;
6976 + nntp_data.group = NULL;
6977 + i = nserv->groups_num;
6978 + strfcpy (buf, "LIST\r\n", sizeof (buf));
6979 + rc = nntp_fetch_lines (&nntp_data, buf, sizeof (buf), msg,
6980 + nntp_add_group, nserv);
6985 + mutt_error ("LIST: %s", buf);
6993 + for (; i < nserv->groups_num; i++)
6995 + NNTP_DATA *nntp_data = nserv->groups_list[i];
6996 + nntp_data->new = 1;
7000 + for (i = 0; i < nserv->groups_num; i++)
7002 + NNTP_DATA *nntp_data = nserv->groups_list[i];
7004 + if (nntp_data && nntp_data->deleted && !nntp_data->newsrc_ent)
7006 + nntp_delete_group_cache (nntp_data);
7007 + hash_delete (nserv->groups_hash, nntp_data->group, NULL, nntp_data_free);
7008 + nserv->groups_list[i] = NULL;
7012 + if (option (OPTLOADDESC))
7013 + rc = get_description (&nntp_data, "*", _("Loading descriptions..."));
7015 + nntp_active_save_cache (nserv);
7018 + mutt_clear_error ();
7022 +/* Check newsgroup for new articles:
7023 + * 1 - new articles found
7025 + * -1 - lost connection */
7026 +static int nntp_group_poll (NNTP_DATA *nntp_data, int update_stat)
7028 + char buf[LONG_STRING] = "";
7029 + anum_t count, first, last;
7031 + /* use GROUP command to poll newsgroup */
7032 + if (nntp_query (nntp_data, buf, sizeof (buf)) < 0)
7034 + if (sscanf (buf, "211 " ANUM " " ANUM " " ANUM, &count, &first, &last) != 3)
7036 + if (first == nntp_data->firstMessage && last == nntp_data->lastMessage)
7039 + /* articles have been renumbered */
7040 + if (last < nntp_data->lastMessage)
7042 + nntp_data->lastCached = 0;
7043 + if (nntp_data->newsrc_len)
7045 + safe_realloc (&nntp_data->newsrc_ent, sizeof (NEWSRC_ENTRY));
7046 + nntp_data->newsrc_len = 1;
7047 + nntp_data->newsrc_ent[0].first = 1;
7048 + nntp_data->newsrc_ent[0].last = 0;
7051 + nntp_data->firstMessage = first;
7052 + nntp_data->lastMessage = last;
7056 + /* update counters */
7057 + else if (!last || (!nntp_data->newsrc_ent && !nntp_data->lastCached))
7058 + nntp_data->unread = count;
7060 + nntp_group_unread_stat (nntp_data);
7064 +/* Check current newsgroup for new articles, leave newsrc locked:
7065 + * MUTT_REOPENED - articles have been renumbered or removed from server
7066 + * MUTT_NEW_MAIL - new articles found
7068 + * -1 - lost connection */
7069 +static int check_mailbox (CONTEXT *ctx)
7071 + NNTP_DATA *nntp_data = ctx->data;
7072 + NNTP_SERVER *nserv = nntp_data->nserv;
7073 + time_t now = time (NULL);
7078 + if (nserv->check_time + NewsPollTimeout > now)
7081 + mutt_message _("Checking for new messages...");
7082 + if (nntp_newsrc_parse (nserv) < 0)
7085 + nserv->check_time = now;
7086 + rc = nntp_group_poll (nntp_data, 0);
7089 + nntp_newsrc_close (nserv);
7093 + nntp_active_save_cache (nserv);
7095 + /* articles have been renumbered, remove all headers */
7096 + if (nntp_data->lastMessage < nntp_data->lastLoaded)
7098 + for (i = 0; i < ctx->msgcount; i++)
7099 + mutt_free_header (&ctx->hdrs[i]);
7100 + ctx->msgcount = 0;
7103 + if (nntp_data->lastMessage < nntp_data->lastLoaded)
7105 + nntp_data->lastLoaded = nntp_data->firstMessage - 1;
7106 + if (NntpContext && nntp_data->lastMessage - nntp_data->lastLoaded >
7108 + nntp_data->lastLoaded = nntp_data->lastMessage - NntpContext;
7110 + ret = MUTT_REOPENED;
7113 + /* .newsrc has been externally modified */
7114 + if (nserv->newsrc_modified)
7118 + unsigned char *messages;
7122 + anum_t first = nntp_data->firstMessage;
7124 + if (NntpContext && nntp_data->lastMessage - first + 1 > NntpContext)
7125 + first = nntp_data->lastMessage - NntpContext + 1;
7126 + messages = safe_calloc (nntp_data->lastLoaded - first + 1,
7127 + sizeof (unsigned char));
7128 + hc = nntp_hcache_open (nntp_data);
7129 + nntp_hcache_update (nntp_data, hc);
7132 + /* update flags according to .newsrc */
7133 + for (i = j = 0; i < ctx->msgcount; i++)
7136 + anum = NHDR (ctx->hdrs[i])->article_num;
7139 + /* check hcache for flagged and deleted flags */
7142 + if (anum >= first && anum <= nntp_data->lastLoaded)
7143 + messages[anum - first] = 1;
7145 + snprintf (buf, sizeof (buf), "%d", anum);
7146 + hdata = mutt_hcache_fetch (hc, buf, strlen);
7151 + dprint (2, (debugfile,
7152 + "nntp_check_mailbox: mutt_hcache_fetch %s\n", buf));
7153 + hdr = mutt_hcache_restore (hdata, NULL);
7154 + mutt_hcache_free (&hdata);
7156 + deleted = hdr->deleted;
7157 + flagged = hdr->flagged;
7158 + mutt_free_header (&hdr);
7160 + /* header marked as deleted, removing from context */
7163 + mutt_set_flag (ctx, ctx->hdrs[i], MUTT_TAG, 0);
7164 + mutt_free_header (&ctx->hdrs[i]);
7171 + if (!ctx->hdrs[i]->changed)
7173 + ctx->hdrs[i]->flagged = flagged;
7174 + ctx->hdrs[i]->read = 0;
7175 + ctx->hdrs[i]->old = 0;
7176 + nntp_article_status (ctx, ctx->hdrs[i], NULL, anum);
7177 + if (!ctx->hdrs[i]->read)
7178 + nntp_parse_xref (ctx, ctx->hdrs[i]);
7180 + ctx->hdrs[j++] = ctx->hdrs[i];
7184 + ctx->msgcount = j;
7186 + /* restore headers without "deleted" flag */
7187 + for (anum = first; anum <= nntp_data->lastLoaded; anum++)
7189 + if (messages[anum - first])
7192 + snprintf (buf, sizeof (buf), "%d", anum);
7193 + hdata = mutt_hcache_fetch (hc, buf, strlen);
7196 + dprint (2, (debugfile,
7197 + "nntp_check_mailbox: mutt_hcache_fetch %s\n", buf));
7198 + if (ctx->msgcount >= ctx->hdrmax)
7199 + mx_alloc_memory (ctx);
7201 + ctx->hdrs[ctx->msgcount] =
7202 + hdr = mutt_hcache_restore (hdata, NULL);
7203 + mutt_hcache_free (&hdata);
7207 + mutt_free_header (&hdr);
7208 + if (nntp_data->bcache)
7210 + dprint (2, (debugfile,
7211 + "nntp_check_mailbox: mutt_bcache_del %s\n", buf));
7212 + mutt_bcache_del (nntp_data->bcache, buf);
7220 + hdr->data = safe_calloc (1, sizeof (NNTP_HEADER_DATA));
7221 + NHDR (hdr)->article_num = anum;
7222 + nntp_article_status (ctx, hdr, NULL, anum);
7224 + nntp_parse_xref (ctx, hdr);
7230 + nserv->newsrc_modified = 0;
7231 + ret = MUTT_REOPENED;
7234 + /* some headers were removed, context must be updated */
7235 + if (ret == MUTT_REOPENED)
7237 + if (ctx->subj_hash)
7238 + hash_destroy (&ctx->subj_hash, NULL);
7240 + hash_destroy (&ctx->id_hash, NULL);
7241 + mutt_clear_threads (ctx);
7249 + ctx->id_hash = NULL;
7250 + ctx->subj_hash = NULL;
7251 + mx_update_context (ctx, ctx->msgcount);
7254 + /* fetch headers of new articles */
7255 + if (nntp_data->lastMessage > nntp_data->lastLoaded)
7257 + int oldmsgcount = ctx->msgcount;
7258 + int quiet = ctx->quiet;
7263 + hc = nntp_hcache_open (nntp_data);
7264 + nntp_hcache_update (nntp_data, hc);
7267 + rc = nntp_fetch_headers (ctx, hc, nntp_data->lastLoaded + 1,
7268 + nntp_data->lastMessage, 0);
7269 + ctx->quiet = quiet;
7271 + nntp_data->lastLoaded = nntp_data->lastMessage;
7272 + if (ret == 0 && ctx->msgcount > oldmsgcount)
7273 + ret = MUTT_NEW_MAIL;
7277 + mutt_hcache_close (hc);
7280 + nntp_newsrc_close (nserv);
7281 + mutt_clear_error ();
7285 +/* Check current newsgroup for new articles:
7286 + * MUTT_REOPENED - articles have been renumbered or removed from server
7287 + * MUTT_NEW_MAIL - new articles found
7289 + * -1 - lost connection */
7290 +static int nntp_check_mailbox (CONTEXT *ctx, int *index_hint)
7292 + int ret = check_mailbox (ctx);
7295 + NNTP_DATA *nntp_data = ctx->data;
7296 + NNTP_SERVER *nserv = nntp_data->nserv;
7297 + nntp_newsrc_close (nserv);
7302 +/* Save changes to .newsrc and cache */
7303 +static int nntp_sync_mailbox (CONTEXT *ctx, int *index_hint)
7305 + NNTP_DATA *nntp_data = ctx->data;
7308 + header_cache_t *hc;
7311 + /* check for new articles */
7312 + nntp_data->nserv->check_time = 0;
7313 + rc = check_mailbox (ctx);
7318 + nntp_data->lastCached = 0;
7319 + hc = nntp_hcache_open (nntp_data);
7322 + for (i = 0; i < ctx->msgcount; i++)
7324 + HEADER *hdr = ctx->hdrs[i];
7327 + snprintf (buf, sizeof (buf), "%d", NHDR (hdr)->article_num);
7328 + if (nntp_data->bcache && hdr->deleted)
7330 + dprint (2, (debugfile, "nntp_sync_mailbox: mutt_bcache_del %s\n", buf));
7331 + mutt_bcache_del (nntp_data->bcache, buf);
7335 + if (hc && (hdr->changed || hdr->deleted))
7337 + dprint (2, (debugfile, "nntp_sync_mailbox: mutt_hcache_store %s\n", buf));
7338 + mutt_hcache_store (hc, buf, hdr, 0, strlen, MUTT_GENERATE_UIDVALIDITY);
7346 + mutt_hcache_close (hc);
7347 + nntp_data->lastCached = nntp_data->lastLoaded;
7351 + /* save .newsrc entries */
7352 + nntp_newsrc_gen_entries (ctx);
7353 + nntp_newsrc_update (nntp_data->nserv);
7354 + nntp_newsrc_close (nntp_data->nserv);
7358 +/* Check for new groups and new articles in subscribed groups:
7359 + * 1 - new groups found
7360 + * 0 - no new groups
7362 +int nntp_check_new_groups (NNTP_SERVER *nserv)
7364 + NNTP_DATA nntp_data;
7367 + char buf[LONG_STRING];
7368 + char *msg = _("Checking for new newsgroups...");
7370 + int rc, update_active = FALSE;
7372 + if (!nserv || !nserv->newgroups_time)
7375 + /* check subscribed newsgroups for new articles */
7376 + if (option (OPTSHOWNEWNEWS))
7378 + mutt_message _("Checking for new messages...");
7379 + for (i = 0; i < nserv->groups_num; i++)
7381 + NNTP_DATA *nntp_data = nserv->groups_list[i];
7383 + if (nntp_data && nntp_data->subscribed)
7385 + rc = nntp_group_poll (nntp_data, 1);
7389 + update_active = TRUE;
7392 + /* select current newsgroup */
7393 + if (Context && Context->magic == MUTT_NNTP)
7396 + if (nntp_query ((NNTP_DATA *)Context->data, buf, sizeof (buf)) < 0)
7400 + else if (nserv->newgroups_time)
7403 + /* get list of new groups */
7404 + mutt_message (msg);
7405 + if (nntp_date (nserv, &now) < 0)
7407 + nntp_data.nserv = nserv;
7408 + if (Context && Context->magic == MUTT_NNTP)
7409 + nntp_data.group = ((NNTP_DATA *)Context->data)->group;
7411 + nntp_data.group = NULL;
7412 + i = nserv->groups_num;
7413 + tm = gmtime (&nserv->newgroups_time);
7414 + snprintf (buf, sizeof (buf), "NEWGROUPS %02d%02d%02d %02d%02d%02d GMT\r\n",
7415 + tm->tm_year % 100, tm->tm_mon + 1, tm->tm_mday,
7416 + tm->tm_hour, tm->tm_min, tm->tm_sec);
7417 + rc = nntp_fetch_lines (&nntp_data, buf, sizeof (buf), msg,
7418 + nntp_add_group, nserv);
7423 + mutt_error ("NEWGROUPS: %s", buf);
7429 + /* new groups found */
7431 + if (nserv->groups_num != i)
7433 + int groups_num = i;
7435 + nserv->newgroups_time = now;
7436 + for (; i < nserv->groups_num; i++)
7438 + NNTP_DATA *nntp_data = nserv->groups_list[i];
7439 + nntp_data->new = 1;
7442 + /* loading descriptions */
7443 + if (option (OPTLOADDESC))
7445 + unsigned int count = 0;
7446 + progress_t progress;
7448 + mutt_progress_init (&progress, _("Loading descriptions..."),
7449 + MUTT_PROGRESS_MSG, ReadInc, nserv->groups_num - i);
7450 + for (i = groups_num; i < nserv->groups_num; i++)
7452 + NNTP_DATA *nntp_data = nserv->groups_list[i];
7454 + if (get_description (nntp_data, NULL, NULL) < 0)
7456 + mutt_progress_update (&progress, ++count, -1);
7459 + update_active = TRUE;
7462 + if (update_active)
7463 + nntp_active_save_cache (nserv);
7464 + mutt_clear_error ();
7468 +/* Fetch article by Message-ID:
7470 + * 1 - no such article
7472 +int nntp_check_msgid (CONTEXT *ctx, const char *msgid)
7474 + NNTP_DATA *nntp_data = ctx->data;
7477 + char tempfile[_POSIX_PATH_MAX];
7478 + char buf[LONG_STRING];
7481 + mutt_mktemp (tempfile, sizeof (tempfile));
7482 + fp = safe_fopen (tempfile, "w+");
7485 + mutt_perror (tempfile);
7486 + unlink (tempfile);
7490 + snprintf (buf, sizeof (buf), "HEAD %s\r\n", msgid);
7491 + rc = nntp_fetch_lines (nntp_data, buf, sizeof (buf), NULL,
7492 + fetch_tempfile, fp);
7496 + unlink (tempfile);
7499 + if (!mutt_strncmp ("430", buf, 3))
7501 + mutt_error ("HEAD: %s", buf);
7505 + /* parse header */
7506 + if (ctx->msgcount == ctx->hdrmax)
7507 + mx_alloc_memory (ctx);
7508 + hdr = ctx->hdrs[ctx->msgcount] = mutt_new_header ();
7509 + hdr->data = safe_calloc (1, sizeof (NNTP_HEADER_DATA));
7510 + hdr->env = mutt_read_rfc822_header (fp, hdr, 0, 0);
7512 + unlink (tempfile);
7514 + /* get article number */
7515 + if (hdr->env->xref)
7516 + nntp_parse_xref (ctx, hdr);
7519 + snprintf (buf, sizeof (buf), "STAT %s\r\n", msgid);
7520 + if (nntp_query (nntp_data, buf, sizeof (buf)) < 0)
7522 + mutt_free_header (&hdr);
7525 + sscanf (buf + 4, ANUM, &NHDR (hdr)->article_num);
7533 + hdr->received = hdr->date_sent;
7534 + hdr->index = ctx->msgcount++;
7535 + mx_update_context (ctx, 1);
7547 +/* Parse XPAT line */
7548 +static int fetch_children (char *line, void *data)
7550 + CHILD_CTX *cc = data;
7554 + if (!line || sscanf (line, ANUM, &anum) != 1)
7556 + for (i = 0; i < cc->ctx->msgcount; i++)
7557 + if (NHDR (cc->ctx->hdrs[i])->article_num == anum)
7559 + if (cc->num >= cc->max)
7562 + safe_realloc (&cc->child, sizeof (anum_t) * cc->max);
7564 + cc->child[cc->num++] = anum;
7568 +/* Fetch children of article with the Message-ID */
7569 +int nntp_check_children (CONTEXT *ctx, const char *msgid)
7571 + NNTP_DATA *nntp_data = ctx->data;
7577 + if (!nntp_data || !nntp_data->nserv)
7579 + if (nntp_data->firstMessage > nntp_data->lastLoaded)
7582 + /* init context */
7586 + cc.child = safe_malloc (sizeof (anum_t) * cc.max);
7588 + /* fetch numbers of child messages */
7589 + snprintf (buf, sizeof (buf), "XPAT References %d-%d *%s*\r\n",
7590 + nntp_data->firstMessage, nntp_data->lastLoaded, msgid);
7591 + rc = nntp_fetch_lines (nntp_data, buf, sizeof (buf), NULL,
7592 + fetch_children, &cc);
7597 + if (mutt_strncmp ("500", buf, 3))
7598 + mutt_error ("XPAT: %s", buf);
7600 + mutt_error _("Unable to find child articles because server does not support XPAT command.");
7605 + /* fetch all found messages */
7606 + quiet = ctx->quiet;
7609 + hc = nntp_hcache_open (nntp_data);
7611 + for (i = 0; i < cc.num; i++)
7613 + rc = nntp_fetch_headers (ctx, hc, cc.child[i], cc.child[i], 1);
7618 + mutt_hcache_close (hc);
7620 + ctx->quiet = quiet;
7622 + return rc < 0 ? -1 : 0;
7625 +struct mx_ops mx_nntp_ops = {
7626 + .open = nntp_open_mailbox,
7627 + .open_append = NULL,
7628 + .close = nntp_close_mailbox,
7629 + .open_msg = nntp_open_message,
7630 + .close_msg = nntp_close_message,
7631 + .check = nntp_check_mailbox,
7632 + .commit_msg = NULL,
7633 + .open_new_msg = NULL,
7634 + .sync = nntp_sync_mailbox,
7636 diff -udprP mutt-1.12.1.orig/nntp.h mutt-1.12.1/nntp.h
7637 --- mutt-1.12.1.orig/nntp.h 1970-01-01 03:00:00.000000000 +0300
7638 +++ mutt-1.12.1/nntp.h 2019-08-11 20:31:26.142940552 +0300
7641 + * Copyright (C) 1998 Brandon Long <blong@fiction.net>
7642 + * Copyright (C) 1999 Andrej Gritsenko <andrej@lucky.net>
7643 + * Copyright (C) 2000-2019 Vsevolod Volkov <vvv@mutt.org.ua>
7645 + * This program is free software; you can redistribute it and/or modify
7646 + * it under the terms of the GNU General Public License as published by
7647 + * the Free Software Foundation; either version 2 of the License, or
7648 + * (at your option) any later version.
7650 + * This program is distributed in the hope that it will be useful,
7651 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7652 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7653 + * GNU General Public License for more details.
7655 + * You should have received a copy of the GNU General Public License
7656 + * along with this program; if not, write to the Free Software
7657 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7663 +#include "mutt_socket.h"
7664 +#include "mailbox.h"
7665 +#include "bcache.h"
7668 +#include "hcache.h"
7672 +#include <sys/types.h>
7673 +#include <stdint.h>
7675 +#define NNTP_PORT 119
7676 +#define NNTP_SSL_PORT 563
7678 +/* number of entries in article cache */
7679 +#define NNTP_ACACHE_LEN 10
7681 +/* article number type and format */
7682 +#define anum_t uint32_t
7694 + unsigned int hasCAPABILITIES : 1;
7695 + unsigned int hasSTARTTLS : 1;
7696 + unsigned int hasDATE : 1;
7697 + unsigned int hasLIST_NEWSGROUPS : 1;
7698 + unsigned int hasXGTITLE : 1;
7699 + unsigned int hasLISTGROUP : 1;
7700 + unsigned int hasLISTGROUPrange : 1;
7701 + unsigned int hasOVER : 1;
7702 + unsigned int hasXOVER : 1;
7703 + unsigned int use_tls : 3;
7704 + unsigned int status : 3;
7705 + unsigned int cacheable : 1;
7706 + unsigned int newsrc_modified : 1;
7708 + char *newsrc_file;
7709 + char *authenticators;
7710 + char *overview_fmt;
7713 + time_t newgroups_time;
7714 + time_t check_time;
7715 + unsigned int groups_num;
7716 + unsigned int groups_max;
7717 + void **groups_list;
7718 + HASH *groups_hash;
7730 + unsigned int index;
7738 + anum_t firstMessage;
7739 + anum_t lastMessage;
7740 + anum_t lastLoaded;
7741 + anum_t lastCached;
7743 + unsigned int subscribed : 1;
7744 + unsigned int new : 1;
7745 + unsigned int allowed : 1;
7746 + unsigned int deleted : 1;
7747 + unsigned int newsrc_len;
7748 + NEWSRC_ENTRY *newsrc_ent;
7749 + NNTP_SERVER *nserv;
7750 + NNTP_ACACHE acache[NNTP_ACACHE_LEN];
7751 + body_cache_t *bcache;
7756 + anum_t article_num;
7757 + unsigned int parsed : 1;
7758 +} NNTP_HEADER_DATA;
7760 +#define NHDR(hdr) ((NNTP_HEADER_DATA*)((hdr)->data))
7762 +/* internal functions */
7763 +int nntp_add_group (char *, void *);
7764 +int nntp_active_save_cache (NNTP_SERVER *);
7765 +int nntp_check_new_groups (NNTP_SERVER *);
7766 +int nntp_open_connection (NNTP_SERVER *);
7767 +void nntp_newsrc_gen_entries (CONTEXT *);
7768 +void nntp_bcache_update (NNTP_DATA *);
7769 +void nntp_article_status (CONTEXT *, HEADER *, char *, anum_t);
7770 +void nntp_group_unread_stat (NNTP_DATA *);
7771 +void nntp_data_free (void *);
7772 +void nntp_acache_free (NNTP_DATA *);
7773 +void nntp_delete_group_cache (NNTP_DATA *);
7775 +/* exposed interface */
7776 +NNTP_SERVER *nntp_select_server (char *, int);
7777 +NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER *, char *);
7778 +NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER *, char *);
7779 +NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER *, char *);
7780 +NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER *, char *);
7781 +int nntp_active_fetch (NNTP_SERVER *, unsigned int);
7782 +int nntp_newsrc_update (NNTP_SERVER *);
7783 +int nntp_post (const char *);
7784 +int nntp_check_msgid (CONTEXT *, const char *);
7785 +int nntp_check_children (CONTEXT *, const char *);
7786 +int nntp_newsrc_parse (NNTP_SERVER *);
7787 +void nntp_newsrc_close (NNTP_SERVER *);
7788 +void nntp_buffer_buffy (BUFFER *);
7789 +void nntp_buffer_expand_path (BUFFER *, ACCOUNT *);
7790 +void nntp_clear_cache (NNTP_SERVER *);
7791 +const char *nntp_format_str (char *, size_t, size_t, int, char, const char *,
7792 + const char *, const char *, const char *,
7793 + unsigned long, format_flag);
7795 +NNTP_SERVER *CurrentNewsSrv INITVAL (NULL);
7798 +header_cache_t *nntp_hcache_open (NNTP_DATA *);
7799 +void nntp_hcache_update (NNTP_DATA *, header_cache_t *);
7802 +extern struct mx_ops mx_nntp_ops;
7804 +#endif /* _NNTP_H_ */
7805 diff -udprP mutt-1.12.1.orig/pager.c mutt-1.12.1/pager.c
7806 --- mutt-1.12.1.orig/pager.c 2019-06-15 18:57:01.000000000 +0300
7807 +++ mutt-1.12.1/pager.c 2019-08-11 20:31:26.143940536 +0300
7808 @@ -1118,6 +1118,11 @@ fill_buffer (FILE *f, LOFF_T *last_pos,
7818 static int format_line (struct line_t **lineInfo, int n, unsigned char *buf,
7819 int flags, ansi_attr *pa, int cnt,
7820 @@ -1583,6 +1588,15 @@ static const struct mapping_t PagerHelpE
7821 { N_("Next"), OP_MAIN_NEXT_UNDELETED },
7825 +static struct mapping_t PagerNewsHelpExtra[] = {
7826 + { N_("Post"), OP_POST },
7827 + { N_("Followup"), OP_FOLLOWUP },
7828 + { N_("Del"), OP_DELETE },
7829 + { N_("Next"), OP_MAIN_NEXT_UNDELETED },
7834 void mutt_clear_pager_position (void)
7836 @@ -1921,6 +1935,10 @@ mutt_pager (const char *banner, const ch
7838 pager_redraw_data_t rd;
7841 + char *followup_to;
7844 if (!(flags & MUTT_SHOWCOLOR))
7845 flags |= MUTT_SHOWFLAT;
7847 @@ -1970,7 +1988,11 @@ mutt_pager (const char *banner, const ch
7848 mutt_buffer_strcpy (helpstr, buffer);
7849 if (IsHeader (extra))
7851 - mutt_compile_help (buffer, sizeof (buffer), MENU_PAGER, PagerHelpExtra);
7852 + mutt_compile_help (buffer, sizeof (buffer), MENU_PAGER,
7854 + (Context && (Context->magic == MUTT_NNTP)) ? PagerNewsHelpExtra :
7857 mutt_buffer_addch (helpstr, ' ');
7858 mutt_buffer_addstr (helpstr, buffer);
7860 @@ -2653,6 +2675,60 @@ search_next:
7861 pager_menu->redraw = REDRAW_FULL;
7866 + CHECK_MODE(IsHeader (extra) && !IsAttach (extra));
7868 + if (extra->ctx && extra->ctx->magic == MUTT_NNTP &&
7869 + !((NNTP_DATA *)extra->ctx->data)->allowed &&
7870 + query_quadoption (OPT_TOMODERATED,_("Posting to this group not allowed, may be moderated. Continue?")) != MUTT_YES)
7872 + ci_send_message (SENDNEWS, NULL, NULL, extra->ctx, NULL);
7873 + pager_menu->redraw = REDRAW_FULL;
7876 + case OP_FORWARD_TO_GROUP:
7877 + CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
7879 + if (extra->ctx && extra->ctx->magic == MUTT_NNTP &&
7880 + !((NNTP_DATA *)extra->ctx->data)->allowed &&
7881 + query_quadoption (OPT_TOMODERATED,_("Posting to this group not allowed, may be moderated. Continue?")) != MUTT_YES)
7883 + if (IsMsgAttach (extra))
7884 + mutt_attach_forward (extra->fp, extra->hdr, extra->actx,
7885 + extra->bdy, SENDNEWS);
7887 + ci_send_message (SENDNEWS|SENDFORWARD, NULL, NULL, extra->ctx, extra->hdr);
7888 + pager_menu->redraw = REDRAW_FULL;
7892 + CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
7895 + if (IsMsgAttach (extra))
7896 + followup_to = extra->bdy->hdr->env->followup_to;
7898 + followup_to = extra->hdr->env->followup_to;
7900 + if (!followup_to || mutt_strcasecmp (followup_to, "poster") ||
7901 + query_quadoption (OPT_FOLLOWUPTOPOSTER,_("Reply by mail as poster prefers?")) != MUTT_YES)
7903 + if (extra->ctx && extra->ctx->magic == MUTT_NNTP &&
7904 + !((NNTP_DATA *)extra->ctx->data)->allowed &&
7905 + query_quadoption (OPT_TOMODERATED,_("Posting to this group not allowed, may be moderated. Continue?")) != MUTT_YES)
7907 + if (IsMsgAttach (extra))
7908 + mutt_attach_reply (extra->fp, extra->hdr, extra->actx,
7909 + extra->bdy, SENDNEWS|SENDREPLY);
7911 + ci_send_message (SENDNEWS|SENDREPLY, NULL, NULL,
7912 + extra->ctx, extra->hdr);
7913 + pager_menu->redraw = REDRAW_FULL;
7919 case OP_GROUP_REPLY:
7920 case OP_GROUP_CHAT_REPLY:
7921 @@ -2689,7 +2765,7 @@ search_next:
7923 if (IsMsgAttach (extra))
7924 mutt_attach_forward (extra->fp, extra->hdr, extra->actx,
7928 ci_send_message (SENDFORWARD, NULL, NULL, extra->ctx, extra->hdr);
7929 pager_menu->redraw = REDRAW_FULL;
7930 diff -udprP mutt-1.12.1.orig/parse.c mutt-1.12.1/parse.c
7931 --- mutt-1.12.1.orig/parse.c 2019-05-25 19:22:39.000000000 +0300
7932 +++ mutt-1.12.1/parse.c 2019-08-11 20:31:26.143940536 +0300
7933 @@ -94,7 +94,7 @@ char *mutt_read_rfc822_line (FILE *f, ch
7937 -static LIST *mutt_parse_references (char *s, int in_reply_to)
7938 +LIST *mutt_parse_references (char *s, int in_reply_to)
7940 LIST *t, *lst = NULL;
7942 @@ -1122,6 +1122,17 @@ int mutt_parse_rfc822_line (ENVELOPE *e,
7943 e->from = rfc822_parse_adrlist (e->from, p);
7947 + else if (!mutt_strcasecmp (line+1, "ollowup-to"))
7949 + if (!e->followup_to)
7951 + mutt_remove_trailing_ws (p);
7952 + e->followup_to = safe_strdup (mutt_skip_whitespace (p));
7960 @@ -1206,6 +1217,27 @@ int mutt_parse_rfc822_line (ENVELOPE *e,
7966 + if (!mutt_strcasecmp (line + 1, "ewsgroups"))
7968 + FREE (&e->newsgroups);
7969 + mutt_remove_trailing_ws (p);
7970 + e->newsgroups = safe_strdup (mutt_skip_whitespace (p));
7977 + /* field `Organization:' saves only for pager! */
7978 + if (!mutt_strcasecmp (line + 1, "rganization"))
7980 + if (!e->organization && mutt_strcasecmp (p, "unknown"))
7981 + e->organization = safe_strdup (p);
7986 if (!ascii_strcasecmp (line + 1, "eferences"))
7988 @@ -1318,6 +1350,20 @@ int mutt_parse_rfc822_line (ENVELOPE *e,
7989 e->x_label = safe_strdup(p);
7993 + else if (!mutt_strcasecmp (line + 1, "-comment-to"))
7995 + if (!e->x_comment_to)
7996 + e->x_comment_to = safe_strdup (p);
7999 + else if (!mutt_strcasecmp (line + 1, "ref"))
8002 + e->xref = safe_strdup (p);
8009 diff -udprP mutt-1.12.1.orig/pattern.c mutt-1.12.1/pattern.c
8010 --- mutt-1.12.1.orig/pattern.c 2019-05-25 19:22:39.000000000 +0300
8011 +++ mutt-1.12.1/pattern.c 2019-08-11 20:31:26.143940536 +0300
8012 @@ -94,6 +94,9 @@ Flags[] =
8013 { 'U', MUTT_UNREAD, 0, NULL },
8014 { 'v', MUTT_COLLAPSED, 0, NULL },
8015 { 'V', MUTT_CRYPT_VERIFIED, 0, NULL },
8017 + { 'w', MUTT_NEWSGROUPS, 0, eat_regexp },
8019 { 'x', MUTT_REFERENCE, 0, eat_regexp },
8020 { 'X', MUTT_MIMEATTACH, 0, eat_range },
8021 { 'y', MUTT_XLABEL, 0, eat_regexp },
8022 @@ -1412,6 +1415,10 @@ mutt_pattern_exec (struct pattern_t *pat
8023 return (pat->not ^ match_mime_content_type (pat, ctx, h));
8024 case MUTT_UNREFERENCED:
8025 return (pat->not ^ (h->thread && !h->thread->child));
8027 + case MUTT_NEWSGROUPS:
8028 + return (pat->not ^ (h->env->newsgroups && patmatch (pat, h->env->newsgroups) == 0));
8031 mutt_error (_("error: unknown op %d (report this error)."), pat->op);
8033 @@ -1497,6 +1504,7 @@ int mutt_pattern_func (int op, char *pro
8034 buf = mutt_buffer_pool_get ();
8036 mutt_buffer_strcpy (buf, NONULL (Context->pattern));
8037 + if (prompt || op != MUTT_LIMIT)
8038 if (mutt_get_field (prompt, buf->data, buf->dsize, MUTT_PATTERN | MUTT_CLEAR) != 0 ||
8039 !(mutt_b2s (buf)[0]))
8041 diff -udprP mutt-1.12.1.orig/po/POTFILES.in mutt-1.12.1/po/POTFILES.in
8042 --- mutt-1.12.1.orig/po/POTFILES.in 2017-12-18 22:31:37.000000000 +0200
8043 +++ mutt-1.12.1/po/POTFILES.in 2019-08-11 20:31:26.143940536 +0300
8044 @@ -47,6 +47,8 @@ mutt_ssl_gnutls.c
8053 diff -udprP mutt-1.12.1.orig/postpone.c mutt-1.12.1/postpone.c
8054 --- mutt-1.12.1.orig/postpone.c 2019-05-25 19:22:39.000000000 +0300
8055 +++ mutt-1.12.1/postpone.c 2019-08-11 20:31:26.143940536 +0300
8056 @@ -125,15 +125,26 @@ int mutt_num_postponed (int force)
8058 if (LastModify < st.st_mtime)
8061 + int optnews = option (OPTNEWS);
8063 LastModify = st.st_mtime;
8065 if (access (Postponed, R_OK | F_OK) != 0)
8066 return (PostCount = 0);
8069 + unset_option (OPTNEWS);
8071 if (mx_open_mailbox (Postponed, MUTT_NOSORT | MUTT_QUIET, &ctx) == NULL)
8074 PostCount = ctx.msgcount;
8075 mx_fastclose_mailbox (&ctx);
8078 + set_option (OPTNEWS);
8083 diff -udprP mutt-1.12.1.orig/protos.h mutt-1.12.1/protos.h
8084 --- mutt-1.12.1.orig/protos.h 2019-05-25 19:22:39.000000000 +0300
8085 +++ mutt-1.12.1/protos.h 2019-08-11 20:31:26.144940521 +0300
8086 @@ -103,6 +103,7 @@ HASH *mutt_make_id_hash (CONTEXT *);
8087 HASH *mutt_make_subj_hash (CONTEXT *);
8089 LIST *mutt_make_references(ENVELOPE *e);
8090 +LIST *mutt_parse_references (char *, int);
8092 char *mutt_read_rfc822_line (FILE *, char *, size_t *);
8093 ENVELOPE *mutt_read_rfc822_header (FILE *, HEADER *, short, short);
8094 diff -udprP mutt-1.12.1.orig/recvattach.c mutt-1.12.1/recvattach.c
8095 --- mutt-1.12.1.orig/recvattach.c 2019-05-25 19:22:39.000000000 +0300
8096 +++ mutt-1.12.1/recvattach.c 2019-08-11 20:31:26.144940521 +0300
8097 @@ -1226,6 +1226,15 @@ void mutt_view_attachments (HEADER *hdr)
8102 + if (Context->magic == MUTT_NNTP)
8105 + mutt_error _("Can't delete attachment from news server.");
8110 if (WithCrypto && (hdr->security & ENCRYPT))
8113 @@ -1320,7 +1329,7 @@ void mutt_view_attachments (HEADER *hdr)
8114 case OP_FORWARD_MESSAGE:
8116 mutt_attach_forward (CURATTACH->fp, hdr, actx,
8117 - menu->tagprefix ? NULL : CURATTACH->content);
8118 + menu->tagprefix ? NULL : CURATTACH->content, 0);
8119 menu->redraw = REDRAW_FULL;
8122 @@ -1331,6 +1340,28 @@ void mutt_view_attachments (HEADER *hdr)
8123 menu->redraw = REDRAW_FULL;
8127 + case OP_FORWARD_TO_GROUP:
8129 + mutt_attach_forward (CURATTACH->fp, hdr, actx,
8130 + menu->tagprefix ? NULL : CURATTACH->content, SENDNEWS);
8131 + menu->redraw = REDRAW_FULL;
8137 + if (!hdr->env->followup_to ||
8138 + mutt_strcasecmp (hdr->env->followup_to, "poster") ||
8139 + query_quadoption (OPT_FOLLOWUPTOPOSTER, _("Reply by mail as poster prefers?")) != MUTT_YES)
8141 + mutt_attach_reply (CURATTACH->fp, hdr, actx,
8142 + menu->tagprefix ? NULL : CURATTACH->content, SENDNEWS|SENDREPLY);
8143 + menu->redraw = REDRAW_FULL;
8149 case OP_GROUP_REPLY:
8150 case OP_GROUP_CHAT_REPLY:
8151 diff -udprP mutt-1.12.1.orig/recvcmd.c mutt-1.12.1/recvcmd.c
8152 --- mutt-1.12.1.orig/recvcmd.c 2019-05-25 19:22:39.000000000 +0300
8153 +++ mutt-1.12.1/recvcmd.c 2019-08-11 20:31:26.144940521 +0300
8154 @@ -398,7 +398,7 @@ static BODY ** copy_problematic_attachme
8155 static void attach_forward_bodies (FILE * fp, HEADER * hdr,
8156 ATTACH_CONTEXT *actx,
8159 + short nattach, int flags)
8162 short mime_fwd_all = 0;
8163 @@ -554,7 +554,7 @@ static void attach_forward_bodies (FILE
8166 /* now that we have the template, send it. */
8167 - ci_send_message (0, tmphdr, tmpbody, NULL, parent_hdr);
8168 + ci_send_message (flags, tmphdr, tmpbody, NULL, parent_hdr);
8172 @@ -581,7 +581,7 @@ bail:
8175 static void attach_forward_msgs (FILE * fp, HEADER * hdr,
8176 - ATTACH_CONTEXT *actx, BODY * cur)
8177 + ATTACH_CONTEXT *actx, BODY * cur, int flags)
8179 HEADER *curhdr = NULL;
8181 @@ -686,23 +686,23 @@ static void attach_forward_msgs (FILE *
8183 mutt_free_header (&tmphdr);
8185 - ci_send_message (0, tmphdr, *tmpbody ? tmpbody : NULL,
8186 + ci_send_message (flags, tmphdr, *tmpbody ? tmpbody : NULL,
8191 void mutt_attach_forward (FILE * fp, HEADER * hdr,
8192 - ATTACH_CONTEXT *actx, BODY * cur)
8193 + ATTACH_CONTEXT *actx, BODY * cur, int flags)
8198 if (check_all_msg (actx, cur, 0) == 0)
8199 - attach_forward_msgs (fp, hdr, actx, cur);
8200 + attach_forward_msgs (fp, hdr, actx, cur, flags);
8203 nattach = count_tagged (actx);
8204 - attach_forward_bodies (fp, hdr, actx, cur, nattach);
8205 + attach_forward_bodies (fp, hdr, actx, cur, nattach, flags);
8209 @@ -795,6 +795,17 @@ attach_reply_envelope_defaults (ENVELOPE
8214 + if ((flags & SENDNEWS))
8216 + /* in case followup set Newsgroups: with Followup-To: if it present */
8217 + if (!env->newsgroups && curenv &&
8218 + mutt_strcasecmp (curenv->followup_to, "poster"))
8219 + env->newsgroups = safe_strdup (curenv->followup_to);
8226 if (mutt_fetch_recips (env, curenv, flags) == -1)
8227 @@ -817,6 +828,7 @@ attach_reply_envelope_defaults (ENVELOPE
8230 mutt_fix_reply_recipients (env);
8232 mutt_make_misc_reply_headers (env, Context, curhdr, curenv);
8235 @@ -879,6 +891,13 @@ void mutt_attach_reply (FILE * fp, HEADE
8236 char prefix[SHORT_STRING];
8240 + if (flags & SENDNEWS)
8241 + set_option (OPTNEWSSEND);
8243 + unset_option (OPTNEWSSEND);
8246 if (check_all_msg (actx, cur, 0) == -1)
8248 nattach = count_tagged (actx);
8249 diff -udprP mutt-1.12.1.orig/rfc2047.c mutt-1.12.1/rfc2047.c
8250 --- mutt-1.12.1.orig/rfc2047.c 2019-05-25 19:22:39.000000000 +0300
8251 +++ mutt-1.12.1/rfc2047.c 2019-08-11 20:31:26.144940521 +0300
8252 @@ -633,6 +633,9 @@ void rfc2047_encode_envelope (ENVELOPE *
8253 rfc2047_encode_adrlist (e->mail_followup_to, "Mail-Followup-To");
8254 rfc2047_encode_adrlist (e->sender, "Sender");
8255 rfc2047_encode_string (&e->x_label);
8257 + if (!option (OPTNEWSSEND) || option (OPTMIMESUBJECT))
8259 rfc2047_encode_string (&e->subject);
8262 diff -udprP mutt-1.12.1.orig/send.c mutt-1.12.1/send.c
8263 --- mutt-1.12.1.orig/send.c 2019-06-14 18:57:33.000000000 +0300
8264 +++ mutt-1.12.1/send.c 2019-08-11 20:31:26.144940521 +0300
8266 #include <sys/types.h>
8275 #include "remailer.h"
8277 @@ -217,17 +222,51 @@ static int edit_address (ADDRESS **a, /*
8281 -static int edit_envelope (ENVELOPE *en)
8282 +static int edit_envelope (ENVELOPE *en, int flags)
8284 char buf[HUGE_STRING];
8285 LIST *uh = UserHeader;
8288 + if (option (OPTNEWSSEND))
8290 + if (en->newsgroups)
8291 + strfcpy (buf, en->newsgroups, sizeof (buf));
8294 + if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) != 0)
8296 + FREE (&en->newsgroups);
8297 + en->newsgroups = safe_strdup (buf);
8299 + if (en->followup_to)
8300 + strfcpy (buf, en->followup_to, sizeof (buf));
8303 + if (option (OPTASKFOLLOWUP) && mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) != 0)
8305 + FREE (&en->followup_to);
8306 + en->followup_to = safe_strdup (buf);
8308 + if (en->x_comment_to)
8309 + strfcpy (buf, en->x_comment_to, sizeof (buf));
8312 + if (option (OPTXCOMMENTTO) && option (OPTASKXCOMMENTTO) && mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) != 0)
8314 + FREE (&en->x_comment_to);
8315 + en->x_comment_to = safe_strdup (buf);
8320 if (edit_address (&en->to, _("To: ")) == -1 || en->to == NULL)
8322 if (option (OPTASKCC) && edit_address (&en->cc, _("Cc: ")) == -1)
8324 if (option (OPTASKBCC) && edit_address (&en->bcc, _("Bcc: ")) == -1)
8330 @@ -262,6 +301,14 @@ static int edit_envelope (ENVELOPE *en)
8335 +char *nntp_get_header (const char *s)
8338 + return safe_strdup (s);
8342 static void process_user_recips (ENVELOPE *env)
8344 LIST *uh = UserHeader;
8345 @@ -274,6 +321,14 @@ static void process_user_recips (ENVELOP
8346 env->cc = rfc822_parse_adrlist (env->cc, uh->data + 3);
8347 else if (ascii_strncasecmp ("bcc:", uh->data, 4) == 0)
8348 env->bcc = rfc822_parse_adrlist (env->bcc, uh->data + 4);
8350 + else if (ascii_strncasecmp ("newsgroups:", uh->data, 11) == 0)
8351 + env->newsgroups = nntp_get_header (uh->data + 11);
8352 + else if (ascii_strncasecmp ("followup-to:", uh->data, 12) == 0)
8353 + env->followup_to = nntp_get_header (uh->data + 12);
8354 + else if (ascii_strncasecmp ("x-comment-to:", uh->data, 13) == 0)
8355 + env->x_comment_to = nntp_get_header (uh->data + 13);
8360 @@ -313,6 +368,12 @@ static void process_user_header (ENVELOP
8361 else if (ascii_strncasecmp ("to:", uh->data, 3) != 0 &&
8362 ascii_strncasecmp ("cc:", uh->data, 3) != 0 &&
8363 ascii_strncasecmp ("bcc:", uh->data, 4) != 0 &&
8365 + ascii_strncasecmp ("newsgroups:", uh->data, 11) != 0 &&
8366 + ascii_strncasecmp ("followup-to:", uh->data, 12) != 0 &&
8367 + ascii_strncasecmp ("x-comment-to:", uh->data, 13) != 0 &&
8369 + ascii_strncasecmp ("supersedes:", uh->data, 11) != 0 &&
8370 ascii_strncasecmp ("subject:", uh->data, 8) != 0 &&
8371 ascii_strncasecmp ("return-path:", uh->data, 12) != 0)
8373 @@ -775,6 +836,10 @@ void mutt_add_to_reference_headers (ENVE
8378 + if (option (OPTNEWSSEND) && option (OPTXCOMMENTTO) && curenv->from)
8379 + env->x_comment_to = safe_strdup (mutt_get_name (curenv->from));
8384 @@ -837,6 +902,16 @@ envelope_defaults (ENVELOPE *env, CONTEX
8386 if (flags & (SENDREPLY|SENDTOSENDER))
8389 + if ((flags & SENDNEWS))
8391 + /* in case followup set Newsgroups: with Followup-To: if it present */
8392 + if (!env->newsgroups && curenv &&
8393 + mutt_strcasecmp (curenv->followup_to, "poster"))
8394 + env->newsgroups = safe_strdup (curenv->followup_to);
8401 @@ -982,7 +1057,18 @@ void mutt_set_followup_to (ENVELOPE *e)
8402 * it hasn't already been set
8405 - if (option (OPTFOLLOWUPTO) && !e->mail_followup_to)
8406 + if (!option (OPTFOLLOWUPTO))
8409 + if (option (OPTNEWSSEND))
8411 + if (!e->followup_to && e->newsgroups && (strrchr (e->newsgroups, ',')))
8412 + e->followup_to = safe_strdup (e->newsgroups);
8417 + if (!e->mail_followup_to)
8419 if (mutt_is_list_cc (0, e->to, e->cc))
8421 @@ -1148,6 +1234,9 @@ static int send_message (HEADER *msg)
8426 + if (!option (OPTNEWSSEND))
8429 return mutt_smtp_send (msg->env->from, msg->env->to, msg->env->cc,
8430 msg->env->bcc, tempfile,
8431 @@ -1563,6 +1652,13 @@ ci_send_message (int flags, /* send mod
8436 + if (flags & SENDNEWS)
8437 + set_option (OPTNEWSSEND);
8439 + unset_option (OPTNEWSSEND);
8442 if (!flags && !msg && quadoption (OPT_RECALL) != MUTT_NO &&
8443 mutt_num_postponed (1))
8445 @@ -1702,12 +1798,33 @@ ci_send_message (int flags, /* send mod
8446 if (flags & SENDREPLY)
8447 mutt_fix_reply_recipients (msg->env);
8450 + if ((flags & SENDNEWS) && ctx && ctx->magic == MUTT_NNTP && !msg->env->newsgroups)
8451 + msg->env->newsgroups = safe_strdup (((NNTP_DATA *)ctx->data)->group);
8454 if (! (flags & (SENDMAILX|SENDBATCH)) &&
8455 ! (option (OPTAUTOEDIT) && option (OPTEDITHDRS)) &&
8456 ! ((flags & SENDREPLY) && option (OPTFASTREPLY)))
8458 - if (edit_envelope (msg->env) == -1)
8459 + if (edit_envelope (msg->env, flags) == -1)
8463 + * If postponed message is a news article, it have
8464 + * a "Newsgroups:" header line, then set appropriate flag.
8466 + if (msg->env->newsgroups)
8468 + flags |= SENDNEWS;
8469 + set_option (OPTNEWSSEND);
8473 + flags &= ~SENDNEWS;
8474 + unset_option (OPTNEWSSEND);
8479 /* the from address must be set here regardless of whether or not
8480 @@ -2016,6 +2133,11 @@ main_loop:
8485 + if (flags & SENDNEWS)
8486 + mutt_message _("Article not posted.");
8489 mutt_message _("Mail not sent.");
8492 @@ -2029,6 +2151,9 @@ main_loop:
8497 + if (!(flags & SENDNEWS))
8499 if (!has_recips (msg->env->to) && !has_recips (msg->env->cc) &&
8500 !has_recips (msg->env->bcc))
8502 @@ -2062,6 +2187,19 @@ main_loop:
8503 mutt_error _("No subject specified.");
8507 + if ((flags & SENDNEWS) && !msg->env->subject)
8509 + mutt_error _("No subject specified.");
8513 + if ((flags & SENDNEWS) && !msg->env->newsgroups)
8515 + mutt_error _("No newsgroup specified.");
8520 /* Scan for a mention of an attachment in the message body and
8521 * prompt if there is none. */
8522 @@ -2184,7 +2322,12 @@ main_loop:
8524 if (!option (OPTNOCURSES) && ! (flags & SENDMAILX))
8526 - mutt_message (i == 0 ? _("Mail sent.") : _("Sending in background."));
8527 + mutt_message (i != 0 ? _("Sending in background.") :
8529 + (flags & SENDNEWS) ? _("Article posted.") : _("Mail sent."));
8536 diff -udprP mutt-1.12.1.orig/sendlib.c mutt-1.12.1/sendlib.c
8537 --- mutt-1.12.1.orig/sendlib.c 2019-06-14 18:57:30.000000000 +0300
8538 +++ mutt-1.12.1/sendlib.c 2019-08-11 20:31:26.145940506 +0300
8540 #include <sys/wait.h>
8547 #ifdef HAVE_SYSEXITS_H
8548 #include <sysexits.h>
8549 #else /* Make sure EX_OK is defined <philiph@pobox.com> */
8550 @@ -1590,6 +1594,14 @@ void mutt_write_references (LIST *r, FIL
8553 int refcnt = 0, refmax = 0;
8554 + int multiline = 1;
8563 for ( ; (trim == 0 || refcnt < trim) && r ; r = r->next)
8565 @@ -1600,9 +1612,11 @@ void mutt_write_references (LIST *r, FIL
8567 while (refcnt-- > 0)
8570 + if (multiline || space)
8573 fputs (ref[refcnt]->data, f);
8575 + if (multiline && refcnt >= 1)
8579 @@ -2018,6 +2032,9 @@ int mutt_write_rfc822_header (FILE *fp,
8580 mutt_write_address_list (env->to, fp, 4, 0);
8582 else if (mode == MUTT_WRITE_HEADER_EDITHDRS)
8584 + if (!option (OPTNEWSSEND))
8586 fputs ("To: \n", fp);
8589 @@ -2026,6 +2043,9 @@ int mutt_write_rfc822_header (FILE *fp,
8590 mutt_write_address_list (env->cc, fp, 4, 0);
8592 else if (mode == MUTT_WRITE_HEADER_EDITHDRS)
8594 + if (!option (OPTNEWSSEND))
8596 fputs ("Cc: \n", fp);
8599 @@ -2039,8 +2059,28 @@ int mutt_write_rfc822_header (FILE *fp,
8602 else if (mode == MUTT_WRITE_HEADER_EDITHDRS)
8604 + if (!option (OPTNEWSSEND))
8606 fputs ("Bcc: \n", fp);
8609 + if (env->newsgroups)
8610 + fprintf (fp, "Newsgroups: %s\n", env->newsgroups);
8611 + else if (mode == 1 && option (OPTNEWSSEND))
8612 + fputs ("Newsgroups: \n", fp);
8614 + if (env->followup_to)
8615 + fprintf (fp, "Followup-To: %s\n", env->followup_to);
8616 + else if (mode == 1 && option (OPTNEWSSEND))
8617 + fputs ("Followup-To: \n", fp);
8619 + if (env->x_comment_to)
8620 + fprintf (fp, "X-Comment-To: %s\n", env->x_comment_to);
8621 + else if (mode == 1 && option (OPTNEWSSEND) && option (OPTXCOMMENTTO))
8622 + fputs ("X-Comment-To: \n", fp);
8627 if (hide_protected_subject &&
8628 @@ -2066,6 +2106,9 @@ int mutt_write_rfc822_header (FILE *fp,
8629 fputs ("Reply-To: \n", fp);
8631 if (env->mail_followup_to)
8633 + if (!option (OPTNEWSSEND))
8636 fputs ("Mail-Followup-To: ", fp);
8637 mutt_write_address_list (env->mail_followup_to, fp, 18, 0);
8638 @@ -2415,6 +2458,24 @@ mutt_invoke_sendmail (ADDRESS *from, /*
8639 size_t extra_argslen = 0, extra_argsmax = 0;
8643 + if (option (OPTNEWSSEND))
8645 + char cmd[LONG_STRING];
8647 + mutt_FormatString (cmd, sizeof (cmd), 0, MuttIndexWindow->cols,
8648 + NONULL (Inews), nntp_format_str, 0, 0);
8651 + i = nntp_post (msg);
8656 + s = safe_strdup (cmd);
8660 /* ensure that $sendmail is set to avoid a crash. http://dev.mutt.org/trac/ticket/3548 */
8663 @@ -2464,6 +2525,10 @@ mutt_invoke_sendmail (ADDRESS *from, /*
8668 + if (!option (OPTNEWSSEND))
8671 if (eightbit && option (OPTUSE8BITMIME))
8672 args = add_option (args, &argslen, &argsmax, "-B8BITMIME");
8674 @@ -2497,6 +2562,9 @@ mutt_invoke_sendmail (ADDRESS *from, /*
8675 args = add_args (args, &argslen, &argsmax, to);
8676 args = add_args (args, &argslen, &argsmax, cc);
8677 args = add_args (args, &argslen, &argsmax, bcc);
8682 if (argslen == argsmax)
8683 safe_realloc (&args, sizeof (char *) * (++argsmax));
8684 @@ -2689,6 +2757,10 @@ int mutt_bounce_message (FILE *fp, HEADE
8686 rfc822_write_address (resent_from, sizeof (resent_from), from, 0);
8689 + unset_option (OPTNEWSSEND);
8693 * prepare recipient list. idna conversion appears to happen before this
8694 * function is called, since the user receives confirmation of the address
8695 diff -udprP mutt-1.12.1.orig/sort.c mutt-1.12.1/sort.c
8696 --- mutt-1.12.1.orig/sort.c 2019-05-25 19:22:39.000000000 +0300
8697 +++ mutt-1.12.1/sort.c 2019-08-11 20:31:26.145940506 +0300
8700 #include "mutt_idna.h"
8710 @@ -155,6 +160,17 @@ static int compare_order (const void *a,
8711 HEADER **ha = (HEADER **) a;
8712 HEADER **hb = (HEADER **) b;
8715 + if (Context && Context->magic == MUTT_NNTP)
8717 + anum_t na = NHDR (*ha)->article_num;
8718 + anum_t nb = NHDR (*hb)->article_num;
8719 + int result = na == nb ? 0 : na > nb ? 1 : -1;
8720 + AUXSORT (result, a, b);
8721 + return (SORTCODE (result));
8725 /* no need to auxsort because you will never have equality here */
8726 return (SORTCODE ((*ha)->index - (*hb)->index));
8728 diff -udprP mutt-1.12.1.orig/url.c mutt-1.12.1/url.c
8729 --- mutt-1.12.1.orig/url.c 2019-05-25 19:22:39.000000000 +0300
8730 +++ mutt-1.12.1/url.c 2019-08-11 20:31:26.145940506 +0300
8731 @@ -40,6 +40,8 @@ static const struct mapping_t UrlMap[] =
8732 { "imaps", U_IMAPS },
8735 + { "news", U_NNTP },
8736 + { "snews", U_NNTPS },
8737 { "mailto", U_MAILTO },
8739 { "smtps", U_SMTPS },
8740 @@ -243,7 +245,7 @@ int url_ciss_tobuffer (ciss_url_t* ciss,
8741 if (!(flags & U_PATH))
8742 mutt_buffer_addstr (dest, "//");
8745 + if (ciss->user && (ciss->user[0] || !(flags & U_PATH)))
8748 url_pct_encode (u, sizeof (u), ciss->user);
8749 diff -udprP mutt-1.12.1.orig/url.h mutt-1.12.1/url.h
8750 --- mutt-1.12.1.orig/url.h 2019-05-25 19:22:39.000000000 +0300
8751 +++ mutt-1.12.1/url.h 2019-08-11 20:31:26.145940506 +0300
8752 @@ -8,6 +8,8 @@ typedef enum url_scheme