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