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