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